akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair<int,int>
#define FI first
#define SE second
using namespace std;
typedef pair<int,int> pii;
static const int  INF = 1<<24;
static const int dx[] = {1,-1,0,0};
static const int dy[] = {0,0,1,-1};

int h,w;
int fld[1001][1001];
int dp[1001][1001][3][3][2][2];
string s[1001];

int dfs(int x,int y,int pbit,int ppbit,int pv,int ppv){
    if(dp[x][y][pbit][ppbit][pv][ppv]!=0)return dp[x][y][pbit][ppbit][pv][ppv];
    if(x<0||x>=w||y<0||y>=h)return INF;
    if(x==w-1&&y==h-1){
        return 0;
    }
    int res=INF;
    vector<pii> v;
    int p=0;
    if(pv==-1){
        p=fld[y][x];
        for(int i=0;i<4;++i){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx<0||nx>=w||ny<0||ny>=h)continue;
            if(fld[ny][nx])v.PB(pii(dx[i],dy[i]));
        }
    }
    else if(pv==ppv||ppv==-1){
        if(pv&&pbit==2)p=fld[y][x];
        else if(pv==0&&pbit==1)p=fld[y][x];
        for(int i=0;i<4;++i){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx<0||nx>=w||ny<0||ny>=h)continue;
            if(pv){
                if(dx[i]==0&&dy[i]==-1)continue;
                if(fld[ny][nx])v.PB(pii(dx[i],dy[i]));
            }
            else {
                if(dx[i]==-1&&dy[i]==0)continue;
                if(fld[ny][nx])v.PB(pii(dx[i],dy[i]));
            }
        }
    }
    else if(pv!=ppv){
        if(pv&&pbit==2)p=fld[y][x];
        else if(pv==0&&pbit==1)p=fld[y][x];
        for(int i=0;i<4;++i){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx<0||nx>=w||ny<0||ny>=h)continue;
            if(pv){
                if(dx[i]==0&&dy[i]==-1)continue;
                if(dx[i]==-1&&dy[i]==0&&(ppbit==1||ppbit==0))continue;
                if(fld[ny][nx])v.PB(pii(dx[i],dy[i]));
            }
            else {
                if(dx[i]==-1&&dy[i]==0)continue;
                if(dx[i]==0&&dy[i]==-1&&(ppbit==2||ppbit==0))continue;
                if(fld[ny][nx])v.PB(pii(dx[i],dy[i]));
            }
        }
    }
    int sum=0;
    bool b=false;
    for(int i=0;i<v.size();++i){
        int nx=x+v[i].FI,ny=y+v[i].SE;
        sum+=fld[ny][nx];
    }
    if(v.size()==0)res=min(dfs(x+1,y,0,pbit,0,pv)+p,min(dfs(x,y+1,0,pbit,1,pv)+p,res));
    else{
        for(int i=0;i<v.size();++i){
            int nx=x+v[i].FI,ny=y+v[i].SE;
            int u=p+sum-fld[ny][nx];
            if((v[i].FI==-1&&v[i].SE==0)||(v[i].FI==0&&v[i].SE==-1)){
                res=min(dfs(x+1,y,0,pbit,0,pv)+u,min(dfs(x,y+1,0,pbit,1,pv)+u,res));
            }
            else if(v[i].FI==1&&v[i].SE==0){
                res=min(dfs(x+1,y,1,pbit,0,pv)+u,min(dfs(x,y+1,1,pbit,1,pv)+u,res));
            }
            else if(v[i].FI==0&&v[i].SE==1){
                res=min(dfs(x+1,y,2,pbit,0,pv)+u,min(dfs(x,y+1,2,pbit,1,pv)+u,res));
            }
        }
    }
    return dp[x][y][pbit][ppbit][pv][ppv]=res;
}

int main(){
    memset(dp,0,sizeof(dp));
    cin>>h>>w;
    for(int y=0;y<h;++y)cin>>s[y];
    for(int y=0;y<h;++y){
        for(int x=0;x<w;++x){
            if(s[y][x]=='.')fld[y][x]=0;
            else fld[y][x]=s[y][x]-'0';
        }
    }
    cout<<dfs(0,0,0,0,-1,-1)<<endl;
}

Measured memory_bytes: 149300
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    X,Y = map(int,input().split())
    
    ans = 0
    tmp = X
    while tmp <= Y:
        ans += 1
        tmp = tmp * 2
        
    print(ans)
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

const ll MOD = 1000000007;

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

    vector<int> x(n);
    vector<int> y(n);
    vector<int> h(n);

    rep(i, n) cin >> x[i] >> y[i] >> h[i];

    const int MAX = 100;

    // 100x100の範囲で全探索
    rep(i, MAX+1) rep(j, MAX+1) {
        int need_h = -1;
        rep(k, n){
            if ( h[k] > 0 ) {
                int tmp_h = abs(x[k] - i) + abs(y[k] - j) + h[k];
                if ( need_h == -1 ) need_h = tmp_h;
                else if ( need_h != tmp_h ) {
                    need_h = -2;
                    break;
                }
            }
        }
        if ( need_h == -2 ) continue;
        rep(k, n) {
            if ( h[k] == 0 ){
                int dist = abs(x[k] - i) + abs(y[k] - j);
                if ( need_h > dist ) {
                    need_h = -2;
                    break;
                }
            }
        }
        if ( need_h == -2 ) continue;
        printf("%d %d %d", i, j, need_h);
        return 0;
    }
}

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

