akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{
    gearup;
    ll n,x;cin >> n >> x;
    vl a(n);
    rep(i,n)cin>>a[i];
    auto b = a;
    ll res = L_INF;
    //iが魔法を唱える回数
    rep(i,n){
        ll now = 0;
        rep(j,n){
            ll idx = j - i;
            if(idx < 0)idx+=n;
            b[j] = min(b[j],a[idx]);
            now += b[j];
        }
        now += x * i;
        res = min(res,now);
    }
    out(res);
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#include <chrono>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
	srand(time(NULL));
	int nowtime=0;
	int TIMEMAX=1980;
	int N;
	ll L[100001],R[100001];
	vpll LR,RL;
	vll Ls,Rs;
	scan(N);
	rep(i,N){
		scan(L[i]>>R[i]);
		LR.push_back({L[i],R[i]});
		RL.push_back({R[i],L[i]});
		Ls.push_back(L[i]);
		Rs.push_back(R[i]);
	}
	sort(ALL(LR));
	sort(ALL(RL));
	sort(ALL(Ls));
	sort(ALL(Rs));
	ll Rml[100002],Rmr[100002],Lxl[100002],Lxr[100002];
	fill(Rml,Rml+N+1,INFl);
	fill(Rmr,Rmr+N+1,INFl);
	fill(Lxl,Lxl+N+1,0LL);
	fill(Lxr,Lxr+N+1,0LL);
	Rml[0]=LR[0].second;
	Lxl[0]=LR[0].first;
	rep1(i,N-1){
		Rml[i]=min(Rml[i-1],LR[i].second);
		Lxl[i]=max(Lxl[i-1],LR[i].first);
	}
	Rmr[N-1]=LR[N-1].second;
	Lxr[N-1]=LR[N-1].first;
	brep(i,N-1){
		Rmr[i]=min(Rmr[i+1],LR[i].second);
		Lxr[i]=max(Lxr[i+1],LR[i].first);
	}
	ll ans=0;
	rep(i,N-1){
		ll g1=max(0LL,Rml[i]-LR[i].first+1);
		ll g2=max(0LL,Rmr[i+1]-LR[N-1].first+1);
		ans=max(ans,g1+g2);
	}

	ll Lxl2[100002],Lxr2[100002];
	fill(Lxl2,Lxl2+N+1,0LL);
	fill(Lxr2,Lxr2+N+1,0LL);
	Lxl2[0]=RL[0].second;
	rep1(i,N-1){
		Lxl2[i]=max(Lxl2[i-1],RL[i].second);
	}
	Lxr2[N-1]=RL[N-1].second;
	brep(i,N-1){
		Lxr2[i]=max(Lxr2[i+1],RL[i].second);
	}
	rep(i,N-1){
		ll g1=max(0LL,RL[0].first-Lxl2[i]+1);
		ll g2=max(0LL,RL[i+1].first-Lxr2[i+1]+1);
		ans=max(ans,g1+g2);
	}
	
	rep(i,N){
		ll lmax,rmin;
		if(i==0) lmax=Lxr[1];
		else if(i==N-1) lmax=Lxl[i-1];
		else lmax=max(Lxl[i-1],Lxr[i+1]);
		if(i==0) rmin=Rmr[1];
		else if(i==N-1) rmin=Rml[i-1];
		else rmin=min(Rml[i-1],Rmr[i+1]);
		ans=max(ans,max(0LL,rmin-lmax+1)+LR[i].second-LR[i].first+1);
	}
/*while(nowtime<TIMEMAX){

		nowtime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start).count();
	}*/
	prin(ans);
	return 0;
}


