akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
int main(){
    long long s,ans=999;
    scanf("%lld",&s);
    while(s>=100){
        if(std::abs(s%1000-753)<ans)ans=std::abs(s%1000-753);
        s/=10;
    }
    printf("%lld",ans);
    return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m;
  cin >> n >> m;
  vector<Pi> a(m);
  rep(i, m) cin >> a[i].second >> a[i].first;
  sort(all(a));
  int ans = 0;
  int last = a[0].first;
  for(Pi p : a) {
    if(p.second < last) continue;
    last = p.first;
    ++ans;
  }
  cout << ans+1 << endl;

  return 0;
}


Measured memory_bytes: 1792
import scala.io.StdIn.{readInt,readLine}
  
object Main {

  def find(s:String) = {
    if(s.length<6) "NA"
    else if(s(0)=='>') {
      if(s(1) == ''') { // maybeA
        var isA = true
        val s2 = s.drop(2).dropRight(1)
        if(s2(s2.length/2) != '#') isA = false
        else {
          val s3 = s2.split("#")
          if(s3(0)!=s3(1) || s3(0).exists(_!='=')) isA = false
        }
        if(isA && s(s.length-1)=='~') "A" else "NA"
      } else if (s(1) == '^') { // maybeB
        var isB = true
        for(i<-2 until s.length-2 by 2) {
          if(s(i)!='Q' || s(i+1)!='=') {
            isB = false
          }
        }
        if(isB && s(s.length-2)=='~' && s(s.length-1)=='~') "B" else "NA"
      } else {
        "NA"
      }
    } else "NA"
  }

  def main(args:Array[String]) = {
    val n = readInt
    for(i<-1 to n) {
      val s = readLine.trim
      println(find(s))
    }
  }
}

Measured memory_bytes: 46512
#include"bits/stdc++.h"
using namespace std;

#define ll long long int
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

template <typename T>
inline void seethis(vector<T>vect)
{
    for(T x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

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...);
}
//LCM
int lcm(int a, int b) {  return a * (b / gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

int main()
{
	FASTIO;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ll n;
	 cin>>n;

	 vector<ll>vect(n);
	 vector<ll>suf_sum(n,0);

	 f(i,0,n)
	 {
	 	cin>>vect[i];
	 }

	 suf_sum[n-1]=vect[n-1];
	 for(ll i=n-2;i>=0;i--)
	 {
	 	suf_sum[i]=(suf_sum[i+1]%mod+vect[i]%mod)%mod;
	 }

	 ll ans=0;


	 for(ll i=0;i<n-1;i++)
	 {
	 	ll temp = ((vect[i]%mod)*(suf_sum[i+1])%mod)%mod;
	 	
	 	ans= (ans%mod + temp%mod)%mod;
	 	
	 }

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

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a - b) <= d && abs(b - c) <= d || abs(a - c) <= d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def resolve():
    # 十進数表記で1~9までの数字がK個入るN桁の数字の数を答える問題
    S = input()
    K = int(input())
    n = len(S)

    # dp[i][k][smaller]:
    # i:桁数
    # K:0以外の数字を使った回数
    # smaller:iまでの桁で値以上になっていないかのフラグ

    dp = [[[0] * 2 for _ in range(4)] for _ in range(105)]
    dp[0][0][0] = 1

    for i in range(n):
        for j in range(4):
            for k in range(2):
                nd = int(S[i])
                for d in range(10):
                    ni = i+1
                    nj = j
                    nk = k
                    if d != 0:
                        nj += 1
                    if nj > K:
                        continue
                    if k == 0:
                        if d > nd: # 値を超えている
                            continue
                        if d < nd:
                            nk += 1
                    dp[ni][nj][nk] += dp[i][j][k]
    ans = dp[n][K][0] + dp[n][K][1]
    print(ans)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9200
a=int(input()) #500
b=int(input()) #100
c=int(input()) #50
x=int(input())
cnt=0


for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                cnt+=1
print(cnt)            
        


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include<iostream>
#include <iomanip>
#include<string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  int a, b, x;
  cin >> a >> b >> x;

  double p = (double)x * 2 / b / a;
  double q = 2 * b - 2 * (double)x / (a * a);
  
  if (a * a * b / 2.0 >= x) {
    double t = atan(p / b);
    t = t / (2 * M_PI) * 360;
    cout << setprecision(12) << 90 - t << endl;
  }
  else {
    double t = atan(q / a);
    t = t / (2 * M_PI) * 360;
    cout << setprecision(12) << t << endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        string[] input1 = Console.ReadLine().Split(' ');
        int x = int.Parse(input1[0]);
        int n = int.Parse(input1[1]);

        string[] input2 = Console.ReadLine().Split(' ');
        /*
        int[] p = new int[] { };
        for(var i =0;i<n;i++)
        {
            p[i] = int.Parse(input2[i]);
        }
        */
        int[] nums = new int[201];
        for (var i = 0; i<=200;i++)
        {
            nums[i] = i;
        }

        for (var i = 0; i <= 100; i++)
        {
            for (var j = 0; j < n; j++)
            {
                if(nums[i] == int.Parse(input2[j]))
                {
                    nums[i] = 201;
                    break;
                }
            }

        }
        int[] p2 = nums.Select(i => Math.Abs(i - x)).ToArray();

        int absMin = 201;
        int noMin=-1;

        if(n == 0)
        {
            noMin = x;
            goto label1;
        }

        for(var i = 0; i<=200; i++)
        {
            if(absMin > p2[i])
            {
                absMin = p2[i];
                noMin = i;
            }
        }
    label1:;
        Console.WriteLine(noMin);

    }
}


Measured memory_bytes: 28300
//#include <bits/stdc++.h>
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
const int mod = 1000000007;

ll gcd(ll a, ll b){return b ? gcd(b,a%b) : a;};//最大公約数
ll lcm(ll a, ll b){return a*b/gcd(a,b);};//最小公倍数
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
//ll a[100000];
//ll dom[100001];

int main(){
  string s,t;
  int a,b;
  cin>>s>>t;
  cin>>a>>b;
  string u;
  cin>>u;
  if(s==u) a--;
  else b--;
  cout<<a<<" "<<b;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAXN = 1<<17, MAXD = 12;

int bio[MAXN];
vector <int> V[MAXN];
int rje[MAXN];
int v[MAXN], d[MAXN], c[MAXN];

void dfs(int node, int dist, int col)
{
  if (dist < 0) return;
  if (bio[node] == -1) rje[node] = col;
  if (bio[node] >= dist) return;
  bio[node] = dist;
  
  for (auto it : V[node])
    dfs(it, dist-1, col);
}

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

  REP(i, m) {
    int a, b;
    scanf("%d%d", &a, &b); a--; b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }

  int brq;
  scanf("%d", &brq);

  for (int i=brq-1; i>=0; i--) {
    scanf("%d%d%d", &v[i], &d[i], &c[i]); v[i]--;
  }

  memset(bio, -1, sizeof bio);

  REP(i, brq)
    dfs(v[i], d[i], c[i]);

  REP(i, n) printf("%d\n", rje[i]);

  return 0;
}


Measured memory_bytes: 9336
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#include <deque>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int flag = 1;
  string a;
  cin >> a;
  int n;
  cin >> n;
  vector<string> left;
  vector<string> right;
  deque<string> ret;
  ret.EB(a);
  REP(i,n) {
    int t,f;
    string c;
    cin >> t;
    if( t == 1 ) {
      flag *= -1;
      continue;
    }
    cin >> f >> c;
    if( f == 2 ) f = -1;
    if( flag == 1 ){
      if( f == 1 ) ret.push_front(c);      
      else ret.EB(c);
    }
    else{
      if( f == 1 ) ret.EB(c);
      else ret.push_front(c);
    }
  }
  if( flag == 1 ){
  rep(i,ret.size()){
    cout << ret[i];
  }
  cout << endl;
  }
  else{
  repr(i,ret.size()) {
    if( ret[i].size() > 0 ) reverse(ret[i].begin(),ret[i].end());
    cout << ret[i]; 
  } 
  cout << endl;
  
  }

  return 0;

}



Measured memory_bytes: 11728
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <map>
#include <stack>
using namespace std;
typedef long long ll;
struct node{
    int a,b;
    bool operator<(const node & T)const{
        if(T.a==a) return b<T.b;
        return a<T.a;
    }
};
node a[111100]={0};
int main()
{
    ios::sync_with_stdio(false);
    cin.tie();
    int n,k,m,d;
    cin >>n >> d;
    for(int i=0;i<n;i++){
        cin >> a[i].a >> a[i].b;
    }
    sort(a,a+n);
    priority_queue<int>q;
    while(!q.empty()){
        q.pop();
    }
    long long sum=0;
    int ind=0;
    for(int i=1;i<=d;i++){
        while(ind<n&&a[ind].a<=i){
            q.push(a[ind].b);
            ind++;
        }

        if(!q.empty()){
            //cout << q.top() << endl;
            sum+=q.top();
            q.pop();

        }
    }
    cout << sum << endl;
    return 0;
}


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

using namespace std;

const int maxn = 100010;
;
long long int nums[maxn];
long long int n, k;

int main(){
	cin >> n >> k;
	for (int i = 0; i < n; i++){
		long long int a, b;
		cin >> a >> b;
		nums[a] += b;
	}

	for (int i = 0; i < maxn; i++){
		k -= nums[i];
		if (k <= 0){
			cout << i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1024
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ;

int n ;
long long c ,x[N] ,add[N] ;
long long ansR[N] ,ansL[N] ,ans ,bestL[N] ,bestR[N] ;
long long solve(long long cur,int ii,int jj){
    if(ii>jj) return 0;
    long long ret = 0 ;
    ret = max(ret ,solve(x[ii],ii+1,jj) - (x[ii]-cur+c)%c + add[ii]) ;
    ret = max(ret ,solve(x[jj],ii,jj-1) - (cur-x[jj]+c)%c + add[jj]) ;
    return ret;
}
int main(){
    scanf("%d%lld",&n,&c);
    for(int i=0;i<n;++i) scanf("%lld%lld",x+i,add+i);
    long long cur = 0 ;
    for(int i=0;i<n;++i){
        if(i) ansL[i] = ansL[i-1] ,bestL[i] = bestL[i-1] ;
        ansL[i] += add[i] - (x[i]-cur+c)%c ;
        ans = max(ans ,ansL[i]);
        bestL[i] = max(bestL[i] ,ansL[i]);
        cur = x[i] ;
    }
    cur = 0 ;
    for(int i=n-1;i>=0;--i){
        ansR[i] = ansR[i+1] ,bestR[i] = bestR[i+1];

        ansR[i] += add[i] - (cur-x[i]+c)%c ;
        ans = max(ans,ansR[i]);
        bestR[i] = max(bestR[i] ,ansR[i]);
        cur = x[i] ;
    }

    for(int i=0;i<n;++i){
        long long xx = ansL[i] - x[i] + bestR[i+1] ;
        ans = max(ans,xx);
    }
    for(int i=n-1;i>=0;--i){
        long long xx= ansR[i] - (c-x[i]) + bestL[i-1] ;
        ans = max(ans,xx);
    }
    cout << ans ;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
struct order { int v, d, c; };
int n, m, q, v, c, d, i, a, b, color[100010], depth[100010];
vector<int> G[100010];
stack<order> S;
void dfs(int v, int c, int d, int p=0){
	if((depth[v]!=0||d!=0)&&depth[v]>=d)	return;
	if(color[v]==0)
		color[v]=c;
	depth[v]=d;
	if(d<1)	return;
	for(auto x:G[v])
		if(x!=p)
			dfs(x, c, d-1, v);
}
int main(){
	ios::sync_with_stdio(false);
	for(cin>>n>>m; i<m; i++){
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(cin>>q; q--; ){
		cin>>v>>d>>c;
		S.push({v,d,c});
	}
	while(!S.empty()){
		struct order o=S.top();	S.pop();
		dfs(o.v, o.c, o.d);
	}
	for(i=1; i<=n; i++)
		cout<<color[i]<<endl;
	return 0;
}

Measured memory_bytes: 8568
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

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

	cout << ((N % 500 <= A) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int A,B,C;
    cin>>A>>B>>C;
    if(A==B&&B==A&&B!=C&&A!=C){
        cout<<"Yes";
    }
    else if(A==C&&C==A&&A!=B&&C!=B){
        cout<<"Yes";
    }
    else if(B==C&&C==B&&C!=A&&B!=A){
        cout<<"Yes";
    }
    else cout<<"No";
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <set>
#include <unordered_set>


using namespace std;


int main()
{
    int N;
    int W[100];
    int dp[100];
    cin >> N ;
    for(int i=0; i<N;i++){
        cin>>W[i];
    }
    dp[0] = W[0];
    for(int i=1; i<N; i++){
        dp[i] = W[i] + dp[i-1];
    }
    int min=std::numeric_limits<int>::max();
    for(int i=0; i<N; i++){
        int S1= dp[i];
        int S2 = dp[N-1] - S1;
        min = std::min(min, abs(S2-S1));
    }

    cout<<min<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
                    
                    
int main(){
    long long N, k, m ,min_num, max_num;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }

    min_num = A[0];
    k = 0;
    m = 1000;
    
    for(int i = 1; i < N; i++) {
        if(min_num < A[i]) {
            k = m / min_num;
            m = m - (k * min_num) + (k * A[i]);
            min_num = A[i];
        } else if(min_num > A[i]) {
            min_num = A[i];
        }
    }

    cout << m << endl;


            
}

Measured memory_bytes: 3636
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int a, b; 
  cin >> a >> b;
  if (b < 10) {
    a = a * 10 + b;    
  } else if (b < 100) {
    a = a * 100 + b;
  } else {
    a = a * 1000 + b;
  }
  int sq = sqrt(a);
  if (sq * sq == a) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

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

int main() {
    list<int> b;
    int n;
    cin >> n;
    vector<int> result;
    for (int i; cin >> i; b.emplace_back(i)) {
    }
    for (int i = 1; i <= n; i++) {
        auto it = b.rbegin();
        for (int j = b.size(); j >= 1; j--) {
            if (j == *it) {
                b.erase(prev(it.base()));
                result.emplace_back(j);
                break;
            }
            it++;
        }
        if (result.size() != i) {
            result.clear();
            result.emplace_back(-1);
            break;
        }
    }
    for (auto it = result.rbegin(); it != rend(result); it++) {
        cout << *it << '\n';
    }
    return 0;
}

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

int main(){
  int a;
  cin >> a;
  double b = a;
  if(a %2 == 0){
    cout << setprecision(10) << 1.0/2.0 << endl;
  }
  else{
    double c = (b+1)/2;
    cout << setprecision(10) << c/b << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,x;
    cin >> n >> x;
    vi a(n);
    cin >> a;
    ll ans = linf;
    auto mod = [&](int i) {
        i %= n;
        i += n;
        i %= n;
        return i;
    };
    rep(i,n) {
        ll nans = ll(x)*i;
        multiset<int> st;
        rep(j,i+1) st.insert(a[mod(-j)]);
        rep(j,n) {
            nans += *st.begin();
            st.erase(st.find(a[mod(j-i)]));
            st.insert(a[mod(j+1)]);
        }
        chmin(ans,nans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,e,f,k;
	cin>>a>>b>>c;
	cin>>k;
	if(a>b){d=b;b=a;a=d;}
	if(a>c){f=a;a=c;c=f;}
    if(b>c){e=b;b=c;c=e;}
    cout<<a+b+c*pow(2,k);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        Map<Integer, List<Integer>> graph = new HashMap<>();
        for(int i = 1; i <= n; i++) {
        	graph.put(i, new ArrayList<>());
        }
        for(int i = 1; i < n; i++) {
        	graph.get(i).add(i + 1);
        	graph.get(i + 1).add(i);
        }
        graph.get(x).add(y);

        Map<Integer, Integer> cntMap = new HashMap<>();
        Queue<Integer> queue = new LinkedList<>();
        Set<Integer> visited = new HashSet<>();
        for(int i = 1; i < n; i++) {
	        queue.clear();
	        queue.offer(i);
	        visited.clear();
	        visited.add(i);
	        int dist = 0;
	        while(!queue.isEmpty()) {
	        	int size = queue.size();
	        	for(int j = 0; j < size; j++) {
	        		int node = queue.poll();
	        		if(node > i)
	        		    cntMap.put(dist, cntMap.getOrDefault(dist, 0) + 1);
	        		if(!graph.containsKey(node)) continue;
	        		for(int adj : graph.get(node)) {
	        			if(visited.contains(adj)) continue;
	        			queue.offer(adj);
	        			visited.add(adj);
	        		}
	        	}
	        	dist++;
	        }
        }
        for(int i = 1; i < n; i++)
        	System.out.println(cntMap.getOrDefault(i, 0));
    }
}


Measured memory_bytes: 277416
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  string s;cin>>s;
  int res=0;
  int n=(int)s.length();
  reverse(ALL(s));
  s.push_back('0');
  rep(i,n){
    int num=s[i]-'0';
    int next=s[i+1]-'0';
    if(num>=6||(num>=5&&next>=5)){
      if(s[i+1]-'0'==9){
        int buf=1;
        while(s[i+buf]=='9'){
          s[i+buf]='0';
          buf++;
        }
        s[i+buf]++;
      }
      else s[i+1]++;
      res+=10-num;
      s[i]='0';
    }
    else res+=num;
    //cout<<res<<endl;
  }
  //cout<<s<<endl;
  res+=s[n]-'0';
  reverse(ALL(s));
  //cout<<s<<endl;
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
 
bool G[11][11];
bool vis[11];
vector<int> node;
int n,cnt;
 
 
void solve(int a){
    if(node.size()==n) cnt++;
    for(int i=1;i<=n;i++){
        if(G[a][i] && (!vis[i])){
            vis[i] = true;
            node.push_back(i);
            solve(i);
            vis[i] = false;
            node.pop_back();
        }
    }
}
 
int main(){
    int m,a,b;
    scanf("%d %d",&n,&m);
    memset(vis,false,sizeof(vis));
    memset(G,false,sizeof(G));
    while(m--){
        scanf("%d %d",&a,&b);
        G[a][b] = true;
        G[b][a] = true;
    }
    
    node.clear();

    vis[1] = true;
    node.push_back(1);
    solve(1);

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

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

using namespace std;

int n,m,q,a[51][5],c[11],ma=0;

void nhap()
{
    scanf("%d %d %d",&n,&m,&q);
    for (int i=1;i<=q;++i)
    {
        for (int j=1;j<=4;++j)
        {
            scanf("%d",&a[i][j]);
        }
    }
}


void check()
{
    int sum=0;
    for (int i=1;i<=q;++i)
    {
        if (c[a[i][2]]-c[a[i][1]]==a[i][3])
            sum+=a[i][4];
    }
    ma=max(ma,sum);
}

void solve(int i,int la)
{
    for (int j=la;j<=m;++j)
    {
        c[i]=j;
        if (i<n) solve(i+1,j);
        else check();
    }
}

int main()
{
    nhap();
    solve(1,1);
    cout<<ma;
    return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
    string s;
    cin >> s;
    ll ans = 700;
    REP(i,3){
        if(s[i] == 'o'){
            ans += 100;
        }
    }
    cout << ans << endl;

}


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

class Program
{
    static void Main(string[] args)
    {
        int x = int.Parse(Console.ReadLine());
        int fh = x / 500;
        x -= fh * 500;
        int f = x / 5;
        Console.WriteLine(fh * 1000 + f * 5);
    }
}

Measured memory_bytes: 13140
//
// Write a program which finds the greatest common divisor of two natural numbers a and b
//
#include <iostream>
using namespace std;

void read(int& x, int& y);
int calcGcd(const int x, const int y);
void write(const int gcd);

int main()
{
    int x = 0, y = 0;
    int ret = 0;

    read(x, y);
    ret = x > y ? calcGcd(x, y) : calcGcd(y, x);
    write(ret);
}

void read(int& x, int& y)
{
    cin >> x >> y;
}

int calcGcd(const int x, const int y)
{
    int r = 0;

    if (x == y)
        return x;

    r = x - y;
    if (y == r)
        return r;

    y > r ? calcGcd(y, r) : calcGcd(r, y);
}

void write(const int gcd)
{
    cout << gcd << endl;
}

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

int main () {
  int N, T; cin >> N >> T;
  vc<int> A(N), B(N); //料理
  rep(i, 0, N) cin >> A[i] >> B[i];
  vc<vc<vc<int>>> dp(N + 1, vc<vc<int>>(T, vc<int>(2, 0)));
  for(int i = N - 1; i >= 0; i--){
    rep(j, 0, T){
      if(j < A[i]){
        dp[i][j][0] = dp[i + 1][j][0];
        dp[i][j][1] = max(dp[i + 1][j][1], dp[i + 1][j][0] + B[i]);
      }else{
        dp[i][j][0] = max(dp[i + 1][j][0], dp[i + 1][j - A[i]][0] + B[i]);
        dp[i][j][1] = max({dp[i + 1][j][1], dp[i + 1][j][0] + B[i], dp[i + 1][j - A[i]][1] + B[i]});
      }
    }
  }
  cout << dp[0][T - 1][1] << endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 100000000000L

using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int n,k;
  ll dp[100000],h[100000];
  cin >> n >> k;
  REP(i,n){
    cin >> h[i];
    dp[i] = INF;
  }
  dp[0]=0;
  REP(i,n){
  	FOR(j,i+1,i+1+k){
      dp[j]=min( ( dp[j] ) ,
               ( dp[i] + abs(h[i]-h[j] ) ) );
    }
  }
  cout << dp[n-1] <<endl;
    return 0;
}


Measured memory_bytes: 5196
#include<cstdio>
int aa[30];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int i;
		for(i=0;i<n;i++)
		{
			scanf("%d",&aa[i]);
		}
		int num=0;
		for(i=1;i<=n-2;i++)
		{
			if(aa[i]>aa[i-1]&&aa[i]<aa[i+1]||aa[i]<aa[i-1]&&aa[i]>aa[i+1])
			num++;
		}
		printf("%d\n",num);
		
	}
	return 0;
}

Measured memory_bytes: 128
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second

void solve()
{
	ll x, n;
	cin >> x >> n;
	if (n == 0)
	{
		cout << x << "\n";
		return;
	}
	vll who(102, 0);
	vll arr(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> arr[i];
		who[arr[i]] = 1;
	}
	if (who[x] == 0)
	{
		cout << x << "\n";
		return;
	}
	ll out = 0;
	ll min_dis = abs(0 - x);
	for (ll i = 0; i <= 101; i++)
	{
		if (who[i] == 0 and abs(i - x) < min_dis)
		{
			out = i;
			min_dis = abs(i - x);
		}
	}
	cout << out << "\n";

}


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);

	// ll t;
	// cin >> t;
	// while (t--)
	// {
	solve();
	// }

	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main() {

  int a, b;
  char c;

  cin>>a>>c>>b;

  if(c == '+') cout<<a+b<<endl;
  else cout<<a-b<<endl;

  return 0;
}


Measured memory_bytes: 256
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$m = (int)$input[1];

$s_list = [];
for ($i=1; $i <= $m; $i++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$k = (int)$input[0];
	for ($j=1; $j <= $k; $j++) { 
		$s_list[$i][] = (int)$input[$j];
	}
}
$input = explode(' ', trim(fgets(STDIN)));
$ps = [];
$default = [];
for ($i=1; $i <= $m; $i++) { 
	$ps[$i] = (int)$input[$i-1];
	$default[$i] = 0;
}

$sum = 0;
$max = pow(2, $n) - 1;
for ($i=0; $i <= $max; $i++) { 
	$m_cnt_list = $default;
	$comb_str = str_pad(decbin($i), $n, '0', STR_PAD_LEFT);
	for ($j=0; $j < $n; $j++) { 
		$tmp_str = $comb_str[$n-$j-1];
		if ($tmp_str === '1') {
			for ($k=1; $k <= $m; $k++) { 
				if (in_array($n-$j, $s_list[$k])) {
					$m_cnt_list[$k] += 1;
				}
			}
		}
	}
	$cnt = 0;
	for ($f=1; $f <= $m; $f++) { 
		if ($m_cnt_list[$f] % 2 === $ps[$f]) {
			++$cnt;
		}
	}
	if ($cnt === $m) {
		++$sum;
	}
}
echo $sum;

Measured memory_bytes: 4728
#include <iostream>
using namespace std;
int main(){
    int n; cin >> n;
    int x; cin >> x;
    int max_1 = 0, max_2 = 0;
    for(int i = 0; i < n-1; i++){
        int y; cin >> y;
        if(x >= y){
            max_2++;
        }
        if(x < y){
            if(max_1 < max_2) {
                max_1 = max_2;
            }
            max_2 = 0;
        }
        x = y;
    }
    if(max_1 >= max_2) cout << max_1 << endl;
    else cout << max_2 << endl;
    return 0;
}

Measured memory_bytes: 256
<?php

// 読み取り
// echo "Please Enter:";
fscanf(STDIN, "%d %d %d", $X, $Y, $Z);

// 読み取り2
//$std_in = trim(fgets(STDIN));
//var_dump($std_in);

echo $Z . " " .$X ." " .$Y;

?>

Measured memory_bytes: 4732
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        l: i32
    };

    let mut v = vec![];

    let mut ate = std::i32::MAX;

    for i in 0..n {
        let x = i as i32 + l;
        if x.abs() < ate.abs() {
            ate = x;
        }
        v.push(x);
    }

    println!("{}", v.iter().sum::<i32>() - ate);
}


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

int n;

char query(set<int> s) {
  cout << '?';
  for (int p : s) {
    cout << ' ' << p%(2*n)+1;
  }
  cout << endl;
  string ans;
  cin >> ans;
  if (ans == "-1") exit(0);
  return ans[0];
}

char query(int p) {
  cout << '?';
  for (int i = 0; i < n; i++) {
    cout << ' ' << (p+i)%(2*n)+1;
  }
  cout << endl;
  string ans;
  cin >> ans;
  if (ans == "-1") exit(0);
  return ans[0];
}

string ans;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cin >> n;
  int blue, red;
  if (query(0) == 'R') red = 0, blue = n;
  else red = n, blue = n*2;
  while (blue-red > 1) {
    int mid = blue+red>>1;
    if (query(mid) == 'B') blue = mid;
    else red = mid;
  }

  ans.resize(n*2);
  ans[red%(n*2)] = 'R';
  ans[(red+n)%(n*2)] = 'B';
  set<int> A, B;
  for (int i = red+1; i < red+n; i++) A.insert(i%(2*n));
  for (int i = red+n+1; i < red+n+n; i++) B.insert(i%(2*n));

  for (int i : A) {
    B.insert(i);
    ans[i] = query(B);
    B.erase(i);
  }
  for (int i : B) {
    A.insert(i);
    ans[i] = query(A);
    A.erase(i);
  }
  cout << "! " << ans << endl;
}


Measured memory_bytes: 724
#include <stdio.h>
#include <bits/stdc++.h>
     
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 1000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-6;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 1.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    int c1 = 0, c2 = 0, c4 = 0;
    rep(i, 0, n)
    {
        int x;
        cin >> x;
        if (x % 4 == 0)
            c4++;
        else if (x % 2 == 0)
            c2++;
        else
            c1++;
    }
    if (c2 == 0 && c1 > c4 + 1 || c2 > 0 && c1 > c4)
        cout << "No\n";
    else
        cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
num = list(map(int,input().split()))
num_list = list(map(int,input().split()))

num_list.sort()
sum = 0

if num[1] >= num[0]:
  ans = 0
elif num[1] < num[0]:
  for i in range(0,num[0]-num[1]):
    sum = sum + num_list[i]
    
  ans = sum

print(ans)

Measured memory_bytes: 26764
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> X(M), L(M);int ans;
	if (N < M) {
		for (int i = 0;i < M;i++) {
			cin >> X[i];
		}
		sort(X.begin(), X.end());
		for (int j = 0;j < M - 1;j++) {
			L[j] = X[j + 1] - X[j];
		}
		sort(L.begin(), L.end(), greater<int>());

		int Lsum = 0;
		for (int i = 0;i < N - 1;i++) {
			Lsum += L[i];
		}
		ans = X[M - 1] - X[0] - Lsum;
	}
	else if (N >= M) {
		ans = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
class UnionFind
  def initialize(n)
    @size = Array.new(n, 1)
    @rank = Array.new(n, 0)
    @parent = []

    (0..n).each do |i|
      @parent[i] = i
    end
  end

  def find(x)
    if @parent[x] == x
      x
    else
      @parent[x] = find(@parent[x])
    end
  end

  def unite(x, y)
    x = find(x)
    y = find(y)
    return if x == y

    if @rank[x] < @rank[y]
      @parent[x] = y
      @size[y] += @size[x]
    else
      @parent[y] = x
      @size[x] += @size[y]

      @rank[x] += 1 if @rank[x] == @rank[y]
    end
  end

  def same?(x, y)
    find(x) == find(y)
  end

  def size(x)
    @size[find(x)]
  end
end

N, M = gets.split.map(&:to_i)
Q = M.times.map { gets.split.map(&:to_i) }

uf = UnionFind.new(N + 1)

Q.each do |a, b|
  uf.unite(a, b)
end

puts (1..N).map { |x| uf.size(x) }.max


Measured memory_bytes: 34872
N, K = map(int, input().split())
D = list(map(int, input().split()))
L = [i for i in range(10) if i not in D]
A = []
for i in L:
  A.append(i)
for i in L:
  for j in L:
    A.append(10*i+j)
for  i in L:
  for j in L:
    for k in L:
      A.append(100*i+10*j+k)
for i in L:
  for j in L:
    for k in L:
      for l in L:
        A.append(1000*i+100*j+10*k+l)

for i in L:
  for j in L:
    for k in L:
      for l in L:
        for m in L:
          A.append(\
10000*i+1000*j+100*k+10*l+m)

for i in A:
  if i >= N:
    print(i)
    break

Measured memory_bytes: 5732
use std::cmp;
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    let mut n: i64 = iter.next().unwrap().parse().unwrap();
    let k: i64 = iter.next().unwrap().parse().unwrap();

    // 0がでたら終了
    // 暫定Nと同じ値がでたら終了

    // 計算時間短縮の為、n/kの余りを計算
    n = n % k;

    let abs: i64 = (n - k).abs();

    println!("{}", cmp::min::<i64>(n, abs));
}


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

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

using namespace std;
using lint=long long;

class union_find{
	int n;
	vector<int> p;
public:
	union_find(int n):n(n),p(n,-1){}
	int find(int u){
		if(p[u]<0) return u;
		return p[u]=find(p[u]);
	}
	void unite(int u,int v){
		u=find(u); v=find(v);
		if(u!=v){ p[u]+=p[v]; p[v]=u; n--; }
	}
	bool is_same(int u,int v){ return find(u)==find(v); }
	int size(){ return n; }
	int size(int u){ return -p[find(u)]; }
};

int main(){
	int n,m; scanf("%d%d",&n,&m);
	int a[100000],b[100000];
	rep(i,m) scanf("%d%d",a+i,b+i), a[i]--, b[i]--;

	lint cnt=n*(n-1LL)/2;
	vector<lint> ans(m);
	union_find U(n);
	for(int i=m-1;i>=0;i--){
		ans[i]=cnt;
		if(!U.is_same(a[i],b[i])){
			cnt-=1LL*U.size(a[i])*U.size(b[i]);
			U.unite(a[i],b[i]);
		}
	}
	rep(i,m) printf("%lld\n",ans[i]);

	return 0;
}


Measured memory_bytes: 3328
from fractions import gcd
from sys import exit

N = int(input())
A = list(map(int, input().split()))

l_gcd_list = [0]*(N+1)
r_gcd_list = [0]*(N+1)
for i in range(N):
    l_gcd_list[i+1] = (gcd(l_gcd_list[i], A[i]))
    r_gcd_list[-(i+2)] = (gcd(r_gcd_list[-(i+1)], A[-(i+1)]))
# print(l_gcd_list)
# print(r_gcd_list)

results = []
for i in range(N):
    results.append(gcd(l_gcd_list[i], r_gcd_list[i+1]))

print(max(results))


Measured memory_bytes: 16148
#include<cstdio>
#include<algorithm> 
using namespace std;
struct node{
	int x;
	double v;
}a[4];

bool cmp(node a, node b) {
	return (double)a.x / a.v < (double)b.x / b.v;
}
long long ans;
int n;

int main() {
	scanf("%d%d%d%d%d", &a[0].x, &a[1].x, &a[2].x, &a[3].x, &n);
	a[0].v = 0.25;
	for(int i = 1; i <= 3; i++) a[i].v = a[i - 1].v * 2; 
	for(int i = 0; i <= 3; i++) {
		sort(a + i, a + 4, cmp);
		//printf("%d %lf\n", a[i].x, a[i].v);
		ans += (long long)(n / a[i].v) * a[i].x;
		n -= a[i].v * (int)(n / a[i].v);
		//printf("%d\n", n);
	}
	printf("%lld", ans);
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define long long ll
using namespace std;
int N,M;
vector<vector<int> > G;
vector<int> memo;
int dfs(int v){
	if(memo[v] != -1) return memo[v];
	memo[v] = 0;
	for(int u=0;u<G[v].size();u++) chmax(memo[v],dfs(G[v][u])+1);
	return memo[v];
}
int main(){
	cin>>N>>M;
	G.resize(N);
	memo = vector<int>(N,-1);
	rep(i,M){
		int x,y;
		cin>>x>>y;
		x--,y--;
		G[x].pb(y);
	}
	int ans = 0;
	rep(i,N) chmax(ans,dfs(i));
	cout<<ans<<endl;
}

Measured memory_bytes: 8192
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

#define ll long long
#define FOR(x,z,y) for(ll x=z; x < (ll)y; x++)



int main() {

    int a,b;
    cin >> a >> b;
    FOR(i,0,1e4) {
        if(floor(i*0.08) == a && floor(i*0.1) == b){
            cout << i;
            return 0;
        }
    }
    cout << "-1";
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int so[246913]={},n;
  for(int i=2;i<246913;i++)if(so[i]==0)for(int j=2;i*j<246913;j++)so[i*j]=1;
  while(1){
  int n,an=0;cin>>n;
  if(n==0)break;
  for(int i=n+1;i<=2*n;i++)if(so[i]==0)an++;
  cout<<an<<endl;
  }
  return 0;
}

Measured memory_bytes: 2132
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int N;
    scanf("%d",&N);
    int i;
    for(i=0;i<3;i++)
    {
        if(N%10==7)
        {
            printf("Yes");return 0;
        }
        else
        {
            N=N/10;
        }
    }
    printf("No");
    return 0;
}


Measured memory_bytes: 1728
#include <string>
#include <iostream>

using namespace std;

int main()
{

  int a, b;
  cin >> a >> b;

  int dif = b - a;

  int sum = 0;
  for (int i = 1; i < dif; ++i)
  {
    sum += i;
  }

  cout << (sum-a) << '\n';

  return 0;


}

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

int main()
{
  double N;
  int K;
  cin >> N >> K;
  double ans = 0;
  rep(i, N) {
    int score = i+1;
    int cnt = 0;
    while (true) {
      if (score >= K) {
        break;
      }
      score *= 2;
      cnt += 1;
    }
    double val = (1.0 / N) * pow(0.5, cnt);
    ans += val;
  }
  cout << std::setprecision(12) << ans << endl;
}

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

int main()
{
  int N, res;
  cin >> N;
  int A[N], B[N], C[N - 1];
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N - 1; i++) cin >> C[i];

  res = B[A[0] - 1];
  for (int i = 1; i < N; i++)
  {
    res += B[A[i] - 1];
    if (A[i] == A[i - 1] + 1)
      res += C[A[i] - 2];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> x;
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		x.push_back(make_pair(b, a));
	}
	SORT(x);

	ll time = 0;;
	rep(i, n) {
		time += x[i].second;
		if (time <= x[i].first) {
			//OK
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}



Measured memory_bytes: 2420
(defun trim-num (x num)
  (if (> x num)
      num
      (- num x)))

(let* ((a (read-line))
       (b (sort (read-from-string (concatenate 'string "(" (read-line) ")")) #'<))
       (c (remove-duplicates b)))
  (if (null b)
      (princ 0)
      (princ (let ((x 0)
                   (num 0)
                   (sum 0))
               (loop for i in b
                     do (cond ((/= x i) (progn (incf sum (trim-num x num))
                                               (setf x i)
                                               (setf num 1)))
                              (t (incf num)))
                     finally (incf sum (trim-num x num)))
               sum))))


Measured memory_bytes: 51552
#include<iostream>
using namespace std;
int main()
{

  int a,b;

  cin >> a >> b;

  if(a>b){
    cout << "a > b" << endl;
  }else if(a<b){
    cout << "a < b" << endl;
  }else{ 
    cout << "a == b" << endl;
  }
  return 0;

}


Measured memory_bytes: 3088
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

const ll inf = 1e18;

int A, B, Q;
ll s[100000];
ll t[100000];

ll g(ll si, ll ti, ll x){
  ll res = inf;
  rep(ds, -1, 2){
    rep(dt, -1, 2){
      int sii = si + ds;
      int tii = ti + dt;
      if(sii >= A) continue;
      if(tii >= B) continue;
      if(sii < 0) continue;
      if(tii < 0) continue;
      ll sx = s[sii];
      ll tx = t[tii];
      res = min(res, abs(sx - tx) + min(abs(x - sx), abs(x - tx)));
    }
  }
  return res;
}

ll f(ll x){
  ll si, ti;
  {
    ll ng = 0;
    ll ok = A - 1;
    while(abs(ok - ng) > 1){
      ll md = (ok + ng) / 2;
      (s[md] >= x ? ok : ng) = md;
    }
    si = ok;
  }
  {
    ll ng = 0;
    ll ok = B - 1;
    while(abs(ok - ng) > 1){
      ll md = (ok + ng) / 2;
      (t[md] >= x ? ok : ng) = md;
    }
    ti = ok;
  }
  return g(si, ti, x);
}

int main(){
  cin >> A >> B >> Q;
  rep(i, A) cin >> s[i];
  rep(i, B) cin >> t[i];
  rep(i, Q){
    ll x;
    cin >> x;
    cout << f(x) << endl;
  }
  return 0;
}


Measured memory_bytes: 2816
#include <iostream>
using namespace std;
#define ll long long int
#define mod 1000000007
ll n, a, b, ans, cur;
ll bigmod (ll b, ll p){
    if (p==1){
    	return b%mod;
    }
    ll h = bigmod(b, p/2);
	if (p%2==0){
		return (h * h)%mod;
    }else{
    	return (((h * h)%mod)*b)%mod;
	}
}
int main(){
    cin>>n>>a>>b;
    ans=bigmod(2, n) - 1;
    cur=1;
    for (ll i=n-a+1; i<=n; i++){
        cur*=(i*bigmod(i-(n-a), mod-2))%mod;
        cur%=mod;
    }
    ans = (ans + mod - cur) % mod;
    cur=1;
    for (ll i=n-b+1; i<=n; i++){
        cur*=(i*bigmod(i-(n-b), mod-2))%mod;
        cur%=mod;
    }
    ans = (ans + mod - cur) % mod;
    cout<<ans%mod<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int score = 0;
    rep(i,s.size()) {
        if(s[i] == s[i+1]) {
            score++;
        }
    }
    int ans = min(n-1,score+2*k);
    cout << ans << endl;
}

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

int main()
{
	int n,ans=0;
	string s;
	int mod=0;
	cin>>n;
	cin>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='I')mod++;
		else mod--;
		ans=max(ans,mod);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
from functools import reduce
import copy

N = int(input())
alist = list(map(int, input().split()))

while len(alist) > 1:
  min_a = min(alist)
  alist.remove(min_a)
  new_alist = [min_a]
  for a in alist:
    if int(a%min_a) != 0:
      new_alist.append(int(a%min_a))
  alist = copy.deepcopy(new_alist)

print(new_alist[0])

Measured memory_bytes: 91028
isPrime = []
prime = []
count = []

def init():
    for i in range(50000 + 1):
        isPrime.append(True)
        count.append(0)

def eratos():
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2, int((50000 ** (1 / 2))) + 1):
        if (isPrime[i]):
            for j in range(i * 2, 50000 + 1, i):
                isPrime[j] = False
    
    for i in range(2, 50001):
        if isPrime[i]:
            prime.append(i)


def table():
    for i in prime:
        for j in prime:
            if i < j:
                continue
            if i + j > 50000:
                continue
            count[i + j] += 1

init()
eratos()
table()

while True:
    n = int(input())
    if n == 0:
        break
    print(count[n])

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

long long rCnt, gCnt, bCnt, ans;

int main() {
	int n;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		switch (s[i]) {
			case 'R': 
				rCnt++;
				break;
			case 'G': 
				gCnt++;
				break;
			case 'B': 
				bCnt++;
				break;
		}
	} 
	ans = rCnt * gCnt * bCnt;
	for (int i = 0; i < n; i++) {
		for (int j = 1; i - j >= 0 && i + j < n; j++) {
			if (s[i] != s[i - j] && s[i] != s[i + j] && s[i - j] != s[i + j]) {
				ans--;
			}
		}
	}
	cout << ans << '\n';
}

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

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

  vector<int> ans(N+1,0);
  int x, y, z;
  for (x = 1; x <= 100; x++)
  {
    for (y = 1; y <= 100; y++)
    {
      for (z = 1; z <= 100; z++)
      {
        if (x*x + y*y + z*z + x*y + y*z + z*x <= N) {
          ans[x*x + y*y + z*z + x*y + y*z + z*x]++;
        }
      }
    }
  }
  for (int i = 1; i <= N; i++)
  {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n;
	cin >> n;
	vector <int> A(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> A[i];
	}
	int c = 0;
	for (int i = 1; i < n; i++) {
		if(A[i] == i) {
			swap(A[i], A[i + 1]);
			c++;
		}
	}
	if(A[n] == n) {
		c++;
	}
	cout << c;
}


Measured memory_bytes: 768