akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int main()
{
	int i,t,m1,m2;
	string s;
	while(cin>>s)
	{
		t=0;m1=0;m2=0;
		for(i=0;i<s.size();i++)
		{
			if(i==0&&s[i]=='A')
			{ 
			   t++;
			   m1++;
			   continue;
			}
			if(i>=2&&i<(s.size()-1)&&s[i]=='C')
			{
			   t++;
			   m2++;
			   continue;
				
			}
			if(s[i]>='a'&&s[i]<='z')
			   t++;
		
		}
		if(t==s.size()&&m1==1&&m2==1)
		   cout<<"AC"<<endl;
		else
		   cout<<"WA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n,m=gets.split.map &:to_i
h=gets.split.map &:to_i
ab=m.times.map{ gets.split.map &:to_i }
lose = []
ab.each do |ar|
  a,b = ar[0],ar[1]
  if h[a-1] > h[b-1] 
    l = b
  elsif h[a-1] < h[b-1]
    l = a
  else
    l = a,b
  end
  lose << l
end
p n - lose.flatten.uniq.size

Measured memory_bytes: 26836
S = input()

cnt1 = S.count(S[0])
cnt2 = S.count(S[1])
cnt3 = S.count(S[2])
cnt4 = S.count(S[3])

if cnt1 == 2 and cnt2 == 2 and cnt3 == 2 and cnt4 == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    N = int(input())
    K = int(input())
    x_list = list(map(int, input().split()))

    ans = 0
    for x in x_list:
        ans += min(abs(x - 0) * 2, abs(x - K) * 2)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AB=sorted([i-m for i,m in zip(A,B)])

if sum(A)<sum(B):
    print(-1)
    exit()

data=[i for i in AB if i<0]
count=len(data)
value=sum(data)
_N=N-1

while value<0:
    value+=AB[_N]
    count+=1
    _N-=1
print(count)


Measured memory_bytes: 18356
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  string s,t,u;
  ll a,b;
  cin >> s >> t>>a >> b >> u;
  if(u==s) a--;
  else b--;
  cout <<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(){

	int a, b, c;
	int i, n;

	scanf( "%d %d %d", &a, &b, &c);

	n = 0;

	for( i=a; i<=b; i++ )
		if( c%i == 0 ) n++;

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


	return 0;


}

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

int main() {
  int n;
  double t, a;
  cin >> n;
  cin >> t >> a;

  int index;
  int tmp;
  double minAbs = 999999999;

  for(int i = 0; i < n; ++i) {
    cin >> tmp;
    double tmpAbs = abs(a - (t - tmp * 0.006));
    if(minAbs > tmpAbs) {
      index = i + 1;
      minAbs = tmpAbs;
    }
  }

  cout << index;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int H, W;

string map[1000];

bool checker[1000][1000];

void fill(int y, int x, char c){
	if(y < 0 || y >= H || x < 0 || x >= W){
		return;
	}
	if(map[y][x] == c && checker[y][x]){
		checker[y][x] = false;
		fill(y - 1, x, map[y][x]);
		fill(y + 1, x, map[y][x]);
		fill(y, x - 1, map[y][x]);
		fill(y, x + 1, map[y][x]);
	}
}

int main(){
	
	int ans;
	
	while(true){
		cin >> H >> W;
		if(H == 0 && W == 0){
			break;
		}
		for(int i = 0; i < H; i++){
			cin >> map[i];
		}
		
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				checker[i][j] = true;
			}
		}
		
		ans = 0;
		
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(checker[i][j]){
					ans++;
					fill(i, j, map[i][j]);
				}
			}
		}
		
		printf("%d\n", ans);
	}
	
	return 0;
}

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

vector<int>x[51], y[51];

