akhauriyash/Code-Regression huggingface dataset:
/*
	|\    /|        |       |
	| \  / |  ____  |___  . |
	|  \/  | |    | |   | | |_
	|	   | |    | |   | | |
	|	   | |____| |   | | |____|

*/


#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;

string str;

int main()
{
	IOS;
	cin>>str;
	ll ans=0;
	ll count=0;
	forn(i,str.size()){
		if(str[i]=='B')
			count++;
		else
			ans+=count;
	}
	cout<<ans<<ln;
}

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

#define pb push_back
#define int ll

using ll=long long;
using pii=pair<int,int>;
using vpii=vector<pii>;
using vvpii=vector<vpii>;
using vi=vector<int>;
using vvi=vector<vi>;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const ll INF = 1e17;
// https://atcoder.jp/contests/abc143/submissions/8034843

int main() {
    // input
    int N;
    cin >> N;

    for (int i=1; i<10; i++)
    {
        for(int j=1; j<10; j++)
        {
            if (i*j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


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

int main(){
  string str;

  getline(cin,str);

  for(int i=0;i<(int)str.size();i++){
      if( islower(str[i]) ){
	str[i]=toupper(str[i]);
      }
      else if( isupper(str[i]) ){
	str[i]=tolower(str[i]);
      }

    }
  cout<<str<<endl;
  return 0;
}


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

int r, c, n;

vector<pair<int, int> > cac;
int cnt[100005];
//int cc=0;

void check(int x, int y, int t)
{
	if(x==0)
	{
		cac.emplace_back(y, t);
	}
	else if(y==c)
	{
		cac.emplace_back(c+x, t);
	}
	else if(x==r)
	{
		cac.emplace_back(r+c+c-y, t);
	}
	else
	{
		cac.emplace_back(r+c+c+r-x, t);
	}
}

signed main()
{
	cin>>r>>c>>n;
	for(int i=1; i<=n; i++)
	{
		int x,y,xx,yy;
		cin>>x>>y>>xx>>yy;
		if((x==0||x==r||y==0||y==c)&&(xx==0||xx==r||yy==0||yy==c))
		{
			check(x, y, i);
			check(xx, yy, i);
		}
	}
//	cout<<cac.size();
	sort(cac.begin(), cac.end());
	stack<int> yo;
	for(auto i:cac)
	{
//		cout<<i.first<<" "<<i.second<<endl;
		if(cnt[i.second]==1)
		{
			if(yo.top()!=i.second)
			{
				cout<<"NO";
				return 0;
			}
			else
			{
				yo.pop();
			}
		}
		else
		{
			cnt[i.second]++;
			yo.push(i.second);
		}
	}
	cout<<"YES";
}

Measured memory_bytes: 6384
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  var a,v= sc.nextLong()
  var b,w= sc.nextLong()
  var t= sc.nextLong()
  var av = BigInt(a+(v*t))
  var bw = BigInt(b+(w*t))
  if (a < b) {
    print(if (av >= bw) "YES" else "NO")
  }else{
    print(if (a-(v*t) <= (b-(w*t))) "YES" else "NO")
  }
}


Measured memory_bytes: 55352
#include<stdio.h>
#include<string.h>
int main() {
	char str[200005];
	int s[3] = {};
	scanf("%s", str);
	int a = strlen(str);
	for (int i = 0; i < a; i++) {
		if (str[i] == 'a') {
			s[0]++;
		}
		else if(str[i]=='b'){
			s[1]++;
		}
		else {
			s[2]++;
		}

		
	}
	int x = s[0] - s[1];
	int y = s[1] - s[2];
	int z = s[2] - s[0];
	if ((x == 1 || x == 0 || x == -1) && (y == 1 || y == 0 || y == -1) && (z == 1 || z == 0 || z == -1)) {
		printf("YES");
		return 0;
	}
	printf("NO");
}

Measured memory_bytes: 256
import random
import time

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum = sum + c[i]*(d-last_d[i])
        
    return int(score - sum)


def main():
    D = int(input())

    c = list(map(int, input().split()))

    s = [list(map(int, input().split())) for i in range(D)]

    start = time.time()
    
    last_d = [0 for i in range(26)]
    
    ans = []
    
    score1 = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
                max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
                idx = j
            elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2:
                idx = j
            
        last_d[idx] = i+1
        score1 += s[i][j]
        score1 = down_score(i+1,c,last_d,score1)
        
        ans.append(idx)

    random.seed(0)
    while time.time() - start < 1.9:
        idx = random.randint(0,25)
        d = random.randint(0,D-1)
        if c[idx] == 0 or ans[d-1] == idx:
            continue
        tmp = ans[d]
        ans[d] = idx
        last_d = [0 for i in range(26)]
        score2 = 0    
        for i in range(D):
            score2 += s[i][ans[i]-1]
            last_d[ans[i]-1] = i+1
            score2 = down_score(i+1, c, last_d, score2)
        
        if score1 > score2:
            ans[d] = tmp
    
    for i in range(D):
        print(ans[i]+1)  

if __name__ == "__main__":
    main()


Measured memory_bytes: 9744
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string S;
  cin >> S;
  int m = 0;
  REP(i, S.size()) {
    int tmp = 0;
    for(int j = i; j < S.size(); j++) {
      if (S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T') {
        tmp += 1;
        continue;
      }
      break;
    }
    // cout << tmp << "tmp" << endl;
    m = max(m, tmp);
  }
  cout << m << endl;
  return 0;
}

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

struct AVL{
 struct Node{
  int l,r,p; int v;
  int d;
  void merge(const Node& l, const Node& r){
   d = max(l.d,r.d) + 1;
  }
 };
 Node Zero = {-1,-1,-1,0,0};
 vector<Node> V;
 int R=-1;

 const Node& get(int v){ if(v==-1) return Zero; else return V[v]; }
 void upd(int v){ V[v].merge(get(V[v].l),get(V[v].r)); }
 int& parentchild(int v){
  if(v==R) return R;
  if(V[V[v].p].l==v) return V[V[v].p].l;
  else return V[V[v].p].r;
 }
 void swapidx(int a,int b){
  swap(parentchild(a), parentchild(b));
  swap(V[a], V[b]);
  if (V[a].l != -1) V[V[a].l].p = a;
  if (V[a].r != -1) V[V[a].r].p = a;
  if (V[b].l != -1) V[V[b].l].p = b;
  if (V[b].r != -1) V[V[b].r].p = b;
 }
 void rotL(int v){
  int w=V[v].r;
  parentchild(v)=w; V[w].p=V[v].p;
  V[v].r=V[w].l; if(V[v].r!=-1) V[V[v].r].p=v;
  V[v].p=w; V[w].l=v;
  upd(v);
  upd(w);
 }
 void rotR(int v){
  int w=V[v].l;
  parentchild(v)=w; V[w].p=V[v].p;
  V[v].l=V[w].r; if(V[v].l!=-1) V[V[v].l].p=v;
  V[v].p=w; V[w].r=v;
  upd(v);
  upd(w);
 }
 int fix(int v){
  if(get(V[v].l).d+1 < get(V[v].r).d){ rotL(v); return V[v].p; }
  else if(get(V[v].l).d > get(V[v].r).d+1){ rotR(v); return V[v].p; }
  upd(v);
  return v;
 }
 void fixall(int v){
  while(v!=-1){ v=V[fix(v)].p; }
 }

 void insert(int v){
  int p=-1; int* pp=&R;
  while(*pp!=-1){
   p=*pp;
   if(v<V[p].v) pp=&V[p].l;
   else if(v>V[p].v) pp=&V[p].r;
   else return;
  }
  *pp=V.size();
  V.push_back({-1,-1,p,v,1});
  fixall(V.size()-1);
 }
 int find(int v){
  int p=R;
  while(p!=-1){
   if(v==V[p].v) return p;
   if(v<V[p].v) p=V[p].l; else p=V[p].r;
  }
  return -1;
 }
 void erase(int v){
  if(v==-1) return;
  while(true){
   if(V[v].l!=-1) rotR(v);
   else if(V[v].r!=-1) rotL(v);
   else break;
  }
  swapidx(v,V.size()-1);
  parentchild(V.size()-1)=-1;
  fixall(V.back().p);
  V.pop_back();
 }
};

AVL T;
int N,Q;
int ans=0;

int main() {
 scanf("%d",&N);
 rep(i,N){
  int a; scanf("%d",&a);
  T.insert(a);
 }
 scanf("%d",&Q);
 rep(i,Q){ int a; scanf("%d",&a); if(T.find(a)!=-1) ans++; }
 printf("%d\n",ans);
}




Measured memory_bytes: 5500
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int numCount = int.Parse(Reader.ReadLine());
        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
        Dictionary<long, int> cnt = new Dictionary<long, int>();
        inpt.ToList().ForEach(a=>{
            if(cnt.ContainsKey(a)) {
                cnt[a]++;
            } else {
                cnt[a] = 1;
            }
        });
        long ans = 0;
        cnt.ToList().ForEach(a=>{
            if(a.Key != a.Value) {
                if(a.Value > a.Key) {
                    ans += a.Value - a.Key;
                } else {
                    ans += a.Value;
                }
            }
        });
        Console.WriteLine(ans);
    }


    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



8
2 7 1 8 2 8 1 8


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 34400
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=105,P=1e9+7;
typedef long long LL;

int n;
int a[N];
LL c[N][N];//区间[l,r]，以r结尾的段的个数
LL f[N][N];//f[i,j]:前i个数，末尾j个是极长的交错段的方案数
LL pw(LL a,LL m){
    LL res=1;
    while(m)m&1?res=res*a%P:0,a=a*a%P,m>>=1;
    return res;
}


int main(){
    scanf("%d",&n);
    FOR(i,1,n)scanf("%d",&a[i]);
    a[0]=1;
    FOR(r,1,n){
        if(a[r]<=a[r+1])continue;
        int lim=a[r+1];
        int cur=a[r];
        ROF(i,r-1,0){
            if(a[i]<cur){
                c[i+1][r]+=cur-max(a[i],lim);
                cur=max(a[i],lim);
            }
            c[i][r]=c[i+1][r];
        }
    }
    //FOR(i,1,n)FOR(j,1,i)if(c[j][i])printf("c[%d,%d]=%lld\n",j,i,c[j][i]);
    f[1][1]=pw(2,c[1][1])*2%P;
    FOR(i,1,n){
        FOR(j,2,i){
            f[i][j]=f[i-1][j-1]*1ll*pw(2,c[i-j+1][i])%P;
            //printf("f[%d,%d]=%lld\n",i,j,f[i][j]);
        }
        FOR(j,1,i-1){
            f[i][1]=(f[i][1]+f[i-1][j]*pw(2,c[i][i]))%P;
        }
        //printf("f[%d,%d]=%lld\n",i,1,f[i][1]);
    }
    LL ans=0;
    FOR(i,1,n)ans=(ans+f[n][i])%P;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 384
def mergesort(A, s, e):
    if s + 1 < e:
        m = (e + s) // 2
        mergesort(A, s, m)
        mergesort(A, m, e)
        merge(A, s, m, e)


def merge(A, s, m, e):
    L = A[s:m] + [('*', 1E10)]
    R = A[m:e] + [('*', 1E10)]
    ix_l = ix_r = 0
    for ix in range(s, e):
        if L[ix_l][1] <= R[ix_r][1]:
            A[ix] = L[ix_l]
            ix_l += 1
        else:
            A[ix] = R[ix_r]
            ix_r += 1


def partition(A, p, r):
    x = A[r][1]
    i = p - 1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


def quicksort(A, p, r):
    if p < r:
        i = partition(A, p, r)
        quicksort(A, p, i - 1)
        quicksort(A, i + 1, r)


if __name__ == '__main__':
    N = int(input().strip())
    AA = [0] * N
    for i in range(N):
        key, val = input().strip().split()
        val = int(val)
        AA[i] = (key, val)
    AA2 = AA[:]
    quicksort(AA, 0, len(AA) - 1)
    mergesort(AA2, 0, len(AA2))
    if all([a == a2 for a, a2 in zip(AA, AA2)]):
        print('Stable')
    else:
        print('Not stable')
    for key, val in AA:
        print('{} {}'.format(key, val))

Measured memory_bytes: 19808
n, q = map(int, input().split())
s = input()
t = [0 for _ in range(n+1)]
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)

questions = []
for i in range(q):
    l, r = map(int, input().split())
    questions.append([l, r])
for qestion in questions:
    print(t[qestion[1] - 1] - t[qestion[0] - 1])


Measured memory_bytes: 24472
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
using ll = long long;

ll a[nax];
ll suf[nax];
int n;


void no() {
    puts("-1");
    exit(0);
}


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

    for (int i = 0 ; i <= n ; ++ i) {
        scanf("%lld", a + i);
    }

    suf[n] = a[n];

    for (int i = n - 1 ; i >= 0 ; -- i) {
        suf[i] = suf[i + 1] + a[i];
    }

    ll ans = 0;

    ll cur_leaf = 1;

    for (int i = 0 ; i <= n;  ++ i) {

        if (cur_leaf > suf[i]) no();

        ll leaf = a[i];

        if (cur_leaf < leaf) no();

        ans += cur_leaf;

        cur_leaf -= leaf;

        cur_leaf = min(cur_leaf * 2, suf[i + 1]);
    }

    printf("%lld\n", ans);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 5392
#include<bits/stdc++.h>
using namespace std;
int main()
{
   char s[10] ;
   char p[2];
   p[0]='h';
   p[1]= 'i';
   cin>> s;
   int l= strlen(s);
   int c=0;
   if(l%2!= 0)
    cout<< "No"<< endl;
   else
   {
       for (int i=0; i<l-1; i=i+2)
       {
           if(s[i]!=p[0] || s[i+1]!= p[1])
           {
               c=1;
               break;
           }
       }
       if(c==0)
       cout<< "Yes"<< endl;
       else
       cout<< "No"<< endl;

   }
   return 0;
}


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int a[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++)
      cin>>a[i][j];
  }
  int n;cin>>n;
  while(n--){
    int t;cin>>t;
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++)
        if(a[i][j]==t)a[i][j]='#';
    }
  }
  if(a[0][0]=='#'&&a[0][1]=='#'&&a[0][2]=='#'){cout<<"Yes"<<endl;return 0;}
  if(a[1][0]=='#'&&a[1][1]=='#'&&a[1][2]=='#'){cout<<"Yes"<<endl;return 0;}
  if(a[2][0]=='#'&&a[2][1]=='#'&&a[2][2]=='#'){cout<<"Yes"<<endl;return 0;}

  if(a[0][0]=='#'&&a[1][0]=='#'&&a[2][0]=='#'){cout<<"Yes"<<endl;return 0;}
  if(a[0][1]=='#'&&a[1][1]=='#'&&a[2][1]=='#'){cout<<"Yes"<<endl;return 0;}
  if(a[0][2]=='#'&&a[1][2]=='#'&&a[2][2]=='#'){cout<<"Yes"<<endl;return 0;}

  if(a[0][0]=='#'&&a[1][1]=='#'&&a[2][2]=='#'){cout<<"Yes"<<endl;return 0;}
  if(a[0][2]=='#'&&a[1][1]=='#'&&a[2][0]=='#'){cout<<"Yes"<<endl;return 0;}

  cout<<"No"<<endl;

  return 0;
}


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