Measured memory_bytes: 12620
#include<stdio.h>
int d[100000];
int abs(int a){return a>=0?a:-a;}
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	int i;
	d[0]=0;
	for(i=1;i<n;i++){
		scanf("%d",&d[i]);
		d[i]+=d[i-1];
	}
	int p=0;
	int ans=0;
	for(i=0;i<m;i++){
		int x;
		scanf("%d",&x);
		ans=(ans+abs(d[p+x]-d[p]))%100000;
		p+=x;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    int n;
    std::cin >> n;
    long long a[n];
    for(int i=0;i<n;i++){
        std::cin >> a[i];
        a[i] -= i+1;
    }
    std::sort(a, a+n);
    long long b = a[n/2], ans = 0LL;
    for(int i=0;i<n;i++){
        ans += abs(a[i] - b);
    }
    std::cout << ans << "\n";
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pi 3.1415926535
#define endl '\n'
using namespace std;
struct custom {
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll inf=1e19;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=(y>>1);
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c,d,x,y,r,k;
    cin>>a>>b>>c>>d>>k;
    x=a*60+b;
    y=c*60+d;
    x=abs(x-y);
    cout<<max(0LL,x-k)<<endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll H, A;
  cin >> H >> A;
  if (H % A == 0) {
    COUT(H / A);
    return 0;
  }
  COUT(H / A + 1);
  return 0;
}

Measured memory_bytes: 256
///******* In the name of Allah *******///

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

//long int ar[90013],br[100013];
//long int gcd(long int a, long int b)
//{
//    if(b==0)
//        return a;
//    return gcd(b,a%b);
//}
//long int sieve(long long int a)
//{
//    //long long int i,j,k = 0;
//    memset(ar,0,sizeof(ar));
//    ar[1] = 1;
//    for(i=2; i<=90013; i++)
//    {
//        if(ar[i]==0)
//        {
//            k++;
//            br[k] = i;
//            for(j=i+i; j<=90013; j+=i)
//            {
//                ar[j] = 1;
//            }
//        }
//    }
//    return br[a];
//}

void Ok()
{
    long int a,b,c,d,h,t,i,j,k,l,m,n;
    long int ans_1,ans_2,ans_3,cnt = 0,Max,Min,flag = 1,temp,sum = 0;
    double aa,bb,cc,dd,ee,ff,gg;
    //char aaa[10013],bbb[10013],ccc[113],ddd;
    string spc,in;

    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>a;
        sum += a;
    }
    if(sum>n)
        cout<<"-1"<<endl;
    else
    {
        ans_1 = n - sum;
        cout<<ans_1<<endl;
    }

    return;
}

int main()
{
    Ok();

    return 0;
}


Measured memory_bytes: 3624
a5 = int(input())
b1 = int(input())
c5 = int(input())
x = int(input())
count = 0
for i in range(a5+1):
    for j in range(b1+1):
        for k in range(c5+1):
            if x == 500*i + 100*j + 50*k:
                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;
using ll = long long;
using P = pair<int,int>;
int main(){
    int n;
    cin >> n;
    ll ans;
    vector<int> xx(n);
    vector<int> yy(n);
    rep(i,n){
        int x,y;
        cin >> x >> y;
        xx[i] = x+y;
        yy[i] = x-y;
    }
    sort(xx.begin(),xx.end());
    sort(yy.begin(),yy.end());
    ans = max(xx[n-1]-xx[0],yy[n-1]-yy[0]);
    cout << ans << endl;

}

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

int main()
{
    long A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int a_num=-1;
    int b_num=-1;
    int c_num=-1;
    long minval = LONG_MAX;
    for (int i=0; i<=2*max(X, Y); i+=2)
    {
        const long zero = 0;
        c_num = i;
        a_num = max(zero, X-i/2);
        b_num = max(zero, Y-i/2);
        minval = min(minval, A*a_num+B*b_num+C*c_num);
    }
    cout << minval << endl;
    //cout << a_num << " " << b_num << " " << c_num << endl;
    
}

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

int main() {
  int n, a, b, sum, tmp, total;
  std::cin >> n >> a >> b;
  total = 0;
  for (int i = 1; i < n+1; i++) {
    sum = 0;
    tmp = i;
    for (int j = 0; j < 5; j++) {
      sum += tmp % 10;
      tmp /= 10;
    }
    if (sum >= a && sum <= b) {
      total += i;
    }
  }
  std::cout << total << std::endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long w = sc.nextLong();
		if (h==1 || w==1) {
			System.out.println(1);
		} else {
			System.out.println((h*w+1)/2);
		}
	}


}


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> r(2*M);
  for(int i=0; i<2*M; i++){
    cin >> r.at(i);
  }
  for(int j=1; j<=N; j++){
    int a=0;
    for(int i=0; i<2*M; i++){
      if(r.at(i)==j){
        a++;
      }
    }
    cout << a << endl;
  }
}


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

using namespace std;

const int N = 100005;

char s[N];
int n;
int lef[N];
int p[N];

void solve(){

    lef[1] = n-1;
    priority_queue<pair<int, int>> q;
    q.emplace(n-1, 1);

    int ne = 2;
    int sz, u;
    for(int i = n / 2; i >= 1; i--) if(s[i] == '1'){
        tie(sz, u) = q.top();
        q.pop();
        if(sz < i){
            printf("-1\n");
            exit(0);
        }
        lef[u] -= i;
        lef[ne] = i-1;
        if(lef[u]) q.emplace(lef[u], u);
        if(lef[ne]) q.emplace(lef[ne], ne);
        p[ne] = u;
        ne++;
    }

    u = 1;
    for(; ne <= n; ne++){
        while(!lef[u]) u++;
        p[ne] = u;
        lef[u]--;
    }
}

int main(){

    scanf("%s", s+1);
    n = (int)strlen(s+1);
    if(s[n] == '1' || s[1] == '0') return printf("-1\n"), 0;

    for(int i = 1; i < n / 2; i++)
        if(s[i] != s[n - i])
            return printf("-1\n"), 0;

    solve();

    for(int i = 2; i <= n; i++)
        printf("%d %d\n", p[i], i);
}


