akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main() {
  int n, a, i, ans = 0;
  scanf("%d", &n);
  
  for(i = 0; i < n; i++) {
    scanf("%d", &a);
  	if ((i+1)%2 != 0 && a%2 != 0)
      ans++;
  }
  
  printf("%d", ans);
  return (0);
}

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

int N,a,b;
vector<int> h(100090),rec(100090);

int dp(int n){
  if(n==1){return 0;}
  else if(n==2){return abs(h[1]-h[2]);}
  else{
    if(rec[n-1]==-1){rec[n-1]=dp(n-1);}
    if(rec[n-2]==-1){rec[n-2]=dp(n-2);}
    return min(rec[n-1]+abs(h[n]-h[n-1]),rec[n-2]+abs(h[n]-h[n-2]));
  }
}

int main(){
  cin >> N;
  for(int i=1;i<=N;i++){cin >> h[i];}
  for(int i=1;i<=N;i++){rec[i]=-1;}
  cout << dp(N) << endl;
}

Measured memory_bytes: 5760
"""https://atcoder.jp/contests/exawizards2019/submissions/4769434
左右どちらから消滅するか確認が必要だと気づかされた"""


def get_pos(index):
    """初期位置indexのロボットのクエリ後の配置を返す
    is_whick_sideの返り値として返す"""
    iws = -1 if index == -1 else 1 if index == N else 0
    if iws != 0:
        return iws
    for t, d in e:
        if t == s[index]:
            if d == 'R':
                index += 1
            else:
                index -= 1
        iws = -1 if index == -1 else 1 if index == N else 0
        if iws != 0:
            return iws
    return 0


N, Q = map(int, input().split())
s = input()

e = [input().split() for _ in range(Q)]
# t: 文字 <- siと比較
# d: 'L', 'R'

# right
left = -1
right = N
while right - left > 1:
    mid = (left + right) // 2
    if get_pos(mid) == 1:
        # 右消滅
        right = mid
    else:
        left = mid
ar = right
# 右消滅開始位置

# left
left = -1
right = N
while right - left > 1:
    mid = (left + right) // 2
    if get_pos(mid) == -1:
        left = mid
    else:
        right = mid
al = left
# 左消滅開始位置
# (al, ar) = 残存区間

print((ar - 1) - (al + 1) + 1)


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

int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  cout << (c%gcd(a, b)==0 ? "YES": "NO") << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,n;
	char c,d;
	scanf("%d",&n);
	c='T';
	for(i=0;i<n;i++)	{
		scanf(" %c",&d);
		if(c=='T' && d=='T')	c='T';
		else if(c=='T' && d=='F')	c='F';
		else if(c=='F' && d=='T')	c='T';
		else c='T';
	}
	printf("%c\n",c);
	return 0;
}


Measured memory_bytes: 2764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
using namespace std;
using ll = long long;
void self_max(int &a,int b){
  a = max(a,b);
}

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

  cout << min(a*b,c) << endl;
  return 0;
}


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

