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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    int t = x/d;
    if(t >= k) {
        x -= k * d;
        cout << x << endl;
        return 0;
    }
    x -= t * d;
    k -= t;
    if(k & 1) {
        x -= d;
        cout << abs(x) << endl;
    }
    else 
        cout << x << endl;

    return 0;
}



Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string n;
  cin >> n;
  cout << "ABC" << n << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	long long n;
	scanf("%lld\n",&n);
	int ans=0;
	for(long long i=2;i*i<=n;i++)if(n%i==0){
		int cnt=0;
		while(n%i==0)n/=i,cnt++;
		for(int j=1;j<=cnt;j++){
			cnt-=j;
			ans++;
		}
	}
	if(n!=1)ans++;
	printf("%d\n",ans);
}

Measured memory_bytes: 1732
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string

let cnt = a 
  |> List.sort compare
  |> List.fold_left (fun acc n ->
    match acc with
      | [] -> [(n, 1)]
      | (v, cnt) as t :: xs -> if v = n then (v, cnt + 1) :: xs else (n, 1) :: t :: xs
  ) []

module IntMap = Map.Make(struct
  type t = int
  let compare = compare
end)

let map = List.fold_left (fun map (k, v) -> IntMap.add k v map) IntMap.empty cnt

let sum = List.fold_left (fun sum (_, cnt) -> sum + cnt * (cnt - 1) / 2) 0 cnt

let () = List.iter(fun i ->
  Printf.printf "%d\n" @@ sum - IntMap.find i map + 1
) a

Measured memory_bytes: 31032
from collections import defaultdict
import sys

input = sys.stdin.buffer.readline

n = int(input())
A = list(map(int, input().split()))
jisho = defaultdict(int)
for a in A:
    jisho[a] += 1
A.sort()
ans = 0
for i in range(n - 1, -1, -1):
    num = A[i]
    if jisho[num] == 0:
        continue
    jisho[num] -= 1
    temp = num // (num & -num)
    keta = temp.bit_length()
    kouho = 1
    for i in range(1, keta):
        if (temp >> i) & 1 == 0:
            kouho += 1 << i
    kouho *= num & -num
    if jisho[kouho] > 0:
        # print(num, kouho)
        jisho[kouho] -= 1
        ans += 1
print(ans)


Measured memory_bytes: 126940
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    cin>>N;
    set<ll> s;
    for(ll i = 1; i * i <= N; ++i){
        if(N % i == 0){
            s.insert(i);
            s.insert(N / i);
        }
    }
    --N;
    for(ll i = 1; i * i <= N; ++i){
        if(N % i == 0){
            s.insert(i);
            s.insert(N / i);
        }
    }
    s.erase(1);
    ++N;
    ll ans = 0;
    for(ll a : s){
        ll temp = N;
        while(temp%a == 0) temp /= a;
        ans += temp%a == 1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
/*
 Abu Jafor Mohammad Saleh
 ios_base :: sync_with_stdio(false);
 cin.tie(NULL);
 */

#include<cstdio>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<limits>
#include <algorithm>
#include <unordered_map>
#include<fstream>
#define f first
#define s second
#define MOD 1000000007

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define BOUNDARY(i, j) ((i >= 0 && i < rows) && (j >= 0 && j < coloums))
#define mx 6e5 + 100;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//#include<bits/stdc++.h>
#define ll long long
const int maxn = 20005;
using namespace std;
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
int rows,coloums;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
    fast;
    int a,b;
    cin>>a>>b;
    if(a<=b)
    {
        for(int i=1;i<=b;i++)
            cout<<a;
    }
    else
        for(int i=1;i<=a;i++)
            cout<<b;
    cout<<endl;
        
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int n,m,i;
	long long sum = 0;
	scanf("%d %d",&n,&m);
	priority_queue<int> q;
	for(i=0;i<n;i++)
	{
		int x;
		scanf("%d",&x);
		q.push(x);
	}
	while (m--)
	{
		int x = q.top();
		q.pop();
		q.push(x / 2);
	}
	while (!q.empty())
	{
		sum += q.top();
		q.pop();
	}
	cout << sum;
	return 0;
}


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

using namespace std;
// a - b
// a inc b dec
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define mmin(a, b) a = min(a, (b))
#define mmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define pb(a) push_back(a)
#define ALL(a) a.begin(),a.end()
#define sqr(x) (x) * (x)
#define fori(i, n) for(int i = 0; i < (int)(n); ++i)
#define cint const int &
#define SZ(a) ((int)(a.size()))
#define f(cnt) (((cnt) + 1) * (cnt) / 2)
#define watch(x) cout << (#x) << " = " << x << endl;
//#define log log10

const double PI = 2 * acos(0.0);

template<typename T>
struct edge {
    int from, to;
    T w;
    edge(int from, int to, T w): from(from), to(to), w(w) { }
    edge() { }
};


template<class T>
void show(T a) {
    for (auto x : a)
        cout << x << " ";
    cout << endl;
}

