akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int digi(int n,int m)
{
	int sum1=n;
	int count1=0;
	while(sum1>0)
	{
		count1+=sum1%10;
		sum1/=10;
	}
	int sum2=m;
	int count2=0;
	while(sum2>0)
	{
		count2+=sum2%10;
		sum2/=10;
	}
	return (count1+count2);
}
int main()
{
	int num;
  scanf("%d",&num);
  int min=digi(1,num-1);
  for (int i=2;i<=num/2;i++)
  {
    if (digi(i,num-i)<min)
      min=digi(i,num-i);
  }
  printf("%d\n",min);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    double x = (double)sum/(4.0*m);

    ll cnt = 0;
    rep(i, n) {
        if(a[i] >= x) {
            cnt++;
        }
    }

    if(cnt >= m) {
        out("Yes");
    }
    else {
        out("No");
    }

    re0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#define ls k<<1
#define rs k<<1|1
#define RG register
#define MAXN 50010
#define LL long long int
using namespace std;
const int INF=0x7fffffff;
struct node{
	int next;
	int to;
	int w;
	int c;
}t[MAXN];
int head[MAXN];
int num;
int dis[MAXN],vis[MAXN],cost[MAXN];
int n,m;
void add(int from,int to,int w,int c)
{
	t[++num].next=head[from];
	t[num].to=to;
	t[num].w=w;
	t[num].c=c;
	head[from]=num;
}
void spfa()
{
	for(int i=1;i<=n;i++)
		{
			dis[i]=INF;vis[i]=0;cost[i]=INF;
		}
	cost[1]=dis[1]=0;vis[1]=1;
	queue<int>q;q.push(1);
	while(!q.empty())
		{
			int u=q.front();q.pop();vis[u]=0;
			for(int i=head[u];i;i=t[i].next)
				{
					int v=t[i].to;
					if(dis[v]>dis[u]+t[i].w||(dis[v]==dis[u]+t[i].w&&cost[v]>t[i].c))
						{
							dis[v]=dis[u]+t[i].w;
							cost[v]=t[i].c;
							if(!vis[v])
								{
									vis[v]=1;q.push(v);
								}
						}
				}
		}
}
int main()
{
//	freopen("1.in","r" ,stdin);
	//freopen("1.out","w",stdout);
	while(1)
		{
			scanf("%d%d",&n,&m);if(n==0&&m==0) break;
			int x,y,z,k;
			memset(head,0,sizeof(head));num=0;
			for(int i=1;i<=m;i++)
				{
					scanf("%d%d%d%d",&x,&y,&z,&k);
					add(x,y,z,k);add(y,x,z,k);
				}
			spfa();
			int ans=0;
			for(int i=1;i<=n;i++) ans+=cost[i];
			cout<<ans<<endl;
		}
	return 0;
}

Measured memory_bytes: 4008
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <cmath>
#include <cstring>

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

using namespace std;
typedef long long ll;

int N;
int P[200001];
int Q[200001];

int main() {
    cin >> N;
    rep(i, N) { cin >> P[i]; P[i] --; }

    int minimum = N;
    rep(i, N) {
        Q[i] = minimum = min(minimum, P[i]);
    }
    int ans = 0;
    rep(i, N) {
        if (P[i] <= Q[i]) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    string a , b ;
    int s = 0 ;
    cin >> a >> b ;
    if (a[0] == b [0]){
        s++ ;
    }
    if (a[1] == b [1]){
        s++ ;
    }
    if (a[2] == b [2]){
        s++ ;
    }
    cout << s ;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int n,m; cin >> n >> m;
    vector<int> cnt(n,1);
    vector<bool> p(n,false);
    p[0] = true;
    rep(i,m){
        int x,y; cin >> x >> y;
        x--; y--;
        if(p[x]){
            p[y] = true;
            cnt[x]--;
            cnt[y]++;
            if(cnt[x] == 0){
                p[x] = false;
            }
        }else{
            cnt[x]--;
            cnt[y]++;
        }
    }
    int ans = 0;
    rep(i,n) if(p[i]) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 640
s = gets.chomp.split("")
cnt = max = 0
s.each do |ch|
  if ch == "A" || ch == "C" || ch == "G" || ch == "T"
    cnt += 1
  else
    if cnt > max
      max = cnt
    end
    cnt = 0
  end
end
if cnt > max
  max = cnt
end
puts max
  


Measured memory_bytes: 1788
import java.awt.Container;
import java.util.*;
public class Main {
	Scanner sc = new Scanner (System.in);
	void run() {
		double min = Double.MAX_VALUE;
		double max = Double.MIN_VALUE;
		while (sc.hasNext()) {
			double val = sc.nextDouble();
			min = Math.min(min, val);
			max = Math.max(max, val);
		}
		System.out.println((max-min));
		
	}
	public static void main(String[] args) {
		new Main().run();
	}
	
}

Measured memory_bytes: 0
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int n;

	while(cin >> n, n) {
		vi num(n);

		REP(i, n) {
			cin >> num[i];
		}

		int ans = INT_MIN;
		FOR(i, 0, n-1) {
			int sum = 0;
			FOR(j, i, n-1) {
				sum += num[j];
				ans = max(sum, ans);
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#define LL long long
using namespace std;
int n,m;
int tot[11];
int f[11][11];
int num[11];
int a[11];
int ans;
int read()
{
	int _=0,__=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')__=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){_=_*10+ch-'0';ch=getchar();}
	return _*__;
}
void dfs(int ce)
{
	if(ce==n+1)
	{
		int nm;
		for(int i=1;i<=m;i++)
		{
			nm=0;
			for(int j=1;j<=tot[i];j++)
			{
				if(a[f[i][j]]==1) nm++;
			}
			if(nm%2!=num[i])
			return ;
		}
		ans++;
		return ;
	}
	for(int i=0;i<=1;i++)
	{
		a[ce]=i;
		dfs(ce+1);
	}
}
int main()
{
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		tot[i]=read();
		for(int j=1;j<=tot[i];j++)
		f[i][j]=read();
	}
	for(int i=1;i<=m;i++)
	num[i]=read();
	dfs(1);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * <p>ClassName:  </p>
 * <p>Description: </p>
 * <p>Company: </p>
 *
 * @author zhangyong
 * @version 1.0.0
 * @date 2020/6/24 20:46
 */
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        Character a=str.charAt(0);
        if (a.charValue()>='A'&&a.charValue()<='Z'){
            System.out.println('A');
        }else if (a.charValue()>='a'&&a.charValue()<='z'){
            System.out.println('a');
        }
    }
}


Measured memory_bytes: 35712
import sys
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)
A,VA = mips()
B,VB = mips()
T = ii()
if A <= B:
    d1 = A + VA * T
    d2 = B + VB * T
    if d1 >= d2:
        print("YES")
    else:
        print("NO")
else:
    d2 = B - VB * T
    d1 = A - VA * T
    if d1 <= d2:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9208
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 3e5+7 ;
const int INF = 1e18 ;
const int MOD = 1e9 + 7 ;
string s ;

int f(int n, int cnt = 1){
	if(n == 0) return 0 ;
	return cnt + f(n/2 , cnt*2) ;
}

void solve(){
	int  H ;
	cin >> H ;
	cout << f(H) << endl ;

}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int a[5] = {0};
    int b[5] = {0};
    int sum = 0;
    int count = 0;
    for (int i = 0; i < 5; ++i) {
        cin >> a[i];

        while(a[i] % 10 != 0){
            a[i]++;
            b[i]++;
        }
        a[i] -= b[i];
    }

    int max = 0;
    int maxk = 0;
    for (int k = 0; k < 5; ++k) {
        if(b[k] > max){
            max = b[k];
            maxk = k;
        }
    }

    int temp = a[4];
    a[4] = a[maxk];
    a[maxk] = temp;

    sort(a,a+3);
    for (int j = 0; j < 4; ++j) {
        sum += a[j];
        while (sum % 10 != 0){
            count++;
            sum++;
        }
    }
    sum += a[4];
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
import java.util.concurrent.LinkedBlockingDeque

fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main() {
    data class Connect(val to: Long, val w: Long)

    val n = readLine()?.toInt() ?: return
    val vertexes = Array(n) { -1L }
    val connections = hashMapOf<Long, MutableList<Connect>>()
    repeat(n - 1) {
        val (u, v, w) = longList()
        val ui = u - 1
        val vi = v - 1
        connections.getOrPut(ui) { mutableListOf() }
            .add(Connect(vi, w))
        connections.getOrPut(vi) { mutableListOf() }
            .add(Connect(ui, w))
    }

    val f = connections.keys.first()
    val arrived = Array(n) { false }
    val queue = LinkedBlockingDeque<Pair<Long, Long>>()
    queue.offer(Pair(f, 0L))
    arrived[f.toInt()] = true
    vertexes[f.toInt()] = 0L
    while (queue.isNotEmpty()) {
        val (p, d) = queue.poll()
        val conn = connections[p]
        conn?.forEach {
            if (!arrived[it.to.toInt()]) {
                arrived[it.to.toInt()] = true
                vertexes[it.to.toInt()] = d + it.w
                queue.offer(Pair(it.to, d + it.w))
            }
        }
    }
    buildString {
        vertexes.forEach {
            appendln(if (it % 2 == 0L) 0 else 1)
        }
    }.let {
        println(it.trimIndent())
    }
}


Measured memory_bytes: 92552
#include <iostream>
using namespace std;
int main(void){
  string S;
  cin >> S;
  int count = 0;
  for(int i = 0; i < 4; i++){
    if(0 == (S[i] - '+')){
      count++;
    }else{
      count--;
    }
  }
  cout << count;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
v_matrix = [[0 for j in range(n+1)] for i in range(n+1)]
for i in range(n):
    u, k, *v = map(int, input().split())
    for vi in v:
        v_matrix[u][vi] = 1

for row in v_matrix[1:]:
    print(" ".join(map(str, row[1:])))


Measured memory_bytes: 5676
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<iomanip>

#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define MOD 1000000007

using namespace std;
using ll=long long int;

int H,W;
vector<string> S;

int main(){
    int N,L;
    cin >> N >> L;
    vector<int> vec(N);
    for(int i=0;i<N;i++){
        vec[i]=L+i;
    }
    int ans=0;
    if(L-1+N>=0&&L<0){
        for(int i=0;i<N;i++){
            if(vec[i]!=0){
                ans+=vec[i];
            }
        }
    }
    else if(L<0){
        for(int i=0;i<N-1;i++){
            ans+=vec[i];
        }
    }
    else{
        for(int i=1;i<N;i++){
            ans+=vec[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import Data.Char
import Data.List

main :: IO ()
main = do
  l1 <- getLine
  l2 <- getLine
  l3 <- getLine
  let [n, k] = map read $ words l1 :: [Int]
      [r, s, p] = map read $ words l2 :: [Int]
      t = l3
      hands = g $ h $ f k t :: [Char]
  print $ sum $ zipWith (rsp r s p) t hands

rsp r s p 'r' 'p' = p
rsp r s p 's' 'r' = r
rsp r s p 'p' 's' = s
rsp _ _ _ _ _ = 0

f k = transpose . f' k

f' _ [] = []
f' k l = l1:f' k l2
  where (l1, l2) = splitAt k l

g = concat . transpose

h = map (h' ' ')

h' hp [c]
  | hn == hp = [head $ delete hp "rsp"]
  | otherwise = [hn]
  where hn = hand c
h' hp (c1:cs) = hn':h' hn' cs
  where (c2:_) = cs
        hn = hand c1
        hf = hand c2
        hn' = if hn == hp then head (delete hp $ delete hf "rsp")
                          else hn

hand 'r' = 'p'
hand 's' = 'r'
hand 'p' = 's'

Measured memory_bytes: 21884
#include<stdio.h>
int P[100005],M[100005],v[100005],i,j,N,Q,t;
long long r;
char q[100005];


int main()
{
	for(;scanf("%d%d",&N,&Q),N;)
	{
		for(i=r=0;i<N;P[i]=i,M[i]=0,i++);
		M[1]=1;
		for(i=2;i<=N;P[i]=t,i++)
			scanf("%d\n",&t);
		for(i=0;i<Q;i++)
		{
			scanf("%c %d\n",&q[i],&v[i]);
			if(q[i]=='M')M[v[i]]++;
		}
		for(i=Q-1;i>=0;i--)
		{
			if(q[i]=='M')
				M[v[i]]--;
			else
			{
				for(t=v[i];!M[t];)
					t=P[t];
				r+=t;
			}
		}
		printf("%lld\n",r);
	}
	return 0;
}

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

using namespace std;
using ll = long long;

int main()
{
    ll N;
    cin >> N;
    ll cnt=0;
    for(ll i = 1;i<=N;i++)
    {
        if(i % 2 == 1)
        {
            cnt++;
        }
    }
    double ans = (double)cnt / (double)N;
    cout << ans << endl;

    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M,C;
    cin >> N >> M >> C;
    ll B[25];
    rep(i,0,M) cin >> B[i];
    ll A[25][25];
    rep(i,0,N){
        rep(j,0,M){
            cin >> A[i][j];
        }
    }
    ll ans = 0;
    rep(i,0,N){
        ll v = C;
        rep(j,0,M){
            v += A[i][j]*B[j];
        }
        if(v > 0) ans++;
    }
    print(ans);
 }

Measured memory_bytes: 256
n = int(input())
a = [ int(x) for x in input().split() ]
b = [ int(x) for x in input().split() ]
c = [ int(x) for x in input().split() ]

res = 0
prev = -10

for i in range(n):
    res += b[a[i]-1]
    if a[i] == prev+1:
        res += c[a[i]-2]
    prev = a[i]

print(res)


Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main() {
    int A, B;

    cin >> A >> B;

    if ((A > B && B != 1) || (A == 1 && B != 1)) {
        cout << "Alice" << endl;
    } else if (A == B) {
        cout << "Draw" << endl;
    } else {
        cout << "Bob" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def lcs(s1,s2,m,n,t):
    l=[]
    for i in range(0,m+1):
        t[i][0]=0
    for i in range(1,n+1):
        t[0][i]=0
    for i in range(1,m+1):
        for j in range(1,n+1):
            if s1[i-1]==s2[j-1]:
                t[i][j]=t[i-1][j-1]+1
            else:
                t[i][j]=max(t[i-1][j],t[i][j-1])
    i=m
    j=n
    while(i>0 and j>0):
        if s1[i-1]==s2[j-1]:
            l.append(s1[i-1])
            i-=1
            j-=1
        else:
            if t[i-1][j]>t[i][j-1]:
                i-=1
            else:
                j-=1
    l.reverse()  
    if len(l)==0:b=""
    else:b="".join(str(a) for a in l)
    return b
s1=input()
s2=input()
m=len(s1)
n=len(s2)
t=[[0 for x in range(n+1)] for x in range(m+1)] 
d=lcs(s1,s2,m,n,t)
print(d)

Measured memory_bytes: 120796
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#include <map>
#include <climits>
#include <vector>
#include <set>
#include <string>
#include <numeric>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define flood(arr, char, size) for (int i=0; i<size; i++) arr[i] = char
//#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
const int N = 1e5 + 2;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

int32_t main() {
    FAST_IO;
    int a, b, c;
    cin >> a >> b >> c;
    bool flag=false;
    int x=a;
    for (int i=1; i<=b; i++) {
        if (x%b==c) flag = true;
        x+=a;
    }
    cout << (flag?"YES":"NO");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    int n, k; cin >> n >> k;
    long double ans = 0;

    for (int i = 1; i < n+1; ++i) {
        if (i < k) {
            int a = i;
            long double b = 1;
            while (a < k) {
                a *= 2.0;
                b /= 2.0;
            }
            ans += b;
        }
        else {
            ++ans;
        }
    }
    ans /= n;

    cout << fixed << setprecision(18) << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int max_count=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            int count=0;
            vector<bool>dp(26,false);
            for(int k=0;k<=j;k++)
            {
                dp[s[k]-'a']=true;
            }
            for(int k=j+1;k<n;k++)
            {
                if(dp[s[k]-'a']==true){
                    dp[s[k]-'a']=false;
                    count++;
                }
            }
            if(max_count<count){
                max_count=count;
            }
        }
    }
    cout<<max_count;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;
const int MOD = 1e9+7;

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    vector<vector<int>> load(n, vector<int>(n, INF));
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        load[a][b] = load[b][a] = c;
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                load[i][j] = min(load[i][j], load[i][k] + load[k][j]);
            }
        }
    }

    vector<vector<int>> load2(n, vector<int>(n, INF));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if(load[i][j] <= l) load2[i][j] = 1;
        }
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                load2[i][j] = min(load2[i][j], load2[i][k]+load2[k][j]);
            }
        }
    }

    int q; cin >> q;
    vector<int> ans(q);
    for (int i = 0; i < q; i++)
    {
        int s, t; cin >> s >> t;
        s--; t--;
        ans[i] = load2[s][t] - 1;
        if(load2[s][t] == INF) ans[i] = -1; 
    }
    for (int i = 0; i < q; i++)
    {
        cout << ans[i] << endl;
    }
    


    return 0;
}

Measured memory_bytes: 1664
/*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define repd(i,s,e)  for(int i=e;i>=s;i--)
#define vb vector<bool>
#define read2(n,m) int n,m; cin >> n >> m;
#define range(v) v.begin(),v.end()
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define sorti(v) sort(v.begin(),v.end())

const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
    read(a);
    int ans = a + pow(a,2) + pow(a,3);
    cout<<ans<<endl;
    return 0;
}

/* Pooja Yadav */

Measured memory_bytes: 4076
/**

         Hlw sir

**/

#include<iostream>

using namespace std;

int main()
{
	long long a, b, c, d;
	long long prdct[4];
	cin >> a >> b >> c >> d;
	prdct[0] = a*c;
	prdct[1] = a*d;
	prdct[2] = b*c;
	prdct[3] = b*d;
	long long max = prdct[0];
	for(int i=1; i<4; i++)
	{
		if(prdct[i] > max)
		{
			max = prdct[i];
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3560
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>

using namespace std;
int n,m;
int a[233333];
long long s[233333];
long long ans=0x3f3f3f3f3f3f3f3fll;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),s[i]=s[i-1]+a[i];
	int e1=1,e3=3;
	for(int e2=2;e2<=n-2;e2++)
	{
		long long min1,min2;
		min1=max(s[e1],s[e2]-s[e1]);
		while(e1<e2-1&&s[e1]<s[e2]-s[e1])
		{
			e1++;
			min1=min(min1,max(s[e1],s[e2]-s[e1]));
		}
		min2=max(s[e3]-s[e2],s[n]-s[e3]);
		while(e3<n-1&&s[e3]-s[e2]<s[n]-s[e3])
		{
			e3++;
			min2=min(min2,max(s[e3]-s[e2],s[n]-s[e3]));
		}
//		cout<<e1<<' '<<e2<<' '<<e3<<' '<<min1<<' '<<s[e2]<<' '<<s[e2]+min2<<' '<<s[n]<<' ';
		long long minn=0x3f3f3f3f3f3f3f3fll,maxx=0;
		minn=min(minn,min1);maxx=max(maxx,min1);
		minn=min(minn,s[e2]-min1);maxx=max(maxx,s[e2]-min1);
		minn=min(minn,min2);maxx=max(maxx,min2);
		minn=min(minn,s[n]-s[e2]-min2);maxx=max(maxx,s[n]-s[e2]-min2);
//		cout<<maxx<<' '<<minn<<' '<<maxx-minn<<endl;
		ans=min(ans,maxx-minn);
		e1--;e3--;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main(void)
{
    int k;

    while (scanf("%d", &k), k){
        int i;
        int sum = 0;

        for (i = 0; i < k * (k - 1) / 2; i++){
            int c;

            scanf("%d", &c);
            sum += c;
        }
        printf("%d\n", sum / (k - 1));
    }

    return 0;
}

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

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int flag = 0;
  
  for(int i=0;i<=k;i++){
    if(a >= b){
      b *= 2;
    }
    else if(b >= c){
      c *= 2;
    }
    else{
      cout << "Yes" << endl;
      flag = 1;
      break;
    }
  }
  
  if(flag == 0)
    cout << "No" << endl;
}

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

using namespace std;

typedef long long int ll;
 
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; }
 
typedef pair<int,int> pair;

int main(){
    int x,y,z; cin >> x >> y >> z;

    int tmp;

    tmp=x;
    x=y;
    y=tmp;

    tmp=x;
    x=z;
    z=tmp;

    printf("%d %d %d\n",x,y,z);
}


Measured memory_bytes: 384
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define F first
#define S second


int main()
{

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
//ios_base& scientific (ios_base& str);
	ll n;
	cin >> n;
	vector<ll> arr_a(n);
	vector<ll> arr_b(n);
	for (int i = 0; i < n; i++)
		cin >> arr_a[i] >> arr_b[i];
	sort(arr_a.begin(), arr_a.end());
	sort(arr_b.begin(), arr_b.end());
	if (n % 2)
	{
		ll med1 = arr_a[n / 2];
		ll med2 = arr_b[n / 2];
		cout << med2 - med1 + 1 << "\n";
	}
	else
	{
		ll med1 = (arr_a[n / 2 - 1] + arr_a[n / 2]);
		ll med2 = (arr_b[n / 2 - 1] + arr_b[n / 2]);
		cout << (med2 - med1) + 1 << "\n";
	}

	return 0;
}

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

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int n;cin>>n;
  vector<vector<int> > graph (n,vector<int>(n,0));
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      for (int k = 0; k < 30; k++)
      {
        if(((i>>k)^(j>>k))&1)
        {
          graph[i][j] = k + 1;
          break;
        }
      }
      
    }
    
  }
  
  for (int i = 0; i < n; i++)
  {
    for (int j = i+1; j < n; j++)
    {
      if(j != i+1)cout<<" ";
      cout<<graph[i][j];
    }
    if(i != n -1)
    cout<<endl;
    
    
  }
  
 
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    auto dist = [&](int i, int j){
        double dx = x[i] - x[j];
        double dy = y[i] - y[j];
        return sqrt(dx*dx + dy*dy);
    };
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        p[i] = i;
    }
    double len = 0;
    int cnt = 0;
    do {
        for(int i = 0; i < n-1; i++){
            len += dist(p[i] , p[i+1]);
        }
        cnt++;
    } while(next_permutation(p.begin(), p.end()));
    double ans = len/cnt;
    printf("%.10f\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, x, N) for (int i = x; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
typedef long long ll;
int main()
{
    int N;
    string S;
    cin >> N >> S;
    int i = 0, j = 0;
    int ans = 0;
    while (j < N)
    {
        if (S[i] != S[j])
        {
            ans++;
            i = j;
            j = i + 1;
        }
        else
            j++;
    }
    cout << ans + 1 << endl;
}


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

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

const long long mod = 1000000007;
long long dp[100010][13];

int toi(char c) {
    return c-'0';
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    string S;
    cin >> S;

    int N = S.size();

    if (S[N-1] == '?') {
        for (int i=0; i<=9; ++i) {
            dp[0][i] = 1;
        }
    } else {
        dp[0][toi(S[N-1])] = 1;
    }

    long long b = 10;
    for (int i=1; i<N; ++i) {
        if (S[N-1-i] == '?') {
            for (long long di=0; di<=9; ++di) {
                for (int j=0; j<13; ++j) {
                    long long kk = (j + (long long)di * b) % 13;
                    dp[i][kk] += dp[i-1][j];
                    dp[i][kk] %= mod;
                }
            }
        } else {
            long long di = toi(S[N-1-i]);
            for (int j=0; j<13; ++j) {
                long long kk = (j + (long long)di * b) % 13;
                dp[i][kk] += dp[i-1][j];
                dp[i][kk] %= mod;
            }
        }
        b = (b * 10) % 13;
    }

    cout << dp[N-1][5] << endl;

    return 0;
}

Measured memory_bytes: 10704
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<vector<int>> a(100001,vector<int>(1));
  long long ans=0;
  for(int i=0;i<n;i++){
    int x;
    cin >> x;
    a.at(x).at(0) ++;
    ans += x;
  }
  int q;
  cin >> q;
  while(q>0){
    int b,c;
    cin >> b >> c;
    long long d = a.at(b).at(0);
    a.at(c).at(0) += a.at(b).at(0);
    a.at(b).at(0) = 0;
    ans -= b*d;
    ans += c*d;
    
    cout << ans << endl;
    q--;
  }
  
}

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