int main()
{
    int k,x; cin >> k >> x;
    std::vector<int> ans;
    

    for(int i=x; i<=1000000&& i<x+k;i++){
    	ans.push_back(i);
    }

    for(int i=x-1;i >= -1000000 && i>x-k;i-- ){
    	ans.push_back(i);
    }

    sort(ans.begin(),ans.end());

    for(int a: ans){
    	cout << a << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long f(long long k){
	return (k*(k-1))/2;
}
int main(){
  long long n;
  long long now=0;
  cin>>n;
  vector<long long> p(n,0);
  long long a[n];
  for(int i=0;i<n;i++){
  	cin>>a[i];
    a[i]--;
    p[a[i]]++;
  }
  for(int i=0;i<n;i++){
  	now+=f(p[i]);
  }
  for(int i=0;i<n;i++){
  	long long k=now;
    k=k-f(p[a[i]])+f(p[a[i]]-1);
    cout<<k<<endl;
  }
}


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

namespace ABiscuitGenerator
{
    class Program
    {
        private string Read()
        {
            return Console.ReadLine();
        }
        private int[] ReadIntArray()
        {
            return Read().Split().Select(int.Parse).ToArray();
        }

        private void S()
        {
            var abt = ReadIntArray();

            var ans = abt[2] / abt[0] * abt[1] + 0.5;
            
            Console.WriteLine(Math.Floor(ans));

        }
        static void Main(string[] args)
        {
            new Program().S();
        }
    }
}


Measured memory_bytes: 13268
#coding:utf-8
                
def BFS(i,A,d,dist):
    dist[i]=d
    for point in A[i]:
        if dist[point-1]==-1 or dist[point-1]>d+1:
            BFS(point-1,A,d+1,dist)

if __name__=="__main__":
    n=int(input())
    A=[]
    for i in range(n):
        A.append(list(map(int,input().split(" ")))[2:])
    dist=[-1]*n
    BFS(0,A,0,dist)

    for i in range(n):
        print("{} {}".format(i+1,dist[i]))

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  int dp = INF;
  
  for(int p = 1;p<=100;p++){
    int sum = 0;
    for(int i=0;i<n;i++){
      sum+=(x[i]-p)*(x[i]-p);
    }
    if(sum<=dp) dp = sum;
  }  

  cout << dp << endl;
  
  return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#endif
using namespace std;

struct Card {
  Card(const string& s) : symbol(s[0]), value(s[1] - '0') {}
  char symbol;
  uint8_t value;
};

ostream& operator<<(ostream& s, const Card& card) {
  return s << card.symbol << static_cast<int>(card.value);
}

bool operator==(const Card& rhs, const Card& lhs) {
  return rhs.value == lhs.value && rhs.symbol == lhs.symbol;
}

namespace std {
template <>
struct less<Card> {
  bool operator()(const Card& lhs, const Card& rhs) {
    return lhs.value < rhs.value;
  }
};

template <>
struct greater<Card> {
  bool operator()(const Card& lhs, const Card& rhs) {
    return lhs.value > rhs.value;
  }
};
}

template <typename T>
void Print(T t) {
  for (auto it = t.begin(); it != t.end(); ++it) {
    cout << *it;
    if (next(it) != t.end()) {
      cout << " ";
    }
  }
  cout << endl;
}

template <typename T>
T BubbleSort(T t) {
  auto cmp = greater<typename T::value_type>();
  for (auto it = t.begin(); it != t.end(); ++it) {
    for (auto it2 = prev(t.end()); distance(it, it2) > 0; --it2) {
      auto prev_ = prev(it2);
      if (cmp(*prev_, *it2)) {
        iter_swap(prev_, it2);
      }
    }
  }
  return move(t);
}

template <typename T>
T SelectionSort(T t) {
  for (auto it = t.begin(); distance(it, t.end()) != 1; ++it) {
    iter_swap(it, min_element(it, t.end(), less<typename T::value_type>()));
  }
  return move(t);
}

bool IsStable(const vector<Card>& cards, const vector<Card>& sorted) {
  for (auto it = sorted.begin() + 1; it != sorted.end(); ++it) {
    auto prev_ = prev(it);
    if (it->value == prev_->value &&
        0 > distance(find(cards.begin(), cards.end(), *prev_),
                     find(cards.begin(), cards.end(), *it))) {
      return false;
    }
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  vector<Card> cards;
  string buf;
  for (int i = 0; i < n; ++i) {
    cin >> buf;
    cards.emplace_back(buf);
  }
  auto bub = BubbleSort(cards);
  auto bub_stable = IsStable(cards, bub);
  Print(bub);
  cout << (bub_stable ? "Stable" : "Not stable") << endl;
  auto sel = SelectionSort(cards);
  auto sel_stable = IsStable(cards, sel);
  Print(sel);
  cout << (sel_stable ? "Stable" : "Not stable") << endl;
}

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

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  if((b-a)%2 == 0) cout << (b-a)/2 << endl;
  else{
    ll ans;
    if(a-1 <= n-b){
      ans = (a-1)+1+(b-a)/2;
    }
    else ans = (n-b)+1+(n-(a+n-b+1))/2;
    cout << ans << endl;
  }
}


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

int a,b,c,d;

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

Measured memory_bytes: 256
c = list(map(int,open(0).read().split()))
a = all([c[i]-c[i+1] == c[i+3]-c[i+4] for i in [0,1,3,4]])
b = all([c[i]-c[i+3] == c[i+1]-c[i+4] for i in [0,1,3,4]])
if a and b:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define lld long double
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	string s;
	cin>>s;

	lli ans=0;
	REP(i,1,s.size()/2){
		if(s.substr(0,i) == s.substr(i,i)){
			ans = 2*i;
		}
	}

	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 256
/*
 * Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$
**/

#include <bits/stdc++.h>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <cmath>

using namespace std;

//typedef
typedef string STR;
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef priority_queue<int> PQI;
typedef vector<LL> VLL;
typedef vector<ULL> VULL;
typedef vector<STR> VS;
typedef vector<char> VC;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<STR,int> PSI;
typedef pair<int,STR> PIS;
typedef vector<PII> VII;
typedef map<int,int> MII;
typedef map<LL,LL> MLL;
typedef map<STR,int> MSI;
typedef map<char,int> MCI;
typedef map<int,STR> MIS;
typedef set<STR> SS;
typedef set<int> SI;
typedef set<LL> SLL;

//symbolic const
#define MOD 1000000007
#define MAXN 1e9
#define SIZE 10000

//STL keywords
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
#define all(v) v.begin(), v.end()

//functions
#define dec(n) cout<<fixed<<setprecision(n);
#define f(i, n)   for(LL i=0; i<n; i++)
#define fa(i,a,n) for(LL i=a; i<n; i++)

//IO
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test int t;cin>>t;while(t--){solve();}

LL maxLL(LL a, LL b){return (a>b?a:b);}
LL minLL(LL a, LL b){return (a<b?a:b);}

void solve() {
 LL n, k; cin>>n>>k;
 VLL h(n); f(i, n) cin>>h[i];
 VLL dp(n, MAXN);
 dp[0]=0;
 //dp[1]=llabs(h[1]-h[0]);
 for(LL i=1; i<n; i++){
     for(LL j=1; j<=k && (i-j)>=0; j++)
       dp[i]=minLL(dp[i-j]+llabs(h[i-j]-h[i]), dp[i]);
 }
 cout<<dp[n-1];
}

int main() {
    sync;
    //test;
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {
    double w;
    while (cin >> w) {
        if (w > 91) {
            cout << "heavy" << endl;
        }
        else if (w > 81) {
            cout << "light heavy" << endl;
        }
        else if (w > 75) {
            cout << "middle" << endl;
        }
        else if (w > 69) {
            cout << "light middle" << endl;
        }
        else if (w > 64) {
            cout << "welter" << endl;
        }
        else if (w > 60) {
            cout << "light welter" << endl;
        }
        else if (w > 57) {
            cout << "light" << endl;
        }
        else if (w > 54) {
            cout << "feather" << endl;
        }
        else if (w > 51) {
            cout << "bantam" << endl;
        }
        else if (w > 48) {
            cout << "fly" << endl;
        }
        else {
            cout << "light fly" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1220
//break_the_bond
//jatt_james_bond
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
#define MAX 1000000009
#define IOS std::ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
bool comp(pair<int, int> &a, pair<int, int> &b)
{
    return a.first < b.first;
}

void solve()
{
    int n;
    cin >> n;
    int arr[n];

    for (int i = 0; i < n; ++i)
    {
        cin >> arr[i];
    }
    int lt = arr[0], sum{0};
    for (int i = 1; i < n; ++i)
    {
        // cout << "bun\n";
        if (arr[i] < lt)
        {
            sum += (lt - arr[i]);
            arr[i] = arr[i]+  (lt - arr[i]);
            
            // cout << " i = "<<i << "  arr[ "<< arr[i] << "lt --= "<<lt<<endl;
        }
        lt = arr[i];
    }

    cout << sum;
}
int32_t main()
{

    // cout << (-11 / -4);

    IOS int testcases = 1;
    // cin >> testcases;
    while (testcases--)
    {
        solve();
    }
    return 0;
}

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

const int INF = (int)1e9;
const int MAX_A = 100000 + 10;
int N;
vector<int> A;

int main(void) {
	int min_a, max_a;

	cin >> N;
	A.resize(MAX_A, 0);
	min_a = INF;
	max_a = -1;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		++A[a];
		if (a < min_a) min_a = a;
		if (a > max_a) max_a = a;
	}

	int ans = 0;
	for (int i = min_a; i <= max_a; ++i) {
		int sum = 0;
		if (i != 0)
			sum += A[i - 1];
		sum += A[i] + A[i + 1];
		if (sum > ans)
			ans = sum;
	}

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    ll w, h, x, y; cin >> w >> h >> x >> y;
    cout << fixed << setprecision(14);
    cout << 1.0 * w * h / 2.0 << " ";

    if (x * 2 == w && y * 2 == h) {
        cout << "1";
    } else {
        cout << "0";
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
s = input().split('T')
dx = list(map(len, s[0::2]))
dy = list(map(len, s[1::2]))
x, y = map(int, input().split())

def check(start, ds, goal):
    cands = {start}
    for d in ds:
        new_cands = set()
        for c in cands:
            new_cands.add(c - d)
            new_cands.add(c + d)
        cands = new_cands
    return goal in cands

x_ok = check(dx[0], dx[1:], x)
y_ok = check(0, dy, y)

print('Yes' if x_ok and y_ok else 'No')


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

const ll mod = 1e9+7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> A(N), B(M);
    map<ll, int> ma, mb;
    bool ok = true;
    rep(i, N) {
        cin >> A[i];
        ma[A[i]]++;
        if (ma[A[i]]>1) ok = false;
    }
    rep(i, M) {
        cin >> B[i];
        mb[B[i]]++;
        if (mb[B[i]]>1) ok = false;
    }
    if (!ok) {
        cout << "0" << endl;
        return 0;
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    ll ans = 1;
    int a = 0, b = 0;
    for (ll num=N*M; num>=1; --num) {
        if (ma.count(num) and mb.count(num)) ans *= 1LL;
        else if (ma.count(num) and !mb.count(num)) {
            ll m = M - (lower_bound(B.begin(), B.end(), num) - B.begin());
            ans *= m;
            ans %= mod;
        }
        else if (!ma.count(num) and mb.count(num)) {
            ll n = N - (lower_bound(A.begin(), A.end(), num) - A.begin());
            ans *= n;
            ans %= mod;
        }
        else {
            ll m = M - (lower_bound(B.begin(), B.end(), num) - B.begin());
            ll n = N - (lower_bound(A.begin(), A.end(), num) - A.begin());
            ll tmp = (n*m)%mod;
            tmp -= N*M-num;
            tmp %= mod;
            ans *= tmp;
            ans %= mod;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
main(){int n,m,i,a,c[1000001];for(std::string s;std::cin>>n>>m>>s,n;printf("%d\n",a))for(a=0,i=m;--i;a+=c[i]>=n)c[i]=s.substr(i,3)=="IOI"?c[i+2]+1:0;}

Measured memory_bytes: 5872
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vii a(n);
    deque<int> b;
    rep(i, 0, n) {
        int a;
        cin >> a;
        if (i%2 == n%2) b.pb(a);
        else b.push_front(a);
    }
    rep(i, 0, n) {
        cout << b[i] << (i != n - 1 ? " " : "\n");
    }
    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

 
int main() {

    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;

    if(s[k-1]=='A') s[k-1]='a';
    if(s[k-1]=='B') s[k-1]='b';
    if(s[k-1]=='C') s[k-1]='c';

    cout<<s<<endl;

 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int sgn(int x) { return x < 0 ? -1 : x == 0 ? 0 : 1; }
int divup(int x, int y) { return (x + y - 1) / y; }
vector<pair<int, int>> route(int K, const vector<pair<int, int>> &A) {
    vector<pair<int, int>> ans;
    int x = A[0].first, y = A[0].second, rest = K;
    for (int i = 1; i < A.size(); i++) {
        while (x != A[i].first || y != A[i].second) {
            int t = min(rest, abs(A[i].first - x) + abs(A[i].second - y));
            x += sgn(A[i].first - x) * t;
            y += sgn(A[i].second - y) * t;
            rest -= t;
            if (rest == 0) ans.emplace_back(x, y), rest = K;
        }
    }
    return ans;
}
vector<pair<int, int>> solve(int K, int X, int Y) {
    if (K % 2 == 0 && (X + Y) % 2) return {};
    int s;
    if (X + Y < K && (X + Y) % 2 == 0) {
        s = 2;
    } else {
        s = divup(X + Y, K);
    }
    if ((s * K - X - Y) % 2) s++;
    int a = (s * K - X - Y) / 2;
    if (a == 0 || K <= a + X) {
        return route(K, {{0, 0}, {0, -a}, {X, -a}, {X, Y}});
    } else if (K % 2 == 0 && K <= a + Y + K/2) {
        return route(K, {{0, 0}, {0, -a}, {X+K/2, -a}, {X+K/2, Y}, {X, Y}});
    } else {
        return route(K, {{0, 0}, {0, -a}, {X+K, -a}, {X+K, Y}, {X, Y}});
    }
}
vector<pair<int, int>> solve2(int K, int X, int Y) {
    if (X < 0) {
        auto ans = solve2(K, -X, Y);
        for (auto &a : ans) a.first *= -1;
        return ans;
    }
    if (Y < 0) {
        auto ans = solve2(K, X, -Y);
        for (auto &a : ans) a.second *= -1;
        return ans;
    }
    if (X < Y) {
        auto ans = solve2(K, Y, X);
        for (auto &a : ans) swap(a.first, a.second);
        return ans;
    }
    return solve(K, X, Y);
}
int main() {
    int K, X, Y;
    cin >> K >> X >> Y;
    auto ans = solve2(K, X, Y);
    if (ans.empty()) {
        cout << -1 << '\n';
    } else {
        cout << ans.size() << '\n';
        for (auto &a : ans) cout << a.first << ' ' << a.second << '\n';
    }
    return 0;
}


Measured memory_bytes: 3952
import sys

inf = float('inf')

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def prim(n, As):
    checked = [False] * n
    d = [inf] * n
    checked[0] = True
    d[0] = 0
    nxt = 0
    tot_wgt = 0

    for i in range(n - 1):
        for j in range(n):
            if As[nxt][j] < d[j]:
                d[j] = As[nxt][j]

        min_w = inf
        min_n = 0
        for j in range(n):
            if not checked[j] and min_w > d[j]:
                min_w = d[j]
                min_n = j

        tot_wgt += min_w
        nxt = min_n
        checked[nxt] = True

    return tot_wgt

def solve():
    n = int(input())
    As = []

    for i in range(n):
        line = [int(j) for j in input().split()]
        As.append([i if i != -1 else inf for i in line])

    ans = prim(n, As)

    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 7804
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	cout << min( N, K ) * X + max( N - K, 0 ) * Y << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	long int n, m;
	cin >> n >> m;
	int a;
	a = m * 2 + 1;
	if (n % a==0)
	{
		cout << n / a;
	}
	else
	{
		cout << n / a + 1;
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n,m,dp[10][10],a,b,ans;
ll f(void){
    ll cnt=0;
    for(int i=0;i<n;i++){
        ll w=0,l=0;
        for(int j=0;j<n;j++){
            if(i==j)continue;
            if(dp[i][j]==1)w++;
            if(dp[i][j]==-1)l++;
            if(dp[i][j]==0)cnt++;
        }
        if(n/2<l||n/2<w)return 0;
    }
    if(cnt==0)return 2;
    return 1;
}
void dfs(void){
    //cout<<f()<<endl;
    if(f()==0)return ;
    if(f()==2){
        ans++;
        /*
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cout<<dp[i][j];
            }
            cout<<endl;
        }
        */
        return ;
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<i;j++){
            if(i!=j&&dp[i][j]==0){
                dp[i][j]=1;
                dp[j][i]=-1;
                dfs();
                dp[i][j]=-1;
                dp[j][i]=1;
                dfs();
                dp[i][j]=0;
                dp[j][i]=0;
                return ;
            }
        }
    }
}
int main(void){
    while(1){
        ans=0;
        cin>>n;
        if(n==0)return 0;
        cin>>m;
        for(int i=0;i<m;i++){
            cin>>a>>b;
            a--,b--;
            dp[a][b]=1;
            dp[b][a]=-1;
        }
        dfs();
        cout<<ans<<endl;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dp[i][j]=0;
            }
        }
    }
}



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

using namespace std;
long long mod = 1000000000+7;
  long long  pow(long long  a, long long  b, long long m)
 {
        stack<int>k;
        int j = 128;
        int l = 1;
       int an = 1;
        while(b){
            if(b>=j){
                k.push(j);
                b-=j;
            }
            j/=2;
        }
        while(!k.empty()){
            if(k.top()==l){
                an = (an*a)%mod;
                k.pop();
            }
            a = (a*a)%mod;
            l*=2;
        }

        return an;
 }

    int bi (long long k,long long n,long long a,long long b){
        int index = -1;
        int l = 0;
        int r = n;
         int mid;
        while(l<=r){
                mid = l+(r-l)/2;
            if(k-(mid*a)>(n-mid)*b){
                    index = mid;
            l = mid+1;
            }
            else {
                r = mid-1;
            }

        }
    return index;
    }

 int main(){
   ios_base::sync_with_stdio(0);cin.tie(NULL);
    //freopen("pizza.in","r",stdin);
    //freopen("pizza.out","w",stdout);
        int n ;
       cin>>n;
       int x[n+1][3];
       x[0][0] = 0;
       x[0][1] = 0;
       x[0][2] = 0;
       int mx = 0;
       for(int i = 1;i<=n;++i){
        cin>>x[i][0]>>x[i][1]>>x[i][2];
        x[i][0] +=max(x[i-1][1],x[i-1][2]);
        x[i][1] +=max(x[i-1][0],x[i-1][2]);
        x[i][2] +=max(x[i-1][1],x[i-1][0]);
        mx = max(x[i][0],max(x[i][1],x[i][2]));
       }
        cout<<mx<<endl;
    return 0;
}


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

int main() {

	int N, M, X, i, right=0, left=0, a;

	cin >> N >> M >> X;

	for (i = 0; i < M;++i) {
		cin >> a;
		if (a > X) ++right;
		else ++left;
	}

	cout << min(right, left) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    int a, b;

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


Measured memory_bytes: 384
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int Tests = sc.nextInt();
		for (int test = 0; test < Tests; test ++) {
			long a = sc.nextInt();
			long b = sc.nextInt();
			long l = sc.nextInt();
			long r = sc.nextInt();
			long len = (Math.max(a, b) - 1) / (Math.min(a, b) + 1) + 1;
			long lena, lenb;
			if (a >= len * b) {
				lena = a + b; lenb = 0;
			} else if (b >= len * a) {
				lena = 0; lenb = a + b;
			} else {
				lena = (len * a - b) / (len - 1);
				lenb = (len * b - a) / (len - 1);
			}
			boolean B = a - lena + lena / (len + 1) - lenb / (len + 1) == 0;
			for (long i = l - 1; i < r; ++ i) {
				char pc;
				if (i < lena) {
					if (i % (len + 1) == len) pc = 'B';
					else pc = 'A';
				}
				else if (i >= a + b - lenb) {
					if ((a + b - i - 1) % (len + 1) != len) pc = 'B';
					else pc = 'A';
				}
				else if (B) pc = 'B';
				else pc = 'A';
				System.out.print(pc);
			}
			System.out.println();
		}
	}
}

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

using namespace std;

int main(){

  int N,M;
  int A[1000];
  int ans = 0;
  
  cin >> N >> M;

  for(int i = 0;i < N;i++)
    cin >> A[i];
  int p = 0;
  do{
    int mini = 1e9;
    int maxm = 0;
    for(int i = 0;i < M;i++){
      mini = min(mini,A[p]);
      maxm = max(maxm,A[p]);
      p = (p + 1) % N;
    }
    ans += (maxm - mini);
  }while(p>0);
  
  cout << ans << endl;

  return 0;
}




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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

    sort(all(s));
    sort(all(t));
    reverse(all(t));

    cout << ((s < t) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

#define INF 100000000;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
int main(){
    string S;
    cin >> S;
    ll ans = 0,cnt[200007];
    bool fin = false;

    rep(i,S.length()) cnt[i] = 0;
    rep(i,S.length()){
        if(S[i] == 'B'){
            cnt[i+1] = cnt[i] + 1;
        }else cnt[i + 1] = cnt[i];
        if (S[i] == 'W') ans += cnt[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int R;
  cin >> R;
  
  if (R < 1200)
    cout << "ABC" << endl;
  else if (R < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
}

Measured memory_bytes: 256
N = input()
l = [int(i) for i in input().split()]
mapped_l = map(str, l)
print(" ".join(mapped_l))
for i in range(1, len(l)):
  key = l[i]
  j = i-1
  while j >= 0 and l[j] > key:
    l[j+1] = l[j]
    j -= 1
  l[j+1] = key
  mapped_l = " ".join(map(str, l))
  print(mapped_l)



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

long long n;
string s;

int main() {
  cin >> n;
  if(n == 0) s = '0';
  while(n != 0) {
    if(max(n, -n) % 2 != 0) {
      s += '1';
      --n;
    }
    else
      s += '0';
    n /= -2;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B,C,D,flag=0;
  string s;
  cin>>N>>A>>B>>C>>D>>s;
  
  if(B>C){
    for(int i=A;i<C-2;i++){
      if(s.at(i)=='#' && s.at(i+1)=='#'){
        flag++;
        break;
      }
    }
    for(int i=B;i<D-2;i++){
      if(s.at(i)=='#' && s.at(i+1)=='#'){
        flag++;
        break;
      }
    }
  }
  
  else if(C<D) {
    for(int i=A;i<D-2;i++){
      if(s.at(i)=='#' && s.at(i+1)=='#'){
        flag++;
        break;
      }
    }
  }
  
  else {
    for(int i=A;i<D-2;i++){
      if(s.at(i)=='#' && s.at(i+1)=='#'){
        flag++;
        break;
      }
    }
    if(flag==0){
      int count;
      flag++;
      for(int i=B-2;i<D-1;i++){
        if(s.at(i)=='.'){
          count=1;
          for(int j=i+1;;j++){
            if(s.at(j)=='.')count++;
            else break;
            if(count>2)break;
          }
          if(count>2){
            flag=0;
            break;
          }
        }
      }
    }
  }
  if(flag==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n;
  cin>>n;
  int color[9];
  for(int i=0;i<9;i++) color[i]=0;
  for(int j=0;j<n;j++){
    int a;
    cin>>a;
    if(a<=399) color[0]=1;
    else if(a<=799) color[1]=1;
    else if(a<=1199) color[2]=1;
    else if(a<=1599) color[3]=1;
    else if(a<=1999) color[4]=1;
    else if(a<=2399) color[5]=1;
    else if(a<=2799) color[6]=1;
    else if(a<=3199) color[7]=1;
    else color[8]++;
  }
  if(color[8]==n) cout<<1<<' '<<color[8]<<endl;
  else{
    int ans=0;
    for(int i=0;i<8;i++){
      if(color[i]==1) ans++;
    }
    cout<<ans<<' '<<ans+color[8]<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define vi vector<int>
#define REP(n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	vi v;
        v.push_back(a);
        v.push_back(b);
        v.push_back(c);
	sort(v.begin(),v.end());
	REP(v.size()){
		if(i) cout<<" "<<v[i]; 
		else cout<<v[i];
	}
	cout<<endl;

}

Measured memory_bytes: 1216
s = input()[::-1]
d = {'maerd', 'remaerd', 'esare', 'resare'}

cnt = 0
while cnt + 5 <= len(s):
    if s[cnt:cnt + 5] in d:
        cnt = cnt + 5
    elif cnt + 6 <= len(s) and s[cnt:cnt + 6] in d:
        cnt = cnt + 6
    elif cnt + 7 <= len(s) and s[cnt:cnt + 7] in d:
        cnt = cnt + 7
    else:
        print('NO')
        break
else:
    print('YES')


Measured memory_bytes: 9280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

string s, t;

int main()
{
    cin >> s >> t;
    int ans = 0;

    for (int i = 0; i < 3; i++)
    {
        ans += (s[i] == t[i]);
    }

    cout << ans << endl;
}

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 ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n)
    cin >> p[i];
  vector<double> e(n);
  rep(i, n)
    e[i] = (1+p[i])*p[i]/2.0/p[i];
  vector<double> sum(n+1);
  rep(i, n)
    sum[i+1] = sum[i]+e[i];
  double ans = 0;
  for (int i = k; i <= n; i++)
    chmax(ans, sum[i]-sum[i-k]);
  cout << fixed << setprecision(9) << ans << endl;
  return 0;
}

Measured memory_bytes: 4736
n=gets.chomp.to_i
a=Array.new(n)
(n-1).times do |i|
  c,s,f=gets.chomp.split(" ").map { |e| e.to_i }
  a[i] = {"c" => c, "s" => s, "f" => f}
end

for j in 0..n-2 do
  time = 0
  for i in j..n-2 do
    if a[i]["s"] > time
      time = a[i]["s"]
    else
      if time%a[i]["f"] != 0
        time += a[i]["f"] - time%a[i]["f"]
      end
    end

    time += a[i]["c"]
  end
  puts time
end
puts 0

Measured memory_bytes: 1916
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
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; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

ll lcm(ll a, ll b)
{
    /* 自然数 a > b を確認・入替 */
    ll tmp;
    ll x = a * b;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
 
    /* ユークリッドの互除法 */
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    return x/b;
}


int main()
{

    ll a,b;
    cin >> a >> b;
    ll ans = lcm(a, b);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2e5+10;
int n,x[N],y[N],l[N],r[N];
pair<pa,int> a[N];
ll ans[N];

const ll inf = 1e15;
map<int,ll>dp[2][N];
inline ll dis(pa a,pa b){
	return abs(x[a.fi]-x[b.fi])+abs(y[a.se]-y[b.se]);
}
inline ll dfs(int l,int r,bool k,int mn,int mx){
	if (dp[k][l].count(r)) return dp[k][l][r];
	ll ans=inf;
	int L=::l[l-1],R=::r[r+1];
	if (l>1&&(a[l-1].fi.se==mn-1||a[l-1].fi.se==mx+1)){
		ans=min(ans,dfs(L,r,0,min(mn,a[L].fi.se),max(mx,a[L].fi.se))+dis(!k?a[l].fi:a[r].fi,a[L].fi));
	}
	if (r<n&&(a[r+1].fi.se==mn-1||a[r+1].fi.se==mx+1)){
		ans=min(ans,dfs(l,R,1,min(mn,a[R].fi.se),max(mx,a[R].fi.se))+dis(!k?a[l].fi:a[r].fi,a[R].fi));
	}
	return dp[k][l][r]=(ans==inf?l-r:ans);
}

int main(){
	n=read();
	For(i,1,n) x[i]=read(),y[i]=read(),a[i]={{x[i],y[i]},i};
	sort(a+1,a+1+n),sort(x+1,x+1+n),sort(y+1,y+1+n);
	For(i,1,n){
		a[i].fi.fi=lower_bound(x+1,x+1+n,a[i].fi.fi)-x;
		a[i].fi.se=lower_bound(y+1,y+1+n,a[i].fi.se)-y;
	}
	l[1]=1;
	For(i,2,n){
		if (abs(a[i].fi.se-a[i-1].fi.se)==1) l[i]=l[i-1];
			else l[i]=i;
	}
	r[n]=n;
	Dow(i,n-1,1)
		if (abs(a[i].fi.se-a[i+1].fi.se)==1) r[i]=r[i+1];
			else r[i]=i;
	For(i,1,n) ans[a[i].se]=dfs(i,i,0,a[i].fi.se,a[i].fi.se);
	For(i,1,n) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 81832
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    ll N;
    cin >> N;
    if(!cin) return;
    double ans = 0;
    for (int i = 0; i < N; ++i) {
        double x;
        string u;
        cin >> x >> u;
        if(u[0] == 'B'){
            ans += x * 380000;
        }
        else{
            ans += x;
        }
    } // end i
    cout << ans;
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        solve(fs);
    }
#else
    solve(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3


def next_line():
    return input()


def next_int():
    return int(input())


def next_int_array_one_line():
    return list(map(int, input().split()))


def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)]


def next_str_array(size):
    return [input() for _ in range(size)]


def main():
    s = next_line()
    x = 0
    if s == "RRR":
        x = 3
    elif s == "RRS" or s == "SRR":
        x = 2
    elif s == "SSS":
        x = 0
    else:
        x = 1
    print(x)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8972
import java.util.Arrays;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.HashSet;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for(int i=0;i<n;i++) {
			for(int k=0;k<d;k++) {
				x[i][k] = sc.nextInt();
			}
		}
		int ans =0;
		for(int i=0;i<n;i++) {
			for(int k=i+1;k<n;k++) {
				double dist = 0;
				for(int l =0;l<d;l++) {
					dist += (x[i][l]-x[k][l])*(x[i][l]-x[k][l]);
				}	
				int dist2 = (int)Math.sqrt(dist);
				if(dist2*dist2 == dist) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
	
	static long factr(long n,long p,long q) {
		if(n==p) {
			return 1l;
		}
		long ma = Math.max(p, q);
		long mi = Math.min(p, q);
		ArrayList<Long> mm = new ArrayList<Long>();
		for(int i=1;i<=mi;i++) {
			mm.add((long) i);
		}
		long ret = fact(n,ma,mm);
		return ret;
	}
	static long fact(long n,long m,ArrayList<Long> mm) {
		if(n==m) {
			return 1l;
		}
		long pre = fact(n-1,m,mm);
		for(int i=0;i<mm.size();i++) {
			if(pre%mm.get(i) ==0) {
				pre = pre/mm.get(i);
				mm.set(i, 1l);
			}
		}
		return (n*pre);
	}
}

Measured memory_bytes: 21204
//In His Name
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> >e;
vector<int>adj[100100];
int n,m,minlvl[100100],lvl[100100];
bool mark[100100];
void dfs(int x,int par){
    mark[x]=true;
    minlvl[x]=lvl[x];
    for(int i=0;i<adj[x].size();i++){
        int v=adj[x][i];
        if(!mark[v]){
            lvl[v]=lvl[x]+1;
            dfs(v,x);
            minlvl[x]=min(minlvl[x],minlvl[v]);
        }
        else if(v!=par) minlvl[x]=min(minlvl[x],minlvl[v]);
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        if(x>y) swap(x,y);
        adj[x].push_back(y);
        adj[y].push_back(x);
        e.push_back(make_pair(x,y));
    }
    for(int i=0;i<n;i++)
        if(!mark[i]) dfs(i,i);
    sort(e.begin(),e.end());
    for(int i=0;i<m;i++){
        int x=e[i].first,y=e[i].second;
        if(lvl[x]<lvl[y]) swap(x,y);
        if(minlvl[x]>lvl[y]) cout<<e[i].first<<" "<<e[i].second<<endl;
    }
    return -0;
}

Measured memory_bytes: 6808
#include <cstdio>
#include <iostream>

#define sentinel 2000000000
using namespace std;

long long int cnt;

void merge(int a[],int left,int mid,int right){
    
int L[mid-left+1],R[right-mid+1];
for(int i=0;i<mid-left;i++){
    L[i] = a[left+i];
}
for(int j=0;j<right-mid;j++){
    R[j] = a[mid+j];
}
L[mid-left] = sentinel;
R[right-mid] = sentinel;

int i = 0;
int j = 0;
int leftnum = 0;

for(int k=0;k<right-left;k++){
    if(L[i]<R[j]){
        a[left+k] = L[i];
        i++;
        leftnum++;
        }
        else {
            a[left+k] = R[j];
            j++;
            cnt += mid - left - leftnum; 
        }
    }
}


void mergesort(int a[],int left,int right){

if(left + 1 < right){
    int mid = (left + right)/2;
    mergesort(a,left,mid);
    mergesort(a,mid,right);
    merge(a,left,mid,right);
}
}

int main(){
    cnt = 0;
    int n;
    scanf("%d",&n);
    int *a = new int[n];
    
    for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    }
    mergesort(a,0,n);
    cout << cnt <<endl;
    delete[] a;
return 0;

}


Measured memory_bytes: 4416
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int ans = 1;
    rep(i,n){
        ans = min(ans * 2, ans + k);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
long n,a[13],b[13],i,j,k,m;
while(cin>>n){
if(n==0)break;
m=0;
for(i=0;i<n;i++)cin>>a[i];
for(;;){
for(i=0;i<n;i++){
for(k=0,j=0;j<n;j++)if(a[i]==a[j])k++;
b[i]=k;
}
for(i=0;i<n;i++)if(a[i]!=b[i])break;
if(i!=n)m++;else break;
for(i=0;i<n;i++)a[i]=b[i];
}
cout<<m<<endl;
cout<<b[0];
for(i=1;i<n;i++)cout<<" "<<b[i];
cout<<endl;
}
return 0;
}

Measured memory_bytes: 1160
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 105 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int n, m, px, py, A[N][N], B[N][N], C[N][N];
char s[N][N];
 
int f[N][N][N];
 
int32_t main(){
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s[i] + 1);
		for (int j = 1; j <= m; ++j) {
			A[i][j] = s[i][j] == 'o';
			B[i][j] = B[i][j - 1] + A[i][j];
			C[i][j] = C[i - 1][j] + A[i][j];
			if (s[i][j] == 'E') px = i, py = j;
		}
	}
	for (int u = 0; u <= px - 1; ++u) {
		for (int d = 0; d <= n - px; ++d) {
			for (int l = 0; l <= py - 1; ++l) {
				for (int r = 0; r <= m - py; ++r) {
					int tu = max(px - u, 1 + d);
					int td = min(px + d, n - u);
					int tl = max(py - l, 1 + r);
					int tr = min(py + r, m - l);
					if (u && px - u == tu && tl <= tr) f[d][l][r] += B[px - u][tr] - B[px - u][tl - 1];
					if (d) f[d][l][r] = max(f[d][l][r], f[d - 1][l][r] + (px + d == td && tl <= tr ? B[px + d][tr] - B[px + d][tl - 1] : 0));
					if (l) f[d][l][r] = max(f[d][l][r], f[d][l - 1][r] + (py - l == tl && tu <= td ? C[td][py - l] - C[tu - 1][py - l] : 0));
					if (r) f[d][l][r] = max(f[d][l][r], f[d][l][r - 1] + (py + r == tr && tu <= td ? C[td][py + r] - C[tu - 1][py + r] : 0));
				}
			}
		}
	}
	printf("%d\n", f[n - px][py - 1][m - py]);
	return 0;
}

Measured memory_bytes: 13132
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	for true {
		n, k := scanInt(sc), scanInt(sc)
		if n == 0 && k == 0 {
			break
		}
		sum := make([]int, n+2)
		for i := 2; i <= n+1; i++ {
			sum[i] = sum[i-1] + scanInt(sc)
		}
		max := math.MinInt32
		for i := 1; i+k <= n+1; i++ {
			if v := sum[i+k] - sum[i]; max < v {
				max = v
			}
		}
		fmt.Println(max)
	}
	return
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}



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

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

#define mx                     200005
#define INF_mx                 1e18
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)
/*
tree<
       int,
     null_type,
     less<int>,
     rb_tree_tag,
     tree_order_statistics_node_update>t;
*/

int main()
{
   ll N,M;
   cin>>N>>M;
   ll ans=N*(N-1)/2;
   ans+=(M*(M-1)/2);
   cout<<ans<<endl;
    return 0;
}
/*

 6 4

 2 4 5
 0

*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int A,B,T,sum;
  sum=0;
  cin>>A>>B>>T;
  sum=T/A*B;
  cout<<sum<<endl;
}

Measured memory_bytes: 256