akhauriyash/Code-Regression huggingface dataset:
#include <queue>
#include <iostream>
using namespace std;
const int MAXN=1e5+7;
struct EDGE {int n,next;} edge[MAXN];
int n,m,cnt,ans;
int in[MAXN],dis[MAXN],head[MAXN];
queue <int> q;
void Add(int x,int y)
{
	edge[++cnt].n=y,edge[cnt].next=head[x],head[x]=cnt;
}
void Topo()
{
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(int i=head[x];i;i=edge[i].next)
		{
			in[edge[i].n]--;
			dis[edge[i].n]=dis[x]+1;
			ans=max(ans,dis[edge[i].n]);
			if(!in[edge[i].n]) q.push(edge[i].n);
		}
	}
}
int main()
{
	cin>>n>>m;
	for(int x,y,i=1;i<=m;i++) cin>>x>>y,Add(x,y),in[y]++;
	for(int i=1;i<=n;i++) if(!in[i]) q.push(i);
	Topo();
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5700
import java.util.Scanner;
public class Main {
  
 public static void main(String[] args)
 {
  Scanner scan = new Scanner(System.in);
  int a = scan.nextInt();
  int b = scan.nextInt();
  int ans = a+b < a-b ? a-b:a+b;
  ans = ans < a*b ? a*b:ans;
  System.out.println(ans);
 }

}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

const int MAX = 510000;

ll dp[100010][4];

ll pow_mod(ll n, ll x)
{
    ll res = 1;
    while (n > 0)
    {
        if ((n & 1) == 1)
        {
            res *= x;
            res %= MOD;
        }
        x = x * x;
        x %= MOD;
        n >>= 1;
    }
    return res;
}

ll a[100010], c[100010], q[100010];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    string s;
    cin >> s;
    ll n = s.size();

    for (int i = 0; i < n; ++i)
    {
        if (s[i] == 'A')
            a[i + 1]++;
        a[i + 1] += a[i];
        if (s[n - i - 1] == 'C')
            c[i + 1]++;
        c[i + 1] += c[i];
        if (s[i] == '?')
            q[i + 1]++;
        q[i + 1] += q[i];
    }
    ll ans = 0;
    ll Q = q[n];
    for (int i = 1; i < n - 1; ++i)
    {
        if (s[i] == '?')
        {
            ll X = Q - 1;
            ans += (a[i]) * (c[n - i]) % MOD * pow_mod(X, 3);
            ans %= MOD;
            ans += (q[i]) * (c[n - i]) % MOD * pow_mod(X - 1, 3);
            ans %= MOD;

            ans += (a[i]) * (q[n] - q[i + 1]) % MOD * pow_mod(X - 1, 3);
            ans %= MOD;
            ans += (q[i]) * (q[n] - q[i + 1]) % MOD * pow_mod(X - 2, 3);
        }
        else if (s[i] == 'B')
        {
            ll X = Q;
            ans += (a[i]) * (c[n - i]) % MOD * pow_mod(X, 3);
            ans %= MOD;
            ans += (q[i]) * (c[n - i]) % MOD * pow_mod(X - 1, 3);
            ans %= MOD;

            ans += (a[i]) * (q[n] - q[i + 1]) % MOD * pow_mod(X - 1, 3);
            ans %= MOD;
            ans += (q[i]) * (q[n] - q[i + 1]) % MOD * pow_mod(X - 2, 3);
        }
        ans %= MOD;
    }

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

Measured memory_bytes: 4560
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n,k;
	cin>>n>>k;
	vi mp(n+1,0);
	rep(i,k){
		int d;
		cin>>d;
		int x;
		rep(j,d){
			cin>>x;
			mp[x]++;
		}
	}	
	int c = 0;
	repa(i,1,n+1){
		if(mp[i] == 0){
			c++;
		}
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ
{
  class Program
  {
    public static void Main()
    {
      var currentDirection = 90;
      var currentX = 0.0;
      var currentY = 0.0;
      foreach (var direction in ReadNumbers().TakeWhile(ds => !(ds[0] == 0 && ds[1] == 0)))
      {
        var rad = DegreeToRadian(currentDirection);
        currentX += Math.Cos(rad) * direction[0];
        currentY += Math.Sin(rad) * direction[0];
        currentDirection -= direction[1];
      }
      Console.WriteLine((int)currentX);
      Console.WriteLine((int)currentY);
    }

    static IEnumerable<int[]> ReadNumbers()
    {
      string line;
      while (!string.IsNullOrEmpty(line = Console.ReadLine()))
        yield return line.Split(',').Select(s => int.Parse(s)).ToArray();
    }

    static double DegreeToRadian(double degree)
    {
      return degree / 180.0 * Math.PI;
    }
  }
}

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

int main(){
  int n;
  cin>>n;
  int c[n-1],s[n-1],f[n-1];
  rep(i,0,n-1){
    cin>>c[i]>>s[i]>>f[i];
  }
  rep(i,0,n){
    int ans=0;
    rep(j,i,n-1){
      if(ans<=s[j]){
        ans=s[j];
      }
      else{
        ans=(ans-s[j]+f[j]-1)/f[j]*f[j]+s[j];
      }
      ans+=c[j];
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
<?php
	$arr = explode(' ', fgets(STDIN));
	$n = $arr[0];
	$a = $arr[1];
	$b = $arr[2];
	$sum_array = array();
	for ($i = 0; $i <= $n; $i ++) {
      	if (strlen($i) > 1) {
          	$tmp_array = str_split($i);
          	$tmp = array_sum($tmp_array);
          	if ($tmp >= $a and $tmp <= $b) {
          	array_push($sum_array, $i);
            }
        } else {
          	if ($i >= $a and $i <= $b) {
          	array_push($sum_array, $i);
            }
        }
    }

	echo array_sum($sum_array);
?>

Measured memory_bytes: 4728
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] sunuke = new int[n];
        int ans = 0;

        for(int i = 0;i < k;i++){
            int d = sc.nextInt();
            for(int j = 0;j < d;j++){
                int num = sc.nextInt();
                sunuke[num-1]++;
            }
        }

        for(int i = 0;i < n;i++){
            if(sunuke[i] == 0)
                ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 46532
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
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); }
int solve(){
  int n;
  string S;
  cin >> n >> S;
  string s = S;
  int l = 0,r = 0;
  rep(i,n - 1){
    if(s[i] == '(')
    REP(j,i + 1,n){
      if(s[j] == ')'){
        s[i] = '#';
        s[j] = '#';
        break;
      }
    }
  }
  rep(i,n){
    if(s[i] == '(')l++;
    else if(s[i] == ')')r++;
  }
  swap(l,r);
  rep(i,l)cout << '(';
  cout << S;
  rep(i,r)cout << ')';
  cout << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
} 

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

class crop{
public:
  string name;
  int price,seeding,youngL,L,flower,
    fruit,numFruit,fruitPrice,times;
  int StoL,LtoFruit,totaltime;
  double sum;
  crop();
  crop(string name,int price,int seeding,int youngL,
       int L,int flower,int fruit,
       int numFruit,int fruitPrice,
       int times):name(name),price(price),
		  seeding(seeding),youngL(youngL),L(L),
		  flower(flower),fruit(fruit),numFruit(numFruit),
		  fruitPrice(fruitPrice),times(times){
    this->StoL= seeding + youngL + L;
    this->LtoFruit = flower + fruit;
    this->totaltime=StoL + LtoFruit * times;
    this->sum = ((times * numFruit  * fruitPrice) - price) / (double)totaltime;
  }
  ~crop(){}
  
  bool operator<(const crop &a)const{
    if(this->sum != a.sum){
      return this->sum > a.sum;
    }else{
      return this->name < a.name;
    }
  }
};

void printCrop(crop &a){
  cout << "name:" << a.name << endl;
  cout << "price:" << a.price << " sum:" << a.sum << 
    " totaltime:"<< a.totaltime<< endl;
}
int main(){
  int n;
  while(cin>>n,n){
    vector<crop> C;
    for(int i=0;i<n;i++){
      string l;
      int p,a,b,c,d,e,f,s,m;
      cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
      C.push_back(crop(l,p,a,b,c,d,e,f,s,m));
    }
    sort(C.begin(), C.end());

    for(int i=0;i<n;i++){
      //printCrop(C[i]);
      cout << C[i].name << endl;
    }
    cout << "#" << endl;
  }
  return 0;
}

Measured memory_bytes: 1228
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 100005

using namespace std;

char str[SIZE];
int zero[SIZE],one[SIZE];

int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	scanf("%s",&str);
	int sz=0;
	int now=0;
	while(now<n)
	{
		while(now<n&&str[now]=='0')
		{
			zero[sz]++;
			now++;
		}
		while(now<n&&str[now]=='1')
		{
			one[sz]++;
			now++;
		}
		sz++;
	}
	int sum=0,ret=0;
	int to=0;
	for(int i=0;i<sz;i++)
	{
		while(to<sz&&to<i+k)
		{
			sum+=zero[to]+one[to];
			to++;
		}
		ret=max(ret,sum);
		sum-=zero[i];
		if(i>0) sum-=one[i-1];
	}
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define int ll
signed main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
        a[i] -= i+1;
    }
    sort(a.begin(),a.end());
    const int INF = INT64_MAX;
    int ans = INF;
    vector<int> s(n+1);
    s[0] = 0;
    rep(i,n) s[i+1] = s[i] + a[i];
    rep(i,n) {
        int b = a[i];
        int tmp = b * i - (s[i] - s[0]);
        tmp += (s[n] - s[i+1]) - b * (n-i-1);
        chmin(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)2e9 + 7)
#define INF ((int)2e9)
#define INFLL ((LL)2e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (2 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 2, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 1) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 2;
    LL sum = a;
    while(b){
        if(b&2)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

double exp(double a, LL b){
    double res = 1;
    double sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

PII operator+(const PII &a, const PII &b){
    return PII(a.first + b.first, a.second + b.second);
}

vector<vector<int> > xc(100001), yc(100001);

PII func(PII p){
    PII res(0, 0);
    if(!xc[p.first].empty()){
        vector<int> line = xc[p.first];
        xc[p.first].clear();
        ++res.first;
        for(auto &i:line){
            res = res + func(PII(p.first, i));
        }
    }
    if(!yc[p.second].empty()){
        vector<int> line = yc[p.second];
        yc[p.second].clear();
        ++res.second;
        for(auto &i:line){
            res = res + func(PII(i, p.second));
        }
    }
    return res;
}

signed  main(){
    int N;
    cin >> N;
    vector<PII> line(N);
    for(auto &i:line)cin>>i.first>>i.second;
    for(auto &i:line){
        xc[i.first].push_back(i.second);
        yc[i.second].push_back(i.first);
    }
    LL ans = 0;
    for(auto &i:line){
        PII d = func(i);
        ans += (LL) d.first * d.second;
    }
    cout << ans - N << endl;
    return 0;
}



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

int main(){
int H,W,sx,sy,co=0;
  cin >> H >> W;
  
   vector<vector<char>> board(H,vector<char>(W));
  vector<vector<int>> count(H,vector<int>(W,0));
  
  pair<int,int> p; 
  queue <pair <int,int>> q; 
  
  rep(i,H){
    rep(j,W){
      cin >> board.at(i).at(j);
      if(board.at(i).at(j)=='.')
        co++;
    }
  }
  

  sx=0;
  sy=0;
  p=make_pair(0,0);
  
  q.push(p);
  
  count.at(0).at(0)=1;
  
   while(!q.empty()){
  q.pop();
  if(sy+1!=W && board.at(sx).at(sy+1)=='.' && count.at(sx).at(sy+1)==0){
    count.at(sx).at(sy+1)=count.at(sx).at(sy)+1;
    p=make_pair(sx,sy+1);
   // cout << "36" << endl;
    q.push(p);
  }if(sy-1!=-1 && board.at(sx).at(sy-1)=='.' && count.at(sx).at(sy-1)==0){
    count.at(sx).at(sy-1)=count.at(sx).at(sy)+1;
    p=make_pair(sx,sy-1);
   // cout << "41" << endl;
    q.push(p);
  }if(sx-1!=-1 && board.at(sx-1).at(sy)=='.' && count.at(sx-1).at(sy)==0){
    count.at(sx-1).at(sy)=count.at(sx).at(sy)+1;
    p=make_pair(sx-1,sy);
    //cout << "46" << endl;
    q.push(p);
  }if(sx+1!=H && board.at(sx+1).at(sy)=='.' && count.at(sx+1).at(sy)==0){
    count.at(sx+1).at(sy)=count.at(sx).at(sy)+1;
    p=make_pair(sx+1,sy);
   // cout << "51" << endl;
    q.push(p);
  }
  
 if(!q.empty()){
  int a,b;
  tie(a,b)=q.front();
  sx=a;
  sy=b;
 
  }
    
}
  if(count.at(H-1).at(W-1)==0)
    cout << "-1" << endl;
  else
    cout << co-count.at(H-1).at(W-1) << endl;
  
 /* rep(i,H){
    rep(j,W){
      cout << count.at(i).at(j) << ' ';
    }
    cout << endl;
  }*/
}

Measured memory_bytes: 256
S  = str(input())
p1 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '0':
            p1 += 1
    else:
        if S[i] == '1':
            p1 += 1
print(min(p1, len(S) - p1))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> pa(n);
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        pa[i]={b,a};
    }
    sort(pa.begin(),pa.end());
    int time=0;
    bool flag=true;
    for(int i=0;i<n;i++){
        time+=pa[i].second;
        if(time>pa[i].first){
            flag=false;
            break;
        }
    }
    cout<<(flag?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 1792
N=int(input())
if N%7==N and not N%4==0:
  print('No')
elif N%4==0 or N%7==0:
  print('Yes')
else:
  A = 'No'
  while N>7:
    N -= 7
    if N%4==0:
      A = 'Yes'
  print(A)

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

int main(){
  long n, m, l, b[100][100], a[100][100], c[100][100] = {};
  cin >> n >> m >> l;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0; i < m; i++){
    for(int j = 0; j < l; j++){
      cin >> b[i][j];
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      for(int k = 0; k < l; k++){
        c[i][k] += a[i][j] * b[j][k];
      }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < l; j++){
      cout << (j == 0 ? "": " ") << c[i][j];
    }
    cout << endl;
  }
}




Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)

ll mod=998244353;
vector <ll> factorials;
ll modExp(ll x, ll n)
{
    if (n==0) return 1;
    if (n==1) return x%mod;
    ll ans = modExp(x,n/2);
    ans = (ans*ans)%mod;
    if (n%2) ans*=x;
    return ans%mod;
}

ll modInv(ll a)
{
    return modExp(a, mod-2)%mod;
}

ll choose(ll n, ll k)
{
    ll num = factorials[n];
    ll den=(modInv(factorials[n-k])*modInv(factorials[k]))%mod;
    return (num*den)%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N, M, K;
    cin >> N >> M >> K;
    factorials.resize(N+1);
    factorials[0]=1;
    loop(i,1,N+1) factorials[i]=(factorials[i-1]*i)%mod;
    vector <ll> dp(N);
    dp[0]=M;
    for (int i=1; i<N; ++i) {
        dp[i]=(dp[i-1]*(M-1))%mod;
    }
    if (M==1 && K==N-1) {
        cout << 1 << "\n";
        return 0;
    }
    ll sum=0;
    for (ll i=0; i<=K; ++i)
    {
        sum += dp[N-1]*((modExp(modExp(M-1, i)%mod, mod-2)*choose(N-1,i))%mod);
        sum%=mod;
    }
    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 6364
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for (int i=1; i<=n; i++)
using namespace std;
using f=float; using ll=long long; using ld=long double;
using ull=unsigned long long; using vi=vector<int>; using pii=pair<int, int>;

int gcd(int a, int b) {
    if ( b < a ) swap(a, b);
    int t;
    while ( b != 0 ) {
        t = a%b; a = b; b = t;
    }
    return a;
}
int gcd3(int a, int b, int c) {
    int d = gcd(a, b);
    return gcd(d, c);
}
int main() {
//    int a = gcd3(3, 6, 12);
    int n;
    cin >> n;
    ll sum = 0;
    REP(i, n ) {
        REP(j, n) {
            REP(k, n) {
                sum += gcd3(i, j, k);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

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

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

    cout << S.at(0) << S.at(1) << S.at(2) << endl;
    
}

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

class card{
public:
  int v;
  char s;
};
int n;
void sel(vector<card>& a){
  for(int i = 0; i < n; i++){
    int minj = i;
    for(int j = i + 1; j < n; j++){
      if(a[j].v < a[minj].v){
        minj = j;
      }
    }
    if(minj == i) continue;
    card t = a[i];
    a[i] = a[minj];
    a[minj] = t;
  }
  return;
}

void bub(vector<card>& a){
  for(int i = 1; i <= n - 1; i++){
    for(int j = n - 1; j >= i; j--){
      if(a[j].v < a[j - 1].v){
        card t = a[j];
        a[j] = a[j - 1];
        a[j - 1] = t;
      }
    }
  }
  return;
}

void solve(){
  cin >> n;
  vector<card> a(n), b(n);
  for(int i = 0; i < n; i++){
    cin >> a[i].s >> a[i].v;
  }
  b = a;
  bub(b);
  for(int i = 0; i < n - 1; i++){
    cout << b[i].s << b[i].v << " ";
  }
  cout << b[n - 1].s << b[n - 1].v << endl;
  cout << "Stable\n";
  sel(a);
  int flag = 0;
  for(int i = 0; i < n - 1; i++){
    if(a[i].s != b[i].s) flag = 1;
    cout << a[i].s << a[i].v << " ";
  }
  cout << a[n - 1].s << a[n - 1].v << endl;
  if(flag == 0) cout << "Stable\n";
  else cout << "Not stable\n";
  return;
}

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



Measured memory_bytes: 3152
// Problem : A - Not
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
using namespace std;


#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define mem(ar,x) memset(ar,x,sizeof(ar))
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define pb push_back
#define ll long long int
#define ff first
#define ss second
#define mod 1000000007
#define maxn 1000003
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



int main(){
	
	fastio;
	int x;
	cin>>x;
	if(x==1)cout<<"0";
	else cout<<"1";
	
	}


	
	
	
	



Measured memory_bytes: 3640
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		int n,m,count=0,i;
		int a[]=new int[10000];
		int b[]=new int[10000];
		Set<Integer> s=new TreeSet<Integer>();
		Set<Integer> test=new TreeSet<Integer>();
		Scanner sc =new Scanner(System.in);
		n=sc.nextInt();
		m=sc.nextInt();
		
		while(true){
			if(n==0 && m==0)
				break;
			for(i=0;i<m;i++){
				a[i]=sc.nextInt();
				b[i]=sc.nextInt();

				if(a[i]==1){
					count++;
					//System.out.println(a[i]+" "+b[i]);
					s.add(b[i]);
					test.add(b[i]);
				}
			}
			
			//System.out.println(s);
			for(i=0;i<m;i++){
				if(s.contains(a[i]) && !test.contains(b[i]) && a[i]!=1 && b[i]!=1){
					count++;
					//System.out.println(a[i]+" "+b[i]);
					test.add(b[i]);
				}
				else if(!test.contains(a[i]) && s.contains(b[i]) && a[i]!=1 && b[i]!=1){
					//System.out.println(s.contains(a));
					count++;
					//System.out.println(a[i]+" "+b[i]);
					test.add(a[i]);
				}
			}

			System.out.println(count);
			//System.out.println(test);
			n=sc.nextInt();
			m=sc.nextInt();
			s.clear();
			test.clear();
			count=0;
		}//while
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 100005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<lint,lint> pii;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    lint n,m,k,sm=0,a,ans=0;
    cin>>n>>m>>k;
    vector<lint> V;
    vector<lint>::iterator it;
    for(lint i=1;i<=n;i++){
        cin>>a;
        sm+=a;
        V.pb(sm);
    }
    V.pb(inf);
    sm=0;
    it=upper_bound(V.begin(),V.end(),k-sm);
    ans=max(ans,(lint)(it-V.begin()));
    for(lint i=1;i<=m;i++){
        cin>>a;
        sm+=a;
        if(sm>k) break;
        it=upper_bound(V.begin(),V.end(),k-sm);
        ans=max(ans,i+(lint)(it-V.begin()));
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5324
import itertools
import bisect
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a = [0] + list(itertools.accumulate(A))
b = [0] + list(itertools.accumulate(B))

result = 0
for i in range(N + 1):
    if a[i] > K:
        break
    j = bisect.bisect_right(b, K - a[i])
    result = max(result, i + j - 1)
print(result)

Measured memory_bytes: 50692
#include<cstdio>
#include<cmath>

struct Point {double x,y;};

void koch(int n, Point a, Point b){
    if(n==0) return;
    
    Point s,t,u;
    double th = M_PI * 60.0 / 180.0;
    
    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
    
    koch(n-1,a,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1,t,b);
}

int main(){
    Point a, b;
    int n;
    
    scanf("%d",&n);
    
    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;
    
    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
    
    return 0;
}


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

typedef long long ll;

int main() {         
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	int cnt = 0;
	while (n > 0) {
		n -= k;
		if (n <= 0) {
			cnt++;
			break;
		}
		n++;
		cnt++;
	}
	cout << cnt;
}


Measured memory_bytes: 3796
#include<iostream>
using namespace std;
int main()
{
  int n,l;
  cin>>n>>l;
  string s[n];
  string ans="";
  for(int i=0;i<n;i++)
    cin>>s[i];
  
    string check;
  for(int i=0;i<n;i++)
    {
      for(int j=i+1;j<n;j++)
      {
        if(s[i]>s[j])
        {
          check=s[j];
          s[j]=s[i];
          s[i]=check;
        }
      }
    }
  for(int i=0;i<n;i++)
    ans+=s[i];
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
mix = lambda x:list(li() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,h):
    res = 0
    count = 0
    for i in range(n-1):
        if h[i] >= h[i+1]:
            count += 1
        else:
            res = max(res, count)
            count = 0
    print(max(res,count))
        

n = ii()
h = mi()
main(n,h)

Measured memory_bytes: 14480
#include <stdio.h>
int main(void){
    int m, f, r;
    int student[50];
    
    while(1) {
        scanf("%d %d %d\n", &m, &f, &r);
        if(m == -1 && f == -1 && r == -1) break;
        int sum = m + f;
        if (m == -1 || f == -1)  printf("F\n"); 
        else if (sum >= 80) printf("A\n"); 
        else if (sum >= 65 && sum < 80) printf("B\n"); 
        else if (sum >= 50 && sum < 65) printf("C\n"); 
        else if (sum >= 30 && sum < 50) {
            if(r >= 50) printf("C\n");
            else printf("D\n");
            }
        else if (sum < 30) printf("F\n"); 
    }
    return 0;
}


Measured memory_bytes: 2104
"""
https://atcoder.jp/contests/abc139/tasks/abc139_c
"""

import numpy as np


def calc(N: int, H: np.ndarray) -> int:
    return calc_inner(N + 1, np.insert(H, 0, -1))


def calc_inner(N: int, H: np.ndarray) -> int:
    diff = np.diff(H)
    not_movable_mask = diff > 0
    not_movable_index = np.arange(N - 1)[not_movable_mask]
    not_movable_index = np.insert(not_movable_index, len(not_movable_index), N - 1)
    diff_nmi = np.diff(not_movable_index)
    return int(np.max(diff_nmi)) - 1


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    N, = load_input_as_int_array()
    H = load_input_as_int_array()
    result = calc(N, H)
    print(result)


main()


Measured memory_bytes: 23384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ans = 0;

		// 整数の入力
		int n = sc.nextInt();
		int limit_a = sc.nextInt();
		int limit_b = sc.nextInt();
		int target = limit_a;

		while (target <= n) {
			if (inRange(limit_a,limit_b,target)) {
				ans = ans + target;
			}
			target++;
		}

		System.out.println(ans);

		sc.close();
	}

	private static boolean inRange(int limit_a, int limit_b, int target) {
		boolean ret = false;

		String s = String.format("%05d", target);
		int n1 = Integer.parseInt(s.substring(0, 1));
		int n2 = Integer.parseInt(s.substring(1, 2));
		int n3 = Integer.parseInt(s.substring(2, 3));
		int n4 = Integer.parseInt(s.substring(3, 4));
		int n5 = Integer.parseInt(s.substring(4, 5));
		int val = n1 + n2 + n3 + n4 + n5;

		if (val >= limit_a && val <= limit_b) {
			ret = true;
		}

		return ret;
	}
}


Measured memory_bytes: 36048
<?php
$a = 0;
while(!feof(STDIN))
{
  $s = "";
  fscanf(STDIN, "%s", $s);
  if($s == "")
    break;
  $b = true;
  for($i = 0; $i < strlen($s); $i++)
  {
    if($s[$i] != $s[strlen($s) - $i - 1])
      $b = false;
  }
  if($b)
    $a++;
}
echo $a . "\n";

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

int main() {
	cout.precision(16);
	ll n, k;
	cin >> n >> k;
	++n;
	vector<ll> p(n);
	for (ll i = 1; i < n; ++i)cin >> p[i];
	for (ll i = 1; i < n; ++i)p[i] += p[i - 1];
	ll ans = 0;
	for (ll i = k; i < n; ++i) {
		ans = max(ans, p[i] - p[i - k]);
	}
	cout << (ans + k) / 2. << endl;
}


Measured memory_bytes: 1792
N = int(input())
S = []
for i in range(N):
    xi, li = map(int, input().split())
    S.append([xi - li, xi + li])

from operator import itemgetter
S = sorted(S, key=itemgetter(1))

ans = 0
last = -1*float('Inf')
for si in S:
    if si[0] >= last:
        ans += 1
        last = si[1]

print(ans)

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

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 2e5;
const num inf = 0x3f3f3f3f3f3f3f3f;
int n;
num d, a[nsz + 5], w1[nsz + 5], w2[nsz + 5];

struct segmnet_tree {
	#define ls  (u << 1)
	#define rs  (u << 1 | 1)
	
	pair<num, int> tr[4 * nsz + 5];
	
	void inline init(num a[], int u = 1, int l = 1, int r = n) {
		if (l == r)  { tr[u] = make_pair(a[l], l); return; }
		int md = (l + r) >> 1;
		init(a, ls, l, md);
		init(a, rs, md + 1, r);
		tr[u] = min(tr[ls], tr[rs]);
	}
	
	void set(int id, num w, int u = 1, int l = 1, int r = n) {
		if (l == r) { tr[u].first = w; return; }
		int md = (l + r) >> 1;
		id <= md ? set(id, w, ls, l, md) : set(id, w, rs, md + 1, r);
		tr[u] = min(tr[ls], tr[rs]);
	}
	
	pair<num, int> qry(int el, int er, int u = 1, int l = 1, int r = n) {
		if (l >= el && r <= er)  return tr[u];
		int md = (l + r) >> 1;
		pair<num, int> res = make_pair(inf, 0);
		if (el <= md)  res = min(res, qry(el, er, ls, l, md));
		if (er > md)  res = min(res, qry(el, er, rs, md + 1, r));
		return res;
	}
};
segmnet_tree tr1, tr2;

struct union_find {
	int sz, pr[nsz + 5];
	vector<int> s[nsz + 5];
	
	int inline operator [] (int id) { return pr[id]; }
	
	void inline init(int sz = n) {
		this->sz = sz;
		cont (u, sz) {
			pr[u] = u;
			s[u].push_back(u);
		}
	}
	
	int qry(int u) { return pr[u]; }
	
	bool inline link(int u, int v) {
		int pu = qry(u), pv = qry(v);
		if (pu == pv)  return 0;
		if (s[pu].size() < s[pv].size())  swap(pu, pv);
		loop (i, s[pv].size()) {
			int v = s[pv][i];
			s[pu].push_back(v);
			pr[v] = pu;
		}
		return 1;
	}
};
union_find uf;

num inline w(int u, int v) {
	if (u < v)  swap(u, v);
	return w1[u] + w2[v];
}

num inline boruvka() {
	uf.init();
	tr1.init(w1);
	tr2.init(w2);
	num res = 0;
	for (int cnt = n; cnt > 1;) {
		vector< pair<int, int> > e;
		cont (u, n) {
			if (uf[u] != u)  continue;
			int su = 0, sv = 0;
			num cur = inf;
			loop (i, uf.s[u].size()) {
				int v = uf.s[u][i];
				tr1.set(v, inf), tr2.set(v, inf);
			}
			loop (i, uf.s[u].size()) {
				int v1 = uf.s[u][i], v2 = tr2.qry(1, v1).second, v3 = tr1.qry(v1, n).second;
				if (v2 && w(v1, v2) < cur)  cur = w(v1, v2), su = v1, sv = v2;
				if (v3 && w(v1, v3) < cur)  cur = w(v1, v3), su = v1, sv = v3;
			}
			loop (i, uf.s[u].size()) {
				int v = uf.s[u][i];
				tr1.set(v, w1[v]), tr2.set(v, w2[v]);
			}
			e.push_back(make_pair(su, sv));
		}
		loop (i, e.size()) {
			int u = e[i].first, v = e[i].second;
			if (!uf.link(u, v))  continue;
			res += w(u, v);
			--cnt;
		}
	}
	return res;
}

int main() {
	scanf("%d%lld", &n, &d);
	cont (i, n) {
		scanf("%lld", &a[i]);
		w1[i] = a[i] + i * d;
		w2[i] = a[i] - i * d;
	}
	printf("%lld\n", boruvka());
}

Measured memory_bytes: 46944
import java.io.*;
import java.util.*;


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        int m=sc.nextInt();
        int[]a=new int[m],del=new int[m];
        int e=0,o=m;
        for(int i=0;i<m;++i)a[i]=sc.nextInt();
        for(int i=0;i<m;++i){
            if(a[i]%2==0)del[e++]=a[i];
            else del[--o]=a[i];
        }
        if(o<m-2){
            out.println("Impossible");
            out.close();
            return;
        }
        int[]b;
        if(o==m){
            b=new int[m+1];
            b[0]=a[0]-1;
            for(int i=1;i<m;++i)b[i]=a[i];
            b[m]=1;
        }else if(o==m-1){
            System.arraycopy(del,0,a,0,m);
            b=new int[a[m-1]==1?m:m+1];
            b[0]=1;
            for(int i=0;i<m-1;++i)
                b[i+1]=a[i];
            if(a[m-1]!=1)
                b[m]=a[m-1]-1;
        }else{
            a[0]=del[m-2];
            a[m-1]=del[m-1];
            for(int i=0;i<m-2;++i)a[i+1]=del[i];
            b=new int[a[m-1]==1?m-1:m];
            b[0]=a[0]+1;
            for(int i=1;i<m-1;++i)
                b[i]=a[i];
            if(a[m-1]!=1)
                b[m-1]=a[m-1]-1;
        }
        for(int i=0;i<m;++i)
            out.print(a[i]+(i==m-1?"\n":" "));
        out.println(b.length);
        for(int i=0;i<b.length;++i)
            out.print(b[i]+(i==b.length-1?"\n":" "));
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

int main() {
  int n, k;
  cin >> n >> k;

  double ans = 0;
  for (int i = 1; i <= n; i++) {
    double p = 1.0 / n;
    int point = i;
    while (point < k) {
      p /= 2;
      point *= 2;
    }
    ans += p;
  }

  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n,K;
vector<int> g[100005];
int ar[100005];
pi dfs(int v,int p){//(dep,cost)
  pi res=mp(0,0);
  for(auto to:g[v]){
    if(to==p) continue;
    pi nxt=dfs(to,v);
    res.sc+=nxt.sc;
    chmax(res.fr,nxt.fr+1);
  }
  if(res.fr==K-1 && ar[v]>0){
    ++res.sc;
    res.fr=-1;
  }
  return res;
}


int main(){
  cin>>n>>K;
  int res=0;
  REP(i,n){
    int a;scanf("%d",&a);
    --a;
    if(i==0){
      if(a) ++res,a=0;
    }else{
      g[a].pb(i);
      g[i].pb(a);
    }
    ar[i]=a;
  }
  pi rec=dfs(0,-1);
  cout<<res+rec.sc<<endl;
  return 0;
}





Measured memory_bytes: 13952
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    s=SI()
    n=len(s)
    dict_=defaultdict(lambda:0)
    for i in range(n):
        dict_[s[i]]+=1
    ans=1+(n*(n-1))//2
    for x in dict_.keys():
        ans-=(dict_[x]*(dict_[x]-1))//2
    print(ans)
        
            
            
            
            
        
    
    
    
    



if __name__=="__main__":
    main()


Measured memory_bytes: 68564
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;

class Program
{
    static void Main(string[] args)
    {   
        var N = long.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(double.Parse).ToArray();
      
        double sum = 0;
        for(int i = 0; i < N ;i++){
          sum += 1/A[i];
        }

        Console.WriteLine(1/sum);
      
    }

}


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


int main() {
  int n , t , a ;
  cin >> n >> t >> a ;
  
  vector<double> x(n);
  vector<double> y(n);
  vector<double> z(n);
  
  for(int i=0 ; i<n ; i++){
    cin >> x.at(i);
    y.at(i)=t-x.at(i)*0.006;
    z.at(i)=abs(a-y.at(i));
    
  }
  
  sort(z.begin(),z.end());
  
  for(int i=0 ; i < n ; i++){
    if(y.at(i)==a-z.at(0)||y.at(i)==z.at(0)+a){
      cout << i+1 << endl ;
      break ;
    }
  }
}

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

struct day
{
  int kind[4];
  int order;
  int sum;
};

int n, k;
int a[100], b[100];
day dp[101];

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

  for(int i = 0; i < k; i++)
    dp[a[i]].order = b[i];

  //day 1
  if(dp[1].order)
    dp[1].sum = dp[1].kind[dp[1].order] = 1;
  else
    for(int i = 1; i <= 3; i++)
      dp[1].sum += dp[1].kind[i] = 1;

  //day 2
  if(dp[2].order)
    dp[2].sum = dp[2].kind[dp[2].order] = dp[1].sum;
  else
    for(int i = 1; i <= 3; i++)
      dp[2].sum += dp[2].kind[i] = dp[1].sum;

  //day 3
  for(int i = 3; i <= n; i++){
    if(dp[i].order){
      if(!dp[i - 1].kind[dp[i].order])
	dp[i].sum = dp[i].kind[dp[i].order] = dp[i - 1].sum;
      else
	dp[i].sum = dp[i].kind[dp[i].order] = dp[i - 1].sum - dp[i - 1].kind[dp[i].order] + dp[i - 2].sum - dp[i - 2].kind[dp[i].order];
    }
    else{
      for(int j = 1; j <= 3; j++){
	
	if(!dp[i - 1].kind[j])
	  dp[i].sum += dp[i].kind[j] = dp[i - 1].sum;
	else
	  dp[i].sum += dp[i].kind[j] = dp[i - 1].sum - dp[i - 1].kind[j] + dp[i - 2].sum - dp[i - 2].kind[j];
      }

      dp[i].sum = dp[i].sum % 10000;
    }
  }

  cout << (dp[n].sum % 10000 + 10000) % 10000 << endl;
  return 0;
}

Measured memory_bytes: 1164
N = int(input())
A = list(map(int, input().split()))

ans = 0

oans, eans = 0, 0
oacum, eacum = 0, 0
acum = 0

for i in range(0, N):
    oacum += A[i]
    eacum += A[i]

    if i & 1:
        # should be neg
        if oacum >= 0:
            oans += abs(oacum) + 1
            oacum = -1
        

        # should be pos
        if eacum <= 0:
            eans += abs(eacum) + 1
            eacum = 1

    else:
        # should be pos
        if oacum <= 0:
            oans += abs(oacum) + 1
            oacum = 1
        

        # should be neg
        if eacum >= 0:
            eans += abs(eacum) + 1
            eacum = -1

print(min(oans, eans))


Measured memory_bytes: 14468
import java.util.Scanner;

// https://atcoder.jp/contests/abc143/tasks/abc143_a

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

        System.out.println(Math.max(0, a - b * 2));
    }
}

Measured memory_bytes: 21844
import collections
import bisect

n,m=map(int,input().split())
a=collections.defaultdict(list)
p=[[int(j) for j in input().split()] for i in range(m)]
for x,y in sorted(p):
  a[x]+=[y]
for x,y in p:
  z=bisect.bisect(a[x],y)
  print("%06d%06d"%(x,z))

Measured memory_bytes: 41012
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

struct Node {
  int key;
  Node *prev, *next;
};

Node* nil;

void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void insert(int key) {
  Node* x = (Node *)malloc(sizeof(Node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

Node* listSearch(int key) {
  Node* cur = nil->next;
  while (cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void deleteNode(Node* t) {
  if (t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst() {
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void printList() {
  Node* cur = nil->next;
  while (cur != nil) {
    cout << cur->key << ((cur->next != nil)? " " : "\n");
    cur = cur->next;
  }
}

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

  while (n--) {
    char command[10];
    int val;
    if (scanf("%s %d", command, &val) == EOF) {
      scanf("%s", command);
    }
    if (!strcmp(command, "insert")) {
      insert(val);
    } else if (!strcmp(command, "delete")) {
      deleteKey(val);
    } else if (!strcmp(command, "deleteFirst")) {
      deleteFirst();
    } else {
      deleteLast();
    }
  }

  printList();
}



Measured memory_bytes: 34404
#include <bits/stdc++.h>
#include <atcoder/scc>

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

template <typename T, typename U>
bool chmin(T &a, const U &b){
  return (a > b ? a = b, true : false);
}

template <typename T, typename U>
bool chmax(T &a, const U &b){
  return (a < b ? a = b, true : false);
}

template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v){
  std::fill((U*)a, (U*)(a + N), v);
}

template <typename T, size_t N, size_t I = N>
auto make_vector(const std::array<int, N> &a, T value = T()){
  static_assert(I >= 1);
  static_assert(N >= 1);
  if constexpr (I == 1){
    return std::vector<T>(a[N - I], value);
  }else{
    return std::vector(a[N - I], make_vector<T, N, I - 1>(a, value));
  }
}

template <typename T>
std::ostream& operator<<(std::ostream &s, const std::vector<T> &a){
  for(auto it = a.begin(); it != a.end(); ++it){
    if(it != a.begin()) s << " ";
    s << *it;
  }
  return s;
}

template <typename T>
std::istream& operator>>(std::istream &s, std::vector<T> &a){
  for(auto &x : a) s >> x;
  return s;
}



namespace solver {
  namespace ac = atcoder;

  void init(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(12);
    std::cerr << std::fixed << std::setprecision(12);
    std::cin.exceptions(std::ios_base::failbit);
  }

  void solve(){
    int N, M; std::cin >> N >> M;

    auto g = ac::scc_graph(N);
    for(int i = 0; i < M; ++i){
      int a, b; std::cin >> a >> b;
      g.add_edge(a, b);
    }

    auto res = g.scc();

    std::cout << res.size() << "\n";
    for(auto v : res){
      std::cout << v.size() << " " << v << "\n";
    }
  }
}

int main(){
  solver::init();
  while(true){
    try{
      solver::solve();
    }catch(const std::istream::failure &e){
      break;
    }
  }
  return 0;
}


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


void solve(){
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int dp[n];
    for(int i=0;i<n;i++)dp[i]=INT_MAX;
    dp[0] = 0;
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i-j>=0){
                dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
            }
        }
    }
    cout<<dp[n-1];
}



int main(){
  solve();
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const ll LINF=1e18;
const int MOD=1e9+7;
//const int MOD=998244353;

int n,k;
int b[1001][1001][2];
int main(){
	cin>>n>>k;
	FOR(i,0,n){
		int x,y;
		char c;
		cin>>x>>y>>c;
		x%=(2*k);
		y%=(2*k);
		int d=(c=='B'?1:0);
		if(x>=k&&y>=k){
			x-=k;
			y-=k;
		}else if(x<k&&y>=k){
			y-=k;
			d=1-d;
		}else if(x>=k&&y<k){
			x-=k;
			d=1-d;
		}
		b[x+1][y+1][d]++;
	}
	FOR(i,1,k+1)FOR(j,0,k+1)b[i][j][0]+=b[i-1][j][0];
	FOR(j,1,k+1)FOR(i,0,k+1)b[i][j][0]+=b[i][j-1][0];
	FOR(i,1,k+1)FOR(j,0,k+1)b[i][j][1]+=b[i-1][j][1];
	FOR(j,1,k+1)FOR(i,0,k+1)b[i][j][1]+=b[i][j-1][1];

	int ans=-INF;
	int koho;
	FOR(i,0,k+1){
		FOR(j,0,k+1){
			koho=b[k][k][0]-b[i][k][0]-b[k][j][0]+2*b[i][j][0];
			koho+=b[i][k][1]+b[k][j][1]-2*b[i][j][1];
			ans=max(koho,ans);
			koho=b[k][k][1]-b[i][k][1]-b[k][j][1]+2*b[i][j][1];
			koho+=b[i][k][0]+b[k][j][0]-2*b[i][j][0];
			ans=max(koho,ans);
		}
	}
	co(ans);
}


Measured memory_bytes: 8064