const int N = 2e5 + 9;


vector<edge<bool>> e;
vi g[N];
int n, m;
bool mark[N];
char used[2][N];

void dfs(int z, int v) {
    used[z][v] = 1;
    for (int id : g[v]) {
        int to = e[id].to;
        if (e[id].w != z) continue;
        if (used[!z][to] == 1) {
            cout << "Yes";
            exit(0);
        } else if (!used[!z][to]) dfs(!z, to);
    }
    used[z][v] = 2;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;
    string s;
    cin >> s;
    fori (i, n) {
        mark[i + 1] = s[i] == 'A';
    }
    fori (i, m) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(e.size());
        e.push_back(edge<bool>(u, v, mark[u] ^ mark[v]));
        g[v].push_back(e.size());
        e.push_back(edge<bool>(v, u, mark[u] ^ mark[v]));
    }

    for (int i = 1; i <= n; ++i) {
        for (int z = 0; z < 2; ++z) {
            if (!used[z][i]) dfs(z, i);
        }
    }
    cout << "No";
}

Measured memory_bytes: 25596
#include <cstdio>
#include <vector>

using namespace std;

char s[100][100];

int H, W;

void dfs(int i, int j, char c)
{
	if (i>=0 && i<H && j>=0 && j<W && s[i][j]==c) {
		s[i][j] = '\0';
		dfs(i-1, j, c);
		dfs(i+1, j, c);
		dfs(i, j-1, c);
		dfs(i, j+1, c);
	}
}


int main()
{
	//freopen("in.txt", "r", stdin);

	while (scanf("%d%d", &H, &W)==2) {
		if (H==0 && W==0) break;
		int i, j;
		for (i=0; i<H; i++) {
			for (j=0; j<W; j++) {
				char c;
				do { c=getchar(); } while (c!='@' && c!='#' && c!='*');
				s[i][j] = c;
			}
		}

		int count = 0;
		for (i=0; i<H; i++) {
			for (j=0; j<W; j++) {
				if (s[i][j]!='\0') {
					count++;
					dfs(i, j, s[i][j]);
				}
			}
		}
		printf("%d\n", count);

	}

	return 0;
}

Measured memory_bytes: 1344
n = int(input())
a = list(input())
b = list(input())
ans = 1
mod = 10**9 + 7
i = 0
while i <= n-1:
  
  if i == 0:
    if a[i] == b[i]:
      ans *= 3
      i += 1
    elif not a[i] == b[i]:
      ans *= 6
      i += 3
  else:
    if a[i-1] == b[i-1]:
      if a[i] == b[i]:
        ans *= 2
        i += 1
      else:
        ans *= 2
        i += 2
    elif not a[i-1] == b[i-1]:
      if not a[i] == b[i]:
        ans *= 3
        i += 2
      else:
        i += 1

print(ans % mod)

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

int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    
    int cnt = 0;
    for ( int i = 0 ; i <= a ; i++ ){
        for ( int j = 0 ; j <= b ; j++ ){
            for ( int k = 0 ; k <= c ; k++ ){
                if ( 500 * i + 100 * j + 50 * k == x )
                    cnt++;
            }
        }
    }
    cout << cnt << endl;
}

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

int main(void){
  const ll MINUSINF = -1e11;
  const ll INF = 1e11;
  int A, B;
  int Q;
  cin >> A >> B;
  cin >> Q;
  ll s[A+2], t[B+2];
  s[0] = MINUSINF; s[A+1] = INF;
  t[0] = MINUSINF; t[A+1] = INF;
  for(int i=1; i<=A; i++) cin >> s[i];
  for(int i=1; i<=B; i++) cin >> t[i];
  
  for(int i=0; i<Q; i++) {
    ll x;
    cin >> x;
    ll *lA, *rA;
    rA = upper_bound(s, s+A+1, x);
    lA = rA - 1;
    
    ll *lB, *rB;
    rB = upper_bound(t, t+B+1, x);
    lB = rB - 1;
    
    ll ans = 0;
    ans = abs(x-*lA) + abs(*lA-*lB); //lA -> lB
    ans = min(ans, abs(x-*lA) + abs(*lA-*rB)); //lA -> rB

    ans = min(ans, abs(x-*rA) + abs(*rA-*lB)); //rA -> lB
    ans = min(ans, abs(x-*rA) + abs(*rA-*rB)); //rA -> rB

    ans = min(ans, abs(x-*lB) + abs(*lB-*lA)); //lB -> lA
    ans = min(ans, abs(x-*lB) + abs(*lB-*rA)); //lB -> rA

    ans = min(ans, abs(x-*rB) + abs(*rB-*lA)); //rB -> lA
    ans = min(ans, abs(x-*rB) + abs(*rB-*rA)); //rB -> rA
    
    printf("%lld\n", ans);
//    cout << ans << endl;
    
//    cout << "x: " << x << ", lA: " << *lA << ", rA: " << *rA << endl;
  }
  return 0;
}