int main()
{
    int i, n, ans, x, y;
    string s;
    cin >> n >> s;

    ans=0;
    x=0;
    y=n-1;

    while(x<y)
    {
        if(s[x]=='R')
            x+=1;
        else
        {
            while(y>x)
            {
                if(s[y]=='R')
                    break;
                y-=1;
            }
            if(y!=x)
            {
                swap(s[x], s[y]);
                ans+=1;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3760
#include <stdio.h>
int main(){
  int x,y;
  while(1){
    scanf("%d %d", &x, &y);
    if(x == 0 && y == 0)break;
    if(x > y){
      printf("%d %d\n", y, x);
    } else if(y > x){
      printf("%d %d\n", x, y);  
    } else if( x == y){
      printf("%d %d\n", x, y);
    }
  }
  
  return 0;
}
	
 

Measured memory_bytes: 600
s=gets.chomp
alphabets = 'abcdefghijklmnopqrstuvwxyz'
if s == 'zyxwvutsrqponmlkjihgfedcba'
  p(-1)
elsif s.size < 26
  for a in alphabets.chars
    if s.count(a) == 0
      puts "#{s}#{a}"
      exit
    end
  end
else
  a = []
  25.downto(0).each do |i|
    if s[i-1] < s[i]
      a << s[i]
      last = a.select{|x| x > s[i-1]}.min
      puts s[0...i-1] + last
      exit
    else
      a << s[i]
    end
  end
end


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define in              insert
#define pb              push_back
#define mp              make_pair
#define lb              lower_bound
#define ub              upper_bound
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n]
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	string a, b; cin >> a >> b;
	int dp[a.length() + 1][b.length() + 1];

	for (int i = 0; i <= (int)a.length(); i++) {
		for (int j = 0; j <= (int)b.length(); j++) {
			if (i == 0 || j == 0) {
				dp[i][j] = 0;
				continue;
			}

			if (a[i - 1] == b[j - 1])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else
				dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
		}
	}

	string ans;

	int n = a.length(), m = b.length();
	while (n > 0 && m > 0) {
		if (dp[n][m] == dp[n - 1][m])
			n--;
		else if (dp[n][m] == dp[n][m - 1])
			m--;
		else
			ans += a[n - 1], n--, m--;
	}

	reverse(ans.begin(), ans.end());
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 73916
from collections import defaultdict
d = defaultdict(int)
n = int(input())
a = list(map(int, input().split()))
for e in a:
  d[e + 1] += 1
  d[e] += 1
  d[e - 1] += 1
d = dict(d)
d = sorted(d.items(), key=lambda x:x[1], reverse=True)
print(d[0][1])

Measured memory_bytes: 24172
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int h, w;
int c[10][10];
int a[200][200];


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

    REP(i, 10) REP(j, 10) {
        int cij;
        cin >> cij;
        c[i][j] = cij;
    }

    REP(i, h) REP(j, w) {
        int ahw;
        cin >> ahw;
        a[i][j] = ahw;
    }

    REP(k, 10) REP(i, 10) REP(j, 10)
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);

    long long sum = 0;

    REP(i, h) REP(j, w) {
        if (a[i][j] != -1)
            sum += c[a[i][j]][1];
    }
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 384
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n, ans int
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		if len(strconv.Itoa(i))%2 == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1024
import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val n: Int = io.StdIn.readInt()
    val children = Array.fill(n)(Seq(-1,-1))
    val parent: Array[Option[Int]] = Array.fill(n)(None)
    val depth = new Array[Int](n)
    val height = new Array[Int](n)

    for {
      _ <- 0 until n
      l = io.StdIn.readLine()
    } {
      val Seq(i, c1, c2): Seq[Int] = l.split(" ", 3).map(_.toInt)
      children(i) = Seq(c1, c2)
      if (c1 != -1) parent(c1) = Some(i)
      if (c2 != -1) parent(c2) = Some(i)
    }

    def dep: Memoized[Int, Int] = Memoized {i =>
      parent(i) match {
        case None => 0
        case Some(x) => 1 + dep(x)
      }
    }
    def hgt: Memoized[Int, Int] = Memoized {i =>
      children(i) match {
        case Seq(-1, -1) => 0
        case Seq(x,  -1) => 1 + hgt(x)
        case Seq(-1,  y) => 1 + hgt(y)
        case Seq(x,   y) => 1 + (hgt(x) max hgt(y))
      }
    }

    for (i <- 0 until n) {
      val p = parent(i).getOrElse(-1)
      val s: Int = if (p == -1) -1 else children(p).filterNot(_ == i).head
      val deg: Int = children(i).filterNot(_ == -1).length
      val t = if (p == -1) "root" else if (deg == 0) "leaf" else "internal node"

      depth(i) = dep(i)
      height(i) = hgt(i)

      println(s"node $i: parent = $p, sibling = $s, degree = $deg, depth = ${depth(i)}, height = ${height(i)}, $t")
    }
  }

  case class Memoized[Arg, Ret](f: Arg => Ret) extends (Arg => Ret) {
    val cache: mutable.Map[Arg, Ret] = mutable.Map[Arg, Ret]()
    def apply(arg: Arg): Ret = cache.getOrElseUpdate(arg, f(arg))

  }
}