Measured memory_bytes: 2160
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,a,b,d1[N],d2[N],cnt,i;
vector<vector<int>>g;
void dfs(int r,int p,int d,int dist[]){
  dist[r]=d;
  for(auto e:g[r])if(e!=p)dfs(e,r,d+1,dist);
}
int main(){
  cin>>n;
  g.resize(n);
  for(i=0;i<n-1;i++){
    cin>>a>>b;a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0,-1,0,d1);
  dfs(n-1,-1,0,d2);
  for(i=0;i<n;i++){
    if(d1[i]<=d2[i])cnt++;
    else cnt--;
  }
  if(cnt>0)cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
}


Measured memory_bytes: 12928
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()



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

	if (A % 2 == 0) {
		if (B % 2 == 0) cout << (B ^ ((B - A + 1) / 2) % 2) << endl;
		else cout << ((B - A + 1) / 2) % 2 << endl;
	}
	else {
		if (B % 2 == 0) cout << ((A ^ B) ^ ((B - A) / 2) % 2) << endl;
		else cout << (A ^ ((B - A) / 2) % 2) << endl;
	}
}

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

int main() {
  long long int n,m,ans=0;
  cin>>n>>m;
  vector<long long int> h;
  vector<long long int> list[n+1];
  //cout<<n<<m<<endl;

  h.emplace_back(0);
  rep(i,0,n){
    long long int tmp;
    cin>>tmp;
    h.emplace_back(tmp);
  }

  rep(i,0,m){
    long long int tmp1=0,tmp2=0;
    cin>>tmp1>>tmp2;
    list[tmp1].emplace_back(tmp2);
    list[tmp2].emplace_back(tmp1);
    //cout<<tmp1<<tmp2<<endl;
  }

  rep(i,1,n+1){
    long long int l;
    bool empty=0;
    l=list[i].size();
    rep(j,0,l){
      //cout<<h[i]<<" "<<h[list[i][j]];
      if(h[i]<=h[list[i][j]]){empty=1;}
    }
    if(empty==0){ans++;}
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 9748
import sys
from collections import deque
n, q = map(int, input().split())

deq = deque()
arrays = {str(i): deque() for i in range(n)}

lines = sys.stdin.readlines()
for i in range(q):
    query, *arg = lines[i].split()
    if query == '0':    # pushback t x
        arrays[arg[0]].append(arg[1])
    elif query == '1':  # dump t
        print(" ".join(arrays[arg[0]]))
    elif query == '2':  # clear t
        arrays[arg[0]].clear()
    else:
        raise AssertionError


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

using namespace std;
int check(string s)
{
    int len=s.size();
    for(int i=0;i<len/2;i++)
    {
        if(s[i]!=s[len-1-i])
            return 0;
    }
    string a=s.substr(0,(len-1)/2);
    int len1 = a.size();
    for(int i=0;i<len1/2;i++)
    {
        if(a[i]!=a[len1-1-i])
            return 0;
    }
    string b=s.substr((len+3)/2-1,(len-3)/2+1);
    int len2 = b.size();
    for(int i=0;i<len2;i++)
    {
        if(b[i]!=b[len2-1-i])
            return 0;
    }
    return 1;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string str;
    cin>>str;
    int ans=check(str);
    if(ans)
        cout<<"Yes"<<"\n";
    else
        cout<<"No"<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int main(){
  long long N,M;
  cin >> N >> M;

  long long S[N] = {}; //A[i]の累積和

  cin >> S[0];
  S[0] %= M;
  for(int i=1;i<N;i++){
    long long tmp;
    cin >> tmp;
    S[i] = S[i-1] + tmp;
    S[i] %= M;
  }


  sort(S, S+N);// M が大きいのでソートで対処？
/*
  for(int i=0;i<N;i++){
    cout << S[i] << " ";;
  }
*/
//  cout << endl;

  long long result = 0;

  long long tmp = S[0];
  long long start = 0;
  for(int i=0;i<N+1;i++){
    if(i == N || tmp != S[i]){
      long long tmpN = i - start;
      if(tmp == 0){
        result += tmpN;
      }
      result += (tmpN-1) * tmpN / 2;
      start = i;
      if(i < N){
        tmp = S[i];
      }
    }
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <array>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

int main (void) {

  int N; std::cin >> N;

  std::array<int,25> Prime = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
  std::unordered_map<int,int> k;  for(auto& p : Prime) k[p] = 0;
  for(auto& p : Prime ) {
    for(int i=2; i<=N; i++) {
      int tmp = i, cnt = 0;;
      while(tmp % p == 0) {
        cnt++;
        tmp = tmp/p;
      }
      k[p] += cnt;
    }
  }

  long long ans = 0;
  for(int i=0; i<25; i++) {
    int p = Prime[i];
    for(int j=i+1; j<25; j++) {
      int q = Prime[j];
      for(int l=j+1; l<25; l++) {
        int r = Prime[l];
        if ( k[p] >= 2 && k[q] >= 4 && k[r] >= 4 ) ans++;
        if ( k[p] >= 4 && k[q] >= 2 && k[r] >= 4 ) ans++;
        if ( k[p] >= 4 && k[q] >= 4 && k[r] >= 2 ) ans++;
      }
      if ( k[p] >= 2  && k[q] >= 24 ) ans++;
      if ( k[p] >= 24 && k[q] >= 2  ) ans++;
      if ( k[p] >= 4  && k[q] >= 14 ) ans++;
      if ( k[p] >= 14 && k[q] >= 4  ) ans++;
    }
    if ( k[p] >= 74 ) ans++;
  }

  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100
#define INF 10000000

int min(int,int);

int main()
{
  int i,j=0,k,n,r,c,p[N+1],m[N+1][N+1],l,d;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d%d",&p[i],&p[i+1]);
  }

  for(i=1;i<=n;i++) m[i][i] = 0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i;k<j;k++){
	m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i - 1] * p[k] * p[j]);
	  }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}
  
int min(int x,int y)
{
  if(x > y) return y;
  else return x;
}

 
 

    



Measured memory_bytes: 2056
#include "bits/stdc++.h"

#pragma GCC optimize(2)

using namespace std;
#define fi first
#define se second

#define pb push_back
#define es erase
#define ins insert

#define pii pair<ll, ll>
#define ll long long
#define lb long double
#define ull unsigned long long

#define ioss                     \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define m_p(i, j) make_pair(i, j)
#define mem(a, x) memset(a, x, sizeof(a))
#define fcout(i) cout << setprecision(i) << fixed
#define endl "\n"
#define mul(a, b, p) (1ll * (a) * (b) % p)

const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;

ll n;
ll a, b, c, d;
int main()
{
    while (scanf("%lld", &n) == 1)
    {
        scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
        for (ll i = 0; i <= n - 1; i++)
        {
            if ((b - a) >= (i * c - (n - i - 1) * d) && (b - a) <= (i * d - (n - i - 1) * c))
            {
                printf("YES");
                return 0;
            }
        }
    }
    printf("NO");
    return 0;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
#define deg(x) ((x)*180/M_PI)
int main () {
    int a,b,x;
    scanf ("%d %d %d",&a,&b,&x);
    if (x*2 > a*a*b) printf ("%.7f\n",deg(atan(double(2*a*a*b-2*x)/(a*a*a))));
    else printf ("%.7f\n",90.0-deg(atan(2*x/double(a*b*b))));
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int n, k;
  cin >> n >> k;
  std::vector<ull> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n-k) {
    if (a[i] < a[i+k]) {
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
  }
}


Measured memory_bytes: 4740
#include <bits/stdc++.h>
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
typedef long long ll;
using namespace std;
const ll INF = 1<<30;
 
ll n;
 
int main(){
    cin >> n;
    vector<ll> a(n, 0);
    rep(i, n)cin >> a[i];
    
    ll sum = 0;
    
    rep2(i, 1, n){
        if(a[i]<a[i-1]){
            sum += a[i-1] - a[i];
            a[i] += a[i-1] - a[i];
        }
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 4820
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans=0,a[200004];
map <ll,ll> mp;
ll num[40];
int main(){
	num[0]=2;
	cin>>n;
	for (ll i=1;i<40;i++)
		num[i]=num[i-1]*2;
	for (ll i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	sort (a,a+n);
	for (ll i=n-1;i>=0;i--){
		ll l=lower_bound(num,num+40,a[i])-num;
		if (num[l]==a[i]) l++;
		ll ano=num[l]-a[i];
		mp[ano]--,mp[a[i]]--;
		if (mp[ano]>=0 && mp[a[i]]>=0) ans++;
		else mp[ano]++,mp[a[i]]++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 26752
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

pair<ll,ll> simplify(const vector<pair<ll,ll>> &xs) {
    int n = xs.size();
    if(n==0) return make_pair(0,0);
    vector<ll> a(n), b(n);
    ll total = 0;
    rep(i,0,n) {
        ll x,y;
        tie(x,y) = xs[i];
        a[i] = x;
        b[i] = y;
        total += b[i];
    }
    int ii = 0;
    rep(i,1,n) if(a[i]>a[ii]) ii = i;
    ll other = 0;
    rep(i,0,n) if(i!=ii) other += b[i];
    ll best=0;
    if(a[ii]>other) best = a[ii]-other;
    else {
        best = total%2;
    }
    return make_pair(best,total);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<vector<int>> g(n);
    rep(i,0,n-1) {
        int a,b;
        cin >>a>>b;
        --a;
        --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ll ans = LLONG_MAX;
    bool found = false;
    rep(i,0,n)  {
        vector<bool> vis(n);
        vis[i] = true;
        function<tuple<ll,ll,int>(int)> dfs = [&](int v) {
            vis[v] = true;
            int tot_nodes = 0;
            if(s[v]=='1') ++tot_nodes;
            vector<pair<ll,ll>> xs;
            for(int w:g[v]) if(!vis[w]) {
                    ll lower,upper;
                    int count;
                    tie(lower,upper,count) = dfs(w);
                    tot_nodes+=count;
                    lower+=count;
                    upper+=count;
                    xs.emplace_back(lower,upper);
                }
            ll low, hi;
            tie(low,hi) = simplify(xs);
            return make_tuple(low,hi,tot_nodes);
        };
        ll best,total;
        tie(best,total,ignore) = dfs(i);
        debug(i);
        debug(best);
        debug(total);
        if(best==0) {
            found = true;
            ans = min(ans,total/2);
        }
    }
    if(!found) ans = -1;
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define f first
#define s second

using namespace std;

typedef pair<int,int> P;
typedef pair<double,P> P3;

int main(void){

  vector<P3>v;
  for(int h=1;h<200;h++){
    for(int w=1;w<200;w++){
      if(w>h)v.push_back(P3(sqrt(h*h+w*w),P(h,w)));
    }
  }
  
  sort(v.begin(),v.end());
  
  int h,w;
  while(cin >> h >> w,h|w){
    for(int i=0;i<v.size();i++){
      if(v[i].s.f==h && v[i].s.s==w){
	cout << v[i+1].s.f << " " << v[i+1].s.s << endl;
	break;
      }
    }
  }
  return 0;
}

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

using namespace std;

#define INF 1e9

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

    while(1){
        int h;
        cin>>h;

        if(h==0)break;

        int c[15][5]={};

        for(int i=0;i<h;i++){
            for(int j=0;j<5;j++){
                cin>>c[i][j];
            }
        }
        
        int ans=0;

        while(1){
            bool f=true;

            for(int i=0;i<h;i++){
                int t=1;
                for(int j=0;j<4;j++){
                    if(c[i][j]==c[i][j+1] && c[i][j]!=0)t++;
                    else{
                        if(t<3)t=1;
                        else{
                            ans+=c[i][j-1]*t;
                            for(int k=0;k<t;k++)c[i][j-k]=0;
                            f=false;
                            t=1;
                        }
                    }
                }
                if(t>2){
                    ans+=c[i][4]*t;
                    for(int j=0;j<t;j++){
                        c[i][4-j]=0;
                    }
                    f=false;
                }
            }

            for(int i=h-2;i>=0;i--){
                for(int j=0;j<5;j++){
                    for(int k=1;i+k<h;k++){
                        if(c[i+k][j]==0){
                            c[i+k][j]=c[i+k-1][j];
                            c[i+k-1][j]=0;
                        }
                    }
                }
            }

            if(f){
                cout<<ans<<endl;

                break;
            }

        }

    }
}


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

int main() {
  int a,b,c,sum=0;
  cin >> a >> b;
  c = b-a;
  //cは柱の高さの差であり、bの柱は西からc番目にある
  for(int i=0;i<c;i++){
   sum = sum+i;
  }
//sumは(i-1)番目の柱の高さ
  cout << sum-a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll x,y;
  cin >> x >> y;
  ll ans=max(0ll,100000*(4-x));
  ans+=max(0ll,100000*(4-y));
  cout << (ans==600000?ans+400000:ans) << endl;
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p_a = 0;
        int p_b = 0;
        for(int i=0; i<n; i++){
            String str_a = sc.next();
            String str_b = sc.next();
            if(str_a.compareTo(str_b) > 0) {p_a += 3;}
            else if(str_a.equals(str_b)) {
                p_a++;
                p_b++;
            }
            else {p_b += 3;}
        }
        System.out.println(p_a + " " + p_b);
    }
}


Measured memory_bytes: 29536
/**
 * Created by abhishek on 8/12/2016.
 */
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args)throws Exception {
     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        StringBuilder sb = new StringBuilder();
        for(int i = 0;i < str.length();i++){
            if(str.charAt(i) != 'B')
                sb.append(str.charAt(i));
            else if(sb.length() > 0)
                sb.deleteCharAt(sb.length() - 1);
        }
        System.out.print(sb.toString());

    }
}


Measured memory_bytes: 8020
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a, b, c, x;
    cin >> a >> b >> c >> x;
    ll y;
    cin >> y;
    ll ans = INF;
    
    rep(i, max(x, y)+1){
        ll tmp = 0;
        tmp += a*max(x-i, 0ll);
        tmp += b*max(y-i, 0ll);
        tmp += 2*c*i;
        //dump(tmp);
        chmin(ans, tmp);
    }
    
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n,A=0;
  cin>>n;
  vector<int> a(n);
  for (int i=0;i<n;i++){
    cin>>a.at(i);
  }
  for (int i=1;i<n-1;i++){
    if(a[i-1]<a[i]&&a[i]<a[i+1]){
      A++;
    }
    else if(a[i-1]>a[i]&&a[i]>a[i+1]){
      A++;
    }
  }
  cout<<A<<endl;
}

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

int main() {
    int N,M;cin >> N >> M;
    int ans;
    if (N < 2 && M > 1) ans = M * (M - 1) / 2;
    else if (N > 1 && M < 2) ans = N * (N - 1) / 2;
    else if (N < 2 && M < 2) ans = 0;
    else ans = (M * (M - 1) / 2) + N * (N - 1) / 2;
    cout << ans << endl;
}

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

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

int main() {
	fastio;
	
    int n;
    cin >> n;
    vector<pii> seq(n);
    forn(i,n){
        cin >> seq[i].fst;
        seq[i].snd=i;
    }
    sort(all(seq));
    

    int res =0;
    forn(i,n){
        res+=(i%2!=seq[i].snd%2);
    }
    cout << res/2 << endl;
	
	return 0;
}



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

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

Bint Max(vector<Bint> x){
  int a=x.size();
  for(int i=0;i<a-1;i++){
    x.at(i+1)=min(x.at(i),x.at(i+1));
  }
  return x.at(a-1);
}

int main() {
  Bint H,W;
  cin>>H>>W;
  Bint a,C=H*W;
  vector<Bint> c(3);
  C++;
  a=C/3;
  C--;
  Bint h=H,w=W,A=a,CC=C,hh=H,ww=W,AA=a,HH=H,WW=W,aa=a,CCC=C,CCCC=C;
  vector<Bint> cc(3);
  vector<Bint> ccc(3);
  vector<Bint> cccc(3);
  
    while(true){
      if(a%H==0){
        C-=a;
        W-=a/H;
        c.at(0)=a;
        break;
      }
      
      else{
        a--;
      }
    }
  while(true){
     if(aa%WW==0){
        CCC-=aa;
        HH-=aa/WW;
        ccc.at(0)=aa;
        break;
      }
    else{
      aa--;
    }
  }
  
  
 //cout<<A<<h<<w;
    while(true){
      //cout<<A;
      if(A%h==0){
        CC-=A;
        w-=A/h;
        cc.at(0)=A;
        break;
      }
      
      else{
        A++;
      }
    }
   while(true){
     if(AA%ww==0){
        CCCC-=AA;
        hh-=AA/ww;
        cccc.at(0)=AA;
        break;
      }
    else{
      AA++;
    }
  }
  //cout<<cc.at(0);
  a=C/2;
  A=CC/2;
  aa=CCC/2;
  AA=CCCC/2;
    while(true){
      if(a%H==0){
        C-=a;
        W-=a/H;
        c.at(1)=a;
        break;
      }
      else if(a%W==0){
        C-=a;
        H-=a/W;
        c.at(1)=a;
        break;
      }
      else{
        a--;
      }
    }
   while(true){
      if(aa%HH==0){
        CCC-=aa;
        WW-=aa/HH;
        ccc.at(1)=aa;
        break;
      }
      else if(aa%WW==0){
        CCC-=aa;
        HH-=aa/WW;
        ccc.at(1)=aa;
        break;
      }
      else{
        aa--;
      }
    }
  
    while(true){
      if(A%h==0){
        CC-=A;
        w-=A/h;
        cc.at(1)=A;
        break;
      }
      else if(A%w==0){
        CC-=A;
        h-=A/w;
        cc.at(1)=A;
        break;
      }
      else{
        A++;
      }
    }
  while(true){
      if(AA%hh==0){
        CCCC-=AA;
        ww-=AA/hh;
        cccc.at(1)=AA;
        break;
      }
      else if(AA%ww==0){
        CCCC-=AA;
        hh-=AA/ww;
        cccc.at(1)=AA;
        break;
      }
      else{
        AA++;
      }
    }
  
  c.at(2)=C;
  cc.at(2)=CC;
  ccc.at(2)=CCC;
  cccc.at(2)=CCCC;
  sort(c.begin(),c.end());
  sort(cc.begin(),cc.end());
  sort(ccc.begin(),ccc.end());
  sort(cccc.begin(),cccc.end());
  //cout<<min(c.at(2)-c.at(0),cc.at(2)-cc.at(0))<<endl;
  vector<Bint> D={c.at(2)-c.at(0),cc.at(2)-cc.at(0),ccc.at(2)-ccc.at(0),cccc.at(2)-cccc.at(0)};
  cout<<Max(D);
}


Measured memory_bytes: 256
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];
#define ALL(v)  (v).begin(),(v).end()

    /*  ペア関連
    //vector<pair<long long, long long> > pairs(N);
    for(long long i=0; i<N; i++){
        long long a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    
    //sort(pairs.begin(), pairs.end(),greater<pair<int,int> >());
	sort(pairs.begin(), pairs.end());
    */

 	//stack<int> sta;   
    //queue<int> que;


int main(){
	
	long long N,M,K;
	string s;
    
	std::cin >> N;
    //std::cin >> N >> M;
    //std::cin >> N >> M >> K;
    
	std::vector<long long> v(N+1);
	std::vector<long long> w(N+1);
    //std::cin >> s;
    
    
    // 配列入力
    
    for(long long i=1; i<=N; i++){
		std::cin >> v[i];
		w[i]=v[i];
	}
	
	//ソート
    std::sort(w.begin(),w.end());//昇順ソート
    //std::sort(v.begin(),v.end(),std::greater<long long>());//降順ソート
    int sum,sum2;
	sum=0;
	sum2=0;
	int index;
	index=0;
	int flg,flg1,cnt,cnt1;
	flg=0;
	flg1=0;
	cnt=0;
	cnt1=0;

    index=(N)/2;
    
	for(long long i=1; i<=N; i++){
		if(v[i]<=w[index]){
			printf("%d\n",w[index+1]);
		}
		else{
			printf("%d\n",w[index]);
		}
	}
	
	
	//文字列入力
	/*
	for(long long i=0; i<s.length(); i++){
		
		if(s[i]!='1'){
	}
	*/
	/*
    if(1){
    	printf("%d",N);
    	//puts("Yes");
    	//文字列の出力
    	//std::cout << s << std::endl;
	}
	else{
		//puts("No");
	}
	*/
	return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
const long long mod = 1e9+7;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main(){
    string s;
    cin>>s;
    int N=s.size();

    for(int i=0;i<N-1;i++){
        if(s[i]==s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }

    for(int i=0;i+2<N;i++){
        if(s[i]==s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;


//    vi a[26];
//    for(int i=0;i<26;i++){
//        a[i] = vector<int>(N+1,0);
//        a[i][0] = 0;
//        if(s[0]-'a'==i) a[i][0]=1;
//        for(int j=1;j<N;j++){
//            if(s[j]-'a'==i) a[i][j]=a[i][j-1]+1;
//            else a[i][j]=a[i][j-1];
//        }
//    }
//
////    for(int i=0;i<26;i++){
////        cout << (char)(i+'a') << endl;
////        for(int j=0;j<N;j++){
////            cout << a[i][j] << " ";
////        }
////        cout << endl;
////    }
//
//    for(int len=2;len<=N;len++){
//        for(int i=0;i<26;i++){
//
//        }
//    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef DEBBY
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b); i++)
#define sz(v)  (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define fs first
#define sd second
#define pb push_back


void solve(){
    int n; cin >> n; vi a(n+1), b(n);
    rep(i,0,n)
      cin >> a[i];
    rep(i,0,n-1)
      cin >> b[i];
    ll defeated = 0LL;
    for(int i=0; i<n; i++){
        defeated+= min(a[i],b[i]);
        if(a[i]<b[i]){
          int q = b[i]-a[i];
          defeated += min(q,a[i+1]);
          a[i+1] = max(0, a[i+1]-q);
        }
    }
    cout << defeated;
} 

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}
    





Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
using namespace std;


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

	

	return 0;
}

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

xx = []
for n in [a, b]:
    x = []
    if n == 1:
        xx.append([n])
        continue

    x.append(1)
    while n % 2 == 0:
        x.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            x.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        x.append(n)
    xx.append(x)

print(len(set(xx[0]) & set(xx[1])))

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

int main() {
    string s; cin >> s;
    string a = "";
    for (int i=0; i<s.size(); ++i) {
        if (s[i] == 'B') {
            if (a.size()) {
                a.erase(a.size()-1);
            }
        }
        else {
            a += s[i];
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1LL << 60;

int N;
long long h[100010];
long long dp[100010];

long long rec(int i){
    if(dp[i] < INF) return dp[i];
    if(i == 0) return 0;
    long long res = INF;
    chmin(res, rec(i-1) + abs(h[i] - h[i-1]));
    if(i > 1) chmin(res, rec(i-2) + abs(h[i] - h[i-2]));

    return dp[i] = res;
}

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; ++i) cin >> h[i];
    for(int i = 0; i < 100010; ++i) dp[i] = INF;
    cout << rec(N-1) << endl;

    return 0;
}

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

using namespace std;
const int N = 1e6 + 1;
int a[N] , avail[N] , b[N] , c[N];
int n , q;
vector <int> V;
void compress(){
    V.push_back(-1);
    for (int i = 1; i <= n; i++) V.push_back(a[i]);
    for (int i = 1; i <= q; i++){
        V.push_back(b[i]);
        V.push_back(c[i]);
    }
    sort(V.begin(),V.end());
    V.resize(unique(V.begin(),V.end()) - V.begin());
    for (int i = 1; i <= n; i++) a[i] = lower_bound(V.begin(),V.end(),a[i]) - V.begin();
    for (int i = 1; i <= q; i++){
        b[i] = lower_bound(V.begin(),V.end(),b[i]) - V.begin();
        c[i] = lower_bound(V.begin(),V.end(),c[i]) - V.begin();
    }
}   
int main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> q;
    for (int i = 1; i <= q; i++) cin >> b[i] >> c[i];
    compress();
    long long sum = 0;
    for (int i = 1; i <= n; i++){
        sum = sum + V[a[i]];
        avail[a[i]]++;
    }
    for (int i = 1; i <= q; i++)
        if (b[i] != c[i]){
            sum = sum - 1LL * V[b[i]] * avail[b[i]];
            sum = sum + 1LL * V[c[i]] * avail[b[i]];
            avail[c[i]] += avail[b[i]];
            avail[b[i]] = 0;
            cout << sum << "\n";
        }
    return 0;
}

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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  string s;int K;cin>>s>>K;
  int N=s.size();
  int ans=0;
  string t=s;
  for(int i=1;i<N;i++){
    if(t[i]==t[i-1]){
      t[i]='#';
      ans++;
    }
  }
  if(t[N-1]!=s[0])fin(ans*K);
  else{
    int a=1;
    string u=s;u[0]='#';
    for(int i=1;i<N;i++){
      if(u[i]==u[i-1]){
        u[i]='#';
        a++;
      }
    }
    if(u[N-1]!=s[0]){
      cout<<(K/2)*(ans+a)+(K&1)*ans<<endl;
    }
    else{
      cout<<ans+a*(K-1)<<endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    string a,b,c;
    cin>>a>>b>>c;
    if (a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
	int n, v;
	scanf("%d", &n);

	int min = 1000000000, max = 0;
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &v);
		min = min > v ? v : min;
		max = max < v ? v : max;
	}

	printf("%d", max - min);

	return 0;
}

Measured memory_bytes: 128
/* warshall_floyd.cpp
    ワーシャルフロイド法を用いて、全点間最短路を求める。

    初期化：dis[i][j] = iからjへの距離(辺がなければINF) (i≠j)
            dist[i][i] = 0
            prev[i][j] = i

    負閉路の検出：dis[i][i] < 0 となる i が存在するか

    verified:
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C&lang=ja
*/

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;

/* warshall_floyd(dist,prev)
    入力：初期化した dist, prev
    計算量：O(|V|^3)
    副作用：dis[i][j]にiからjへの最短路のコストを格納、prev[i][j]にiからjへの最短路でのjの1つ前の点を格納
*/
void warshall_floyd(vector<vector<long long>> &dist, vector<vector<long long>> &prev) {
    int V = dist.size();
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                if (dist[i][k] + dist[k][j] < dist[i][j]) {
                    dist[i][j] = dist[i][k] + dist[k][j];
                    prev[i][j] = prev[k][j];
                }
            }
        }
    }
}

/* get_path(prev, s, t)
    入力：warshall_floyd で得た prev, スタート s, ゴール t
    出力：s から t への最短路のパス
*/
vector<int> get_path(const vector<vector<long long>> &prev, int s, int t) {
    vector<int> path;
    for (int cur = t; cur != s; cur = prev[s][cur]) {
        path.push_back(cur);
    }
    path.push_back(s);
    reverse(path.begin(), path.end());
    return path;
}

/* is_negative(dist)
    入力：warshall_floyd で得た dist
    出力：負の有向路を含むかどうか
*/
bool is_negative(const vector<vector<long long>> &dist) {
    int V = dist.size();
    for (int i = 0; i < V; i++) {
        if (dist[i][i] < 0) {
            return true;
        }
    }
    return false;
}

int main() {
    int V, E, R;
    cin >> V >> E >> R;
    vector<int> r(R);
    for (int i = 0; i < R; i++) {
        cin >> r.at(i);
        r[i]--;
    }

    // initialization
    vector<vector<long long>> dist(V, vector<long long>(V, INF));
    vector<vector<long long>> prev(V);
    for (int i = 0; i < V; ++i) {
        dist[i][i] = 0;
        prev[i] = vector<long long>(V, i);
    }

    // input
    for (int i = 0; i < E; i++) {
        long long s, t, c;
        cin >> s >> t >> c;
        s--, t--;
        dist[s][t] = c;
        dist[t][s] = c;
    }

    warshall_floyd(dist, prev);

    sort(r.begin(), r.end());
    long long ans = INF;
    do {
        long long sum = 0;
        for (int i = 0; i < R - 1; i++) {
            sum += dist[r[i]][r[i + 1]];
        }
        ans = min(ans, sum);
    } while (next_permutation(r.begin(), r.end()));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 896