Measured memory_bytes: 2816
N = int(input())
src = [input() for i in range(N)]
ans = a = 0
for s in src:
    if s == 'A': a += 1
    elif a > 0:
        a -= 1
    else:
        print('NO')
        break
else:
    print('YES' if a == 0 else 'NO')

Measured memory_bytes: 5604
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll beki(ll n){
	if(n==0) return 1;
	else return beki(n-1)*2;
}
int main(){
  	ll N, M;
  	cin >> N >> M;

  	cout << (1900*M + 100*(N-M))*beki(M) <<endl;

    
  	return 0;
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
map<pii,LL>mp;
int  main()
{
    LL n;
    cin>>n;
    for(LL i=1;i<=n;i++)
    {
        LL a=i;
        LL cnt=0;
        while(a)
        {
            a=a/10;
            cnt++;
        }
        a=1;
        while(cnt>1)
        {
            a=a*10;
            cnt--;
        }
        a=i/a;
        LL b=i%10;
//        cout<<i<<" "<<a<<" "<<b<<endl;
        mp[{a,b}]++;
    }
    LL cnt=0;
    for(LL i=1;i<=9;i++)
    {
        for(LL j=1;j<=9;j++)
        {
            cnt+=mp[{i,j}]*mp[{j,i}];
        }
    }
    cout<<cnt;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	char last = ' ';
	int res = 0;
	for (auto ss : s) {
		if (ss != last) res++;
		last = ss;
	}
	cout << res << endl;
}


Measured memory_bytes: 3768
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e3 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
int dp[N][N], a[N], b[N];

signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= m; i++)
        cin >> b[i];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            if(i == 0 && j == 0)
                dp[i][j] = 1;   
            else if(i == 0)
                dp[i][j] = dp[i][j-1];
            else if(j == 0)
                dp[i][j] = dp[i-1][j];
            else{
                dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + mod) % mod;
                if(a[i] == b[j])
                    dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % mod;
            }
        }
    }   
    cout << dp[n][m];
    return 0;
}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x=0,n,a[100];
  cin>>n;
  for(int i = 0 ; i < n; i++){
    cin>>a[i];
  }
  for(int i=0;i<n-1;i++){
    int min=i;
    for(int j=i;j<n;j++){
      if(a[min]>a[j]) min=j;
    }
    if(min==i) 1;
    else {
      int tmp;
      tmp=a[i];
      a[i]=a[min];
      a[min]=tmp;
      x++;
    }
  }
  for(int i=0; i<n;i++){
    if(i!=0) cout<<" ";
    cout<<a[i];
  }
  cout<<endl<<x<<endl;
  return 0;
}



Measured memory_bytes: 3092
n = int(raw_input())
a = map(int, raw_input().split())

flag = 1
count = 0
while flag:
    flag = 0
    for j in range(n-1, 0, -1):
        if a[j] < a[j-1]:
            tmp = a[j]
            a[j] = a[j-1]
            a[j-1] = tmp
            count += 1
            flag = 1
            #print a

for i in range(n):
    if i == n -1:
        print a[i]
    else:
        print a[i],

print count

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

int min(int a, int b)
{
    if(a>b)
    return b;
    else
    return a;
}

int maxim(int a, int b)
{
    if(a>b)
    return a;
    else
    return b;
}

int main()
{
    int N;
    long int W;
    cin >> N >> W ;
    int v[N];
    int w[N];

    for(int i=0;i<N;i++)
    {
        cin>>w[i]>>v[i];
    }

    int val_sum=0;
    for(int i=0;i<N;i++)
    {
        val_sum = v[i]+val_sum;
    }

    vector <long long> dp(val_sum+1,INT_MAX);
    dp[0]=0;
    for(int i=1;i<N+1;i++)
    {
        for(int j=val_sum;j>=1;j--)
        {
            if(v[i-1]<=j)
            {
                dp[j]=min(w[i-1]+dp[j-v[i-1]],dp[j]);
            }
           
        }
    }
    int max_val=0;

    for(int i=0;i<val_sum+1;i++)
    {
        if(dp[i]<=W)
        max_val=maxim(i,max_val);
        else
        continue;
        
    }
    cout<<max_val;
    return 0;

}

Measured memory_bytes: 4044
N = int(input())
XL = sorted([list(map(int,input().split())) for i in range(N)],key = lambda x:x[0]+x[1])
count = 0
now = -float('inf')
for i in range(N):
    if now <= XL[i][0]-XL[i][1]:
        count += 1
        now = XL[i][0]+XL[i][1]
print(count)