Measured memory_bytes: 44452
n = int(input())
s = input()
ans = s.count("R")
ans *= s.count("G")
ans *= s.count("B")
for i in range(n):
    for d in range(n):
        j = i+d
        k = j+d
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1

print(ans)

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

long long n;
string ans;

int main()
{
    scanf("%lld",&n);
    while(n)
    {
        n--;
        ans+='a'+n%26;
        n/=26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
#define MOD 998244353
using namespace std;
typedef long long ll;
ll best[3030][3030], a[3030], N, S;

int main() {
  cin>>N>>S;
  for(int i=1;i<=N;++i) {
    cin>>a[i];
  }
  best[0][0] = 1;
  for(int i=1;i<=N;++i) {
    for(int j=0;j<=S;++j) {
      best[i][j] = 2LL*best[i-1][j];
      if(j >= a[i]) {
        best[i][j] += best[i-1][j-a[i]];
      }
      best[i][j] %= MOD;
    }
  }
  
  cout<<best[N][S]<<"\n";
  return 0;
} 


Measured memory_bytes: 74604
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8

int calc(int k){
	int ret=0;
	ret+=k/500;
	k%=500;
	ret+=k/100;
	k%=100;
	ret+=k/50;
	k%=50;
	ret+=k/10;
	return ret;
}

int main(){
	int t=0;
	while(1){
		int x,a,b,c,d,A,B,C,D,ret=100;
		cin>>x;
		if(x==0)return 0;
		cin>>a>>b>>c>>d;
		REP(i,a+1){
			REP(j,b+1){
				REP(k,c+1){
					REP(l,d+1){
						int m = i*10+j*50+k*100+l*500;
						if(m<x)continue;
						int tmp=calc(m-x);
						tmp += a-i+b-j+c-k+d-l;
						if(tmp < ret){
							ret = tmp;
							A=i;
							B=j;
							C=k;
							D=l;
						}
					}
				}
			}
		}
		if(t)cout<<endl;
		if(A!=0)cout << 10 << " " << A << endl;
		if(B!=0)cout << 50 << " " << B << endl;
		if(C!=0)cout << 100 << " " << C << endl;
		if(D!=0)cout << 500 << " " << D << endl;
		t++;
	}
}

Measured memory_bytes: 1164
val h: MutableMap<Pair<Long, Long>, Long> = mutableMapOf()

fun main(args: Array<String>) {
    val line = readLine()!!.trim()
    val n = line.toLong()

    var result: Long = 0L

    for (a: Long in 1..n)  {
        for (b: Long in 1..n)  {
            for (c: Long in 1..n) {
                result += gcd3(a, b, c)
            }
        }
    }

    println("${result}")
}


fun gcd3(a: Long, b: Long, c: Long): Long {
    return gcdWithCache(c, gcdWithCache(a, b))
}

fun gcdWithCache(a: Long, b: Long): Long {
    val (a_, b_) = sortKey(a, b)
    val key = Pair(a_, b_)
    if (h.containsKey(key)) {
        return h.get(key)!!
    }

    val result = gcdSub(a_, b_)
    h.put(key, result)
    return result
}

fun sortKey(a: Long, b: Long): Pair<Long, Long> {
    if (a < b) {
        return Pair(a ,b)
    }

    return Pair(b, a)
}

fun gcdSub(a: Long, b: Long): Long {
    if (b == 0L) {
        return a
    }
    return gcdSub(b, a % b)
}


Measured memory_bytes: 63684
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    S =     _in[1]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = S.count('R')*S.count('G')*S.count('B')
    for i in range(N):
        for j in range(i+1,N):
            k = 2*j-i
            if k<N:
                if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                    cnt -= 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)
    

Measured memory_bytes: 73608
#include <stdio.h>


int selectionSort(int A[], int N) {
    int i, j, t, sw =0, minj;
    for(i=0;i<N-1;i++) {
        minj = i;
        for(j=i;j<N;j++) {
            if(A[j]<A[minj]) minj = j;
        }
        t=A[i]; A[i]=A[minj]; A[minj]=t;
        if(i!=minj) sw++;
    }
    return sw;
}

int main(void) {
    int A[100], N, i, sw;

    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = selectionSort(A,N);

    for(i=0;i<N;i++) {
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",sw);

    return 0;
}


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

long long Max = -INF;

int main(){
    int N, Q;cin >> N >> Q;
    string S; cin >> S;
    set<int> ST;
    for(int i = 0; i < S.size()-1; i++){
        if(S[i] == 'A' && S[i+1] == 'C') ST.insert(i);
    }
    vector<int> n(100000+10);
    int cnt = 0;
    for(auto st : ST) {n[st] = cnt;cnt++;}
    
    for(int i = 0; i < Q; i++){
        int l, r; cin >> l >> r;
        if(r == 1 || l == r || ST.size() == 0) {cout << 0 << endl;}
        else{
            l--;r--;
            //cout << " "<<l << " " << r-1 << endl;
            auto itr1 = ST.lower_bound(l);
            auto itr2 = ST.upper_bound(r-1);
            itr2--;
            //if(*itr2 > r-1)
            //cout << *itr1 << " " << *itr2 << endl;
            if(itr1 == ST.end() || *itr2 > r-1 ||*itr2 < *itr1) cout << 0 << endl;
            else cout << n[*itr2] - n[*itr1] +1 << endl;
        }
    }

}

Measured memory_bytes: 3712
x, k, d = map(int, input().split())

x = abs(x)

moves = x//d

if moves >= k:
	print(abs(x-k*d))
else:
	k -= moves
	if k%2 == 0:
		print(abs(x-moves*d))
	else:
		print(abs(x-(moves+1)*d))

Measured memory_bytes: 9104
import java.util.Scanner;

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

		n = sc.nextInt();
		while (n != 0) {
			a = new int[n];
			f(n, a, 0);
			n = sc.nextInt();
		}
	}

	public static void f(int n, int a[], int k) {
		if (n == 0) {
			System.out.print(a[0]);
			for (int i = 1; i < k; i++) {
				System.out.print(" " + a[i]);
			}
			System.out.println();
		}
		for (int i = n; 0 < i; i--) {
			if (k == 0 || i <= a[k - 1]) {
				a[k] = i;
				f(n - i, a, k + 1);
				a[k] = 0;
			}
		}
	}
}

Measured memory_bytes: 12000