akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#define DBG
using namespace std;
using ll = long long;
ll X, K, D;
int main(){
    string s;
    cin >> X >> K >> D;
    cin.ignore();

    if (X <= 0) X = -X; // 正からに統一。どっちも一緒。

    // とりあえず正の最小まで移動
    ll con_K = X / D;
    if(con_K >= K){
        #ifdef DBG
        cout << "P1" << endl;
        cout << X << " " << K << " " << D << endl;
        #endif
        X -= D * K;
        cout << X << endl;
        return 0;
    }
    K -= con_K;
    X %= D;
    if(K%2 == 0){
        #ifdef DBG
        cout << "P2" << endl;
        #endif
        cout << X << endl;
        return 0;
    } else {
        #ifdef DBG
        cout << "P3" << endl;
        #endif
        cout << D - X << endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  int n = (int) s.length();
  if (n < 26) {
    for (char c = 'a'; c <= 'z'; c++) {
      if (s.find(c) == string::npos) {
        cout << s + c << endl;
        return 0;
      }
    }
  }
  for (int i = n - 1; i > 0; i--) {
    if (s[i - 1] < s[i]) {
      char c = 'z';
      for (int j = i; j < n; j++) {
        if (s[j] > s[i - 1]) c = min(c, s[j]);
      }
      cout << s.substr(0, i - 1) + c << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
typedef long long LL;

int main() {
	string s;
	cin >> s;
	for(auto& c: s)
		if(c=='1') c='9';
		else if(c=='9') c='1';
	cout << s << endl;
}



Measured memory_bytes: 256
// ~maqsat~

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
	fre("");
	ACCELERATE;

    string s;
    cin >> s;
    
    for(int i = 0; i < sz(s); i++) {
        if(i & 1) {
            if(s[i] == 'R') return cout << "No", 0;
        }
        else {
            if(s[i] == 'L') return cout << "No", 0;
        }
    }
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	
	words := make(map[string]int)
	
	word := ""
	for i := 0; i < n; i++ {
		fmt.Scan(&word)
		words[word]++
	}
	
	var m int
	fmt.Scan(&m)
	for i := 0; i < m; i++ {
		fmt.Scan(&word)
		words[word]--
	}
	max := -100
	for i := range words {
		if max < words[i] {
			max = words[i]
		}
	}
	max = Max(0,max)
	
	fmt.Println(max)
}

func Max(num1,num2 int)int {
	if num1 > num2 {
		return num1
	}
	return num2
}

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

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

map<int, int> primeFactor(int n){
	map<int, int> res;
	for(int i = 2; i * i <= n; i++){
		while(n % i == 0){
			++res[i];
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

//i番目のビットを返す
bool getBit(int num, int i){
	return ((num & (1 << i)) != 0);
}

//i番目を1にする
int setBit(int num, int i){
	return num | (1 << i);
}

//i番目を0にする
int clearBit(int num, int i){
	int mask = ~(1 << i);
	return num & mask;
}

//i番目をvで置き換える
int updateBit(int num, int i, int v){
	int mask = ~(1 << i);
	return (num & mask) | (v << i);
}

const int INF = 1e18;

signed main(){
	int n, m;
	cin >> n >> m;

	vector<int> a(m), bit(m);
	rep(i,m){
		int k;
		cin >> a[i] >> k;
		rep(j,k){
			int a;
			cin >> a;
			bit[i] = setBit(bit[i], a - 1);
		}
	}

	vector<int> dp(100005, INF);
	dp[0] = 0;
	rep(s, 1 << n){
		rep(i, m){
			int nxtBit = s bitor bit[i];
			dp[nxtBit] = min(dp[nxtBit], dp[s] + a[i]);
		}
	}
	if(dp[(1 << n) - 1] == INF) cout << -1 << endl;
	else cout << dp[(1 << n) - 1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#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 REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define int long long int
/* ll comb(ll x, ll y);
int main(void);

ll comb(ll x, ll y){

}
 */

signed main(void){

    int N;
    cin >> N;

    vector<string> S;
    rep(i,N){
        string s;
        cin >> s;
        S.push_back(s);
    }

    rep(i,N){
        sort(all(S[i]));
    }
    sort(all(S));

    string T = S[0]; 
    int cnt = 0;
    int ans = 0;
    rep(i,N){
        if(S[i] == T){
            cnt++;
        }else{
            ans += cnt*(cnt-1)/2;
            T = S[i];
            cnt = 1;
        }
    }
    if(cnt>1){
        ans += cnt*(cnt-1)/2;
    }

   /* rep(i,N){
       cout << S[i] << endl;
   } */

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


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

int A[100000] = {}, B[100000] = {};

int main(){
    int a, b, i, m, x, y, c, res = MOD, tem = MOD;
    cin >> a >> b >> m;
    for(i=0; i<a; i++){
        cin >> A[i];
        res = min(res, A[i]);
    }
    for(i=0; i<b; i++){
        cin >> B[i];
        tem = min(tem, B[i]);
    }
    res += tem;
    for(i=0; i<m; i++){
        cin >> x >> y >> c;
        res = min(res, A[x-1]+B[y-1]-c);
    }
    cout << res << "\n";
    return 0;
}

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

using namespace std;

int main(int argc, const char * argv[]) {
    
    int inptcnt;
    cin>>inptcnt;
    
    int ary[inptcnt];
    for(int i = 0;i<inptcnt;i++){
        int nb;
        cin >> nb;
        ary[i]=nb-1;
    }
    
    int ans = 0;
    
    for(int i = 0;i<inptcnt;i++){
        if( i == ary[ary[i]]){
            ans++;
        }
    }
    cout<<ans/2<<endl;
    
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL ans;
string s;
map<LL,LL>m;
int main(){
    cin>>s;
    REP(i,s.size()){
        m[s[i]-'a']++;
    }
    ans=s.size()*(s.size()-1)/2+1;
    for(auto it=m.begin();it!=m.end();it++){
        LL b=it->second;
        ans-=(b*(b-1)/2);
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys


def solve(K: int, S: int):
    cnt = 0
    for x in range(K+1):
        for y in range(K+1):
            z = S - x - y
            if z >= 0 and z <= K:
                cnt += 1
    print(cnt)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;

double ans, a;

int main(){
    cin >> n;
    REP(i, n){
        cin >> a;
        ans += 1.0/a;
    }
    cout << fixed << setprecision(13) << 1.0/ans << endl;
}

Measured memory_bytes: 256
S=list(input())
def main():
    while True:
        if 1<=int(S[0]+S[1])<=12:
            if 1<=int(S[2]+S[3])<=12:
                return 'AMBIGUOUS'
            else:
                return 'MMYY'
        else:
            if 1<=int(S[2]+S[3])<=12:
                return 'YYMM'
            else:
                return 'NA'

print(main())

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

using namespace std;

#ifdef Lin1043
    #define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)
    #define massert(...) assert(...)
#else
    #define DEBUG(...)
    #define massert(...)
#endif

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

struct iopener
{
    iopener()
    {
#ifdef Lin1043
        freopen("./in" , "r" , stdin);
#endif
    }
} iop;

typedef long long LL;

template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }

template<typename T>inline T read(T &f)
{
    f = 0; int x = 1 ; char c = getchar();
    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
    return f = x * f;
}

const int N = 1000 + 5;

int n , m; char A[N][N];

int S[N][N] , T[N][N];

int main()
{
    read(n) , read(m);
    rep(i , 1 , n)
        scanf("%s" , A[i] + 1);
    rep(i , 1 , n) rep(j , 1 , m)
    {
        if(A[i][j] == '#')
            S[i][j] = T[i][j] = 1;
    }
    rep(j , 1 , m)
    {
        S[1][j] = T[n][j] = 1;
    }
    rep(i , 2 , n - 1) rep(j , 1 , m)
    {
        if(j % 2 == 0)
            S[i][j] = 1;
        else
            T[i][j] = 1;
    }
    rep(i , 1 , n)
    {
        rep(j , 1 , m)
        {
            if(S[i][j])
                putchar('#');
            else
                putchar('.');
        }
        puts("");
    }
    puts("");
    rep(i , 1 , n)
    {
        rep(j , 1 , m)
        {
            if(T[i][j])
                putchar('#');
            else
                putchar('.');
        }
        puts("");
    }
    return 0;
}



Measured memory_bytes: 9088
n = int(input())
S = input()
c_w = 0
c_r = 0
for i in range(len(S)):
    if S[i] == 'W':
        c_w += 1
    else:
        c_r += 1
p_1 = c_w
p_2 = c_r
p_3 = 0
for i in range(c_r):
    if S[i] == 'W':
        p_3 += 1
print(min(p_1,p_2,p_3))


Measured memory_bytes: 9484
#include <iostream>
#include <string>
#include <set>
using namespace std;
typedef long long ll;
int main()
{
	ll N, Y;
	cin >> N >> Y;
	for (ll a = 0; a <= N; ++a) {
		for (ll b = 0; b <= N - a; ++b) {
			ll c = N - a - b;
			if (10000 * a + 5000 * b + 1000 * c == Y) {
				cout << a;
				cout << ' ';
				cout << b;
				cout << ' ';
				cout << c;
				cout << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

Measured memory_bytes: 3192
/*
memo for solution
*/
#include <cstdlib> 
#include <numeric>
#include <cstring>
#include <cstdio> 
#include <cfloat> 
#include <map> 
#include <cassert>
#include <cmath> 
#include <climits> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <iomanip>
#include<sys/time.h>
using namespace std; 
double e_time(void){static struct timeval now;gettimeofday(&now, NULL);return (double)(now.tv_sec  + now.tv_usec/1000000.0);}
#define REP(i,b,n) for(int i=b;i<n;i++) 
#define rep(i,n)      REP(i,0,n) 
#define pb push_back  
#define mp make_pair 
#define ALL(C)   (C).begin(),(C).end() 
#define fe(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr != (c).end();itr++)
#define BITSHIFT(X)     ( (1<<(X)) )
#define CONTAIN(S,X) ( ((S)&BITSHIFT(X)) != 0)
typedef complex<double>P; 
typedef long long ll; 
typedef unsigned long long ull; 
typedef pair<int,int> pii; 
typedef vector<int> vint;
template<class T> void vp(T &a,int p){rep(i,p)cout << a[i]<<" ";cout << endl;}  
template<class T> T ceilUp(const T& a,const T& b){return (a+b-1)/b;}
const ll mod =   1000000009;
inline ll modadd(ll a,ll b){a %= mod;b %= mod;return (a+b)%mod;}
inline ll modsub(ll a,ll b){a %= mod;b %= mod;a-=b;a%=mod;if (a<0)a+=mod;return a;}
inline ll modmul(ll a,ll b){a %= mod;b %= mod;return (a*b)%mod;}
inline ll modeq(ll a,ll b,ll m){a = (a%m+m)%m; b = (b%m+m)%m;return a == b;}
//ll modpow(ll n,ll p){if (p == 0)return 1;if (p == 1)return n;ll ret=mypow(n,p/2);ret=ret*ret%mod;if (p&1)ret=ret*n%mod;return ret;}
//ll getinv(ll a){return mypow(a,mod-2);}
ll mypow(ll n,ll p){
  if (p == 0)return 1;
  if (p == 1)return n;
  ll ret=mypow(n,p/2);
  ret=ret*ret;
  if (p&1)ret=ret*n;
  return ret;
}

bool ismonth(string &in){
  if (in[0] == '0' && (in[1] != '0'))return true;
  if (in[0] == '1' && (in[1] == '0' || in[1] == '1' || in[1] == '2' ))return true;
  return false;
}

bool isyear(string &in){
  //if (in[0] == '0' && in[1] == '0')return false;
  return true;
}

bool ismy(string &a, string &b){
  return ismonth(a) && isyear(b);
}

bool isym(string &a, string &b){
  return isyear(a) && ismonth(b);
}


int main(){
  string in;
  cin >> in;
  string a = in.substr(0, 2), b = in.substr(2);
  bool my = ismy(a, b), ym = isym(a,b);
  if (my && ym){
    cout <<"AMBIGUOUS"<<endl;
  } else if (my){
    cout << "MMYY" << endl;
  } else if (ym){
    cout <<"YYMM" << endl;
  } else {
    cout << "NA"<<endl;
  }
  
  
  
  return 0;
}


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

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

    int ans = 9999;
    for (int i = 0; i < s.length()-2; i++) {
        int temp = 100*(s[i]-'0') + 10*(s[i+1]-'0') + (s[i+2]-'0');
        temp = abs(753-temp);
        ans = min(ans,temp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define all(x) (x).begin(), (x).end() 
 
typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
long long INF=numeric_limits<long long>::max();
 
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	ll w,h,x,y;
	cin >> w >> h >> x >> y;
	bool mult = 0;
	ld area = w*h;
	area /= 2;
	if(w%2==0&&x==w/2&&h%2==0&&y==h/2)mult = 1;
	cout << area << ' ' << mult << endl;
}


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

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

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int max_1st = 0, max_2nd = 0;
  rep(i, n) {
    cin >> a[i];
    if (a[i] > max_1st) {
      max_2nd = max_1st;
      max_1st = a[i];
    } else if (a[i] > max_2nd) {
      max_2nd = a[i];
    }
  }
  rep(i, n) {
    if (a[i] == max_1st) {
      cout << max_2nd << endl;
    } else {
      cout << max_1st << endl;
    }
  }

  return 0;
//  int ans = n - (int)(n - (float)n / (2 * d + 1)); // 切り上げ
//  cout << ans << endl;

//  vector<int> a(n);
//  rep(i,n) cin >> a[i];
//  ll x2 = 0;
//  rep(i,n) {
//    if (i%2) x2 -= a[i];
//    else x2 += a[i];
//  }
//  vector<int> ans(n);
//  ans[0] = x2/2;
//  rep(i,n-1) {
//    ans[i+1] = a[i]-ans[i];
//  }
//  rep(i,n) ans[i] *= 2;
//  rep(i,n) printf("%d%c", ans[i], i==n-1?'\n':' ');
}


Measured memory_bytes: 2432
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {

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

      char ca = "a".charAt(0);
      char cz = "z".charAt(0);
      int[] count = new int[26];

      br.lines()
        .filter(s -> s != null && !s.isEmpty())
        .map(String::toLowerCase)
        .map(s -> IntStream.range(0,s.length())
          .mapToObj(i -> s.charAt(i))
          .filter(c -> !(ca > c  || c > cz))
          .mapToInt(c -> count[c -ca] += 1) 
          .toArray() )
        .toArray();
      
      IntStream.range(0, count.length)
        .forEach(i -> System.out.println(Character.valueOf((char)(ca + (char)i)).toString() + " : " + count[i]));
    }
  }
}


Measured memory_bytes: 31704
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort()
B.sort()
C.sort()

answer = 0
for b_i in range(len(B)):
    value = B[b_i]
    """Aについて"""
    right = len(A)
    left = -1
    while right - left > 1:
        center = (right + left) // 2
        if A[center] >= value:
            right = center
        else:
            left = center
    a_num = left + 1
    
    """Cについて"""
    right = len(C)
    left = -1
    while right - left > 1:
        center = (right + left) // 2
        if C[center] <= value:
            left = center
        else:
            right = center
    c_num = len(C) - right

    answer += a_num*c_num

print(answer)

Measured memory_bytes: 23292
#include<stdio.h>

int N;
int a[108];
int c=0;

int main(){
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    a[N]=0;

    int A=0;
    for(int i=0;i<N-1;i++){
        A=a[i];
        int j=1;
        for(i;i<N&&a[i+1]==A;i++)j++;
        c+=j/2;

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

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct node{
	int x,y;
};
node a[101],b[101];

int dist(node da,node db){
	return abs(da.x-db.x)+abs(da.y-db.y);
}
int main(){
	int i,j,n,m,id,dism,disc;
	cin>>n>>m; 
	for(i=1;i<=n;i++){
		cin>>a[i].x>>a[i].y;
	} 
	for(j=1;j<=m;j++){
		cin>>b[j].x>>b[j].y;
	}
	for(i=1;i<=n;i++){
		dism=dist(a[i],b[1]);
		id=1;
		for(j=2;j<=m;j++){
			disc=dist(a[i],b[j]);
			if(disc<dism){
				dism=disc;
				id=j;
			}
		}
		cout<<id<<endl; 
	}
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
const int INF = 1<<20;
const int N = 101;
int cost[N][N];
int tim[N][N];
using namespace std;
int main()
{
	int n, m, a, b, co, ti,r;
	while (1){
		cin >> n >> m;
		if (n == 0 && m == 0)return 0;
		for (int i = 0; i < N; i++){
			for (int i2 = 0; i2 < N; i2++){
				cost[i][i2] = INF;
				tim[i][i2] = INF;
			}
		}
		for (int i = 0; i < n; i++){
			cin >> a >> b >> co >> ti;
			cost[a][b] = co;
			cost[b][a] = co;
			tim[a][b] = ti;
			tim[b][a] = ti;
		}
		for (int k = 0; k < N; ++k)
			for (int i = 0; i < N; ++i)
				for (int j = 0; j < N; ++j)
				{
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
					tim[i][j] = min(tim[i][j], tim[i][k] + tim[k][j]);
				}
		cin >> m;
		for (int i = 0; i < m; i++){
			cin >> a >> b >> r;
			if (r == 0){
				cout << cost[a][b] << endl;
			}
			else
				cout << tim[a][b] << endl;
		}
	}
}

Measured memory_bytes: 1240
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      br.readLine();
      final var a = Arrays.stream(br.readLine().split(" "))
          .mapToInt(Integer::parseInt)
          .toArray();
      final var q = Integer.parseInt(br.readLine());
      final var bc = new int[q][2];
      for (int i = 0; i < q; i++) {
        final var line = br.readLine().split(" ");
        bc[i][0] = Integer.parseInt(line[0]);
        bc[i][1] = Integer.parseInt(line[1]);
      }

      Map<Integer, Long> counts = new HashMap<>();
      for (int i = 0; i < a.length; i++) {
        counts.put(
            a[i],
            counts.containsKey(a[i]) ? counts.get(a[i]) + 1 : 1
        );
      }

      long sum = counts
          .entrySet()
          .stream()
          .mapToLong(entry -> entry.getKey() * entry.getValue())
          .sum();

      for (int i = 0; i < q; i++) {
        final long replaceCount = counts.containsKey(bc[i][0]) ?
                                  counts.get(bc[i][0]) :
                                  0L;

        if (replaceCount > 0) {
          counts.put(
              bc[i][1],
              counts.containsKey(bc[i][1]) ? counts.get(bc[i][1]) + replaceCount : replaceCount
          );
          counts.put(
              bc[i][0],
              0L
          );
        }

        sum += replaceCount * (bc[i][1] - bc[i][0]);

        System.out.println(sum);
      }
    }
  }
}


Measured memory_bytes: 67248
from itertools import permutations
def main():
    C = list(map( int, input().split()))
    S = [1, 2, 4,8]
    N = 4*int( input())
    ans = 10**20
    for P in permutations( range(4)):
        cost = 0
        left = N
        for i in P:
            cost += left//S[i]*C[i]
            left -= left//S[i]*S[i]
        if cost < ans:
            ans = cost
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.*;

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

      if(N<=M){
		System.out.println("Yes");
    }else{
		System.out.println("No");
    }
}
}

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

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 Unionfind {
    vector<int> par;
    vector<int> sizes;

    Unionfind(int n) : par(n), sizes(n, 1) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }

    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        par[ry] = rx;
        sizes[rx] += sizes[ry];
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return sizes[root(x)];
    }

};

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

    string s;
    cin >> s;

    string ans = s;

    if(s.back() == 's') {
        ans += "es";
        cout << ans << endl;
        return 0;
    }
    else {
        ans += "s";
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  string s;
  cin >> s;
  ll n=s.size();
  if(s[0]!='1'||s[n-1]!='0') {
    cout << -1 << "\n";
    return 0;
  }
  for(ll i=0;i<n&&n-2-i>=0;i++) {
    if(s[i]!=s[n-2-i]) {
      cout << -1 << "\n";
      return 0;
    }
  }
  set<ll> f;
  for(ll i=0;i<n;i++) {
    if(s[i]=='1'||i==n-1) {
      for(auto j=f.begin();j!=f.end();j=f.erase(j)) {
        cout << *j+1 << " " << i+1 << "\n";
      }
    }
    f.insert(i);
  }
}

Measured memory_bytes: 8328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  string s;
  getline(cin, s);
  stack<int> st;
  for (int i = 0; i < s.size(); ++i)
  {
    if (isdigit(s[i]))
    {
      int val = s[i] - '0';
      while (isdigit(s[i + 1]))
      {
        val *= 10;
        val += s[i + 1] - '0';
        i++;
      }
      st.push(val);
    }
    else if (s[i] != ' ')
    {
      int r = st.top();
      st.pop();
      int l = st.top();
      st.pop();
      int val = 0;
      if (s[i] == '+')
        val = l + r;
      else if (s[i] == '-')
        val = l - r;
      else if (s[i] == '*')
        val = l * r;
      else if (s[i] == '/')
        val = l / r;
      st.push(val);
    }
  }
  cout << st.top() << endl;

  return 0;
}



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

const ll mod = 1000000007;
const double eps = 1e-8;
const ll INF = 100000000;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N;
    cin >> N;
    vector<ll> A(N+1);
    for (int i=0; i<N+1; ++i) cin >> A[i];

    if (A[0] > 0) {
        if (A[0] == 1 && N == 0) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }

    ll sum = 1;
    vector<ll> left(N+2, 0), lazy(N+2, 0);
    left[0] = 2;
    left[N+1] = INF;
    int k = 0;
    for (int i=1; i<=N; ++i) {
        while (A[i]) {
            while (left[k] == 0) {
                k ++;
                if (lazy[k]) {
                    left[k] += lazy[k];
                    lazy[k+1] += lazy[k];
                    lazy[k] = 0;
                }
                if (k >= i) {
                    cout << -1 << endl;
                    return 0;
                }
            }
            ll d = min(left[k], A[i]);
            sum += (i - k) * d;
            A[i] -= d;
            left[k] -= d;
            lazy[k+1] += d;
            lazy[i] -= d;
        }
    }
    cout << sum << endl;

    return 0;
}

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

using namespace std;
using ll = long long;

int K;

template<class T>
struct Vector {
  vector<T> v;
  Vector(int sz) : v(sz, 0) {}
  Vector() : v(0) {}
  Vector(vector<T> t) : v(t) {}
  inline auto& operator[](size_t pos) {
    return v[pos];
  }
  auto begin() {
    return v.begin();
  }
  auto end() {
    return v.end();
  }
  inline auto size() {
    return v.size();
  }
  auto push_back(T t) {
    v.push_back(t);
  }
  auto pop_back() {
    v.pop_back();
  }
  inline auto& back() {
    return v.back();
  }
  friend auto& operator>>(istream& lhs, Vector& rhs) {
    for (int i = 0; i < rhs.size(); i++) lhs >> rhs[i];
    return lhs;
  }
  friend auto& operator<<(ostream& lhs, Vector& rhs) {
    for (int i = 0; i + 1 < rhs.size(); i++) lhs << rhs[i] << endl;
    if (rhs.size()) lhs << rhs.back();
    return lhs;
  }
};

Vector<ll> calc(Vector<ll>& x, Vector<ll>& y)
{
  Vector<ll> res;
  for (ll X : x) {
    for (ll Y : y) {
      res.push_back(X + Y);
    }
  }
  sort(res.begin(), res.end(), greater<ll>());
  while (res.size() > K) res.pop_back();
  return res;
}

int main()
{
  int x, y, z;
  cin >> x >> y >> z >> K;
  Vector<ll> a(x), b(y), c(z);
  cin >> a >> b >> c;
  auto v = calc(a, b);
  v = calc(v, c);
  cout << v << endl;
}


Measured memory_bytes: 42728
#include<bits/stdc++.h>  
    using namespace std;  
       
    template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }  
    template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " "<<a.second; }  
    template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }  
    template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }  
       
    #define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)  
    #define ALL(v) (v).begin(), (v).end()  
    #define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}  
    #define fr first  
    #define sc second  
       
    typedef pair< char , int > Pi;  
    typedef pair< int , Pi > Pii;  
       
    typedef long long int64;  
    const int INF = 1 << 28;  
      
    int main(){  
      int N;  
      vector< int > D, A, Buffer(7), pos(7);  
      vector< vector< int > > Rank, dp, next;  
      
      /* 順番の組み合わせ */  
      for(int i = 0; i < 7; i++) Buffer[i] = i;  
      do Rank.push_back(Buffer); while(next_permutation(ALL(Buffer)));  
      
      cin >> N;  
      D.resize(N), A.resize(N);  
      next.resize( Rank.size(), vector< int >(8));  
      cin >> D;  
      cin >> A;  
        
      for(int i = 0; i < Rank.size(); i++){  
        vector< int > tmp1, tmp2;  
        for(int j = 0; j < 8; j++){  
          tmp1 = Rank[i];  
          for(int k = 0; k < 7; k++){  
            if(tmp1[k] >= j) tmp1[k]++;  
          }  
          tmp2.clear();  
          for(int k = 1; k <= 7; k++){  
            tmp2.push_back(tmp1[k]);  
            if(tmp2[k - 1] > tmp1[0]) tmp2[k - 1]--;  
          }  
      
          next[i][j] = lower_bound(ALL(Rank), tmp2) - Rank.begin();  
        }  
      }  
      dp.resize( 101, vector< int >( Rank.size(), 0));  
      
      int ret = 0;  
      for(int i = 0;i < N;i++){  
        for(int j = 0;j < Rank.size();j++){  
          for(int k = 0;k < 7;k++){  
            pos[Rank[j][k]] = k;  
          }  
      
          int res = dp[i][j];  
          for(int k = 0;k < 7;k++){  
            if(i - 7 + k >= 0 && 7 - k <= D[i]) res += A[i];  
          }  
          for(int k = 0; k < 8; k++){ //小籠包iを何番目に食べるか  
            dp[i + 1][next[j][k]] = max( dp[i + 1][next[j][k]], res);  
            ret = max( ret, dp[i + 1][next[j][k]]);  
            if(i - 7 + pos[k] >= 0 && 7 - pos[k] <= D[i]) res -= A[i];  
            if(i - 7 + pos[k] >= 0 && 7 - pos[k] <= D[i - 7 + pos[k]]) res += A[i - 7 + pos[k]];  
          }  
        }  
      }  
      cout << ret << endl;  
    }  

Measured memory_bytes: 3912
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define mk make_pair
#define endl '\n'

int main()
{
    IOS;
    int n,m;
    cin>>n>>m;
    vector<int> height(n+1,0);
    for (int i = 1; i < n+1; i++)
    {
        cin>>height[i];
    }
    vector<bool> flag(n+1,1);
    for (int i = 0; i < m; i++)
    {
        int x,y;
        cin>>x>>y;
        if(height[x]<=height[y])    flag[x]=0;
        if(height[y]<=height[x])    flag[y]=0;
    }
    int count=0;
    for (int i = 1; i < n+1; i++)
    {
        if(flag[i]) count++;
    }
    cout<<count;
}

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

struct state {
  ll v, cost;
  bool operator>(const state s) const { return cost > s.cost; }
};

vector<ll> dijkstra(const vector<vector<pair<int, ll>>> &graph, int s) {
  vector<ll> dp(graph.size(), 1e18);
  priority_queue<state, vector<state>, greater<state>> q;
  q.push(state{s, 0});
  while (!q.empty()) {
    int v = q.top().v;
    ll cost = q.top().cost;
    q.pop();
    if (dp[v] <= cost) continue;
    dp[v] = cost;
    for (auto e : graph[v]) {
      ll nv = e.first, ncost = cost + e.second;
      if (dp[nv] > ncost) q.push(state{nv, ncost});
    }
  }
  return dp;
}

int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;
  vector<vector<pair<int, ll>>> a(n), b(n);
  for (int i = 0; i < m; i++) {
    int u, v, ai, bi;
    cin >> u >> v >> ai >> bi;
    u--;
    v--;
    a[u].push_back({v, ai});
    a[v].push_back({u, ai});
    b[u].push_back({v, bi});
    b[v].push_back({u, bi});
  }
  vector<ll> c = dijkstra(a, s), d = dijkstra(b, t);
  vector<ll> r(n);
  for (int i = 0; i < n; i++) {
    r[i] = c[i] + d[i];
  }
  for (int i = n - 2; i >= 0; i--) {
    r[i] = min(r[i], r[i + 1]);
  }
  for (auto e : r) {
    cout << (ll)1e15 - e << endl;
  }
}


Measured memory_bytes: 19004
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int[] a = new int[8];
			int[] b = new int[8];
			int[] c = new int[8];
			int[] d = new int[6];
			
			double[] at = new double[8];
			double[] bt = new double[8];
			double[] ct = new double[8];
			double[] dt = new double[6];
			double[] temp = new double[8];
			double[] tempd = new double[6];
			
			for(int i=0;i<8;i++){
				a[i] = sc.nextInt();
				at[i] = sc.nextDouble();
			}
			temp = Arrays.copyOf(at, 8);
			Arrays.sort(temp);
			for(int i=0;i<8;i++) if(at[i]==temp[0]) System.out.printf("%d %.2f\n", a[i],at[i]);
			for(int i=0;i<8;i++) if(at[i]==temp[1]) System.out.printf("%d %.2f\n", a[i],at[i]);
			for(int i=0;i<8;i++){
				if(at[i]==temp[2]){
					d[0] = a[i];
					dt[0] = at[i];
				}else if(at[i]==temp[3]){
					d[1] = a[i];
					dt[1] = at[i];
				}
			}
			
			for(int i=0;i<8;i++){
				b[i] = sc.nextInt();
				bt[i] = sc.nextDouble();
			}
			temp = Arrays.copyOf(bt, 8);
			Arrays.sort(temp);
			for(int i=0;i<8;i++) if(bt[i]==temp[0]) System.out.printf("%d %.2f\n", b[i],bt[i]);
			for(int i=0;i<8;i++) if(bt[i]==temp[1]) System.out.printf("%d %.2f\n", b[i],bt[i]);
			for(int i=0;i<8;i++){
				if(bt[i]==temp[2]){
					d[2] = b[i];
					dt[2] = bt[i];
				}else if(bt[i]==temp[3]){
					d[3] = b[i];
					dt[3] = bt[i];
				}
			}
			
			for(int i=0;i<8;i++){
				c[i] = sc.nextInt();
				ct[i] = sc.nextDouble();
			}
			temp = Arrays.copyOf(ct, 8);
			Arrays.sort(temp);
			for(int i=0;i<8;i++) if(ct[i]==temp[0]) System.out.printf("%d %.2f\n", c[i],ct[i]);
			for(int i=0;i<8;i++) if(ct[i]==temp[1]) System.out.printf("%d %.2f\n", c[i],ct[i]);
			for(int i=0;i<8;i++){
				if(ct[i]==temp[2]){
					d[4] = c[i];
					dt[4] = ct[i];
				}else if(ct[i]==temp[3]){
					d[5] = c[i];
					dt[5] = ct[i];
				}
			}
			
			tempd = Arrays.copyOf(dt, 6);
			Arrays.sort(tempd);
			for(int i=0;i<6;i++) if(dt[i]==tempd[0]) System.out.printf("%d %.2f\n", d[i],dt[i]);
			for(int i=0;i<6;i++) if(dt[i]==tempd[1]) System.out.printf("%d %.2f\n", d[i],dt[i]);
			
		}
	}	
}