using namespace std;

struct sushi_t {
  int d;
  int t;
};

static int n, k;
static std::array<sushi_t, 100000> sushis{};
static std::array<int, 100001> worstSushis{0};
static std::array<int, 100000> replaceables{};
static std::array<int, 100000> replacements{};

int64_t solve() {
  int64_t ret0 = 0;
  int64_t nn = 0;
  int replaceableIdx = 0;
  int i = 0;
  for (; i < k; ++i) {
    const auto& s = sushis[i];
    int const prev = worstSushis[s.t];
    worstSushis[s.t] = i + 1;
    ret0 += int64_t(s.d);
    if (prev <= 0) {
      nn++;
    } else {
      replaceables[replaceableIdx++] = i;
    }
  }
  int64_t ret = ret0 + nn * nn;
  int replacementIdx = 0;
  for (; i < n; ++i) {
    const auto& s = sushis[i];
    int const prev = worstSushis[s.t];
    worstSushis[s.t] = i + 1;
    if (prev <= 0) {
      replacements[replacementIdx++] = i;
    }
  }

  int const replacementSize = replacementIdx;
  replaceableIdx--;
  replacementIdx = 0;
  for (++nn; nn <= k && replaceableIdx >= 0 && replacementIdx < replacementSize;
       ++nn, --replaceableIdx, ++replacementIdx) {
    ret0 -= int64_t(sushis[replaceables[replaceableIdx]].d);
    ret0 += int64_t(sushis[replacements[replacementIdx]].d);
    if (ret0 + int64_t(k) * int64_t(k) <= ret) {
      break;
    }
    ret = std::max(ret0 + nn * nn, ret);
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    auto& s = sushis[i];
    std::cin >> s.t >> s.d;
    s.t--;
  }
  std::sort(sushis.begin(), sushis.begin() + n,
            [](const auto& lhs, const auto& rhs) { return lhs.d > rhs.d; });
  std::cout << solve() << std::endl;
  return 0;
}


Measured memory_bytes: 1664
import sys
input = sys.stdin.readline

k,n=map(int,input().split())
a=[int(x) for x in input().split()]
a.sort()
mini=a[n-1]-a[0]
for i in range(n):
    if 0<i<n-1:
        mini=min(mini,min(abs(a[i]-a[i+1]+k)%k,(a[(i-1)%n]-a[i]+k)%k))
    else:
        if i==0:
            mini=min(mini,a[i]-a[i+1]+k)
        else:
            mini=min(mini,a[i-1]-a[i]+k)
print(mini)    


Measured memory_bytes: 72268
#include <iostream>
#include <vector>

using namespace std;
const vector<int> v{1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25};