Measured memory_bytes: 33064
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double EPS=1e-9;
const int MOD=1e9+7;
int main(){
    int n,m;cin>>n>>m;
    string s;cin>>s;
    vector<vector<int>> G(n);
    vector<int> c1(n),c2(n);
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;--a;--b;
        G[a].push_back(b);
        G[b].push_back(a);
        if(s[a]=='A'){
            c1[b]++;
        }else{
            c2[b]++;
        }
        if(s[b]=='A'){
            c1[a]++;
        }else{
            c2[a]++;
        }
    }
    stack<int> st;
    int co=0;
    for(int i=0;i<n;i++){
        if(c1[i]==0||c2[i]==0){
            st.push(i);
            co++;
        }
    }
    while(!st.empty()){
        int v=st.top();st.pop();
        for(auto e:G[v]){
            if(s[v]=='A'){
                c1[e]--;
                if(c1[e]==0&&c2[e]){
                    st.push(e);
                    co++;
                }
            }else{
                c2[e]--;
                if(c1[e]&&c2[e]==0){
                    st.push(e);
                    co++;
                }
            }
        }
    }
    if(co!=n){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 12164
#include <iostream>

using namespace std;

int main()
{
  int a,b,c;

  cin >> a >> b >> c;

  if(a == b && b == c)
    cout << "1" << endl;
  else if(a == b || a == c || b == c)
    cout << "2" << endl;
  else
    cout << "3" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(ll i=0;i<n;i++)
#define revf(i,n) for(ll i=n-1;i>=0;i-=2)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define inp(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define outp(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" "
#define outp1(a,n) for(ll i=1;i<n;i++)cout<<a[i]<<" "
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))
#define pb push_back
#define mp make_pair
#define mem(x,n) memset(x,n,sizeof(x))
#define BINSC binary_search
#define BITOUT __builtin_popcount
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define cn cout<<"\n";
int main()
{
        string s;
        cin>>s;
        if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')
        cout<<3;
        else if(s[0]=='R'&&s[1]=='R')
        cout<<2;
        else if(s[1]=='R'&&s[2]=='R')
        cout<<2;
        else if(s[0]=='R'||s[1]=='R'||s[2]=='R')
        cout<<1;
        else cout<<0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(i, n) a[idx][i] = v[i]; idx++; PER = a;} while(next_permutation(ALL(v)));} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const int INF = 1e9;
const LL MOD = 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;}

void END(){cout << 1 << endl; exit(0);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x;
  cin >> x;
  int ans = 0;
  ans += (x/500) * 1000;
  x %= 500;
  ans += (x/5) * 5;
  cout << ans;

  return 0;
}


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

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

string s, s1, s2, s3, s4;
int m, l;

int main()
{
    cin >> m;
    REP(m)
    {
        set<string> ss;
        cin >> s;
        l = s.size();

        rep(j,l-1)
        {
            s1 = s.substr(0, j+1);
            s2 = s.substr(0, j+1); reverse(s2.begin(), s2.end());
            s3 = s.substr(j+1, l - j - 1);
            s4 = s.substr(j+1, l - j - 1); reverse(s4.begin(), s4.end());
            

            ss.insert(s1 + s3);
            ss.insert(s3 + s1);
            ss.insert(s1 + s4);
            ss.insert(s4 + s1);
            ss.insert(s2 + s3);
            ss.insert(s3 + s2);
            ss.insert(s2 + s4);
            ss.insert(s4 + s2);
        }
        cout << ss.size() << endl;
    }

    return 0;
}