Measured memory_bytes: 20204
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const ll INF = 1 << 29;
int N, M;
int x[100001];
int y[100001];
bool redpos[100001];
int number[100001];

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

    cin >> N >> M;
    for(int i = 0; i < M; ++i){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }

    redpos[0] = true;
    for(int i = 0; i < N; ++i){
        number[i] = 1;
    }
    for(int i = 0; i < M; ++i){
        if(redpos[x[i]]){
            redpos[y[i]] = true;
            if(number[x[i]] == 1){
                redpos[x[i]] = false;
            }
        }
        number[x[i]]--;
        number[y[i]]++;
    }
    int cnt = 0;
    for(int i = 0; i < N; ++i){
        if(redpos[i]){
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1536
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
int m[102];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x,n,k,i,j,d,c=0;
    cin>>n>>k;
    for(i=0;i<k;++i){
    	cin>>d;
    	for(j=0;j<d;++j){
    		cin>>x;
    		m[x]++;
		}
	}
	for(i=1;i<=n;++i){
		if(!m[i]){
			c++;
		}
	}
	cout<<c;
}

Measured memory_bytes: 3644
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){


    string S;
    int N;
    
    cin >> N;
    cin >> S;

    char target;

    int tar;
    for( int si = 0 ; si <S.length() ; si++ ){
        tar = (int)S[si];
        tar = ( (tar+N-65) % 26 );
        printf("%c",'A'+tar);

    }
    


}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>  //setprecision(桁)
using namespace std;
#define pb push_back
#define ll long long int
#define rep(i,n) for(int i = 0;i < n;i++)
#define INF 1e+9
const ll MOD = 1000000007;