int main() {
    string n;
    getline(cin, n);

    for (int count = 0; count < stoi(n); count++) {
        string s;
        getline(cin, s);

        bool finished = false;
        for (auto alpha:v) {
            vector<int> conv(26);
            for (int beta = 0; !finished && beta < 26; beta++) {
                for (int c = 0; c < 26; c++) {
                    int x = alpha * c + beta;
                    conv[x % 26] = c;
                }

                string after = s;
                for (int i = 0; i < s.size(); i++) {
                    if (after[i] == ' ')continue;
                    after[i] = conv[after[i] - 'a'] + 'a';
                }

                bool found = false;
                for (int i = 0; i < after.size() - 3; i++) {
                    string now = after.substr(i, 4);
                    if (now == "that" || now == "this")found = true;
                }
                if (found) {
                    cout << after << endl;
                    finished = true;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗
// GCD, LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
template<typename T>
vector<T> smallest_prime_factors(T n) {

    vector<T> spf(n + 1);
    for (int i = 0; i <= n; i++) spf[i] = i;


    for (T i = 2; i * i <= n; i++) {

        // 素数だったら
        if (spf[i] == i) {

            for (T j = i * i; j <= n; j += i) {

                // iを持つ整数かつまだ素数が決まっていないなら
                if (spf[j] == j) {
                    spf[j] = i;
                }
            }
        }
    }

    return spf;
}

int main() {
    int n;
    cin >> n;
    Vi v(n);
    rep(i,n) cin >> v[i];
    Vi prime(2000001,0);
    rrep(i,2,1000001){
        if(prime[i]!=0) continue;
        ll x=2*i;
        while(x<=1000000){
            
            prime[x]=1;
            x+=i;
        }
    }
    Vi cnt(1000001,0);
    auto spf = smallest_prime_factors(2000000);
    rep(i,n){
        int x=v[i];
        while(x!=1){
            int a=spf[x];
            cnt[a]++;
            while(x%a==0){
                x/=a;
            }
        }
    }
    bool b=1;
    rrep(i,2,1000001){
        if((!prime[i])&&cnt[i]>=2) b=0;
    }
    if(b){
        cout << "pairwise coprime" << endl;
        return 0;
    }
    ll g=v[0];
    rep(i,n) g=gcd(g,v[i]);
    if(g==1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;

}

Measured memory_bytes: 26720
#include<iostream>
using namespace std;
int n,a,b;
int cur;
void go(int k){
	for(int i=cur-k+1; i<=cur ;i++) cout << i << ' ';
	cur-=k;
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> a >> b;
	if(1LL*a*b<n || a+b>n+1){
		cout << "-1\n";
		return 0;
	}
	if(b==1){
		for(int i=1; i<=n ;i++) cout << i << ' ';
		cout << endl;
		return 0;
	}
	int num1=(n-a)/(b-1);
	int num2=(n-a)%(b-1);
	cur=n;
	go(a);
	for(int i=1; i<=num2 ;i++){
		go(num1+1);
	}
	for(int i=num2+1; i<=b-1 ;i++){
		go(num1);
	}
	cout << endl;
}

Measured memory_bytes: 2176
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final Scanner sc  = new Scanner(System.in);
    static final int MOD = (int) 1E9 + 7;
    static final int INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        char[] S = nchars();
        for (int i = 0; i < S.length; i++) {
            if (i % 2 == 0 && S[i] == 'L') { //奇数文字目
                System.out.println("No");
                return;
            }
            if (i % 2 == 1 && S[i] == 'R') {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
    
    
    private static int nint() {
        return sc.nextInt();
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static double ndouble() {
        return sc.nextDouble();
    }
    
    private static double[] ndoubles(int n) {
        return ndoubles(n, 0, 0);
    }
    
    private static double[] ndoubles(int n, int padL, int padR) {
        double[] d = new double[n + padL + padR];
        for (int i = 0; i < n; i++) {
            d[padL + i] = ndouble();
        }
        return d;
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }
    
    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0, 0);
    }

    private static char[][] nchars2(int h, int w, int padLU, int padRD) {
        char[][] a2 = new char[h + padLU + padRD][w + padLU + padRD];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[padLU + i], padLU, w);
        return a2;
    }
    
    private static long min(long... ls) {
        return Arrays.stream(ls).min().getAsLong();
    }
    
    private static long max(long... ls) {
        return Arrays.stream(ls).max().getAsLong();
    }
    
    private static long abs(long a, long b) {
        return Math.abs(a - b);
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
main(x,y,t){ for(;scanf("%d%d",&x,&y),x;){ int cnt=0; if(x<y) t=x,x=y,y=t; do{ x%=y; t=x,x=y,y=t; cnt++; }while(y); printf("%d %d\n",x,cnt); } exit(0); } 


Measured memory_bytes: 2040
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

    bool contain = false;
    for(int i = 0; i < s.size(); i ++){
        if(s[i] == '7'){
            contain = true;
        }
    }

    if(contain){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

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

  cout << max(A+B, max(A-B, A*B)) << endl;
  return 0;
}


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

// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std

Jehian Norman Saviero;

// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;

// MACROS FOR ATTRIBUTE
#define fi first
#define se second

// MACROS FOR FUNCTION AND METHOD
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define RESET(x) memset((x), 0, sizeof(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define ALL(x) (x).begin(), (x).end()
#define ALLSIZE(x,n) (x), (x)+(n)
#define SQR(x) ((x)*(x))
#define CUBE(x) (SQR(x)*(x))

// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

string ADD(string A, ll x){
	ll curr = 0;
	for (auto& x : A){
		curr *= 26;
		curr += x - 'A' + 1;
	}
	curr += x;
	string ans = "";
	while (curr){
		ans.pb(curr % 26 + 'A' + 1);
		curr /= 26;
	}
	reverse(ALL(ans));
	return ans;
}

int main(){
	ll N;
	scll(N);
	ll add = N/1000;
	if (add){
		puts("ABD");
	} else {
		puts("ABC");
	}
	return 0;
}

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

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

    long long int ans=0;
    int len;
    len = S.size();

    for (int i=0; i<(1<<(len-1)); ++i) {
        int pos = 0;
        for (int j=0; j<(len-1); ++j) {
            if (i >> j & 1) {
                ans += stoll(S.substr(pos,j+1-pos));
                pos = j + 1;
            }
        }
        ans += stoll(S.substr(pos,len-pos));
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#define PB push_back
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define MOD 1000000007;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n {}, d {};
    cin >> n >> d;

    if (n >= 10) cout<<d<<endl;
    else {
    	cout<<d+(100)*(10-n)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n,t=map(int,input().split())
A=[]
for i in range(n):
    A.append(list(map(int,input().split())))

mic=1001
for i in range(n):
    if A[i][1]<=t :
        mic=min(mic,A[i][0])

if mic<1001 :
    print(mic)
else:
    print("TLE")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
/* 答えをにぶたんで狭めていく系 */

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

const int MAX = 2000005;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

int x, y;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    cin >> x >> y;
    COMinit();
    int a = 0;   /* (1, 2) */
    int b = 0;     /* (2, 1) */

    if((2*y-x) % 3 != 0) {
        cout << "0" << endl;
        return 0;
    } else {
        a = (2*y - x) / 3;
    }

    if((2*x - y) % 3 != 0) {
        cout << "0" << endl;
        return 0;
    } else {
        b = (2*x - y) / 3;
    }

    
    cout << COM(a+b, b) << endl;
    
    return 0;
}


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




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

  int64_t g=0;
  for(int i=0;i<(1<<f-1);i++)
  {
  bitset<10>df(i);
    int64_t b=0;
    for(int j=0;j<f;j++)
  {
  
    
  if(df.test(j))
  {
  b=b*10+s.at(j)-'0';
  g=g+b;  
  b=0;
  }
  else 
  {
  b=b*10+s.at(j)-'0';
  }
  
    
    
  
  }
 
  g=g+b;  
}
  cout<<g;
}



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

using namespace std;

int T, N, K[200005];
long long int L[200005], R[200005];

int ST[800005];
 int M = 1LL << 18;

void UPDATE(int k, int val) {
	ST[k + M] = val;

	int p = (k + M) / 2;

	while (p >=1) {
		if (ST[p * 2] >= ST[p * 2 + 1]) { ST[p] = ST[p * 2]; }
		else { ST[p] = ST[p * 2 + 1]; }
		p /= 2;
	}

}

int Q(int a, int b, int l, int r, int k) {
	if (b < l || r < a) { return 0; }

	if (a<=l && r<=b) { return ST[k]; }

	int tmp1 = Q(a, b, l, (l + r) / 2, k * 2);
	int tmp2 = Q(a, b, (l + r) / 2 + 1, r, k * 2 + 1);

	if (tmp1 >= tmp2) { return tmp1; }

	return tmp2;
}


vector<pair<long long int,int>  > V;

int main(void) {

	cin >> T;

	for (int t = 1; t <= T; t++) {

		cin >> N;
		for (int i = 1; i <= N; i++) {
			cin >> K[i] >> L[i] >> R[i];
		}

		long long int sum = 0;
		int num;
		//====
		num = 0; V.clear();
		for (int i = 1; i <= N; i++) {
			if (L[i] >= R[i]) { V.push_back(make_pair(L[i] - R[i], K[i])); sum += R[i]; }
		}

		//cout << "sum= " << sum << endl;
		sort(V.rbegin(), V.rend());

		/*cout << "V" << endl;
		for (auto y : V) {
			cout << y.first << " " << y.second << endl;
		}*/

		num = V.size();
		for (int j = 1; j <= num; j++) { UPDATE(j, j); }

		for (int j = 0; j < num; j++) {
			long long int delta = V[j].first;
			int K = V[j].second;

			int pos = Q(1, min(K,num), 0, M-1, 1);
			//cout << "pos= " << pos << endl;
			if (1<=pos && pos <= K) {
				sum += delta; //cout << "sum= " << sum << endl;
				UPDATE(pos, 0);
			}
			else {
				pos = Q(1, num, 0, M - 1, 1);
				UPDATE(pos, 0);
			}
		}
		//=====
		//cout << "sum= " << sum << endl;
		num = 0; V.clear();
		for (int i = 1; i <= N; i++) {
			if (L[i] < R[i]) { V.push_back(make_pair(R[i] - L[i], N - K[i])); sum += L[i]; }
		}

		//cout << "sum= " << sum << endl;

		sort(V.rbegin(), V.rend());

		/*cout << "V" << endl;
		for (auto y: V) {
			cout << y.first << " " << y.second << endl;
		}*/

		num = V.size();
		for (int j = 1; j <= num; j++) { UPDATE(j, j); }

		for (int j = 0; j < num; j++) {
			long long int delta = V[j].first;
			int K = V[j].second;

			int pos = Q(1, min(K,num), 0, M - 1, 1);

			if (1 <= pos && pos <= K) {
				sum += delta;
				UPDATE(pos, 0);
			}
			else {
				pos = Q(1, num, 0, M - 1, 1);
				UPDATE(pos, 0);
			}
		}
		//==---

		cout << sum << endl;

	}


	
	return 0;
}

Measured memory_bytes: 9692
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
    int k = inputValue();
  int x = inputValue();
  int min = (x - k + 1);
  int max = (x + k - 1);
  repd(i,min,max + 1)
  {
    cout << i;
    cout << " ";
  }
    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<cmath>

using namespace std;
#define REP(i,m,n) for(int i=m;i<n;++i)
#define REPll(i,m,n) for(ll i=m;i<n;++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

int main() {
	int n, k, ans = 0;
	cin >> n >> k;
	int hoge = 0;
	REP(i, 0, n) {
		int tmp;
		cin >> tmp;
		if (tmp == 1) {
			hoge = i;
		}
	}
	k--;
	n--;
	ans = (n + k - 1) / k;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    int n,m,x;
    int a[111],k[111];
    cin>>n>>m>>x;
    int ans=0,ans2=0;
    for(int i=0;i<=n;i++)k[i]=i;
    for(int i=0;i<m;i++)cin>>a[i];
    for(int i=x;i<n;i++){
        for(int j=0;j<m;j++){
            if(k[i]==a[j])ans++;
        }
    }
    for(int i=x;i>0;i--){
        for(int j=0;j<m;j++){
            if(k[i]==a[j])ans2++;
        }
    }
    cout<<min(ans,ans2)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int maximumRectangule(int h, int w, char m[505][505]){
    int c[505][505] = {{0}};
    rep(i,w){
        int cnt = 0;
        rep(j,h){
            if(m[j][i] == '.'){
                cnt++;
                c[j][i] = cnt;
            }else{
                cnt = 0;
            }
        }
    }
    rep(i,h) c[i][w] = 0;

    int ans = 0;
    rep(i,h){
        vector<pair<int, int>> v; //height, pos
        rep(j,w + 1){
            if(v.empty()) v.emplace_back(c[i][j],j);
            else{
                if(v.back().first < c[i][j]) v.emplace_back(c[i][j],j);
                else{
                    int target = j;
                    while(not v.empty() && v.back().first >= c[i][j]){
                        ans = max(ans, v.back().first * (j - v.back().second));
                        target = v.back().second;
                        v.pop_back();
                    }
                    v.emplace_back(c[i][j],target);
                }
            }
        }
    }
    return ans;
}

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

        char m[505][505];
        rep(i,h) rep(j,w) cin >> m[i][j];

        cout << maximumRectangule(h,w,m) << endl;
    }
}

Measured memory_bytes: 4236
n = int(input())
tmp = 1
 
for i in range(1,10**6+1): #10**12とかにしてしまうとTLE　
  #たとえばn=2*大きい素数である時を考えると，この時は全回ししてまう
  if n%i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif tmp == 1 and i >= n/i:
    break
      
print(tmp + (n//tmp) -2)

Measured memory_bytes: 3060
A, B = map(int, input().split())

def isOK(num):
    tax8 = num * 8 // 100
    tax10 = num * 10 // 100
    if tax8 == A and tax10 == B:
        return True
    else:
        return False

for i in range(1, 100001):
    if isOK(i):
        print(i)
        break
else:
    print(-1)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;

int main()
{
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
    for(int i=0; i<N; i++){
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    int ans=h[K-1]-h[0];
    for(int i=0; i<=N-K; i++){
        ans=min(ans, h[K-1+i]-h[i]);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 640
N,X,Y = map(int, input().split())

ans = [0]*N
for i in range(1, N+1):
    for j in range(i+1, N+1):
        d = min(j-i, abs(i-X)+1+abs(j-Y))
        ans[d] += 1

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

Measured memory_bytes: 3444
#include <iostream>

using namespace std;

int main() {
  int x1, x2, x3, x4, x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;

  int ans = -1;
  if (x1 == 0) { ans = 1; }
  if (x2 == 0) { ans = 2; }
  if (x3 == 0) { ans = 3; }
  if (x4 == 0) { ans = 4; }
  if (x5 == 0) { ans = 5; }

  cout << ans << endl;
}


Measured memory_bytes: 3564
# -*- coding: utf-8 -*-

def solve(N, A):
    a_max = max(A)
    a_min = min(A)
    res = float("INF")
    for i in range(a_min, a_max+1, 1):
        sum = 0
        for j in range(N):
            sum += (A[j] - i)**2
        res = min(res, sum)
    print(res)
    
if __name__ == '__main__':
    N = int(input())
    A = [int(a) for a in input().split()]
    
    solve(N, A)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
	char arr[2][3];
	scanf("%s",arr[0]);
	scanf("%s",arr[1]);
	int left=strlen(arr[1])-1;
	int boolean=0;
	for(int i=0;i<3;i++)
	{
		if(arr[0][i]!=arr[1][left])
		{
			printf("NO");
			boolean=1;
			break;
		}
		left--;
	}
	if(boolean==0)
	{
		printf("YES");
	}
	return 0;
}

Measured memory_bytes: 128
using System;

namespace tes
{
    class Program
    {
        public static void Main()
        {
            String str = Console.ReadLine();
            String[] num = str.Split();
            if (int.Parse(num[1]) > int.Parse(num[0]) && int.Parse(num[1]) < int.Parse(num[2]))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 5296
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int ht[n+1]={0};
	for(int i=1;i<=n;i++)
		cin>>ht[i];
	vector<int> dp(n+2,1e9);
	dp[1]=0;
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(i-j>0)
				dp[i]=min(dp[i],abs(ht[i]-ht[i-j])+dp[i-j]);
		}
	}
	cout<<dp[n];
}


Measured memory_bytes: 4032
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#pragma warning(disable:4996)
int main(){
	int n = 0;
	int arr[105][105] = { 0 };
	scanf("%d", &n);
	for (int m = 0; m < n; m++){
		int a = 0;
		int b = 0;
		scanf("%d %d", &a, &b);
		for (int x = 0; x < b; x++){
			int c = 0;
			scanf("%d", &c);
			getchar();
			arr[a - 1][c - 1] = 1;
		}
	}
	for (int m = 0; m < n; m++){
		for (int o = 0; o < n-1; o++){
			printf("%d ", arr[m][o]);
		}
		printf("%d", arr[m][n-1]);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n,maxval=0,currval = 0;
    cin>>n;
    ll a[n];
    cin>>a[0];
    for(int i = 1 ; i < n ; ++i){
    	cin>>a[i];
    	if(a[i] <= a[i-1]) currval++;
    	else currval = 0;
    	if(currval > maxval) maxval = currval;
    }
    cout<<maxval<<endl;
    return 0;
}

Measured memory_bytes: 1152
n=int(input())
l=[0]*(10**4+1)
for x in range(1,100):
    for y in range(x,100):
        for z in range(y,100):
            t=x*x+y*y+z*z+x*y+y*z+z*x
            if t<=10**4:
                if (x!=y) and y!=z:
                    l[t]+=6
                elif x==y and y==z:
                    l[t]+=1
                else:
                    l[t]+=3
for i in range(1,n+1):
    print(l[i])

Measured memory_bytes: 69532
import java.util.Hashtable;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		Hashtable<String, int[]> card = new Hashtable<String, int[]>();

		String[] priority = {"S", "H", "C", "D"};

		int[] s = new int[13];
		card.put("S", s);
		int[] h = new int[13];
		card.put("H", h);
		int[] c = new int[13];
		card.put("C", c);
		int[] d = new int[13];
		card.put("D", d);

		for(int i = 0; i < n; i++) {
			String name = scan.next();
			int value = scan.nextInt();
			card.get(name)[value - 1] = -1;
		}

		for(int i = 0; i < 4; i++) {
			for(int j = 0; j < 13; j++) {
				if(card.get(priority[i])[j] == 0) {
					System.out.println(priority[i] + " " + (j + 1));
				}
			}
		}

		scan.close();
	}
}


Measured memory_bytes: 26384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Card {
  String suit;
  int value;
  int storedNo;

  public Card( String suit, int value, int storedNo ) {
    this.suit  = suit;
    this.value = value;
    this.storedNo = storedNo;
  }
  public Card( Card card ) {
    this(card.suit, card.value, card.storedNo);
  }

  @Override
  public String toString() {
    return suit + String.valueOf(value);
  }
}

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      Card[][] cards = new Card[3][n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++) {
        cards[0][i] = new Card(
          line[i].substring(0, 1),
          Integer.parseInt(line[i].substring(1)),
          i );
        cards[1][i] = new Card(cards[0][i]);
        cards[2][i] = new Card(cards[0][i]);
      }

      bubbleSort(cards[1], n);
      dispIntArray(cards[1]);
      System.out.println(isStableSorted(cards[0], cards[1], n) ? "Stable" : "Not stable");
      selectionSort(cards[2], n);
      dispIntArray(cards[2]);
      System.out.println(isStableSorted(cards[0], cards[2], n) ? "Stable" : "Not stable");
    }
  }

  static int bubbleSort(Card[] a, int n) {
    int count=0;
    Card t;

    for(int i=0,f=1; f==1 || i<n; i++ ) {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j].value < a[j-1].value) {
          t = a[j]; a[j] = a[j-1]; a[j-1] = t;
          count++;
          f=1;
        }
      }
    }

    return count;
  }

  static int selectionSort(Card a[], int n) {
    int count = 0;
    Card t;

    for(int i=0,min; i<n-1; i++ ) {
      min = i;
      for(int j=i+1; j<n; j++ ) {
        if( a[min].value > a[j].value) min = j;
      }
      if( min != i ) {
        t = a[i]; a[i] = a[min]; a[min] = t;
        count++;
      }
    }

    return count;
  }

  static boolean isStableSorted(Card[] origin, Card[] sorted, int n) {
    boolean ret = true;

    for (int i=0, max=n-1; i < max; i++) {
      if( sorted[i].value == sorted[i+1].value
        && sorted[i].storedNo > sorted[i+1].storedNo )
        ret = false;
    }

    return ret;
  }

  public static void dispIntArray(Card[] a) {
    StringBuilder s = new StringBuilder();

    for (Card c : a) { s.append(c.toString()).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 24288
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;


  cout<<min(a,b)+min(c,d)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
int n,m;
vector<int> G[1501];
vector<int> rG[1501];
vector<int> vs;
vector<int> Group[1501];
bool used[1501];
int cmp[1501];
vector<int> rGroup[1501];
ll dp[1501][2];

void dfs(int v){
	used[v]=true;
	for(int i=0;i<G[v].size();i++){
		if(!used[G[v][i]])dfs(G[v][i]);
	}
	vs.push_back(v);
}

int ddfs(int v){
	used[v]=true;
	int res=cmp[v];
	for(int i=0;i<G[v].size();i++){
		if(!used[G[v][i]])res=max(ddfs(G[v][i]),res);
	}
	for(int i=0;i<rG[v].size();i++){
		if(!used[rG[v][i]])res=max(ddfs(rG[v][i]),res);
	}
	return res;
}

void rdfs(int v,int k){
	used[v]=true;
	cmp[v]=k;
	Group[k].push_back(v);
	for(int i=0;i<rG[v].size();i++){
		if(!used[rG[v][i]])rdfs(rG[v][i],k);
	}
}

int scc(){
	memset(used,false,sizeof(used));
	vs.clear();
	for(int v=0;v<n;v++){
		if(!used[v])dfs(v);
	}
	memset(used,false,sizeof(used));
	int k=0;
	for(int i=vs.size()-1;i>=0;i--){
		if(!used[vs[i]])rdfs(vs[i],k++);
	}
	return k;
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		f--;
		t--;
		G[f].push_back(t);
		rG[t].push_back(f);
	}
	int k=scc();
	for(int i=0;i<n;i++){
		for(int j=0;j<rG[i].size();j++){
			if(cmp[i]!=cmp[rG[i][j]])rGroup[cmp[i]].push_back(cmp[rG[i][j]]);
		}
	}
	for(int i=0;i<k;i++){
		dp[i][0]=1;
		dp[i][1]=1;
		for(int j=0;j<rGroup[i].size();j++){
			int u=rGroup[i][j];
			dp[i][1]=(dp[i][1]*((dp[u][0]+dp[u][1])%MOD))%MOD;
		}
	}
	memset(used,false,sizeof(used));
	ll res=1;
	for(int i=0;i<k;i++){
		for(int j=0;j<Group[i].size();j++){
			if(!used[Group[i][j]]){
				int b=ddfs(Group[i][j]);
				res=(res*((dp[b][0]+dp[b][1])%MOD))%MOD;
			}
		}
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 1324
#include <stdio.h>
int main(){
    int n,m;
    while(scanf("%d %d",&n,&m)!=EOF){
        while(1){
            if(n>m){
                int t=m;
                m=n;
                n=t;
            }
            m%=n;
            if(m==0){
                printf("%d\n",n);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int N, M, R;
int r[8];
int dp[8][1<<8];
int d[200][200];

int main() {
	cin >> N >> M >> R;
	REP(i, R) scanf("%d", r + i), r[i]--;
	
	fill(d[0], d[N], INF);
	REP(i, M) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		a--; b--;
		chmin(d[a][b], c);
		chmin(d[b][a], c);
	}
	REP(i, N) d[i][i] = 0;
	
	REP(k, N) REP(i, N) REP(j, N) chmin(d[i][j], d[i][k] + d[k][j]);
	
	fill(dp[0], dp[R], INF);
	REP(i, R) dp[i][1<<i] = 0;
	
	REP(i, 1<<R) {
		REP(j, R) {
			if (dp[j][i] == INF) continue;
			
			REP(k, R) chmin(dp[k][i | (1<<k)], dp[j][i] + d[r[j]][r[k]]);
		}
	}
	
	int ans = INF;
	REP(i, R) chmin(ans, dp[i][(1<<R)-1]);
	cout << ans << endl;
		
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
int sum[2000][2000];
int calc(int x1, int y1, int x2, int y2) {
	if (x1 > x2 || y1 > y2) return 0;
	int ret = sum[x2][y2];
	if (x1 > 0) ret -= sum[x1 - 1][y2];
	if (y1 > 0) ret -= sum[x2][y1 - 1];
	if (x1 > 0 && y1 > 0) ret += sum[x1 - 1][y1 - 1];
	return ret;
}
int main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		int x, y;
		string c;
		cin >> x >> y >> c;
		if (c == "W") y += K;
		sum[x % (2 * K)][y % (2 * K)]++;
	}
	for (int i = 0; i < 2 * K; i++) {
		for (int j = 0; j < 2 * K; j++) {
			if (j > 0) sum[i][j] += sum[i][j - 1];
		}
	}
	for (int i = 1; i < 2 * K; i++) {
		for (int j = 0; j < 2 * K; j++) {
			sum[i][j] += sum[i - 1][j];
		}
	}
	int ans = 0;
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			int tmp = calc(0, 0, i - 1, j - 1) + calc(i + K, 0, 2 * K - 1, j - 1) + calc(i, j, i + K - 1, j + K - 1) + calc(0, j + K, i - 1, 2 * K - 1) + calc(i + K, j + K, 2 * K - 1, 2 * K - 1);
			ans = max(ans, max(tmp, N - tmp));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 16000
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
using namespace std;
using ll = long long;
int main(){
    int n; cin >> n;
    int h[n]; cinf(n,h);
    int ans=h[0];
    for(int i=0;i<n-1;i++){
        if(h[i+1]-h[i]>0) ans+=h[i+1]-h[i];
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = 1LL<<59;
static const long long MOD = (ll)1e9+7;

#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i, n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}

void solve() {
    str S;
    cin >> S;
    ll n = S.size();
    ll ans = n * (n - 1) / 2 + 1;
    map<char, ll> mp;
    REP(i, n) {
        mp[S[i]]++;
    }
    for(auto &p:mp) {
        ll m = p.second;
        ans -= m * (m - 1) / 2;
    }
    out(ans);
}

int main() {
    fast_io;
    solve();
    return 0;
}


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

int main(void) {
	char letter[3];
	char buf[256];

	fgets(buf, sizeof(buf), stdin);
	letter[0] = *strtok(buf, " ");
	letter[1] = *strtok(NULL , " ");
	letter[2] = *strtok(NULL , " ");

	printf("%c%c%c\n", letter[0], letter[1], letter[2]);

	return 0;
}


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

int main(){
    int n,syurui=0,x=0,j=0;
    cin>>n;
    vector<string>keihin(n);
    
    for(int i=0;i<n;i++){
        cin>>keihin.at(i);
    }

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

    while(j<n){
       for(int i=x;i<n;i++){
            if(keihin.at(x)==keihin.at(i)){
                j++;
            }else{
                x=i;
                break;
            }
        }
        syurui++;
    }
   
    cout<<syurui<<endl;
}

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

#define BeatMeScanf    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tc(x)          int x; cin >> x; while(x--)
#define ll             long long
#define vi             vector<int>
#define pii            pair<int,int>
#define mii            map<int,int>
#define inf            1<<28
#define mem(x,y)       memset(x, y, sizeof(x))
#define ps(x,y)        fixed<<setprecision(y)<<x
#define show(val)      cout<< #val << " -> " << val << endl
#define Case           cout<< "Case "<< ++cs << ": "
#define all(v)         (v).begin(), (v).end()
#define rall(v)        (v).rbegin(), (v).rend()
#define mod            1000000007
double arr[1001];

int main()
{
    BeatMeScanf;
    int n, m, cnt=0, sum = 0;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
    {
        cin >> arr[i];
        sum += arr[i];
    }
    
    double temp = (sum/(4.00*m));

    for (int i = 0; i < n; ++i)
    {
        if(arr[i] <  temp) cnt++;
    }

    if((n-cnt)>=m) cout<< "Yes" <<'\n';
    else cout<< "No" <<'\n';
    return 0;
}


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

int main() {
	ll n;
	cin >> n;
	string s;
	cin >> s;
	
	ll res = 0;
	
	for(ll i = 0; i < n-2; i++){
	    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
	        res++;
	    }
	}
	
	cout << res << endl;
	return 0;
}

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

void solve(int64_t X, int64_t K, int64_t D)
{
    X = abs(X);
    if (K <= X / D)
    {
        cout << X - K * D << endl;
        return;
    }
    int64_t q = X / D;
    int64_t r = X % D;
    if ((K - q) % 2 == 0)
        cout << r << endl;
    else
        cout << D - r << endl;
}

int main()
{
    int64_t X;
    cin >> X;
    int64_t K;
    cin >> K;
    int64_t D;
    cin >> D;
    solve(X, K, D);
    return 0;
}


Measured memory_bytes: 3632
n = int(input())
ans = 1
max_count = 0
for i in range(1, n + 1):
    j = i
    count = 0
    while i % 2 == 0 and i > 0:
        count += 1
        if count > max_count:
            ans = j
            max_count = count
            break
        i =  i / 2
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

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

	int A, B;

	int a = 1;
	int b = 1;
	rep(i, N) {
		cin >> A >> B;

		while (a % A) a++;
		while (b % B) b++;
		
		if (b < a / A * B) b = a / A * B;
		if (a < b / B * A) a = b / B * A;
	}
	cout << a + b << endl;

	return 0;
}


Measured memory_bytes: 256
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.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Coer
 */
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);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            String t = in.next();
            int n = s.length();
            int m = t.length();
            int[][] dp = new int[n + 1][m + 1];
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if (s.charAt(i - 1) == t.charAt(j - 1)) {
                        dp[i][j] = dp[i - 1][j - 1] + 1;
                    } else {
                        dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                    }
                }
            }
            char[] res = new char[dp[n][m]];
            int i = n, j = m;
            while (dp[i][j] > 0) {
                if (s.charAt(i - 1) == t.charAt(j - 1)) {
                    res[dp[i][j] - 1] = s.charAt(i - 1);
                    i--;
                    j--;
                } else {
                    if (dp[i][j] == dp[i - 1][j]) {
                        i--;
                    } else {
                        j--;
                    }
                }
            }
            for (char c : res) {
                out.print(c);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}

Measured memory_bytes: 81260
N = int(input())
s = list(input())
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = r * g * b
for i in range(N):
    for j in range(i+1,N):
        if len(s) <= 2*j-i:
            break;
        k = s[2*j-i]
        if (k != s[i]) and (k !=s[j]) and (s[i] != s[j]):
            ans -= 1
print(ans)

Measured memory_bytes: 68480