Measured memory_bytes: 1000
/*input
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define N
#define bit(x,y) ((x>>y)&1LL)
#define loop(x) for(int xv=1; xv<=x; xv++)

#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
	return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
	os << '[';
	for (unsigned int i = 0; i < a.size(); i++)
		os << a[i] << (i < a.size() - 1 ? ", " : "");
	os << ']';
	return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &a) {
	os << '{';
	for (typename set<T>::iterator it = a.begin(); it != a.end(); it++) {
		typename set<T>::iterator jt = it;
		os << *it << (++jt != a.end() ? ", " : "");
	}
	os << '}';
	return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, map<T1, T2> &a) {
	os << "{\n";
	for (typename map<T1, T2>::iterator it = a.begin(); it != a.end(); it++) {
		typename map<T1, T2>::iterator jt = it;
		os << "  " << it->first << ": " << it->second << (++jt != a.end() ? ",\n" : "\n");
	}
	os << '}';
	return os;
}

int n, m, q;
vector<int> a;
vector<int> allVal;

multiset<pair<int, int> > mstVal;
multiset<int> mstPos;

bool check(int lo, int hi) {
	mstPos.clear(); mstVal.clear();
	int remQ = q;
	for (int i = 0; i < n; i++) {
		mstVal.insert(mp(a[i], i)); mstPos.insert(i);
		if (remQ == 0) return true;
		if (mstVal.size() == m) {
			if (lo <= mstVal.begin()->fi && mstVal.begin()->fi <= hi) {
				mstPos.erase(mstVal.begin() -> se);
				mstVal.erase(mstVal.begin());
				remQ--;
			}
			else {
				mstVal.erase(mp(a[*mstPos.begin()], *mstPos.begin()));
				mstPos.erase(mstPos.begin());
			}
		}
	}
	if (remQ == 0) return true;
	return false;
}

const int INF = 2e9;
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m >> q;
	for (int i = 0; i < n; i++) {
		int t; cin >> t;
		a.push_back(t);
		allVal.push_back(t);
	}
	sort(allVal.begin(), allVal.end()); allVal.resize(distance(allVal.begin(), unique(allVal.begin(), allVal.end())));
	int ans = INF;
	int it = 0;
	for (int hi = 0; hi < allVal.size(); hi++) {
		while (it <= hi) {
			if (check(allVal[it], allVal[hi])) {
				ans = min(ans, allVal[hi] - allVal[it]);
				it++;
			}
			else break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <stdlib.h>
#include <stdio.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(10) << ans << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n,m;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


signed main(){
    int h,w;
    int dp[10][10];
    int input,ans=0;
    cin >> h >> w;
    REP(i,10){
        REP(j,10){
            cin >> dp[i][j];
        }
    }
    REP(k,10){
        REP(i,10){
            REP(j,10){
                if(dp[i][j] > dp[i][k] + dp[k][j]){
                    dp[i][j] = dp[i][k] + dp[k][j];
                }
            }
        }
    }
    REP(i,h){
        REP(j,w){
            cin >> input;
            if(input == 1 || input == -1){

            }
            else{
                ans += dp[input][1];
            }
        }
    }
    print(ans);


    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 256
unittest
{
	assert( [ "aba", "4" ].solve == "b" );
	assert( [ "atcoderandatcodeer", "5" ].solve == "andat" );
	assert( [ "z", "1" ].solve == "z" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	input.popFront;
	auto k = input.front.to!( long );
	
	bool[ dstring ] ks;
	foreach( i; 1L .. 5 + 1 )
	{
		foreach( j; 0L .. s.length.signed - i + 1 )
		{
			ks[ s[ j .. j + i ].idup ] = true;
		}
	}
	return ks.keys.sort().drop( k - 1 ).front;
}


Measured memory_bytes: 4736
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair

int read()
{
    int v = 0, f = 1;
    char c = getchar();
    while (c < 48 || 57 < c) {if (c == '-') f = -1; c = getchar();}
    while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
    return v * f;
}

const int N = 2e6 + 10;
const ll MOD = 1e9 + 7;

ll fac[N], inv[N], ans;
int X1, X2, X3, X4, X5, X6;
int Y1, Y2, Y3, Y4, Y5, Y6;

ll C(int u, int v)
{
    if (u < 0 || v < 0) return 0;
    return fac[u + v] * inv[u] % MOD * inv[v] % MOD;
}

ll cal(int a, int b, int c, int d)
{
    ll re = 0;
    for (int i = X3; i <= X4; i++)
        re = (re + C(i - a, Y3 - 1 - b) * C(c - i, d - Y3) % MOD * (- i - Y3 + MOD) % MOD) % MOD;
    for (int i = Y3; i <= Y4; i++)
        re = (re + C(X3 - 1 - a, i - b) * C(c - X3, d - i) % MOD * (- i - X3 + MOD) % MOD) % MOD;
    for (int i = X3; i <= X4; i++)
        re = (re + C(c - i, d - Y4 - 1) * C(i - a, Y4 - b) % MOD * (Y4 + i + 1) % MOD) % MOD;
    for (int i = Y3; i <= Y4; i++)
        re = (re + C(c - X4 - 1, d - i) * C(X4 - a, i - b) % MOD * (X4 + i + 1) % MOD) % MOD;
    return re;
}

int main()
{

    inv[0] = inv[1] = 1;
    for (int i = 2; i <= 2000000; i++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
    for (int i = 1; i <= 2000000; i++) inv[i] = inv[i - 1] * inv[i] % MOD;
    fac[0] = 1;
    for (int i = 1; i <= 2000000; i++) fac[i] = fac[i - 1] * i % MOD;

    X1 = read(), X2 = read(), X3 = read(), X4 = read(), X5 = read(), X6 = read();
    Y1 = read(), Y2 = read(), Y3 = read(), Y4 = read(), Y5 = read(), Y6 = read();

    ans = (ans + cal(X1 - 1, Y1 - 1, X6 + 1, Y6 + 1)) % MOD;
    ans = (ans - cal(X1 - 1, Y1 - 1, X6 + 1, Y5) + MOD) % MOD;
    ans = (ans - cal(X1 - 1, Y1 - 1, X5, Y6 + 1) + MOD) % MOD;
    ans = (ans + cal(X1 - 1, Y1 - 1, X5, Y5)) % MOD;

    ans = (ans - cal(X1 - 1, Y2, X6 + 1, Y6 + 1) + MOD) % MOD;
    ans = (ans + cal(X1 - 1, Y2, X6 + 1, Y5)) % MOD;
    ans = (ans + cal(X1 - 1, Y2, X5, Y6 + 1)) % MOD;
    ans = (ans - cal(X1 - 1, Y2, X5, Y5) + MOD) % MOD;

    ans = (ans - cal(X2, Y1 - 1, X6 + 1, Y6 + 1) + MOD) % MOD;
    ans = (ans + cal(X2, Y1 - 1, X6 + 1, Y5)) % MOD;
    ans = (ans + cal(X2, Y1 - 1, X5, Y6 + 1)) % MOD;
    ans = (ans - cal(X2, Y1 - 1, X5, Y5) + MOD) % MOD;

    ans = (ans + cal(X2, Y2, X6 + 1, Y6 + 1)) % MOD;
    ans = (ans - cal(X2, Y2, X6 + 1, Y5) + MOD) % MOD;
    ans = (ans - cal(X2, Y2, X5, Y6 + 1) + MOD) % MOD;
    ans = (ans + cal(X2, Y2, X5, Y5)) % MOD;
    
    printf("%lld\n", ans);
}


Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
typedef long long int i64;
int main(){
    int N;cin>>N;
    int A[3][N];
    REP(i,3)REP(j,N) cin>>A[i][j];
    REP(i,3) sort(A[i],A[i]+N);
    i64 sum=0;
    REP(i,N) sum+=(lower_bound(A[0],A[0]+N,A[1][i])-A[0])*(A[2]+N-upper_bound(A[2],A[2]+N,A[1][i]));
    cout<<sum<<endl;
}

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

#define M 100000

int dp[101][101][4];

int main(){
	int w, h;
	while(cin >> w >> h, w != 0){
		dp[1][1][1] = 1;
		for(int i = 1; i <= h; ++i){
			if(i != 1){	dp[i][1][2] = 1;	}
			for(int j = 2; j <= w; ++j){
				dp[i][j][0] = (dp[i][j-1][0] + dp[i][j-1][1]) % M;
				dp[i][j][1] = dp[i][j-1][2];
				dp[i][j][2] = (dp[i-1][j][2] + dp[i-1][j][3]) % M;
				dp[i][j][3] = dp[i-1][j][0];
			}
		}
		
		cout << (dp[h][w][0] + dp[h][w][1] + dp[h][w][2] + dp[h][w][3]) % M << '\n';
	}
}

Measured memory_bytes: 1320
s=input()
if (s[0]=="0" and s[1]!="0") or (s[0]=="1" and int(s[1])<=2):
    if (s[2]=="0" and s[3]!="0") or (s[2]=="1" and int(s[3])<=2):
        print("AMBIGUOUS")
    else:
        print("MMYY")
elif (s[2]=="0" and s[3]!="0") or (s[2]=="1" and int(s[3])<=2):
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi=3.1415;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
ll gojou(ll n){return pow(n,5);}
int main()
{
   int n,m,x,ans=100100100,A[12][12]={};
   bool f=true;
   cin>>n>>m>>x;
   vector<int>c(n);
   rep(i,n){
   	cin>>c[i];
   	rep(j,m)cin>>A[i][j];
   }
   rep(i,pow(2,n)){
   vector<int>v(m,0);
   	int sum=0;
   	rep(j,n){
   		if((i>>j)&1){
   			rep(k,m){
   				v[k]+=A[j][k];
   			}
   				sum+=c[j];
   		}
   	}
   	//cout<<sum<<endl;
   	bool f=true;
   	rep(j,m){
   		if(v[j]<x)f=false;
   		if(!f)break;
   		};
   	if(f){ans=min(sum,ans);}
   }
   if(ans==100100100)cout<<-1;
   else cout<<ans;
}


Measured memory_bytes: 4100
# N, S = map(int, input().split())  # 入力
N = int(input())
S = input()
S = [c for c in S]

# print(N, S)
ans = 0
for i in range(N - 1):
    first = set(S[0:i+1])
    second = set(S[i+1:])
    # print(S[0:i+1], S[i+1:])
    # print(first, second)
    tmpans = 0
    for index, n in enumerate(range(len(first))):
        if list(first)[index] in list(second):
            tmpans += 1
            ans = max(ans, tmpans)


print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2 - y2 + y1 << " " << y2 + x2 - x1 << " " << x1 - y2 + y1 << " " << y1 + x2 - x1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

void solve(void){
    int N;
    cin >> N;
    vector <ll> n(3*N);
    rep(3*N, i) cin >> n.at(i);
    sort(all(n));
    ll ans = 0LL;
    int cnt = 0;
    for (int i = 3*N-2; cnt < N; i-=2) {
        ans += n[i];
        cnt++;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 2560
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iostream>
#include <limits>
#include <queue>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef stringstream ss;
const int mii = numeric_limits<int>::min();
const int mai = numeric_limits<int>::max();
const ll mil = numeric_limits<long long>::min();
const ll mal = numeric_limits<long long>::max();

#define REP(i, a, b) for(int i=a; i<=b; ++i)
#define RREP(i, a, b) for(int i=a; i>=b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

void pushNode(int node, queue<int> & next, bool * visited) {

    if(!visited[node]) {
        next.push(node);
        visited[node] = true;
    }
}

int main(int argc, char **argv) {
    int n, x, y;
    cin >> n >> x >> y;

    vector<vector<int>> dists(n+1, vector<int>(n + 1, mai));

    int counter = 0;

    REP(i, 1, n) {
        queue<int> next;
        next.push(i);
        bool visited[2001] = {false};
        visited[i] = true;
        int currDist = 0;

        while(!next.empty()) {
            int lvlSize = next.size();

            while(lvlSize != 0) {
                int node = next.front();
                next.pop();
                ++counter;

                if(node != i) {
                    dists[i][node] = currDist;
                    dists[node][i] = currDist;
                }
                if(node < n)
                    pushNode(node + 1, next, visited);
                if(node > 1)
                    pushNode(node - 1, next, visited);
                if(node == x)
                    pushNode(y, next, visited);
                if(node == y)
                    pushNode(x, next, visited);
                --lvlSize;
            }

            ++currDist;
        }
    }

    /*REP(i, 1, n) {
        REP(j, 1, n) {
            int distIJ = min(abs(i-j), min(abs(x-i) + 1 + abs(y-j), abs(y-i) +1 + abs(x-j)));
            dists[i][j] = distIJ;
            dists[j][i] = distIJ;
        }
    }*/

    map<int, set<pair<int, int>>> dist1;

    REP(i, 1, n) {
        REP(j, 1, n) {
            if(i == j)
                continue;

            dist1[dists[i][j]].insert(MP(min(i, j), max(i, j)));
        }
    }

    REP(i, 1, n-1) {
        cout << (dist1[i].size() > 0 ? dist1[i].size() : 0) << endl;
    }

    return 0;
}