struct edge {
    int to;
    ll cost;
};

// <最短距離, 頂点の番号>
using P = pair<double, int>;

int V;
const int ci = 2e5+ 5;
vector<edge> G[ci];
double d[ci];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i=0; i<G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

vector<edge> g[100005];
int main() {
    string s; cin >> s;
    int n = s.size();
    vector<int> r,l,check,R,L;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R'){
            cnt++;
        }else{
            if(cnt) {
                r.pb(cnt);
                check.pb(i);
            }
            cnt = 0;
        }
    }
    for(int i = 0; i < n; i++){
        if(s[i] == 'L'){
            cnt++;
        }else{
            if(cnt) l.pb(cnt);
            cnt = 0;
        }
    }l.pb(cnt);

    int N = r.size();
    vector<int> ans(n);
    for(int i = 0; i < N; i++){
        ans[check[i] - 1] = r[i] - r[i] / 2 + l[i] / 2;
        ans[check[i]] = l[i] - l[i] / 2 + r[i] / 2;
    }
    rep(i,n) cout << ans[i] << " ";
    cout << endl;
}


Measured memory_bytes: 10428
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>//cout << fixed からの cout << setprecision(n) << 小数　によって小数を整数部分含めてn桁表示できるようにする
#include <cctype>
#include <unordered_map>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  //cout << a << endl;

  deque<string> b;
  if(n % 2 == 0){
    for(int i = 0;i < n; i++){
      if (i % 2 == 0) b.push_back(a[i]);
      else b.push_front(a[i]);
    }
  }else{
    for(int i = 0;i < n; i++){
      if (i % 2 != 0) b.push_back(a[i]);
      else b.push_front(a[i]);
    }
  }
  string ans = "";
  for(int i = 0;i < n; i++){
    if (i != n-1) ans += b[i]+' ';
    else ans += b[i];
  }
  cout << ans << endl;
  return 0;

  /*
  string b = "";

  if (n % 2 == 0){
    for(int i = 0; i < n; i++){
      if (i % 2 == 0) b += a[i] +" ";
      else b = a[i] + " " + b;
    }
  }else{
    for(int i = 0; i < n; i++){
      if (i % 2 != 0) b += a[i] +" ";
      else b = a[i] + " " + b;
    }
  }

  cout << b.substr(0,b.length()-1) << endl;
  */
}