bool judge(int a) {
	if (x[0].size() != x[a].size())return false;
	rep(i, 4) {
		swap(x[a], y[a]);
		for (int&k : x[a])k = -k;
		int d1 = x[a][0], d2 = y[a][0];
		for (int&k : x[a])k -= d1;
		for (int&k : y[a])k -= d2;
		bool ok = true;
		rep(i, x[0].size()) {
			if (x[0][i] != x[a][i] || y[0][i] != y[a][i]) {
				ok = false; break;
			}
		}
		if (ok)return true;
	}
	return false;
}
int main() {
	int n;
	while (scanf("%d", &n), n) {
		rep(i, n + 1) {
			int m; scanf("%d", &m);
			x[i] = y[i] = vector<int>(m);
			rep(j, m)scanf("%d%d", &x[i][j], &y[i][j]);
		}
		judge(0);
		for (int i = 1; i <= n; i++) {
			if (judge(i)) {
				printf("%d\n", i); continue;
			}
			reverse(x[i].begin(), x[i].end());
			reverse(y[i].begin(), y[i].end());
			if (judge(i)) {
				printf("%d\n", i);
			}
		}
		puts("+++++");
	}
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define asc(i,a,n) for (I i=a;i<n;i++)
#define dsc(i,a,n) for (I i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define P auto
typedef vector<long long int> VI;
typedef long long int I;
typedef pair<long long int,long long int> PII;
typedef double D;
typedef set<long long int> OSI;
typedef unordered_set<long long int> USI;
typedef list<long long int> LI;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("cnsl/input.txt", "r", stdin);
    freopen("cnsl/output.txt", "w", stdout);
    #endif*/
    string s;
    cin>>s;
    I n=s.size();
    I a[n+1];
    a[0]=0;
    a[1]=(s[n-1]-'0')%2019;
    I b[n];
    b[0]=1;
    asc(i,1,n){
      b[i]=b[i-1]*10;
      b[i]%=2019;
    }
    asc(i,2,n+1){
      a[i]=a[i-1]+(b[i-1]*(s[n-i] -'0'));
      a[i]%=2019;
    }
    unordered_map<I,I> m;
    asc(i,0,n+1){
      P it=m.find(a[i]);
      if(it!=m.end()){
        (*it).se++;
      }else{
        m.insert(mp(a[i],1));
      }
    }
    I ans=0;
    for(P it=m.begin();it!=m.end();it++){
      ans+=(((*it).se)*((*it).se -1))/2;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6828
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmin(ll &a,ll b){if(a>b) a = b ;}

int main(){
	ll a,b ;
	cin >> a >> b ;
	cout << (a*3+b)/2 << endl ;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp1 {
    public class Class1 {
        static void Main(string[] args) {
            int[] data = Console.ReadLine().Trim().Split(' ').Select(_ => int.Parse(_)).ToArray();
            int[] nums = Console.ReadLine().Trim().Split(' ').Select(_ => int.Parse(_)).ToArray();

            int a = data[0] - nums.Sum();

            if (a < 0) {
                Console.Write("-1");
            } else {
                Console.Write(a);
            }
        }
    }
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans=0;
  for(int i=0; i<=999; i++){
    vector<int> a(3);
    a.at(0)=i/100;
    a.at(1)=(i-a.at(0)*100)/10;
    a.at(2)=i%10;
    int k=0;
    for(int j=0; j<N; j++){
      if(S.at(j)=='0'+ a.at(k)){
        k++;
        if(k==3){
          ans++;
          break;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
    	int T = sc.nextInt();
    	int S = sc.nextInt();
    
    	if(D <= S * T){
        	System.out.println("Yes");
        }
        else{
       System.out.println("No");
       }
    }
 }

Measured memory_bytes: 35776
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int a, b, c, d, e, f, g, h, i = 0;
    a = N / 100000000;
    b = (N - a * 100000000) / 10000000;
    c = (N - a * 100000000 - b * 10000000) / 1000000;
    d = (N - a * 100000000 - b * 10000000 - c*1000000) / 100000;
    e = (N - a * 100000000 - b * 10000000 - c*1000000- d*100000) / 10000;
    f = (N - a * 100000000 - b * 10000000 - c*1000000- d*100000 - e* 10000) / 1000;
    g = (N - a * 100000000 - b * 10000000 - c*1000000- d*100000 - e* 10000 - f* 1000) / 100;
    h = (N - a * 100000000 - b * 10000000 - c*1000000- d*100000 - e* 10000 - f* 1000 - g*100) / 10;
    i = (N - a * 100000000 - b * 10000000 - c*1000000- d*100000 - e* 10000 - f* 1000 - g*100 - h*10) / 1;
     
    int sum = a + b + c + d + e + f + g + h + i;
    
    if(N % sum ==0){
    cout << "Yes"<< endl;
    }
    else{
    cout << "No" << endl;
    }
    }
  


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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    vector<pair<int, int>> menu;
    REP(i, 5) {
        int a;
        std::cin >> a;
        menu.emplace_back(a % 10, a);
    }

    SORT(menu);

    int  ans  = 0;
    bool wait = false;
    REP(i, 5) {
        if(menu[i].second % 10 == 0) {
            ans += menu[i].second;
        }
        else {
            if(!wait) {
                ans += menu[i].second;
                wait = true;
            }
            else {
                ans += menu[i].second + 10 - (menu[i].second % 10);
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

int main() {
  ios::sync_with_stdio(0);
  //int n; cin >> n;
  string s, t;
  cin >> s >> t;
  int num = 0;
  for(int i = 0; i < s.size(); i++) num += (s[i] == t[i]);
  cout << num << endl;
}
/*
#include <bits/stdc++.h>
using namespace std;

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

  return 0;
}
 */

Measured memory_bytes: 256
import sys
import heapq
import copy
import numpy as np
from collections import deque

h,w=list(map(int,input().split()))
s=np.array([[x for x in input()] for i in range(h)])
d=[[0]*w for i in range(h)]

q=deque([[1,0,0]])

while len(q)>0:
    cnt,hh,ww=deque.popleft(q)

    if hh==h-1 and ww==w-1:
        nblack=np.sum(s=="#",dtype=np.int)
        print(h*w-nblack-cnt)
        exit(0)
    for nh,nw in [[hh+dh,ww+dw] for dh,dw in [[1,0],[-1,0],[0,1],[0,-1]]]:
        if 0>nh or nh>=h or 0>nw or nw>=w or d[nh][nw]==1 or s[nh][nw]=='#':
            continue
        d[nh][nw]=1
        deque.append(q,[cnt+1,nh,nw])

print(-1)

Measured memory_bytes: 12164
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <time.h>
#include <complex>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;
using std::complex;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;
typedef complex<double> cd;

inline ll max(ll a, ll b)
{
    if (a > b)
        return a;
    return b;
}

inline ll min(ll a, ll b)
{
    if (a < b)
        return a;
    return b;
}

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

const ll MOD = 1e9 + 7;
ll n, d;
ll x[50][50];

int main()
{
    ios_base::sync_with_stdio();
    cin.tie(0);
    cout.tie(0);
    cin >> n >> d;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            cin >> x[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            ll y = 0;
            for (int k = 0; k < d; k++)
            {
                y = y + (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            ll pay = sqrt(y);
            for (ll x = pay - 3; x <= pay + 3; x++)
            {
                if (x * x == y)
                {
                    ans++;
                    break;
                }
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
import math

n,m = map(int, input().split())


ans = 0
for i in range(1, math.ceil(math.sqrt(m))+1):
    if m % i == 0:
        if min(i, m//i) >= n:
            ans = max(ans, max(i, m//i))
        elif max(i, m//i) >= n:
            ans = max(ans, min(i, m//i))
print(ans)

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

int main() {
    ll x, sum = 0, ans = 0;
    cin >> x;
    sum += x / 11;
    if (x <= 6) {
        ans = 1;
    } else {
        if (6 < x && x <= 11) {
            ans = 2;
        } else {
            if (x % 11 != 0) {
              	if (x % 11 >= 7) {
                  	ans = sum * 2 + 2;
                } else { 
                	ans = sum * 2 + 1;
                }
            } else {
                ans = sum * 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
  int i;
  int n;
  while(scanf("%d",&n),n){
    int a[10000];
    for(i=0;i<n;++i)
      scanf("%d",a+i);
    sort(a,a+n);
    long long sm=0;
    for(i=0;i<n-1;++i)
      sm+=a[i]*(n-i-1);
    printf("%lld\n",sm);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
 return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
 return cl(a + b - 1, b);//b=0だと積む
}
int main() {
int so=1;
while(so==1){
 int n,m, ba,tu,ch; int ans = 1;
 cin >> n;
 if(n==0){
     so=0;
 }
 else{
 int sizc = n;
 int sizd = n;
 vector<int> c(2*n,0);
 vector<int> d(2 * n,0);
 for (int i = 0; i < n; i++) {
  int x;
  cin >> x;
  c[x-1] = 1;
 }
 for (int i = 0; i < 2*n; i++) {
  d[i] = 1 - c[i];
 }
 tu = 0;
 ba = 0;
 while (sizc != 0 and sizd != 0) {
  int ok = 0;
  ch = ba;
  if (tu == 0) {
   while (ok == 0 and ch < 2*n) {
    if (c[ch] == 1) {
     c[ch] = 0;
     ba = ch;
     ok = 1;
     tu = 1;
     sizc = sizc - 1;
    }
    else {
     ch = ch + 1;
    }
   }
   if (tu == 0) {
    ba = 0;
    tu = 1;
   }
  }
  else {
   while (ok == 0 and ch < 2*n) {
    if (d[ch] == 1) {
     d[ch] = 0;
     ba = ch;
     ok = 1;
     tu = 0;
     sizd = sizd - 1;
    }
    else {
     ch = ch + 1;
    }
   }
   if (tu == 1) {
    ba = 0;
    tu = 0;
   }
  }
 }
 cout << sizd <<endl<< sizc<<endl;      
 }
}
}



Measured memory_bytes: 3012
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int r = in.nextInt();
        int s = in.nextInt();
        int p = in.nextInt();
        String t = in.next();
        StringBuilder t2 = new StringBuilder(t);
        long sum = 0;
        for(int i=0; i<n; i++) {
            char c = t.charAt(i);
            int currentPoint = r;
            if(c == 'p') {
                currentPoint = s;
            }
            else if(c == 'r') {
                currentPoint = p;
            }

            if(i >= k) {
                char prevC = t2.charAt(i-k);
                if(prevC == c) {
                    currentPoint = 0;
                    t2.replace(i, i+1, "n");
                }
            }
            sum += currentPoint;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 27732
#include<bits/stdc++.h>
using namespace std;
int a,ans;
int main(){
	scanf("%d",&a);
	for(int i=1;i<=a;i++){
		int z=i,p=0;
		while(z)z/=10,p++;
		ans+=p%2!=0;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
open Batteries
open Printf

let ($) g f x = g (f x)

module MyList = struct
  include List
  let foldl = fold_left
  let foldli = fold_lefti
  let foldr = fold_right
  let foldri = fold_righti
  
  let flatmap = concat_map

  let zipf = map2
  let zipfi = map2i
end

module L = MyList

let swap = Tuple2.swap

let atoi = int_of_string
let itoa = string_of_int
let atof = float_of_string
let ftoa = string_of_float
let ctoi = int_of_char
let itoc = char_of_int

let ctos = String.of_char
let stocl = String.to_list
let cltos = String.of_list

module MyString = struct
  include String

  let map_to_list f s = L.map f (stocl s)
  let mapi_to_list f s = L.map f (stocl s)

  let zipf f a b = L.zipf f (stocl a) (stocl b)
  let zipfi f a b = L.zipfi f (stocl a) (stocl b)

  let mkstr f sep ls =
    L.foldl (fun acc x -> acc ^ sep ^ (f x)) (f @@ L.hd ls) (List.tl ls)
end

module S = MyString

let spoc = S.split_on_char
let spsp s = spoc ' ' s

module MySet = struct
  include Set

  let fold' f s z = fold f z s
end

module St = MySet

module MyMap = struct
  include Map

  let apply = find
  let apply_or = find_default
end

module Mp = MyMap


let rds () = read_line ()

let rdi () = atoi @@ rds ()

let rdhs () = spsp @@ rds ()
let rdhi () = rdhs () |> L.map atoi

let rds2 () = match rdhs () with
  | a::b::_ -> (a, b)
  | _ -> ("", "")

let rdi2 () = match rdhi () with
  | a::b::_ -> (a, b)
  | _ -> (0, 0)

let rdi3 () = match rdhi () with
| a::b::c::_ -> (a, b, c)
| _ -> (0, 0, 0)

let rdi4 () = match rdhi () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0, 0, 0, 0)

let rdi5 () = match rdhi () with
| a::b::c::d::e::_ -> (a, b, c, d, e)
| _ -> (0, 0, 0, 0, 0)

let rdv n rdf =
  let rec rdv' n =
    if n <= 0 then []
    else (
      let s = rdf () in
      s::(rdv' (n - 1))
    )
  in rdv' n

let rdvi n = rdv n rdi
let rdvi2 n = rdv n rdi2
let rdvi3 n = rdv n rdi3
let rdvi4 n = rdv n rdi4

let puts s = print_endline s
let putyn b = puts (if b then "Yes" else "No")
let puti i = puts @@ itoa i

let set_power ls =
  let rec set_power' ls pls =
    match ls with
    | [] -> pls
    | hd::tl -> set_power' tl (L.flatmap (fun p -> [p; hd::p]) pls)
  in set_power' ls [[]]


let rdhf () = rdhs () |> L.map atof
let rdf4 () = match rdhf () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0., 0., 0., 0.)


module Graph = struct

  type 'a t = { nb : (int, int St.t) Mp.t; vdt : (int, 'a) Mp.t }

  let nothing = { nb = Mp.empty; vdt = Mp.empty }

  let add_edge (e : int * int) g =
    let (v1, v2) = e in
    let nbvs = g.nb |> Mp.apply_or St.empty v1 in
    let nb1 = g.nb |> Mp.add v1 (nbvs |> St.add v2) in
    { g with nb = nb1 }

  let add_uedge e g =
    add_edge e (add_edge (swap e) g)

  let from_edges es =
    es |> L.foldl (fun g e -> add_edge e g) nothing

  let from_uedges es =
    es |> L.foldl (fun g e -> add_uedge e g) nothing


end

module G = Graph


let _ =
  let (a',b') = rds2 () in
  let a = atoi a' and b = atof b' in
  let b100 = Float.round_to_int (b *. 100.) in
  let mul = a * b100 / 100 in
  puti mul
;;


Measured memory_bytes: 5680
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=20;
const int INF=1061109567;
int n;
int a[N],b[N];
int f[1<<N][N];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(int i=0;i<n;i++)
		scanf("%d",&b[i]);
	memset(f,63,sizeof(f));
	f[0][0]=0;
	for(int s=1;s<(1<<n);s++)
	{
		int t=__builtin_popcount(s);
		for(int i=0;i<n;i++)
			if(s&(1<<i))
			{
				int v=(abs(t-(i+1))&1)?b[i]:a[i];
				int num=0;
				for(int j=i+1;j<n;j++)
					if(s&(1<<j)) num++;
				for(int j=0;j<n;j++)
					if((s^(1<<i))==0)
					{
						f[s][i]=min(f[s][i],f[s^(1<<i)][j]+num);
						continue;
					}
					else if((s^(1<<i))&(1<<j))
					{
						int vt=(abs(t-1-(j+1))&1)?b[j]:a[j];
						if(vt<=v) f[s][i]=min(f[s][i],f[s^(1<<i)][j]+num);
					}
			}
	}
	int ans=INF;
	for(int i=0;i<n;i++)
		ans=min(ans,f[(1<<n)-1][i]);
	if(ans>=INF) printf("-1");
	else printf("%d",ans);
	return 0;
}

Measured memory_bytes: 85708
import java.util.BitSet;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[][] paths = new int[N - 1][2];
        for (int i = 0; i < paths.length; i++) {
            sc.nextLine();
            int a = sc.nextInt();
            int b = sc.nextInt();
            paths[i][0] = Math.min(a, b);
            paths[i][1] = Math.max(a, b);
        }

        sc.nextLine();
        final int M = sc.nextInt();
        BitSet[] constraints = new BitSet[M];
        for (int i = 0; i < M; i++) {
            sc.nextLine();
            int u = sc.nextInt();
            int v = sc.nextInt();
            BitSet constraint = new BitSet(paths.length);
            travel(constraint, paths, u, v);
            constraints[i] = constraint;
        }
        //        for (int i = 0; i < paths.length; i++) {
        //            System.out.println(i + ": " + paths[i][0] + " -> " + paths[i][1]);
        //        }
        //        for (BitSet constraint : constraints) {
        //            System.out.println(constraint);
        //        }

        long finalResult = 0;
        for (int i = 0; i < (int) Math.pow(2, M); i++) {
            BitSet result = new BitSet(paths.length);
            int orCount = 0;
            for (int j = 0; j < M; j++) {
                if (((1 << j) & i) == (1 << j)) {
                    result.or(constraints[j]);
                    orCount++;
                }
            }
            long tmpResult = (long) Math.pow(2, N - 1 - result.cardinality());
            //System.out.println(result + ":" + tmpResult);
            if (orCount % 2 == 0) {
                finalResult += tmpResult;
            } else {
                finalResult -= tmpResult;
            }
        }
        System.out.println(finalResult);
    }

    static boolean travel(BitSet constraint, int[][] paths, int from, int to) {
        int tmp = Math.min(from, to);
        to = Math.max(from, to);
        from = tmp;
        for (int i = 0; i < paths.length; i++) {
            if (constraint.get(i)) {
                continue;
            }
            int[] path = paths[i];
            if (path[0] == from && path[1] == to) {
                constraint.set(i);
                return true;
            } else if (path[0] == from) {
                constraint.set(i);
                if (travel(constraint, paths, path[1], to)) {
                    return true;
                }
                constraint.set(i, false);
            } else if (path[1] == from) {
                constraint.set(i);
                if (travel(constraint, paths, to, path[0])) {
                    return true;
                }
                constraint.set(i, false);
            }
        }
        return false;
    }
}

Measured memory_bytes: 45268
n,q = map(int, input().split())
s = input()
a = [0]*n
for i in range(1,n):
    a[i] = a[i-1]
    if (s[i]=="C"):
        if (s[i-1]=="A"):
            a[i] += 1

for i in range(q):
    l,r = map(int, input().split())
    print(a[r-1]-a[l-1])
            

Measured memory_bytes: 6060
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(long long A, long long B, long long C, long long K) {
  ll num = 0;
  if (K % 2 == 0) {
    num = A - B;
  } else {
    num = B - A;
  }

  if (abs(num) > 1e18) {
    print("Unfair");
  } else {
    print(num);
  }
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  long long K;
  scanf("%lld", &K);
  solve(A, B, C, K);
  return 0;
}


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

int main(){
	// sengen
	int s,w;
	// nyuryoku
	cin >> s >> w;
	// keisan
	if(s > w){
		cout << "safe";
	}else{
		cout << "unsafe";
	}
	// syutsuryoku
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
ll a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(c>a+b&&4*a*b<(c-a-b)*(c-a-b))
	cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""
import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

"""
N = int(input())

s = [""]*N

cnt  = 0
cnt_A= 0
cnt_B= 0
cnt_BA=0
for n in range(N):
    s[n] = input()
    cnt += s[n].count("AB")
    if s[n][0] == "B" and s[n][-1] == "A":
        cnt_BA+=1
        continue
    elif s[n][0]=="B":
        cnt_B +=1
    elif s[n][-1]=="A":
        cnt_A +=1
    else:
        pass
    
            

def main(): 
    #print(s, cnt)
    if cnt_A == 0 and cnt_B ==0:
        if cnt_BA ==0:
            print(cnt)
        else:
            print(cnt + cnt_BA-1)
    else:
        print(cnt + min(cnt_BA+cnt_B, cnt_BA+cnt_A))
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  int32 res = 0;
  REP(i, n){
    int32 b;
    cin >> b;
    while(b%2 == 0){
      b/=2;
      res++;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

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

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n, m := r.nextInt(), r.nextInt()

	qac := make(map[int]int, n)
	qwa := make(map[int]int, n)
	for i := 0; i < m; i++ {
		r.Scan(true)
		q, a := r.nextInt(), r.nextString()

		if qac[q] <= 0 {
			if strings.Compare(a, "AC") == 0 {
				qac[q]++
			} else {
				qwa[q]++
			}

		}
	}

	accnt := 0
	wacnt := 0
	for i := 1; i <= n; i++ {
		if qac[i] > 0 {
			wacnt += qwa[i]
		}
		accnt += qac[i]
	}
	fmt.Fprintln(stdout, accnt, wacnt)
}


Measured memory_bytes: 9088
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int n;
    
    scanf("%d", &n);
    
    if (n<1000) {
        printf("ABC");
    } else {
        printf("ABD");
    }
    
    return 0;
}



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

int main() 
{
    int N; cin >> N;
    vector<int> A(N+1);
    vector<int> B(N+1);

    for (int i = 1; i <= N; i++)
    {
        int tmp;
        cin >> tmp;
        A[i] = tmp;
    }
    int M = 0;
    for (int i = N; i >= 1; i--) {
        int sum = 0;
        for (int j = 2*i; j <= N; j += i)
        {
            sum += B[j];
        }        
        if (sum % 2 != A[i]) {
            B[i] = 1;
            M++;
        }
    }

    cout << M << "\n";
    for (int i = 1; i <= N; i++)
    {
        if (B[i] == 1)
            cout << i << " ";
    }
    
}

Measured memory_bytes: 2432
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n, m = map(int, input().split())
minv = 1
maxv = n
for _ in range(m):
    l, r = map(int, input().split())
    if maxv > r: maxv = r
    if minv < l: minv = l
print(max(maxv - minv + 1, 0))

Measured memory_bytes: 5076
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using namespace std;

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;
using vs=vector<string>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N; cin >>N;
  vll X(N);
  rep(i,0,N) {cin >>X[i];}
  vll Y(N);
  Y=X;
  sort(all(Y));
  int m=N/2;
  int mida=Y[m-1];
  int midb=Y[m];
  rep(i,0,N) {
    if (X[i]<=mida) {
      cout <<midb <<endl;
    } else {
      cout <<mida <<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 6340
import math

import sys
import math

def Sieve_of_Eratosthenes(N):
    if N<2: return set()
    prime=set(i for i in range(2,N+1))
    for i in range(2,math.ceil(N**0.5)+1):
        tmp=set()
        for j in prime:
            if j>i and j%i==0: tmp.add(j)
        for j in tmp:
            prime.remove(j)

    return list(prime)

N=int(input())


s=int(math.sqrt(N))+2
d={}
ans=N-1
for i in range(1,s):
    if N%i==0:
        ans=min(ans,i+N//i-2)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std ;
#define m 1000000007
int main (){
	long long int n ; cin >> n ;
	long long int a[n];
	long long int sum =0;
	for(int i = 0;i < n; i ++){
		cin >> a[i];
	}
	long long int suff[n];
	for(long long int  i = n-1, suffs =0  ; i >=0;i--){
		suffs = (suffs+a[i])%m;
		suff[i] = suffs;
	}
	for(int i =0 ;i<n-1;i++){
		sum = (sum + a[i]*(suff[i+1]%m))%m;
	}
	cout <<  sum ;
}


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

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

ll mod = 998244353;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;

  ll ret = 1;
  int n = s.length();
  vector<int> cnt(n);
  cnt[0] = 1;
  for(int i = 1;i < s.length();i++){
    cnt[i] = cnt[i-1];
    if(s[i] != s[i-1]){
      cnt[i]++;
    }else{
      if(i >= 3){
        cnt[i] = cnt[i-3] + 2;
      }else if(i == 2){
        cnt[i] = 2;
      }else{
        cnt[i] = 1;
      }
    }
  }
  cout << cnt[n-1] << endl;
}

Measured memory_bytes: 1428
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;

typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr long long MOD = (ll) 1e9+7;

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

struct Edge {
	int to, cap, rev;
	Edge(int _to, int _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
	G[from].push_back(Edge(to, cap, G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}

void solve() {

	ll x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	Array p(a), q(b), r(c);
	REP(i, a) cin >> p[i];
	REP(i, b) cin >> q[i];
	REP(i, c) cin >> r[i];

	sort(all(p), greater<ll>());
	sort(all(q), greater<ll>());

	priority_queue<ll> que;
	REP(i, x) que.push(p[i]);
	REP(i, y) que.push(q[i]);
	REP(i, c) que.push(r[i]);

	ll ans = 0;
	REP(i, x + y) ans += que.top(), que.pop();
	cout << ans << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


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

int main() {
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for (int i = 0; i < m; ++i) cin >> b[i];
    int ans = 0;
    for (int j = 0; j < n; ++j) {
        int score = 0;
        for (int i = 0; i < m; ++i) {
            int a;
            cin >> a;
            score += a * b[i];
        }
        score += c;
        if (score > 0) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
S=input()
a=0
b=0
c=0
for i in range(len(S)):
  if S[i]=='a':
    a+=1
  elif S[i]=='b':
    b+=1
  else:
    c+=1
# print(a,b,c)
if abs(a-b)<=1 and abs(b-c)<=1 and abs(c-a)<=1:
  print('YES')
else:
  print('NO')

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

int N,W;

unordered_map<int,int> dp[2];

int main(){
	cin>>N>>W;
	int from = 0, to = 1;
	dp[from][0] = 0;
	REP(i,N){
		dp[to] = dp[from];
		int w,v;
		cin>>w>>v;
		for(auto &p:dp[from]){
			Int w0 = p.first;
			int v0 = p.second;
			w0+=w;
			v0+=v;
			if(w0<=W){
				dp[to][w0] = max(dp[to][w0],v0);
			}
		}
		swap(from,to);
	}
	int ans = 0;
	for(auto &p:dp[from]){
		if(p.first<=W){
			ans=max(ans,p.second);
//			cerr<<p.first<<" "<<p.second<<endl;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;



int main(){
	double xa[2],ya[2],xb[2],yb[2];
	while(cin>>xa[0]){
		cin>>ya[0];
		cin>>xa[1]>>ya[1];
		rep(i,2){
			cin>>xb[i]>>yb[i];
		}
		double minxa=min(xa[0],xa[1]);
		double maxxa=max(xa[0],xa[1]);
		double minxb=min(xb[0],xb[1]);
		double maxxb=max(xb[0],xb[1]);
		double minya=min(ya[0],ya[1]);
		double maxya=max(ya[0],ya[1]);
		double minyb=min(yb[0],yb[1]);
		double maxyb=max(yb[0],yb[1]);
		if(minxb>maxxa || minxa>maxxb || minyb>maxya || minya>maxyb)cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
from bisect import bisect_left
from bisect import bisect_right


N = int(input())
L = list(map(int, input().split()))
L.sort()

"""
短いほうから２本固定して条件に合うものをさがす（長いほうから２本固定でもOK）
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""


ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        #b = L[j]
        # そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや！
        k = bisect_left(L, a+L[j])
        ans += k - j - 1



"""
ans = 0
for i in range(N):
    for j in range(i+1, N):
        l = L[j] - L[i]
        r = L[j] + L[i]
        #  a < b < c（場合によっては等号を含む）で考えたときの、b - a < cを満たすもの 
        il = bisect_right(L, l, lo=j)
        #  a < b < c（場合によっては等号を含む）で考えたときの、c < a + bを満たすもの
        ir = bisect_left(L, r, lo=j)
        # b - a < cを満たすものがない場合、飛ばす
        if il == N-1:
            break
        
        ans += ir - il - 1
"""

print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long int a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	long long int ans=a*c;
	ans=max(a*d,ans);
	ans=max(b*c,ans);
	ans=max(b*d,ans);
	printf("%lld\n",ans);
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var xx = ReadInts();
            WriteLine(Abs(xx[0] - xx[1]));
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



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

using namespace std;

int main(void)
{
  unsigned long int N, K;
  unsigned long int num;
  vector<unsigned long int> H;

  cin >> N >> K;

  for(unsigned long int i = 0; i < N; i++)
  {
    cin >> num;
    H.push_back(num);
  }

  sort(H.begin(), H.end());
  reverse(H.begin(), H.end());

  num = 0;

  for(unsigned long int i = K; i < H.size(); i++)
  {
    num += H[i];
  }

  cout << num;
  
  return 0;
}


Measured memory_bytes: 2420
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader sc, PrintWriter w) {

            String str = sc.next();
            int flag = 0;
            String temp = str;
            int max = 0;
            while (temp.length() > 0) {
                if (flag != 0 && temp.length() % 2 == 0) {
                    int mid = temp.length() / 2;
                    String str1 = temp.substring(0, mid);
                    String str2 = temp.substring(mid);

                    if (str1.equals(str2)) {
                        max = Math.max(temp.length(), max);
                    }
                }
                temp = temp.substring(0, temp.length() - 1);
                flag++;
            }

            w.println(max);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21332