Measured memory_bytes: 109824
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		solve();

	}

	public static void solve() {
		Scanner sc = new Scanner(System.in);

		while (true) {
			int num = sc.nextInt();
			int min = sc.nextInt();
			int max = sc.nextInt();

			if (num == 0 && min == 0 && max == 0) {
				break;
			}

			int[] Tensu = new int[num];
			for (int i = 0; i < num; i++) {
				Tensu[i] = sc.nextInt();
			}

			int passNum = max - min + 1;
			int[] Gap = new int[passNum];
			int ans = 0;
			int BL = 0;

			for (int j = min; j < max + 1; j++) {
				Gap[j - min] = Tensu[j - 1] - Tensu[j];
			}

			for (int k = 0; k < Gap.length; k++) {
				if (ans <= Gap[k]) {
					ans = Gap[k];
					BL = k;

				}

			}

			System.out.println(BL + min);
		}

	}
}

Measured memory_bytes: 57392
def dfs(s,num):
    if int(s)>num:
        return 0
    if s.count('7')>0 and s.count('5')>0 and s.count('3')>0:
        ret=1
    else:
        ret=0
    for i in "753":
        ret+=dfs(s+i,num)
    return ret
n=int(input())
print(dfs('0',n))

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

int main()
{
    int N, A, B;
    int plan_1;
    cin >> N >> A >> B;
    plan_1 = A * N;
    if (plan_1 > B)
    {
        cout << B << endl;
    }
    else
    {
        cout << plan_1 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>

using namespace std;

typedef pair<int,bool> Pair;

int STEP[1000001];
int MEMO[1000001];

int kaidan(int N){

    int ans = 0;

	if(MEMO[N] != -1) return MEMO[N];
	
	if(N==0) return 1;

	if(N < 0) return 0;
	else if(STEP[N]==0)	return 0;
	else if(STEP[N]==1){
	
		ans = (kaidan(N-1) + kaidan(N-2))%1000000007;

	}

	MEMO[N] = ans;
	
	return ans;
	
}

int main(){

  int N,M,ANA;
   
  cin >> N >> M;
   
  for(int i = 0; i <= N; ++i) STEP[i] = 1;
  for(int i = 0; i <= N; ++i) MEMO[i] = -1;
  
  for(int i = 0; i < M; ++i){

    cin >> ANA;
    STEP[ANA] = 0;
	
  }  
  
  cout << kaidan(N);
  
  return 0;

}


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

int n;
int a[111];

int main() {
	scanf("%d", &n);
	for(int i=1;i<=n;i++) a[i] = 1e9;
	for(int i=1;i<n;i++) {
		int x;
		scanf("%d", &x);
		a[i] = min(a[i], x);
		a[i+1] = min(a[i+1], x);
	}
	int s = 0;
	for(int i=1;i<=n;i++) s += a[i];
	printf("%d\n", s);
	
	return 0;
}

Measured memory_bytes: 256
local x = io.read("n")
if x <= 2 then
    print(2)
    return
end
local primes = {2}
for n=3,100003,2 do
    local isprime = true
    for _, p in ipairs(primes) do
        if p * p > n then
            break
        end
        if n % p == 0 then
            isprime = false
            break
        end
    end
    if isprime then
        primes[#primes + 1] = n
        if n >= x then
            print(n)
            return
        end
    end
end

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

int main()
{
    // ここにプログラムを追記
    int a, b;

    cin >> a >> b;

    if ((a + b) % 2 == 0)
    {
        cout << (a + b) / 2 << endl;
    }
    else
    {
        cout << (a + b) / 2 + 1 << endl;
    }
}

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

template<std::size_t N, std::uint_fast64_t MOD>
struct Fact {
    std::uint_fast64_t val[N + 1];

    constexpr Fact() : val() {
        val[0] = 1;
        for (std::size_t i = 1; i <= N; ++i) val[i] = val[i - 1] * i % MOD;
    }
};

constexpr std::uint_fast64_t MOD = 1000000007, maxN = 100000;

constexpr auto fact = Fact<maxN, MOD>();

long long N, M;

int main(){
    scanf("%lld%lld", &N, &M);
    if(abs(N - M) > 1)return 0 & puts("0");
    if(N != M)return 0 & printf("%lld\n", fact.val[N] * fact.val[M] % MOD);
    printf("%lld\n", 2 * (fact.val[N] * fact.val[M] % MOD) % MOD);
    return 0;
}


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

using namespace std;


void solve() {
    int n,m,k;
    cin >> n >> m >> k;
    vector<pair<int, int>> a;
    for (int _ = 0; _ < k; _++) {
        int x,y;
        cin >> x >> y;
        if (x >= y) {
            a.emplace_back(x,y);
        }
    }
    sort(a.begin(), a.end());

    int res = n;
    int block = 0;
    for (auto& _: a) {
        int x,y;
        tie(x,y) = _;
        if (y+block < x) {
            res = x-1;
            break;
        } else if (y + block == x) {
            block++;
        }
    }

    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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


int dp[101][4][2];


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

  dp[0][0][0] = 1;

  rep(i, n) {
    int ni = s[i] - '0'; // N の上から i 桁目の数
    rep(j, K+1) rep(k, 2) rep(x, 10) {
      int j2 = j, k2 = k; // 遷移前の状態をコピーする

      if (x != 0) ++j2;     // 次に使う数 x が非ゼロなら j2 を更新
      if (j2 > K) continue; // 非ゼロの数が K より大きいことが確定したら無視

      if (!k && (x > ni)) continue; // N より大きい数であることが確定したら無視
      if (x < ni) k2 = 1;           // N より小さい数であることが確定したら k2 を更新

      dp[i+1][j2][k2] += dp[i][j][k]; // 遷移式
    }
  }

  int ans = dp[n][K][0] + dp[n][K][1];
  cout << ans << '\n';
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define endl '\n'
#define debug(X) cout << #X << " = " << X << endl

using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	#ifdef UTP
	freopen("input.txt", "r", stdin);
	#endif
	int n; cin >> n;
	vector<int> a(n), prv(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++) {
		if (i > 0 && a[i] == 0 && a[i - 1] == 0) prv[i] = prv[i - 1];
		else prv[i] = i - 1;
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		int j = i, curr = 0;
		while (j >= 0 && (curr & a[j]) == 0) {
			curr |= a[j];
			ans += j - prv[j];
			j = prv[j];
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

int main(){
	string s;
	cin>>s;
	int n=s.size();
	ll ans=0;
	REP(bits,1<<(n-1)){
		ll p=0,cur=s[0]-'0';
		FOR(i,1,n){
			if(bits&(1<<(i-1))){
				p+=cur;
				cur=0;
			}
			cur=cur*10+s[i]-'0';
		}
		ans+=p+cur;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int64
	scanner.Scan()
	N, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	var S string
	scanner.Scan()
	S = scanner.Text()
	fmt.Println(solve(N, S))
}
func solve(N int64, S string) int {
	ss := []rune(S)
	rSum := strings.Count(S, "R")
	gSum := strings.Count(S, "G")
	bSum := strings.Count(S, "B")
	cnt := rSum * gSum * bSum
	for i := 0; i < int(N-2); i++ {
		for j := i + 1; j < int(N-1); j++ {
			k := j + (j - i)
			if k >= int(N) {
				continue
			}
			if ss[i] != ss[j] && ss[i] != ss[k] && ss[j] != ss[k] {
				cnt--
			}
		}
	}
	return cnt
}


Measured memory_bytes: 1804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll dp[110][100010];

int main() {
    int n,W; cin >> n >> W;
    vector<int> w(n); vector<int> v(n);
    for(int i=0;i<n;i++){
        cin >> w[i] >> v[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=W;j++){
            if(j>=w[i]){
                chmax(dp[i+1][j],dp[i][j-w[i]]+v[i]);
            }
            chmax(dp[i+1][j],dp[i][j]);
        }
    }
    cout << dp[n][W] << endl;
}

Measured memory_bytes: 79360