Measured memory_bytes: 19716
import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
perm = itertools.permutations(range(1, N+1), N)

cnt = 0
flg = 0
for p in perm:
  cnt = cnt + 1
  if p == P:
    cnt_P = cnt
    flg = flg + 1
  if p == Q:
    cnt_Q = cnt
    flg = flg + 1
  if flg == 2:
    break
print(abs(cnt_P - cnt_Q))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define ARRAY_LEN(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INTINF = 2147483647;
const int MOD = 1000000007;

int main() {
  int x, a, b; cin >> x >> a >> b;
  string result;
  if (abs(x-a) <= abs(x-b)) result = "A";
  else result = "B";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int h,w;
	cin>>h>>w;
	char c[51][51]={};
	rep(i,0,h) rep(j,0,w) cin>>c[i][j];
	int dp[51][51]={};
	rep(i,0,h) rep(j,0,w) dp[i][j]=10000;
	dp[0][0]=0;
	rep(i,0,h){
		rep(j,0,w){
			if(i!=0) dp[i][j]=min(dp[i][j],dp[i-1][j]+(c[i][j]-'0'));
			if(j!=0) dp[i][j]=min(dp[i][j],dp[i][j-1]+(c[i][j]-'0'));
		}
	}
	cout<<dp[h-1][w-1]<<endl;
}

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

vector<int> a, b, c, d;
int ans = 0;

void dfs(int val, int n, int m, int q, vector<int> A) {
	if (A.size() == n) {
		int tmp = 0;
		for (int i = 0; i < q; i++) {
			if (A[b[i]] - A[a[i]] == c[i]) tmp += d[i];
		}
		ans = max(ans, tmp);		
	}
	else {
		A.push_back(val);
		for (int i = 1; i <= m; i++) {
			if (i < val) continue;
			dfs(i, n, m, q, A);
		}
	}
	return;
}


int main() {

	int n, m, q; cin >> n >> m >> q;
	a.resize(q);
	b.resize(q);
	c.resize(q);
	d.resize(q);
	for (int i = 0; i < q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		--a[i];
		--b[i];
	}
	vector<int> A;
	int val = 1;
	dfs(val, n, m, q, A);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

string s;

Int dp[100000+10][15];



int main(void) {
    cin>>s;

    int n = s.size();

    dp[0][0] = 1;
    for(int i = 0;i < n;i++) {
        int c;
        if(s[i] == '?') {
            c = -1;
        } else {
            c = s[i] - '0';
        }

        for(int j = 0;j < 10;j++) {
            if(c != -1 && c != j)
                continue;
            for(int ki = 0;ki < 13;ki++) {
                dp[i+1][(ki*10 + j) % 13] += dp[i][ki];
            }
        }

        for(int j = 0;j < 13;j++) {
            dp[i+1][j] %= MOD;
        }

    }

    cout<<dp[n][5]<<endl;

    return 0;
}


Measured memory_bytes: 12160
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 1e+9
#define int long long
using namespace std;
 
typedef pair<int,int> P;
 
 int n,l,t,x[100000],w[100000],cnt = 0,start,ans[100000];
 vector<P> vec;
 
signed main(){
	cin >> n >> l >> t;
	for(int i = 0;i < n;i++){
		cin >> x[i] >> w[i];
		if(w[0] != w[i]){
			if(w[0] == 1 && (x[i] - x[0]) <= t * 2) cnt += (t * 2 - (x[i] - x[0])) / l + 1;
			if(w[0] == 2 && (l + x[0] - x[i]) <= t * 2) cnt += (t * 2 - (l + x[0] - x[i])) / l + 1;
		}
	}
	cnt %= n;
	if(w[0] == 2) cnt = -cnt;
	for(int i = 0;i < n;i++){
		if(w[i] == 1) (x[i] += t) %= l;
		else x[i] = (x[i] - t + 2 * (int)INF * l) % l;
		vec.push_back(P(x[i],-w[i]));
	}
	sort(vec.begin(),vec.end());
	for(int i = 0;i < n;i++){
		if(vec[i].first == x[0] && vec[i].second == -w[0]) start = i;
	}
	for(int i = 0;i < n;i++) ans[(i + cnt + n) % n] = vec[(i + start) % n].first;
	for(int i = 0;i < n;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 5232
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main(){
  //順列生成
  int n;
  cin >> n;
  vector<int> p(n),q(n);
  int i;
  for(i=0;i<n;i++) cin >> p[i];
  for(i=0;i<n;i++) cin >> q[i];
  vector<int> v; //push_backするからサイズ未指定
  for(i=0;i<n;i++) v.push_back(i+1);
  int cnt = 0;
  int a=0, b=0;
  do{
    cnt++;
    bool flaga = true,flagb = true;
    for(i=0;i<n;i++) if(p[i] != v[i]) flaga = false;
    for(i=0;i<n;i++) if(q[i] != v[i]) flagb = false;
    if(flaga) a=cnt;
    if(flagb) b=cnt;
  }while(next_permutation(v.begin(),v.end()));
  cout << abs(a-b) << "\n";
  return 0;
}

Measured memory_bytes: 256