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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n, k; cin >> n >> k;
  
  int ans = 1;
  rep(i, n) {
    if (i == 0) ans *= k;
    else ans *= (k-1);
  }

  cout << ans << endl;
  
  return (0);
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1);

int main(){
  int card[200][3] = {0};
  int n, score[200] = {0};
  cin >> n;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 3; j++){
      cin >> card[i][j];
    }
  }
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < n; j++){
      int cnt = 0;
      for(int k = 0; k < n; k++){
        if(card[j][i] == card[k][i] && j != k){
          cnt++;
        }
      }
      if(cnt == 0) score[j] += card[j][i];
    }
  }
  for(int i = 0; i < n; i++){
    cout << score[i] << endl;
  }
}

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

int main() {
    int N;
    std::cin >> N;

    std::priority_queue<std::pair<int, int>> queue;
    for (int i = 0; i < N; i += 1) {
        int Ai, Bi;
        std::cin >> Ai >> Bi;
        queue.push({-Bi, Ai});
    }

    int current = 0;
    while (!queue.empty()) {
        std::pair<int, int> pair = queue.top();
        queue.pop();
        current += pair.second;
        if (current > -pair.first) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
    return 0;
}


Measured memory_bytes: 2548
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
abd = [list(map(int,input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
for a,b,d in abd:
  graph[a].append((b,d))
for i in range(1,n):
  graph[i+1].append((i,0))
import heapq as hq
dist = [10**18]*(n+1)
dist[1] = 0
q = [(0,1)]
hq.heapify(q)
while q:
  d,x = hq.heappop(q)
  for y,dd in graph[x]:
    if dist[y] > dist[x]+dd:
      dist[y] = dist[x]+dd
      hq.heappush(q,(dist[y],y))
if dist[n] == 10**18:
  print(-1)
else:
  print(dist[n])

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

#define int         long long
#define ld          long double
#define fastio      ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define sz(x)       (int)x.size()
#define mod         1000000007
#define mod2        998244353

using namespace std;

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
int gcd(int a,int b)
{
    if(a%b == 0)return b;
    return gcd(b,a%b);
}*/
int n;
stack<int>s;

signed main()
{
    fastio;
    cin >> n;
    if(!n){cout << 0;return 0;}
    while(n!=0)
    {
        if(n<0)
        {
            if((-1*n)%2 == 0){s.push(0);n=-n/2;}
            else {s.push(1);n=(-n+1)/2;}
        }
        else
        {
            if(n%2 == 0){s.push(0);n=-n/2;}
            else {s.push(1);n=(-n+1)/2;}
        }
    }
    while(!s.empty())
    {
        cout << s.top();
        s.pop();
    }

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7, MAX = 1e9, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
long long sum = 0;

typedef pair<int, int> Pa;
typedef long long ll;

int main() {
    cin >> N;
    int div = 0;
    int curr = N;
    while(curr > 0){
        div += curr%10;
        curr /= 10;
    }
    if(N%div == 0) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<pii> vpii;
set <int> st;
stack<pii> s;
ll a, b,k,cnt=0;
int main(int argc,char const* argv[])
{
  cin >> a>> b >> k;
  for(int i=0;i<k;i++)
    {
      if(i%2==0)
	{
	  if(a%2!=0)
	    {
	      a--;
	    }
	  a/=2;
	  b+=a;
	}
      else
	{
	  if(b%2!=0)
	    {
	      b--;
	    }
	  b/=2;
	  a+=b;
	}
    }
  cout << a << ' ' <<  b << endl;
        

  return 0;
}


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

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

    vector<ll> a(n);
    rep(i, n) cin >> a.at(i);

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

    ll a_i = a.at(n - 1);

    ll a_j = 0;
    rep(i, n - 1)
    {
        if (abs(a_j * 2 - a_i) > abs(a.at(i) * 2 - a_i))
        {
            a_j = a.at(i);
        }
    }

    cout << a_i << " "  << a_j << endl;
    return 0;
}

Measured memory_bytes: 4020
#include<cstdio>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
if(a==b&&b==c)
	printf("1\n");
	else if(a!=b && a!=c && c!=b)
		printf("3\n");
		else
			printf("2\n");
}

Measured memory_bytes: 128
a, b, c, x, y = map(int, input().split())

if a+b >= 2*c:
    if x >= y:
        ans = y*c*2
        ans = ans+min((x-y)*a, (x-y)*2*c)
    else:
        ans = x*c*2
        ans = ans+min((y-x)*b, (y-x)*2*c)
else:
    ans = a*x + b*y

print(ans)


Measured memory_bytes: 39696
#include <stdio.h>
int main(void){
    // Your code here!
    char s[101],p[101];
    int i,j,sn=0,pn=0,t;
    
    scanf("%s %s", s, p);
    
    while(s[sn]!='\0') sn++;
    while(p[pn]!='\0') pn++;
    
    for(i=0;i<sn;i++){
        t=1;
        for(j=0;j<pn;j++){
            if(s[(i+j)%sn]!=p[j]) t=0;
        }
        if(t) break;
    }
    
    if(t) printf("Yes\n");
    else printf("No\n");
    
    return 0;
}



Measured memory_bytes: 2108
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BAcrostic {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.nextString();
            int w = in.nextInt();

            String ans = "";
            for (int i = 0; i < s.length(); i += w) {
                ans += s.charAt(i);
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 21332
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N, M;
int A[100000];
ll cost1[100001] ={}, cost2[100001]={};

signed main(){
    cin >> N >> M;
    rep(i, N){
        cin >> A[i];
        A[i]--;
    }
    
    rep(i, N-1){
        cost1[0] += (M+A[i+1] - A[i]) % M;
        cost1[M] -= (M+A[i+1] - A[i]) % M;
        if(A[i] < A[i+1]){
            cost2[A[i]+1]++;
            cost2[A[i+1]+1]--;
            cost1[A[i]+1] += A[i]+1;
            cost1[A[i+1]+1] -= A[i]+1;
        }
        else{
            cost2[A[i]+1]++;
            cost2[M]--;
            cost1[A[i]+1] += A[i]+1;
            cost1[M] -= A[i]+1;

            cost2[0]++;
            cost2[A[i+1]+1]--;
            cost1[0] -= M-A[i]-1;
            cost1[A[i+1]+1] += M-A[i]-1;
        }
    }

    ll ans = LLONG_MAX;
    rep(i, M){
        cost1[i+1] += cost1[i];
        cost2[i+1] += cost2[i];
        //cout << cost1[i] << " " << cost2[i] << " " << cost1[i]-i*cost2[i] <<  endl;
        ans = min(ans, cost1[i]-i*cost2[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5508
#include<iostream>
#include<string>
#include<vector>

using namespace std;
int main()
{
    string s;
    cin >> s;

    bool flag = true;
    for(int r=0,l = s.size()-1; r < l; ++r, --l)
    {
        if(s[r] != s[l])
        {
            flag = false;
            break;
        }
    }

    if(flag)
    {
        for(int r=0,l = (s.size() -2)/2; r < l; ++r, --l)
        {
            if(s[r] != s[l])
            {
                flag = false;
                break;
            }
        }    
    }
    
    if(flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int main() {

    int q;
    while (cin >> q && q != -1) {
        double x = q / 2.0;
        while (abs(x * x * x - q) >= 0.00001 * q) {
            x = x - (x * x * x - q) / (3 * x * x);
        }
        printf("%.6f", x);
        cout << endl;

    }
     
    return 0;
}

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

ll x = 1e9 + 7; 
const int INF = 1001001001;


int main() {
  int n;
  cin >> n;
  n++;
  cout << n/2 << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

// 値がでかい順に入れる。後ろ二個を見て比較して決める。
void solve() {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    sort(ALL(A));
    reverse(ALL(A));

    // N = 2ならでかい方を出して終わり
    // TODO 後でテスト
    if(N == 2) {
        cout << *max_element(ALL(A)) << endl;
        return;
    }

    ll ans = 0;
    ll bef = A[0];
    A.erase(A.begin());
    for(const auto &it: A) {
        ans+=bef;
        bef = it;
    }
    cout << ans << endl;

}

// 値がでかい順に入れる。後ろ二個を見て比較して決める。
void solve2() {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    sort(ALL(A));
    reverse(ALL(A));

    ll ans = 0;
    REP(i,N-1) ans += A[(i+1)/2];
    cout << ans << endl;
}

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

Measured memory_bytes: 4836
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

int N,K;
int a[200005];
vector<P1> b;
int c[200005];

class BIT{
public:
    int bit[200005],n;
    BIT(int m){
        n = m;
        for(int i=0;i<m;++i)bit[i] = 0;
    }
    int sum(int i){
        int s = 0;
        while(i>0){
            s+=bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int i,int x){
        while(i<=n){
            bit[i]+=x;
            i += i & -i;
        }
    }
};

signed main(){
    cin>>N>>K;
    for(int i=0;i<N;++i)cin>>a[i];
    b.PB(P1(0,0));
    for(int i=1;i<=N;++i)b.PB(P1(b[i-1].fi+a[i-1],i));
    for(int i=1;i<b.size();++i)b[i].fi -= K*i;
    sort(b.begin(),b.end());
    int tmp = 0;
    for(int i=0;i<b.size();++i){
        int id = b[i].se;
        if( ( b[i].fi!=b[i-1].fi ) && i ){
            tmp++;
            c[id] = tmp;
        }
        else c[id] = tmp;
    }
    BIT V(200005);
    int ans = 0;
    for(int i=0;i<b.size();++i){
        ans+=V.sum(c[i]+1);
        V.add(c[i]+1,1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9068
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;
 
 
ll factors(ll n)
{
	ll cnt = 0;
	for(ll i = 1; i*i <= n; i++)
	{
		if(n % i == 0)
		{
			if(n/i == i)
				cnt++;
			else
				cnt = cnt+2;
		}
	}
	return cnt;
}
int main() 
{
	fast;
	ll n; cin>>n; ll ans = 0;
	ll add = factors(n-1);
	for(ll k = 2; k*k <= n; k++)
	{
		ll t = n;
		if(t % k == 0)
		{
			t = t/k;
			while(t % k == 0) t = t/k;
			
			if(t % k == 1) 
			{
		//		cout << k << endl;
				ans++;
			}
		}
	}
	cout << ans+add << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    string s;
    cin >> s;
    char prev = s[0];
    int n = 1;
    for (int i = 1; i < N; ++i) {
        if (s[i] == prev) { continue; }
        prev = s[i];
        n++;
    }
    cout << n << endl;
    return 0;
}


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

int main(){
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    if(n>k)cout<<k*x+y*(n-k)<<endl;
    else cout<<n*x<<endl;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int t = 0;
  int p;
  cin>>p;
  for(int i = 1;i<=9;i++){
    for(int k = 1;k<=9;k++){
      if(p == i*k){
        t = 1;
      }
    }
  }
  if(t == 1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static int ans = 0;
    static long N;
    static void Main(string[] args)
    {
        N = long.Parse(ReadLine());
        int[] nums = { 3, 5, 7 };
        serch("");
        WriteLine(ans);
    }
    static void serch(string s)
    {
        if (s.Length != 0 && long.Parse(s) > N)
            return;
        if (s.Distinct().Count() == 3)
            ans++;
        serch(s + "3");
        serch(s + "5");
        serch(s + "7");
    }
}

Measured memory_bytes: 15312
package main

import "fmt"

func main() {
    var n, x, ans int64
    var a, b int64

    fmt.Scan(&n, &x)

    ans += n

    // a > b
    if n-x > x {
        a = n-x
        b = x
    } else {
        a = x
        b = n-x
    }

    for b != 0 {
        q := a / b
        r := a % b
        ans += (b*2) * q

        if r == 0 {
            ans -= b
        }
        a = b
        b = r
    }

    fmt.Println(ans)
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <functional>
#include <cassert>

typedef long long int ll;

int main()
{
    int N, M;
    std::cin >> N >> M;

    const long long mod=1e9+7;

    //大丈夫なところはtrue
    std::vector<bool> a(N+1, true);
    for(int i=0; i<M; ++i)
    {
        int num;
        std::cin >> num;
        a[num] = false;
    }

    std::vector<ll> dp(N+1);
    dp[0] = 1;
    for(int i=0; i<N; ++i)
    {
        for(int j=i+1; j<=std::min(i+2, N); ++j)
            if(a[j])
            {
                dp[j] += dp[i];
                dp[j] %= mod;
            }
    }

    std::cout << dp[N] << std::endl;

    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	IOS;
	using ld = long double;
	ld l;
	cin >> l;
	ld res = l / 3;
	res = res * res * res;
	cout << setprecision(20) << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    unordered_map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    ll ans = 0;
    for(auto& p : mp) {
        int s = p.second;
        ans += (ll)s*(s-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10660
/*
[abc131] B - Bite Eating
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_L = 100;

int N, L;

ll solve() {
    int ans = 0;
    int m = MAX_L;
    int mi;
    for (int i = 0; i < N; i++) {
        if (m > abs(L + i)) {
            m = abs(L + i);
            mi = i;
        }
        ans += L + i;
    }
    ans -= L + mi;

    return ans;
}

int main() {
    cin >> N >> L;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdint>

using namespace std;

void solve(int a, int b, const string& s) {
    int total = 0;
    int bsum = 0;
    for (auto c : s) {
        if (c == 'a') {
            if (total < a + b) {
                cout << "Yes" << endl;
                ++total;
            } else {
                cout << "No" << endl;
            }
        } else if (c == 'b') {
            if (total < a + b && bsum < b) {
                cout << "Yes" << endl;
                ++total;
                ++bsum;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        } 
    }
}


int main() {
    int n, a, b;
    cin >> n >> a >> b;

    string s;
    cin >> s;

    // cout << solve(a, b, s) << endl;
    solve(a, b, s);

    return 0;
}

Measured memory_bytes: 896
S=list(input())
T=list(list(input()))
ans='No'
def counter(i,max):
    a=[]
    for  j in range(i,max+1):
        a.append(j)
    for k in range(i):
        a.append(k)
    return a
for i in range(len(S)):
    a=[]
    for j in counter(i,len(S)-1):
        a.append(S[j])
    if(a==T):
        ans='Yes'
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on

int N, K;
int dp[MAX_N + 1], h[MAX_N];

void solve()
{
  dp[0] = 0;
  dp[1] = abs(h[0] - h[1]);
  for (int i = 2; i < N; i++) {
    int minc = INT_MAX;
    for (int j = i - 1; j >= max(i - K, 0); j--) {
      minc = min(minc, dp[j] + abs(h[i] - h[j]));
    }
    dp[i] = minc;
  }
  cout << dp[N - 1] << endl;
}

int main(void)
{
  cin >> N >> K;
  REP(i, N) cin >> h[i];
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long

signed main() {
  int n;
  cin >>n;
  int a[4];
  rep(i,4) a[i]=0;
  rep(i,n) {
    string s;
    cin >> s;
    if(s=="AC") a[0]++;
    else if(s=="WA") a[1]++;
    else if(s=="TLE") a[2]++;
    else a[3]++;
  }
  cout << "AC x "<<a[0] << endl;
    cout << "WA x "<<a[1] << endl;
      cout << "TLE x "<<a[2] << endl;
        cout << "RE x "<<a[3] << endl;
  return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>
int main()
{
    int a,b,c,n,i;

    scanf("%d",&n);
    for(i=1;i<=n;i++){
    scanf("%d %d %d",&a,&b,&c);
        if(((a*a)+(b*b)==(c*c))||((a*a)+(c*c)==(b*b))||((b*b)+(c*c)==(a*a))){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
 
long long n, x, y, arr[100005];
 
int main () {
	cin>>n;
	
	for(int i=1; i<=n; i++){
		cin>>arr[i];
	}
	sort(arr+1, arr+n+1);
    
    for(int i=n; i>0; i--){
        if(arr[i]==arr[i-1]){
            if(x==0){
                x=arr[i];
                i--;
            }
            else{
                y=arr[i];
                break;
            }
        }
    }
    
    cout<<x*y<<endl;
}

Measured memory_bytes: 4416
import sys
X,N=map(int, input().split())
p=set(list(map(int, input().split())))
count=0
if N==0:
    print(X)
    sys.exit()

while(True):
    x1=X-count
    x2=X+count
    if x1 not in p:
        print(x1)
        sys.exit()
    if x2 not in p:
        print(x2)
        sys.exit()    
    count+=1


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

#define fi first
#define se second
#define ll long long

const int N = 303;
const int mod = 998244353;

using namespace std;

int n, k;
int d[N][N];
int f[N][N];
int rem;
string s;

void add(int &x, int y)
{
        x += y;
        if(x >= mod){
                x -= mod;
        }
}

void make(int x)
{
        rem -= x;
        for(int i = 0; i <= k; i++){
                for(int j = 0; j <= i; j++){
                        for(int h = min(x, i - j); h >= 0; h--){
                                add(f[i][j + h], d[i][j]);
                        }
                        for(int h = min(rem, k - i); h > 0; h--){
                                add(f[i + h][j], d[i][j]);
                        }
                }
        }
        for(int i = 0; i <= k; i++){
                for(int j = 0; j <= k; j++){
                        d[i][j] = f[i][j];
                        f[i][j] = 0;
                }
        }
}

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> s >> k;
        n = s.size();
        k = min(k, n);
        rem = n;

        vector < int > a = {0};
        for(int i = 0; i < n; i++){
                if(s[i] == '0'){
                        a.push_back(0);
                } else{
                        a.back() += 1;
                }
        }
        n = a.size();
        d[0][0] = 1;
        for(int x: a){
                make(x);
        }
        int res = 0;
        for(int i = 0; i <= k; i++){
                add(res, d[i][i]);
        }

        cout << res << "\n";
}


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

long long merge(vector<int>& A, const int left, const int mid, const int right){
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> L(n1+1), R(n2+1);   //新しく配列分の領域が必要
                                    //他のソートアルゴリズムに比べメモリが必要になる
                                    //番兵分に一つ多くの要素が必要
    for(int i = 0; i < n1; ++i){
        L[i] = A[left + i];
    }
    for(int i = 0; i < n2; ++i){
        R[i] = A[mid + i];
    }

    L[n1] = R[n2] = INT_MAX;    //番兵
    
    int i = 0, j = 0;
    long long cnt = 0;
    for(int k = left; k < right; ++k){
        if(L[i] <= R[j]){
            A[k] = L[i++];
        }
        else{   // R[j] が L[i] より小さいと反転が起きる
            A[k] = R[j++];
            cnt += (long long)n1 - i;
        }
    }
    return cnt;
}

// 戻り値は比較した回数
long long merge_sort(vector<int>& A, const int left, const int right){
    long long cnt = 0;
    if(left+1 < right){             //1つになるまで分割
        int mid = (left + right)/2;
        cnt += merge_sort(A, left, mid);
        cnt += merge_sort(A, mid, right);
        cnt += merge(A, left, mid, right);
    }
    return cnt;
}

int main(){

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

    long long cnt = merge_sort(a, 0, n);

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 4388
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i, s;
    char n[1001];
    
    while (1) {
        scanf("%s", n);
        if (n[0] == '0') {
            break;
        }
        s=0;
        for(i=0; n[i]; i++){
            s += n[i] - '0';
        }
        printf("%d\n", s);
    }
    return 0;
}


Measured memory_bytes: 2048
h,w=map(int,input().split())
Ch,Cw=map(int,input().split())
Dh,Dw=map(int,input().split())
s=[list(input()) for _ in range(h)]

Ch,Cw=Ch-1,Cw-1
Dh,Dw=Dh-1,Dw-1
todo=[[0,Ch,Cw]]
ntodo=[]
d=[[-1]*w for _ in range(h)]
d[Ch][Cw]=0
toho=[[0,1],[0,-1],[1,0],[-1,0]]
wiz=[[2,2],[2,1],[2,0],[2,-1],[2,-2],[1,2],[1,1],[1,-1],[1,-2],[0,2],[0,-2],[-1,2],[-1,1],[-1,-1],[-1,-2],[-2,2],[-2,1],[-2,0],[-2,-1],[-2,-2]]
while todo or ntodo:
  if not todo:
    todo=ntodo
    ntodo=[]
  cnt,nh,nw=todo.pop()
  if d[nh][nw]<cnt:continue
  for dh,dw in toho:
    if 0<=nh+dh<h and 0<=nw+dw<w and s[nh+dh][nw+dw]!='#':
      if d[nh+dh][nw+dw]==-1 or d[nh+dh][nw+dw]>cnt:
        d[nh+dh][nw+dw]=cnt
        todo.append([cnt,nh+dh,nw+dw])
  for dh,dw in wiz:
    if 0<=nh+dh<h and 0<=nw+dw<w and s[nh+dh][nw+dw]!='#':
      if d[nh+dh][nw+dw]==-1 or d[nh+dh][nw+dw]>cnt+1:
        d[nh+dh][nw+dw]=cnt+1
        ntodo.append([cnt+1,nh+dh,nw+dw])
print(d[Dh][Dw])


Measured memory_bytes: 151488
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=3005;
int n,md,i,j,k,x,w,u,s2[N][N],ans,pw2[N],Pw2[N],jc[N],rjc[N],inv[N];
int pw(int a,int b)
{
	int rtn=1;
	while(b)
	{
		if(b&1)
			rtn=1ll*rtn*a%md;
		a=1ll*a*a%md;
		b>>=1;
	}
	return rtn;
}
int C(int n,int m)
{
	return 1ll*jc[n]*rjc[m]%md*rjc[n-m]%md;
}
int main()
{
	scanf("%d%d",&n,&md);
	inv[1]=1;
	for(i=2;i<=n;++i)
		inv[i]=1ll*inv[md%i]*(md-md/i)%md;
	jc[0]=rjc[0]=1;
	for(i=1;i<=n;++i)
		jc[i]=1ll*jc[i-1]*i%md,rjc[i]=1ll*rjc[i-1]*inv[i]%md;
	s2[0][0]=1;
	for(i=1;i<=n;++i)
		for(j=1;j<=i;++j)
			s2[i][j]=(s2[i-1][j-1]+1ll*s2[i-1][j]*j)%md;
	pw2[0]=Pw2[0]=1;
	for(i=1;i<=n;++i)
		pw2[i]=1ll*pw2[i-1]*2%(md-1),Pw2[i]=1ll*Pw2[i-1]*2%md;
	for(i=0;i<=n;++i)
	{
		
		w=0;
		for(k=0,x=1;k<=i;++k,x=1ll*x*Pw2[n-i]%md)
		{
			u=1ll*s2[i][k+1]*(k+1)%md;
			u=(u+s2[i][k])%md;
			w=(w+1ll*u*x)%md;
		}
		w=1ll*w*pw(2,pw2[n-i])%md;
		ans=(ans+1ll*C(n,i)*w%md*(i&1?-1:1)+md)%md;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 34176
#include <bits/stdc++.h>
using namespace std;
int par[100001];
bool f[100001];
int find(int s){
	if (par[s]==s) return s;
	else return par[s]=find(par[s]); 
}
int main(){
	int n, m, t=0;
	cin >> n >> m;
	for (int i=1; i<=n; i++) par[i]=i;
	for (int i=1; i<=m; i++){
		int x, y;
		cin >> x >> y;
		x=find(x), y=find(y);
		if (x!=y) par[x]=y;
	}
	for (int i=1; i<=n; i++)
		f[find(i)]=true;
	for (int i=1; i<=n; i++)
		if (f[i]) t++, f[i]=false;
	cout << t-1 << endl;
	return 0;
}

Measured memory_bytes: 4120
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define def(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
    string s; cin>>s;
    cout<<s[0]<<s[1]<<s[2]; 
    }   
}



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

int main() {
  int A, B;
  int ANS = 0;

  cin >> A >> B;

  for (int i = A; i <= B; i++){
    if (((i / 10000  == i % 10) && (i / 1000 % 10 == i % 100 / 10)))
      ANS++; 
  }

  cout << ANS;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

R, G, B, N = map(int, input().rstrip().split())

cnt = 0

S = [x*R for x in range((N//R)+1)]

for s in S:
    if s == N:
        cnt += 1
        continue
    
    T = [y*G for y in range(((N-s)//G)+1)]

    for t in T:

        if s+t == N:
            cnt += 1
            continue
            
        if (N-(s+t))%B == 0:
            cnt += 1

print(cnt)

Measured memory_bytes: 3316
package main

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

func NewScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 1000005), 1000005)
	s.Split(bufio.ScanWords)
	return s
}

func NewWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func ScanString(s *bufio.Scanner) string {
	if !s.Scan() {
		panic("scan string failed")
	}
	return s.Text()
}

func ScanInt(s *bufio.Scanner) int {
	return int(ScanInt64(s))
}

func ScanInts(s *bufio.Scanner, n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = ScanInt(s)
	}
	return ints
}

func ScanInt64(s *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(ScanString(s), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

// https://atcoder.jp/contests/abc052/tasks/abc052_a
func main() {
	s := NewScanner()
	w := NewWriter()
	defer w.Flush()

	ints := ScanInts(s, 4)
	rec1 := ints[0] * ints[1]
	rec2 := ints[2] * ints[3]
	if rec1 > rec2 {
		fmt.Fprintln(w, rec1)
	} else {
		fmt.Fprintln(w, rec2)
	}
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=a;i<n;i++)
int comp(const void* a,const void* b){
	return *(int*)b-*(int*)a;
}
typedef struct LIST{
	int num;
	struct LIST *next;
}Graph;
Graph** init(int v){
	Graph **g=(Graph**)calloc(v,sizeof(Graph*));
	return g;
}
void add(Graph **g,int s,int n){
	Graph *tmp=(Graph*)malloc(sizeof(Graph));
	tmp->num=n;
	tmp->next=g[s];
	g[s]=tmp;
	return;
}
void delete_graph(Graph **g,int v){
	int i;
	Graph *e,*tmp;
	FOR(i,0,v){
		e=g[i];
		while(e!=NULL){
			tmp=e->next;
			free(e);
			e=tmp;
		}
	}
	return;
}
Graph **g;
int dp[100000];
int s[100000];
void dfs(int v){
	int i;
	int *a=calloc(s[v],sizeof(int));
	int size=0;
	Graph *k;
	for(k=g[v];k!=NULL;k=k->next){
		dfs(k->num);
		a[size++]=dp[k->num];
	}
	qsort(a,size,sizeof(int),comp);
	FOR(i,0,size){
		dp[v]=MAX(dp[v],a[i]+i+1);
	}
	return;
}
int main(void){
	int n,p,i;
	scanf("%d",&n);
	g=init(n);
	FOR(i,1,n){
		scanf("%d",&p);
		add(g,--p,i);
		s[p]++;
	}
	dfs(0);
	printf("%d\n",dp[0]);
	delete_graph(g,n);
}


Measured memory_bytes: 12672
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include <iomanip>
#include<stack>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

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 ll;
typedef long double ld;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    ll a, p;
    cin >> a >> p;
    ll h = 3*a + p;

    cout << h/2;


}


Measured memory_bytes: 764
#include<iostream>
#include<fstream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>
#include<set>

using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl
#define pb push_back
#define mp make_pair

typedef long long tint;
typedef pair<int,int> pint;
typedef pair<tint,tint> ptint;
typedef unsigned long long utint;
typedef long double ldouble;

typedef vector<int> vint;

int toNumber (string s)
{
	int Number;
	if ( ! (istringstream(s) >> Number) ) Number = 0; // el string vacio lo manda al cero
	return Number;
}

string toString (int number)
{
    ostringstream ostr;
    ostr << number;
    return  ostr.str();
}

tint ele(tint a, tint b){
	if(b==0)return 1;
	if(b%2==0){
		return ele(a*a, b/2);
	}else{
		return a*ele(a*a, b/2);
	}
}

tint mcd(tint a, tint b){
	if(a==0)return b;
	return mcd(b%a, a);
}

double d_abs(long a, long b){
	if(a>b){
		return a-b;
	}
	return b-a;
}

void solve(){
	tint a, b, n;
	string s;
	vector<tint> v;
	tint m;
	cin>>n>>a>>b;
	if(a>b){
		cout<<0<<endl;
		return;
	}
	if(a==b){
		cout<<1<<endl;
		return;
	}
	if(n==1){
		cout<<0<<endl;
		return;
	}
	cout<<(n-1)*(b-a)+a-b+1<<endl;
}




int main (){
	int T;
	T=1;
	while(T--){
		solve();
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const int maxN = 1e6 + 55;

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

    ll n, k;    cin >> n >> k;

    n %= k;

    cout << min(abs(n - k), n) << '\n';

    return 0;
}


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

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

	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '0') {
			ans += '0';
		}
		else if (s[i] == '1') {
			ans += '1';
		}
		else if (s[i] == 'B') {
			if (ans.empty()) {

			}
			else {
				ans.pop_back();
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;

  // ここにプログラムを追記
  int sum = 0,x,Adis,Bdis;
  for(int i = 0; i < N; i++){
   cin >> x;
   
   Adis = x*2;
    
   if(x<K){
     Bdis = (K-x)*2;
   }else{
     Bdis = (x-K)*2;
   }
    
   if(Adis < Bdis){
     sum += Adis;
   }else{
     sum += Bdis;
   }
  }
  
  cout << sum << endl;
 
}


Measured memory_bytes: 256
S = input()
# A = [int(i) for i in input().split()]
K = int(input())

count_list = []
count = 0
for i in range(len(S)):
    count += 1
    if i == len(S) - 1:
        count_list.append([S[i], count])
        break
    if S[i] != S[i+1]:
        count_list.append([S[i], count])
        count = 0

if len(count_list) == 1:
    print(len(S) * K // 2)
else:
    count = 0
    for _, c in count_list:
        count += c//2
    if count_list[0][0] != count_list[-1][0]:
        print(count * K)
    else:
        head_count = count_list[0][1]
        tail_count = count_list[-1][1]
        mid_change = count - head_count // 2 - tail_count // 2
        con_change = (head_count + tail_count) // 2
        print(head_count // 2 + tail_count // 2 + mid_change * K + con_change * (K-1))


Measured memory_bytes: 3064
#include <stdio.h>
int Min(int a,int b){
    if(a<=b)return a;
    return b;
}
int main()
{   int q,h,s,d,n;
    scanf("%d%d%d%d%d",&q,&h,&s,&d,&n);
    long min=Min(8*q,Min(4*h,Min(2*s,d)));
    long ans=n/2*min+(n%2)*Min(4*q,Min(2*h,s));
    printf("%ld",ans);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  int B=A[0],S=A[0];
  int C=0,D=0;
  rep(i,0,N){
    if(B<A[i]){
      B=A[i];
      C=i;
    }
    if(S>A[i]){
      S=A[i];
      D=i;
    }
  }
  queue<pii> Q;
  if(-S<=B){
    rep(i,1,N){
      while(A[i]<A[i-1]){
        Q.push(mp(C+1,i+1));
        A[i]+=B;
        if(B<A[i]){
          B=A[i];
          C=i;
        }
      }
    }
  }
  else{
    REP(a,2,N){
      int i=N-a;
      while(A[i]>A[i+1]){
        Q.push(mp(D+1,i+1));
        A[i]+=S;
        if(S>A[i]){
          S=A[i];
          D=i;
        }
      }
    }
  }
  cout<<Q.size()<<endl;
  while(Q.size()){
    cout<<Q.front().first<<" "<<Q.front().second<<endl;
    Q.pop();
  }
  }


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

const double PI = acos(-1);

int main(){	
	ll n;
	cin >> n;
	string ans;
	while(n){
		n--;
		ans += 'a'+n%26;
		n /= 26;
	}
	reverse(ans.begin(),ans.end());
	cout << ans << endl;

	return 0;

}





Measured memory_bytes: 3564
#include<iostream>
#include<string>
using namespace std;
int a, b, i;
string s;
int main()
{
	cin >> a >> b >> s;
	if(s.substr(a, 1) != "-") {
		cout << "No" << endl;
		return 0;
	}
	for(i = 0; i <= a + b; i ++)
	{
		if(i != a){
			if(s.substr(i, 1) < "0" || s.substr(i, 1) > "9"){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner io = new Scanner(System.in);
		int N = io.nextInt();
		int M = io.nextInt();
		boolean[] node = new boolean[N];
		int a,b;
		for(int i=0;i<M;i++){
			a = io.nextInt()-1;
			b = io.nextInt()-1;
			node[a] = !node[a];
			node[b] = !node[b];
		}
		
		String ans = "YES";
		for(int i=0;i<N;i++){
			if(node[i]) ans = "NO";
		}
		System.out.println(ans);
	}
		
}

Measured memory_bytes: 65632
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>

using namespace std;
typedef long long int ll;

ll x,y,a,b,c,res;
vector<ll>red,green,cls;

int main()
{
    cin>>x>>y>>a>>b>>c;
    red.resize(a);
    for(int i=0;i<a;i++)
        cin>>red[i];
    sort(red.begin(),red.end(),greater<ll>());
    green.resize(b);
    for(int i=0;i<b;i++)
        cin>>green[i];
    sort(green.begin(),green.end(),greater<ll>());
    cls.resize(c);
    for(int i=0;i<c;i++)
        cin>>cls[i];
    for(int i=0;i<x;i++)
        cls.push_back(red[i]);
    for(int i=0;i<y;i++)
        cls.push_back(green[i]);
    sort(cls.begin(),cls.end(),greater<ll>());
    res=0;
    for(int i=0;i<(x+y);i++)
        res+=cls[i];
    cout<<res<<endl;
}


Measured memory_bytes: 6000
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cassert>
#include <iostream>
using std::cin; using std::cout; using std::endl;
#include <algorithm>
using std::sort; using std::min; using std::max;
#include <vector>
using std::vector;
#include <set>
using std::set;
#include <queue>
using std::queue; using std::priority_queue;
#include <utility>
using std::pair;
typedef pair<int, int> pii;
typedef long long LL;
typedef long double LD;
#define pass printf("%s : Line.%d\n", __FUNCTION__, __LINE__);
LL ans = 0;
int main() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		LL x; scanf("%lld", &x);
		ans += x - 1;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int N;
    cin >> N;
    int n100, n10, n1;
    n100 = N / 100;
    n10 = (N / 10) % 10;
    n1 = N % 10;

    if (n100 == 7 || n10 == 7 || n1 == 7) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3640
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]

def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)

def main():
    #t=int(input())
    t=1
    for _ in range(t):
        n=int(input())
        st=input()
        #n=len(st)
        red=0
        white=0
        for i in range(n):
            if st[i]=='R':
                red+=1
            else:
                white+=1
        ans=0
        for i in range(red):
            if st[i]=="W":
                ans+=1
        print(ans)








BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()
    #threadin.Thread(target=main).start()


Measured memory_bytes: 87092
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>

using namespace std;

int n, m;
int k[32], a[32][32];
vector<int>V;
int cnt[50];
int answer = 0;

int main(){
  cin >> n >> m;
  
  for(int i = 0; i < n; ++i){
    cin >> k[i];
    //cout << k[i] << endl;
    for(int j = 0; j < k[i]; ++j){
      cin >> a[i][j];
      cnt[a[i][j]]++;
      //cout << a[i][j] << endl;
    }
  }
  for(int i = 0; i < m; ++i){
    if(cnt[i + 1] == n){
      answer++;
    }
  }
  //if(n == 1){
  //  cout << k[0] << endl;
  //}else{
  cout << answer << endl;
  //}
  //cout << n << endl;
  //cout << cnt[5] << endl;
}

Measured memory_bytes: 256