using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;
using int32 = __uint32_t;

void solve() {
    int n;
    cin >> n;

    multiset<int> st;    
    for (int i = 0, tp; i < n; i++) {
        cin >> tp;
        st.insert(tp);
    }
    int ans = 0;
    for(int i = 0; i < n and st.size(); i++){
        int tp = *(--st.end());
        st.erase(--st.end());
        for(int j = 0; j < 32; j++){
            if(st.find((1ll << j) - tp) != st.end()){
                ans++;
                st.erase(st.find((1ll<<j) - tp));
                break;
            }
        }
    }
    cout << ans;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
	    int K=gi();
        int[] D=new int[K];
        boolean[] F=new boolean[N];
        for (int i=0; i<N; i++) {
        	F[i]=true;
        }
        for (int i=0; i<K;i++) {
        	D[i]=gi();
        	for (int j=0; j<D[i];j++) { 
        		int a=gi();
        		F[a-1]=false;
        	}
        }
        int c=0;
        for (int i=0; i<N; i++) {
        	if(F[i])c++;
        }


        System.out.print(c);

//        if (N%2==0 && s.substring(0, N/2).equals(s.substring(N/2))) {
//        	System.out.println("Yes");
//        }else{
//        	System.out.println("No");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main() {
	int i,ans=0;
	string s,t;
	cin >> s >> t;
	for(i=0; i<s.size(); i++){
		if(s[i]!=t[i]){
			ans++;
		}
	}
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define ll long long
#define ls o<<1
#define rs o<<1|1
const int N=200000+10,M=2000+10,inf=0x3f3f3f3f;
const ll P=1e9+7;
int n,a[N],b[N];
ll ans=0,inv2=500000004,fac[9000],ifac[9000],f[4500][4500];
template<class t>void rd(t &x){
    x=0;int w=0;char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    x=w?-x:x;
}

void Mod(ll &x){x=(x>=P)?x-P:x;}
ll C(int x,int y){return (fac[x]*ifac[y]%P)*ifac[x-y]%P;}
ll qpow(ll x,ll y){
	ll ret=1ll;
	while(y){
		if(y&1) ret=ret*x%P;
		x=x*x%P,y>>=1;
	}
	return ret;
}

int main(){
	rd(n);
	for(int i=1;i<=n;++i) rd(a[i]),rd(b[i]),++f[M-a[i]][M-b[i]];
	for(int i=1;i<=(M<<1);++i)
		for(int j=1;j<=(M<<1);++j)
			f[i][j]+=f[i-1][j],Mod(f[i][j]),f[i][j]+=f[i][j-1],Mod(f[i][j]);
	fac[0]=fac[1]=1ll;
	for(int i=2;i<=(M<<2);++i) fac[i]=fac[i-1]*(ll)i%P;
	ifac[M<<2]=qpow(fac[M<<2],P-2);
	for(int i=(M<<2);i;--i) ifac[i-1]=ifac[i]*i%P;
	for(int i=1;i<=n;++i) ans+=f[M+a[i]][M+b[i]],Mod(ans),ans+=(P-C(((a[i]+b[i])<<1),(a[i]<<1))),Mod(ans);
	printf("%lld",ans*inv2%P);
    return 0; 
}


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

int main(){
	int n,m,a[100],b[100],s,k[21]={1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
	cin >> n >> m ;
	for(int i=0;i<m;i++){
		cin >> a[i] >> b[i] ;
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<m;j++){
			if(k[a[j]]==0){
				b[j]=0;
			}
		}
		while(k[i]==0){
			i++;
		}
		if(i>n){
			break;
		}
		s=0;
		for(int j=0;j<m;j++){
			if(b[j]==i){
				s++;
			}
		}
		if(s==0){
			k[i]=0;
			cout << i << "\n";
			i=0;
		}
	}
	cout << "2" << "\n";
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() {

int x; cin>>x;
  int a=2000-x-1;
  cout<<a/200+1<<endl;
  
 
  
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll N, R;
  cin >> N >> R;

  cout << R + 100 * max(0LL, 10 - N) << endl;
}

Measured memory_bytes: 764
N = int(input())
memo = [[0,0,0] for i in range(N)]#a, b, cに対応
for i in range(N):
    a, b, c = map(int, input().split())
    if i ==0:
        memo[i][0] = a
        memo[i][1] = b
        memo[i][2] = c
    else:
        memo[i][0] = max(memo[i-1][1]+a, memo[i-1][2]+a)#do a
        memo[i][1] = max(memo[i-1][0]+b, memo[i-1][2]+b)
        memo[i][2] = max(memo[i-1][0]+c, memo[i-1][1]+c)
print(max(memo[N-1]))

Measured memory_bytes: 59552
import math
D, G = list(map(int, input().split()))

arr = []
for i in range(1, D + 1):
    p, c = list(map(int, input().split()))
    arr.append([i * 100, p, c])

min_n_solved_problems = 1e100
for i in range(2 ** D):
    solved_flag = [False] * D
    score = 0
    n_solved_problems = 0
    for j in range(D):
        if ((i >> j) & 1):
            solved_flag[j] = True
            point, num, bonus = arr[j]
            score += point * num + bonus
            n_solved_problems += num
        else:
            biggest_unsolved_ind = j

    if score < G:
        point, num, bonus = arr[biggest_unsolved_ind]
        n_add = math.ceil((G - score) / arr[biggest_unsolved_ind][0])
        if n_add > num - 1: # If we use num - 1 of the biggest one and still cannot reach, it's not the case
            continue
        score += n_add * point
        n_solved_problems += n_add

    if min_n_solved_problems > n_solved_problems:
        min_n_solved_problems = n_solved_problems
print(min_n_solved_problems)


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

using str = string;
using ss = stringstream;

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

    int n;
    str s,t;
    cin>>n>>s>>t;

    int ans=2*n;

    for(int i=n;i>0;i--)
    {
        bool c=true;
        for(int j=0;j<i;j++)if(t[j]!=s[j+n-i]){c=false;break;}
        if(c){ans=n+(n-i);break;}
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3604
#ifndef COMPETITIVE_HEADER
    #pragma GCC optimize ("Ofast")
    #ifdef ONLINE_JUDGE
        #pragma GCC target ("avx512f")
    #else
        #pragma GCC target ("avx")
    #endif
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;
#endif

int n, ai;
map<int,int> a;
bool erat[1000010];

signed main(){
    cin >> n;
    REP(i,n){
        cin >> ai;
        a[ai]++;
    }
    int ans = 0;
    for(auto p : a){
        if (erat[p.first]) continue;
        if (p.second == 1) ans++;
        for(int j = p.first; j <= 1000000; j += p.first){
            erat[j] = 1;
        }
    }
    cout << ans << endl;

}

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

int main()
{
	int d, g; cin >> d >> g;
	
	vector<int> p(d), c(d); for (int i = 0; i < d; i++) cin >> p[i] >> c[i];

	int ans = 2147483647;
	for (int bit = 0; bit < (1<<d); bit++) {

		vector<bool> f(d, false);
		int tmp_score = 0;
		int tmp_ans = 0;
		for (int i = 0; i < d; i++) {			

			if (bit & (1 << i)) {
				tmp_score += c[i];				
				tmp_score += 100 * (i + 1) * p[i];
				tmp_ans += p[i];
				f[i] = true;
			}

		}

		// search maximum
		int maxIndex = -1;
		for (int i = d - 1; i >= 0; i--) {
			if (f[i] == false) {
				maxIndex = i;
				break;
			}
		}

		if (maxIndex == -1) {
			ans = min(ans, tmp_ans);
		}
		else {
			if (g <= tmp_score) {
				ans = min(ans, tmp_ans);
			}
			else {
				for (int i = 0; i < p[maxIndex] - 1; i++) {
					tmp_score += 100 * (maxIndex + 1);
					tmp_ans++;
					if (g <= tmp_score) {
						ans = min(ans, tmp_ans);
						break;
					}					
				}
			}
		}
		
	}	

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

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    H, W, K = Scanner.map_int()

    L = []
    for i in range(1 << (W - 1)):
        l = [False for _ in range(W - 1)]
        for j in range(W-1):
            if i >> j & 1:
                l[j] = True
        for j in range(W - 2):
            if l[j] and l[j + 1]:
                break
        else:
            L.append(l)

    m = [[0 for _ in range(W)]for _ in range(W)]
    if W == 1:
        m[0][0] = 1
    else:
        for l in L:
            for w in range(W):
                k = w
                if w < W - 1 and l[w]:
                    k = k + 1
                elif w - 1 >= 0 and l[w - 1]:
                    k = k - 1
                m[w][k] += 1
    dp = [[0 for _ in range(W)]for _ in range(H + 1)]
    dp[0][0] = 1

    for h in range(H):
        for w in range(W):
            for i in range(W):
                dp[h + 1][w] += m[w][i] * dp[h][i]
                dp[h + 1][w] %= MOD
    print(dp[H][K - 1])


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 61804
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
	


int main() {
	string s;
	cin >> s;
	cout << (s[0] == s[2] ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int kazuKisu(int x) {
    return (x < 10) ? x :
           (x < 100) ? 9 :
           (x < 1000) ? x - 90 :
           (x < 10000) ? 9 + 900 :
           (x < 100000) ? x - 90 - 9000 : 9 + 900 + 90000;
}

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

    printf("%d\n", kazuKisu(N));

    return 0;
}

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

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            // 整数配列の入力
            var a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long maxValue = Math.Abs(a[0]);

            for(long i = 1; i < n; i++) {
                maxValue += Math.Abs(a[i] - a[i - 1]);
            }

            maxValue += Math.Abs(a[n - 1]);

            for (long i = 0; i < n; i++) {
                long value = maxValue;
                if (i == 0) {
                    value -= Math.Abs(a[i]);
                    value -= Math.Abs(a[i + 1] - a[i]);
                    value += Math.Abs(a[i + 1]);
                }else if(i == n - 1) {
                    value -= Math.Abs(a[i] - a[i - 1]);
                    value -= Math.Abs(a[i]);
                    value += Math.Abs(a[i - 1]);
                } else {
                    value -= Math.Abs(a[i] - a[i - 1]);
                    value -= Math.Abs(a[i + 1] - a[i]);
                    value += Math.Abs(a[i - 1] - a[i + 1]);
                }

                Console.WriteLine(value);
            }

            Console.Out.Flush();
        }
    }
}


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

int main()
{
	int N, x = 0, max = 0;
	string S;
	cin >> N;
	cin >> S;

	for (int i = 0; i < N; i++) {
		if (S[i] == 'I') {
			if (++x > max)
				max = x;
		}
		else
			x--;
	}

	printf("%d\n", max);
	return 0;
}

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

int N,a[100010];

int main(){
    cin >> N;

    int i;
    for (i=1; i<=N; i++) cin >> a[i];

    int ans=0;
    for (i=1; i<=N; i++)
        if (a[a[i]]==i) ans++;

    cout << ans/2 << "\n";
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int a,b;
    char c;
    scanf("%d %c %d",&a,&c,&b);
    while(c!='?')
    {
        if(c=='+')
        {
            printf("%d\n",a+b);
        }
        else if(c=='-')
        {
            printf("%d\n",a-b);
        }
        else if(c=='*')
        {
            printf("%d\n",a*b);
        }
        else if(c=='/')
        {
            printf("%d\n",a/b);
        }
        scanf("%d %c %d",&a,&c,&b);
    }
    return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
int h,w,k;
ll dp[101][8];
int a[8]={1,1,2,3,5,8,13,21};
const ll m=1000000007;
int main(){
  cin >> h >> w >> k;
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(j==0) dp[i+1][j]=(dp[i][j]*a[j]*a[w-1-j]+dp[i][j+1]*a[j]*a[w-2-j])%m;
      else if(j==w-1) dp[i+1][j]=(dp[i][j]*a[j]*a[w-1-j]+dp[i][j-1]*a[j-1]*a[w-1-j])%m;
      else  dp[i+1][j]=(dp[i][j]*a[j]*a[w-1-j]+dp[i][j+1]*a[j]*a[w-2-j]+dp[i][j-1]*a[j-1]*a[w-1-j])%m;
    }
  }
  cout << dp[h][k-1] << "\n";
  return 0;
}


Measured memory_bytes: 256
S=input()
Q=int(input())
Query=[input().split() for i in range(Q)]
bf=''
af=''
Flag=True

for i in range(Q):
    if Query[i][0] == '1':
        Flag = not Flag
    else:
        if Query[i][1] == '1':
            if Flag:
                bf = bf + Query[i][2]
            else:
                af = af + Query[i][2]
        else:
            if Flag:
                af = af + Query[i][2]
            else:
                bf = bf + Query[i][2]

ans = bf[::-1] + S + af

if not Flag:
    ans = ans[::-1]

print(ans)

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

int main(){
  int N,K;
  cin >> N >> K;
  string S;
  cin >> S;
   
  if(S[K-1] == 'A'){
    S[K-1] = 'a';
  }
    if(S[K-1] == 'B'){
    S[K-1] = 'b';
    }
  
      if(S[K-1] == 'C'){
      S[K-1] = 'c';
     }
  
  cout << S << endl;
}
  

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 1e15;
const double eps = 1e-6;

int main() {
	ll X, Y;
	cin >> X >> Y;
	ll ans = 0;
	while (X <= Y) {
		ans++;
		X *= 2;
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
	string s;
	cin >> s;
	string t;
	cin >> t;
	t.pop_back();
	if(s==t)
		cout << "Yes";
	else
		cout << "No";
	//////////////////////////////////
	//--------end--------
	//
	return 0;
}


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

int bubbleSort(int a[],int n)
{
  int tot=0;
  bool flag=1;
  for(int i=0;flag;i++)
  {
      flag=0;
      for(int j=n-1;j>=i+1;j--){
          if(a[j]<a[j-1])
          {
              swap(a[j],a[j-1]);
              flag=1;
              tot++;
          }
      }
      
  }
  return tot;
    
}
int main(){
    int a[100],n,tot;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i];
    tot=bubbleSort(a,n);
    for(int i=0;i<n;i++){
        if(i) cout<<" ";
        cout<<a[i];
    }
    cout<<endl;
    cout<<tot<<endl;
    return 0;
}


Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {
	final boolean DEBUG = false;
	class Node {
		int id, s, deg;
		Node p, l, r;
		Node(int id) {
			this.id = id;
			this.s = -1;
			this.deg = 0;
			this.p = this.l = this.r = null;
		}
		
		void print() {
			System.out.print("node " + this.id + ": ");
			System.out.print("parent = " + (this.p == null ? -1 : this.p.id) + ", ");
			System.out.print("sibling = " + this.s + ", ");
			System.out.print("degree = " + this.deg + ", ");
			int depth = 0;
			Node n = this.p;
			while (n != null) {
				depth++;
				n = n.p;
			}
			System.out.print("depth = " + depth + ", ");
			System.out.print("height = " + this.getHeight(0) + ", ");
			if(this.p == null)
				System.out.println("root");
			else if (this.l == null && this.r == null)
				System.out.println("leaf");
			else
				System.out.println("internal node");
		}
		
		int getHeight(int dep) {
			if (DEBUG)
				System.out.println("node " + this.id + ": " + dep);
			if (this.l == null && this.r == null)
				return dep;
			else if (this.l == null)
				return this.r.getHeight(dep + 1);
			else if (this.r == null)
				return this.l.getHeight(dep + 1);
			else
				return Math.max(this.l.getHeight(dep + 1), this.r.getHeight(dep + 1));
		}
	}
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Node[] nodes = new Node[n];
		for (int i = 0; i < n; i++)
			nodes[i] = new Node(i);
		for (int i = 0; i < n; i++) {
			int id = scan.nextInt();
			int left  = scan.nextInt();
			int right = scan.nextInt();
			if (left != -1) {
				nodes[id].l = nodes[left];
				nodes[id].deg += 1;
				nodes[left].p = nodes[id];
			}
			if (right != -1) {
				nodes[id].r = nodes[right];
				nodes[id].deg += 1;
				nodes[right].p = nodes[id];
			}
			if (left != -1 && right != -1) {
				nodes[right].s = left;
				nodes[left].s = right;
			}
		}
		for (int i = 0; i < n; i++)
			nodes[i].print();
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 26368
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  
  a[0] = toupper(a[0]);
  b[0] = toupper(b[0]);
  c[0] = toupper(c[0]);
  
  cout << a[0] <<  b[0] << c[0];
}

Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<cassert>
#include<deque>
using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
////////////////////

int const K = 41;
int const INF = 1e9 + 41;
int const N = 2e5 + 41;

string s;
int n;
ll ans;
deque<int> p[K];

int F[N];

void upd(int x, int v){
	while(x < N){
		F[x] += v;
		x |= (x + 1);
	}
}

int get(int x){
	int r = 0;
	while(x >= 0){
		r += F[x];
		x = (x&(x+1))-1;
	}
	return r;
}

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

int cost(int id, int rem){
	if(sz(p[id]) < 2) return INF;
	int x0 = p[id].front();
	int x1 = p[id].back();
	int res = 0;
	res += get(x0) - 1;
	res += rem - get(x1);
	return res;
}

void remtwo(int id){
	int i = p[id].front();
	p[id].pop_front();
	upd(i, -1);
	int j = p[id].back();
	p[id].pop_back();
	upd(j, -1);
}

ll calc(){
	fi(0, n) upd(i, 1);
	ll res = 0;
	int rem = n;
	fi(0, n/2){
		int bv = INF;
		int b = -1;
		fj(0, K){
			int v = cost(j, rem);
			if(v < bv){
				b = j;
				bv = v;
			}
		}
		rem -= 2;
		res += bv;
		remtwo(b);
	}
	return res;
}

void solve(){
	n = sz(s);
	fi(0, sz(s)){
		p[s[i]-'a'].pb(i);
	}
	int o = 0;
	fi(0, K){
		if(sz(p[i]) % 2 == 1) ++o;
	}
	if(o > 1) bad();
	ans = calc();
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	cin >> s;

	solve();

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <set>
#include <cmath>
using namespace std;

int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> t(N), d(N);
    for(long long i=0; i<N; i++){
        cin >> t[i] >> d[i];
        t[i]--;
    }

    vector<pair<long long, long long>> dt(N);
    for(long long i=0; i<N; i++)
        dt[i] = make_pair(d[i], t[i]);
    sort(dt.begin(), dt.end(), greater<pair<long long, long long>>());

    vector<vector<long long>> v(N);
    long long ans = 0;
    long long dsum = 0;
    set<long long> st;
    for(long long i=0; i<K; i++){
        dsum += dt[i].first;
        st.insert(dt[i].second);
        v[dt[i].second].push_back(dt[i].first);
    }
    long long x = st.size();

    ans = dsum + x*x;

    for(int i=0; i<N; i++)
        sort(v[i].begin(), v[i].end());

    vector<long long> hoge;
    for(int i=0; i<N; i++)
        for(int j=0; j<int(v[i].size())-1; j++)
            hoge.push_back(v[i][j]);
    sort(hoge.begin(), hoge.end());

    vector<long long> mx(N);
    for(long long i=0; i<N; i++)
        if(st.find(t[i]) == st.end())
            mx[t[i]] = max(mx[t[i]], d[i]);

    sort(mx.begin(), mx.end(), greater<long long>());
    for(long long i=0; i<hoge.size(); i++){
        if(mx[i] == 0) break;
        dsum += mx[i] - hoge[i];
        x++;
        ans = max(ans, dsum + x*x);
    }

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


Measured memory_bytes: 11772
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/assoc_container.hpp> 
using namespace std; using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_mset;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define F0R(i,a) for(int i = 0; i < a; i++)
#define F0Rd(i,a) for (int i = a - 1; i >=0 ; i--)
#define FORd(i,a,b) for (int i = b - 1; i >= a; i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define newl '\n'

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define print(x) cout << x << newl;
#define finish(x) return cout << x << "\n", 0;
#define bug(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " " << 

const int MXN = 2e5 + 5;
//const int MXN = 1e6 + 5;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;

int N, W, weights[105];
ll vals[105], dp[100005];


int main(){ FAST
	//ifstream cin("/Users/konwoo/input.txt");
	//ofstream cout("/Users/konwoo/output.txt");

    cin >> N >> W;
    F0R(i,100005) dp[i] = INF;
    dp[0] = 0;
    F0R(i,N){
        cin >> weights[i+1] >> vals[i+1];
    }
    F0R(i,N){
        FORd(j,vals[i+1],100005){
            dp[j] = min(dp[j],dp[j-vals[i+1]] + weights[i+1]);
        }
    }
    F0Rd(i,100005){
        if (dp[i] <= W){
            finish(i);
        }
    }












	return 0;
}


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

using namespace std;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
	
	int  N,D; cin>>N>>D;
	vector<vector<int>> plot(N, vector<int>(D));
	for (int i = 0; i < N; i++) {
	    for (int j = 0; j < D; j++)
	        cin>>plot[i][j];
	}

	int ans = 0;
    for (int i = 0; i < N-1; i++) {
        for (int j = i+1; j < N; j++) {
            double sum = 0;
            for (int k = 0; k < D; k++) {
                sum += pow(plot[i][k]-plot[j][k], 2);
            }
            double rt = sqrt(sum);
            if (rt == double(int(rt)))
                ans++;
        }
    }
    cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
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;}
// clang-format on

void solve(std::string T) {
  replace(all(T), '?', 'D');
  ANS(T);
}

// clang-format off
int main() {
  std::string T;
  std::cin >> T;
  solve(T);
  return 0;
}


Measured memory_bytes: 3924
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <string>
//typedef long long LL;
using namespace std;

int main(){
    int n;
    bool kuku = false;
    cin >> n;
    for(int i=1; i<=9;i++){
        if(n%i==0){
            if(n/i>=1 && n/i<=9){
                kuku = true;
            }
        }
    }
    if(kuku==true){
        cout << "Yes";
    }else{
        cout << "No";
    }
    cout << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <numeric>
#include <vector>
#include <math.h>
#include <string>
#include <queue>

using namespace std;



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

	vector<vector<int>> edge(N+1, vector<int>());

	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		edge[a].emplace_back(b);
		edge[b].emplace_back(a);
	}

	vector<int> s;
	for (int i = 1; i <= N; i++)
	{
		s.push_back(i);
	}

	int count = 0;
	do
	{
		bool flag = true;

		for (int i = 0; i < s.size() - 1; i++)
		{
			bool tmp = false;

			for (int j = 0; j < edge[s[i]].size(); j++)
			{
				if (edge[s[i]][j] == s[i + 1])
				{
					tmp = true;
					break;
				}
			}

			if (!tmp)
			{
				flag = false;
				break;
			}
		}

		if (flag)
		{
			count++;
		}

	} while (next_permutation(s.begin() + 1, s.end()));


	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
i;j;m;s;t[9<<14];main(){for(;~scanf("%d",&t[i]);i++)i*(t[i]>m)?m=t[i]:0;for(;++j<t[0]+2;)abs(t[j]-m/2)<abs(s-m/2)?s=t[j]:0;printf("%d %d",m,s);}

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

int main(){
  int num;
  cin >> num;
  string cmd;
  typedef set<string> set_t;
  set_t A;
  while(cin >> cmd){
    if (cmd == "insert"){
      string word;
      cin >> word;
      A.insert (word);
    }
    else if (cmd == "find"){
      string word;
      cin >> word;
      if (A.count(word)) cout << "yes" << endl;
      else cout << "no" << endl;
    }
  }

}



Measured memory_bytes: 32088