akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  tourist
 *    created: 08.01.2020 23:01:02       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  for (int it = 0; it < 787788; it++) {
    if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
      cout << it << '\n';
      return 0;
    }
    int x = (a + b) / 2;
    int y = (b + c) / 2;
    int z = (a + c) / 2;
    a = x;
    b = y;
    c = z;
  }
  cout << -1 << '\n';
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;
    
    print(N * N);
    
}


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

long long x,y,g,ans=0;

int main()
{
    cin>>x>>y;
    g=__gcd(x,y);
    for (long long i=2;i<=g/i;i++)
    {
        if (g%i==0)
        {
            ans++;
            while(g%i==0)  g/=i;
        }
    }
    if (g>1)  ans++;
    cout<<ans+1<<endl;
    return 0;
}

Measured memory_bytes: 256
intxt = input().split()
n = int(intxt[0])
k = int(intxt[1])

def graph(n, k):
    edges = [[1, i] for i in range(2, n + 1)]


    max_k = (n - 1) * (n - 2) // 2

    if k > max_k:
        print(-1)
        return

    diff = max_k - k

    for i in range(2, n + 1):
        if diff == 0:
            break
        for j in range(i + 1, n + 1):
            edges.append([i, j])
            diff -= 1
            if diff == 0:
                break
    
    print(len(edges))
    for i in edges:
        print(str(i[0]) + " " + str(i[1]))

graph(n, k)



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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

//#define int int64_t
//int a[N+2];

int32_t  main(){
	IOS;
  int a,b,t;cin>>a>>b>>t;
  int ans=0;
  for(int i=a;i<=t;++i){
    if(i%a==0)ans+=b;
  }
  cout<<ans<<endl;

  return 0;
}



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

int main(){
  int n, k;
  cin >> n >> k;
  
  int num = 1;
  rep(i,n){
    if(num < k){
      num *= 2;
    }else{
      num += k;
    }
  }
  
  cout << num << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define out(a) cout<<fixed<<setprecision((a))


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

	ll a,b;
	string s;
	cin >> a >> b;
	if(a<b)cout << 0 << endl;
	else cout << 10<< endl;
}


Measured memory_bytes: 256
/*
  Submitter: Nick Hudson
  Anumber: A01634984

https://atcoder.jp/contests/abc150/submissions/9540530
  */

#include <iostream>

int main(){

  int N,total = 0;
  std::string S;

  std::cin>>N;
  std::cin>>S;
  // std::cout<<N<<std::endl;
  // std::cout<<S<<std::endl;

  for(int letter = 0; letter < N-2; ++letter){
    if(S[letter]=='A' && S[letter+1]=='B' && S[letter+2]=='C')
      ++total;
  }

  std::cout<<total;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int n, q;
  cin >> n >> q;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < q; i++) {
    ll x;
    cin >> x;
    ll res = 0;
    int right = 0;
    ll sum = 0;
    for (int left = 0; left < n; left++) {
      while (right < n && sum + a[right] <= x) {
        sum += a[right];
        right++;
      }

      res += (right - left);
      if (right == left)
        right++;
      else
        sum -= a[left];
    }
    cout << res << endl;
  }
}


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

void input(int& rnMaxNum, int& rnWinPnt)
{
  cin >> rnMaxNum >> rnWinPnt;
}

double calcWinRate(int nMaxNum, int nWinPnt)
{
  vector<int> vnBorder;

  int nBorder = nWinPnt;
  vnBorder.push_back( nBorder );

  while (nBorder > 1)
  {
    nBorder = (nBorder + 1) / 2;           // 切り上げ
    vnBorder.push_back( nBorder );
  }
  double nWinRate = 0.0;

  for (int nPower = vnBorder.size() - 1; nPower > 0; nPower--)
  {
    double nOneRate = 0.0;
    int nNum = vnBorder[nPower];

    while (nNum < min(vnBorder[nPower - 1], nMaxNum + 1))
    {
      nOneRate += 1.0 / nMaxNum;
      nNum++;
    }
    for (int n = 0; n < nPower; n++)
      nOneRate /= 2;

    nWinRate += nOneRate;
  }
  if (nMaxNum >= vnBorder[0])
  {
    int nDiff = nMaxNum - vnBorder[0] + 1;
    nWinRate += (double)nDiff / nMaxNum;
  }
  return nWinRate;
}
 
int main()
{
  int nMaxNum, nWinPnt;
  input(nMaxNum, nWinPnt);
  cout << fixed << setprecision(10) << calcWinRate(nMaxNum, nWinPnt) << endl;

  return 0;
}

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

using namespace std;

template<typename T,int N>
class stack{
private:
  int size;
  T array[N];
public:
  stack(){
    size = 0;
  }

  bool push(T x){
    if(isFull()){
      return false;
    }
    array[size] = x;
    size++;

    return true;
  }

  T pop(){
    size--;
    return array[size];
  }

  bool isEmpty(){
    if(size == 0){
      return true;
    }else{
      return false;
    }
  }

  bool isFull(){
    if(size >= N){
      return true;
    }else{
      return false;
    }
  }

};

int main(){
  stack<int,20000> st;
  string a;
  while(cin >> a){
    if(a[0] == '+'){
      int a = st.pop();
      int b = st.pop();
      st.push(b+a);
    }else if(a[0] == '-'){
      int a = st.pop();
      int b = st.pop();
      st.push(b-a);
    }else if(a[0] == '*'){
      int a = st.pop();
      int b = st.pop();
      st.push(b*a);
    }else{
      int x = 0;
      for(int i = 0; i < a.size(); i++){
        x*=10;
        x+=a[i]-'0';
      }
      st.push(x);
    }
  }
  cout << st.pop() << "\n";
  return 0;
}



Measured memory_bytes: 3156
from collections import defaultdict
from itertools import combinations
N = int(input())
S = defaultdict(set)
march = 'MARCH'
for i in range(N):
    a = input()
    for j in range(5):
        if a[0] == march[j]:
            S[j].add(a)
sv = []
for i in S.values():
    sv.append(len(i))
if len(sv) < 3:
    print(0)
else:
    ans = 0
    for a,b,c in combinations(sv,3):
        ans += a*b*c
    print(ans)

Measured memory_bytes: 14700
S = input()
N = len(S) + 1
ans = [0]*N

for i in range(len(S)):
    if S[i] == '<': ans[i+1] = ans[i] + 1
for i in range(len(S)-1,-1,-1):
    if S[i] == '>': ans[i] = max(ans[i], ans[i+1] + 1)
print(sum(ans))


Measured memory_bytes: 46320
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> v;
int main (){
    for(int i=0; i<3; i++){
        int a;
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    cout << ( v[2] - v[1])  + (v[1] - v[0]) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n,m;
int p[maxn], head[maxn];
int mn[maxn], bad[maxn];
deque<int> all;
int get(int x,int y) {
    if(p[x]<p[y]) return x;
    return y;
}
int findhead(int x) {
    if(x==head[x]) return x;
    return head[x] = findhead(head[x]);
}
int main() {
    int i,x,y;
    long long ans = 0;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++) scanf("%d",&p[i]);
    for(i=1;i<=n;i++) head[i] = i;
    for(i=0;i<m;i++) {
        scanf("%d%d",&x,&y);
        head[findhead(x+1)] = findhead(y+1);
    }
    p[0] = 2e9;
    for(i=1;i<=n;i++) {
        x = findhead(i);
        mn[x] = get(mn[x], i);
    }
    for(i=1;i<=n;i++) bad[mn[i]] = 1;
    for(i=1;i<=n;i++) if(!bad[i]) all.push_back(p[i]);
    sort(all.begin(),all.end());
    for(i=1;i<=n;i++) if(bad[i]) all.push_front(p[i]);
    if((n-m-1)*2>all.size()) return !printf("Impossible");
    for(i=0;i<(n-m-1)*2;i++) ans += all[i];
    printf("%lld",ans);
}


Measured memory_bytes: 2176
S0=input()

for i in range(1<<3):
  S=S0
  for j in range(3):
    if ((i>>j)&1)==1:
      S=S[:3-j]+'+'+S[3-j:]
    else:
      S=S[:3-j]+'-'+S[3-j:]
  if eval(S)==7:
    print(S+'=7')
    exit()

Measured memory_bytes: 3060
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
ll=[]
for i in range(0,len(l)-1):
  ll.append(abs(l[i]-l[i+1]))
ll.sort()
if m==1:
  print(0)
elif n>=m:
  print(0)
elif n==1:
  print(abs(l[0]-l[len(l)-1]))
else:
  print(sum(ll[:-(n-1)]))
  


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


bool is_prime(int x) {
    if (x <= 1) return false;
    for (int i = 2; i*i < x; i++) {
        if (x%i == 0) return false;
    }
    return true;
}

int main(int argc, char const *argv[]) {
    int x;
    cin >> x;

    int p = x;
    while (!is_prime(p)) p++;

    cout << p << endl;
    return 0;
}


Measured memory_bytes: 3564
n, m = map(int, input().split())
is_ac = [False]*n
 
ac = 0
wa_cnt = [0]*n

for i in range(m):
    p, s = input().split()
    p = int(p)
    if is_ac[p-1] == False:
        if s == 'AC':
            is_ac[p-1] = True
            ac += 1
        else:
            wa_cnt[p-1] += 1

wa = 0
for i in range(n):
    if is_ac[i]:
        wa += wa_cnt[i]
print(ac, wa)

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

using ll = long long;

int main() {

    int n;

    cin >> n;

    vector<ll> v(n);

    vector<ll> answer(n, 0);

    ll sum = 0;

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

        sum += i % 2 ? -v[i] : v[i];

    }

    cout << sum << " ";
    int prev = sum;

    for(int i = 0; i < n - 1; ++i) {
        cout << 2*v[i] - prev << " ";
        prev = 2 * v[i] - prev;
    }
    cout << endl;

    return 0;
}




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

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

    string str;
    cin >> str;
    bool flag = false;
    for(int i=0; i<str.size(); i++){
        if(str[i]=='C') flag = true;
        if(flag && str[i]=='F') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 764
h,w = [int(i) for i in input().split()]
l = [[i for i in input()] for _ in range(h)]

# はみだす判定が面倒なので適当な文字で囲む
fill_l = []
for i in range(-1,h+1):
    if i == -1 or i == h:
        fill_l.append(['?' for _ in range(w+2)])
    else:
        ext = ['?']
        ext.extend(l[i])
        ext.append('?')
        fill_l.append(ext)
        
flg = True
for i in range(1,h):
    for j in range(1,w):
        if fill_l[i][j] == '#' and not (fill_l[i+1][j] == '#' or fill_l[i-1][j] == '#' or fill_l[i][j-1] == '#' or fill_l[i][j+1] == '#'):
            flg = False
            break
        
print('Yes' if flg else 'No')
            

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  int ans = 1000 - (N % 1000);
  if (ans == 1000)
    ans = 0;
  cout << ans << endl;
  return 0;
}

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

int main() {
	int n,k,i,j,ans,cur,res;
	cin >> n >> k;
	vector<int> a(n+1),b(k);
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	a[n]=n+1;
	sort(a.begin(),a.end());
	i=1; j=0;
	cur=a[0]; res=1;
	while(i<=n){
		if(a[i]==cur){
			res++;
		}else{
			cur=a[i]; 
				if(j<k-1){
					b[j]=res;
					j++;
				}else if(j==k-1){
					b[j]=res;
					sort(b.begin(),b.end());
					j++;
				}else if(res>b[0]){
					b[0]=res;
					sort(b.begin(),b.end());
				}
			
			res=1;
		}
		i++;
	}
	ans=n;
	for(i=0; i<k; i++){
		ans-=b[i];
	}
	cout << ans;
}


Measured memory_bytes: 1792
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;

void main()
{
    auto nmq = readln.chomp.split.to!(long[]);
    long N = nmq[0];
    long M = nmq[1];
    long Q = nmq[2];
    long[] L = new long[](M);
    long[] R = new long[](M);
    long[] Qp = new long[](Q);
    long[] Qq = new long[](Q);

    foreach (i; 0 .. M)
    {
        auto lr = readln.chomp.split.to!(long[]);
        L[i] = lr[0];
        R[i] = lr[1];
    }
    foreach (i; 0 .. Q)
    {
        auto pq = readln.chomp.split.to!(long[]);
        Qp[i] = pq[0];
        Qq[i] = pq[1];
    }

    long[][] table = new long[][](N + 1, N + 1);
    foreach (t; zip(L, R))
        table[t[0]][t[1]]++;
    foreach (i, ref r; table[1 .. $])
        r[] += table[i][];

    // table.writeln;

    foreach (query; zip(Qp, Qq))
    {
        long result;
        foreach (i; query[0] .. query[1] + 1)
        {
            result += table[query[1]][i] - table[query[0] - 1][i];
            // writeln(table[query[1]][i] - table[query[0] - 1][i]);
        }
        result.writeln;
    }
}


Measured memory_bytes: 10236
# coding: utf-8

#素因数分解
def prime_factorize(N):
    f = []
    while N % 2 == 0:
        f.append(2)
        N //= 2
    i = 3
    while i * i <= N:
        while N % i == 0:
            f.append(i)
            N //= i
        i += 2
    #最後残った数について
    if N != 1:
        f.append(N)
    return f

#main
N = int(input())
MOD = 10**9 + 7
exp = [0] * (N+1)

for i in range(2, N+1):
    F = prime_factorize(i)
    for j in range(len(F)):
        exp[F[j]] += 1

ans = 1
for i in range(N+1):
    ans *= exp[i] + 1
    ans %= MOD
print(ans)

Measured memory_bytes: 3064
N = int(input())
V = input()
C = input()

Vs = [V.split()[i] for i in range(0, N)]
Cs = [C.split()[i] for i in range(0, N)]

sum = 0
for v_i, c_i in zip(Vs, Cs):
  sub = int(v_i) - int(c_i)
  if sub > 0:
    sum += sub

print(sum)

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

const int N = 1000005;

int n, m, num[N], was[N];
vector<int> g[N], cols[N + N];

int main() {
    ios::sync_with_stdio(false);

    cin >> n;
    fill(num, num + n, -1);
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        --x;
        cols[y].push_back(x);
        num[x] = y;
    }
    for (int i = 0; i < N + N - 1; ++i) {
        for (auto& v : cols[i]) {
            for (auto& to : g[v]) {
                if (num[to] == -1) {
                    num[to] = i + 1;
                    cols[i + 1].push_back(to);
                } else
                if (abs(num[to] - i) != 1) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 0; i < n; ++i) {
        cout << num[i] << '\n';
    }
    return 0;
}


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

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

    int A[n][m], B[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 < l; j++) {
            long long value = 0;
            for (int k = 0; k < m; k++) {
                value += A[i][k] * B[k][j];
            }
            cout << value;
            if (j != l - 1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1232
#include<stdio.h>
int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int Deg(const int a){int b=360;while(b%a){b+=360;}return b;}
int main(void){int X=IN();return printf("%d\n",Deg(X)/X),0;}

Measured memory_bytes: 1488
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int ans1;
    ans1=n*a;
    if(ans1>=b){
        cout<<b<<endl;
    }else{
        cout<<ans1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;

int main(){
    lint N,M,ans=0;
    cin>>N>>M;
    lint k[M],p[M],s[M][N];
    bool x[N];
    rep(i,M){
        cin >>k[i];
        rep(j,k[i]){
            cin >> s[i][j];
        }
    }
    rep(i,M){
        cin>>p[i];
    }
    rep(i,1<<N){
        lint count=0;
        lint count1=0;
        rep(j,N){
            if(i&1<<j)x[j]=true;
            else x[j]=false;
        }
        rep(c,M){
        rep(l,k[c]){
            if(x[s[c][l]-1]==true)count++;
        }
    if(count%2==p[c])count1++;
    count=0;
        }
        if(count1==M)ans++;
    }
    cout << ans;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        string s; cin >> s;
        int n = sz(s);
        vector<int> a(n, 1);
        auto apply = [&]() {
                vector<int> b(n);
                for (int i = 0; i < n; i++) {
                        if (s[i] == 'L') b[i - 1] += a[i];
                        else b[i + 1] += a[i];
                        b[i] -= a[i];
                }

                for (int i = 0; i < n; i++) a[i] += b[i];
        };


        vector<int> ans(n);
        for (int i = 0; i < n; i++) {
                //explore R
                int l = 0, r =  0;
                while (i < n && s[i] == 'R') i++, l++;
                int j = i - 1;
                while (i < n && s[i] == 'L') i++, r++;
                ans[j] = ans[j + 1] = (l + r) / 2;
                if (l % 2 != r % 2) {
                        ans[j] += l % 2;
                        ans[j + 1] += r % 2;
                }
                i--;
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 4224
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n; cin >> n;
  vector<ll> a(n); cin >> a;
  ll sum = 0;
  rep(i, n) sum += a[i];
  vector<P> v;
  rep(i, n) {
    v.eb(abs(a[i] * n - sum), i);
  }
  sort(all(v));
  cout << v[0].second << endl;
}


Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		String s = sc.next();
		if (a >= 3200) {
			System.out.println(s);
		}else{
			System.out.println("red");
		}

	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> res(n, 0);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        res[a - 1]++;
        res[b - 1]++;
    }

    for (int i = 0; i < n; i++) {
        cout << res[i] << 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 ull = unsigned long long;
using p  = pair<int, int>;
using vec_int = vector<int>;
using vec_str = vector<string>;
#define INF (1<<29)
ll ans = 0;

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}

void debug_input(vec_str& argv)
{
    // デバッグ用引数読み込み
    ifstream file("./input.txt");
    string str;
    while( getline(file, str) ) {
        argv.push_back(str);
    }
}

void debug_split_string(const string& str, vec_str& v)
{
    stringstream ss{str};
    string buf;
    while (getline(ss, buf, ' ')) {
        v.push_back(buf);
    }
}

void debug_split_int(const string& str, vec_int& v)
{
    stringstream ss{str};
    string buf;
    while (getline(ss, buf, ' ')) {
        istringstream ss(buf);
        int temp;
        ss >> temp;
        v.push_back(temp);
    }
}

int main()
{
    int S, W = 0;
	cin >> S >> W;
#if 0
	cin >> S;
#endif
#if 0
    vec_str v(N);
    //vec_int v(N);
    rep(i, N) cin >> v[i];
#endif

#if 0
    p pp = make_pair(1, 2);
    //cout << pp.first << endl;
    //cout << pp.second << endl;
#endif

#if 0 // for debug
    vec_str argv;
    debug_input(argv);

    // 文字列行の読み込み
    vec_str v;
    debug_split_string(argv[1], v);

    // 数値行の読み込み
    //debug_split_int(argv[0], v);
#endif
    

    if( S <= W )cout << "unsafe" << endl;
    else cout << "safe" << endl;

    
    
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include<stdio.h>
#include<functional>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
int N, A[200000];
int main() {
    int a,b,c,x;
    cin >> a>> b>>c;
    x=c-(a-b);
    if (x<=0){x=0;}

    cout << x<< endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cout << #x " = " << (x) << '\n';
#define P(x) cout << #x << '\n';    
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;
	if(a1 + a2 + a3 >= 22)
		cout << "bust" << '\n';
	else
		cout << "win" << '\n';
		
	
	return 0;
}






Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << x << "\n"
#define int long long
using namespace std;
using point = pair< int,int >;

signed main() {
    int n, M;
    map< point, int > mp;
    int h, m;

    cin >> n;
    REP (i, n) {
        scanf("%lld%lld", &h, &m);
        mp[point(h, m)]++;
    }

    cin >> M;
    REP (i, M) {
        scanf("%lld%lld", &h, &m);
        mp[point(h, m)]++;
    }

    bool isout = false;
    for (auto i : mp) {
        if (isout) printf(" ");
        else isout = true;
        printf("%lld:%02lld", i.F, i.S);
    }
    OUT("");

    return 0;
}




Measured memory_bytes: 3236
package main

import "fmt"

func main() {
	var a int
	fmt.Scan(&a)

	list := make([]int, a)
	for i := 0; i < a; i++ {
		fmt.Scan(&list[i])
	}

	max := 0

	for i := 0; i < a; i++ {
		for j := 0; j < a; j++ {
			if max < list[i]-list[j] {
				max = list[i] - list[j]
			}
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	int cnt[100001] = {};
	cin >> n;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		cnt[a]++;
	}
	int overnum = 0;
	for(int i = 1; i <= 100000; i++){
		overnum += max(0, cnt[i] - 1);
	}
	cout << n - (overnum / 2 + overnum % 2) * 2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <cstdlib>
using namespace std;

template <class T> int streamvar(std::istream& in, T& var)
{
    if (!in) {
        cerr << "invalid istream" << endl;
        return 1;
    }
    in >> var;
    if (in.fail()) {
        cerr << "no var" << endl;
        return 1;
    }
    return 0;
}
template <class T> int streamvec(std::istream& in, std::vector<T> &v)
{
    v.clear();
    string s;

    if (!in) {
        cerr << "invalid istream" << endl;
        return 1;
    }
    getline(in, s);
    if (in.fail()) {
        cerr << "no line" << endl;
        return 1;
    }
    istringstream is(s);
    while (1) {
        T tmp;
        is >> tmp;
        if (is.fail())
            break;
        v.push_back(tmp);
    }
    return 0;
}

#define NUM 1000000
int main(void)
{
    bool prime[NUM];
    int array[NUM] = {};
    for (int i = 0; i < NUM; i++) 
        prime[i] = 1;
    prime[0] = prime[1] = 0;

    for (int i = 0; i < NUM; i++) {
        if (prime[i]) {
            for (int j = i*2; j < NUM; j+=i) {
                prime[j] = 0;
            }
        }
    }
    array[0] = 0;
    for (int i = 1; i < NUM; i++) 
        array[i] = array[i-1] + prime[i];

    int n;
    while (cin >> n) {
        cout << array[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 6048
n,m = list(map(int,input().split()))
ans_l = [-1]*n
#print(ans_l)
flag = True
for i in range(m):
    s,c, =list(map(int,input().split()))
    if ans_l[s-1]!=-1 and ans_l[s-1]!=c:
        flag=False
        break
    ans_l[s-1]=c

if 1<n and ans_l[0]==0:
    flag=False
if 1<n and ans_l[0]==-1:
    ans_l[0]=1
if n==1 and ans_l[0]==-1:
    ans_l[0]=0
for i in range(n):
    if ans_l[i]==-1:
        ans_l[i]=0
if flag:
    print(''.join([str(n) for n in ans_l]))
else:print(-1)


Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
	long long n,m,s;
	scanf("%lld %lld",&n,&m);
	if(2*n<=m)
	{
		s=n;
		m=m-2*n;
		s+=m/4;
		printf("%lld\n",s);
	}
	else 
	{
		printf("%lld\n",m/2);
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define pb push_back
#define MAXN 21010
#define Scan(a) scanf("%I64d", &a)
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int n, l, r;
ll a[55], c[55][55];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    FOR(i,0,50)
        FOR(j,0,i)
            if (j == 0 || j == i) c[i][j] = 1;
            else c[i][j] = c[i-1][j] + c[i-1][j-1];
    cin >> n >> l >> r;
    FOR(i,1,n) cin >> a[i];
    sort(a+1, a+n+1);
    ll g = 0;
    FORE(i,n,n-l+1) g += a[i];
    cout << fixed << setprecision(6) << g / double(l) << endl;
    ll res = 0;
    FOR(k,l,r) {
        ll h = 0;
        FORE(i,n,n-k+1) h += a[i];
        if (h*l != g*k) break;
        int cnt = 0, sumCnt = 0;
        FOR(i,n-k+1,n)
            if (a[i] == a[n-k+1]) cnt++;
        FOR(i,1,n)
            if (a[i] == a[n-k+1]) sumCnt++;
        res += c[sumCnt][cnt];
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
const int INF = 1000000007;
 
int main(void){
	int h[1100] = {0};
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>h[i];
 
	int ans=0;
	for(int l=0;l<n;l++) {
		while(h[l] > 0) {
			int r;
			for(r=l+1;r<n;r++) {
				if(h[r] == 0) break;
			}
 
			for(int i=l;i<r;i++) --h[i];
			ans++;
		}
	}
 
	cout<< ans <<endl;
 
	return 0;
}

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

#define MAX 104

enum direction{UP,RIGHT,DOWN,LEFT};

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

	for(int x = 0; x < d; ++x){
		int n;
		int s, t;
		int dir;
		short m[MAX][MAX] = {{0,}};
		cin >> n;

		if( x > 0 )
			cout << endl;

		for(int i = 0; i < n + 4; ++i){
			if( i == 0 || i == n+3 )
				for(int j = 1; j < n+3; ++j)
					m[i][j] = 1;
			m[i][0] = m[i][n+3] = 1;
		}

		s = n + 1;
		t = 2;
		dir = UP;
		while( true )
		{
			int cnt = 0;
			const int ds[] = {-1,0,1,0};
			const int dt[] = {0,1,0,-1};

			m[s][t] = 1;

			for(int i = 0; i < 4; ++i){
				if( m[ s + ds[i] ][ t + dt[i] ] )
					++cnt;
			}
			if( cnt >= 2 ){
				m[s][t] = 0;
				break;
			}

			switch( dir ){
				case UP: if( m[s-2][t] ) dir = RIGHT; break;
				case RIGHT: if( m[s][t+2] ) dir = DOWN; break;
				case DOWN: if( m[s+2][t] ) dir = LEFT; break;
				case LEFT: if( m[s][t-2] ) dir = UP; break;
			}
			switch( dir ){
				case UP: --s; break;
				case RIGHT: ++t; break;
				case DOWN: ++s; break;
				case LEFT: --t; break;
			}
		}

		for(int i = 2; i < n + 2; ++i){
			for(int j = 2; j < n + 2; ++j)
				cout << ( m[i][j] ? '#' : ' ' );
			cout << endl;
		}
	}
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    long long sum = 0 ;
    for (int div = 1; div <= N; div++)
    {
        int n = div;
        while (n <= N)
        {
            sum += n;
            n += div;
        }
    }
    cout << sum;
    return 0;
}

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

int main(){
    int rooms[5][4][11],n;
    
    for(int i=1; i<=4; i++)
        for(int j=1; j<=3; j++)
            for(int k=1; k<=10; k++) rooms[i][j][k]=0;
                
    cin>>n;
    for(int k=0; k<n; k++){
        int b,f,r,v;
        cin>>b>>f>>r>>v;
        rooms[b][f][r]+=v;
    }
    
    for(int b=1; b<=4; b++){
        if(b>1) cout<<"####################"<<"\n";
        for(int f=1; f<=3; f++){
            for(int r=1; r<=10; r++){
                cout<<" "<<rooms[b][f][r];
            }
            cout<<endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>

using namespace std;
typedef pair<int,int> P;
int N;
P A[500000];
bool compare_y(P a, P b) {
  return a.second < b.second;
}

int closest_pair(P *a ,int n) {
  if(n <= 1) return 2 << 27;
  int m = n /2;
  int x = a[m].first;
  int d = min(closest_pair(a,m),closest_pair(a + m, n - m));
  inplace_merge(a, a + m, a + n, compare_y);

  vector<P> b;
  for(int i = 0; i < n; i++) {
    if(abs(a[i].first - x) >= d) continue;
    for(int j = 0; j < b.size(); j++) {
      int dx = a[i].first - b[b.size() - j - 1].first;
      int dy = a[i].second - b[b.size() - j - 1].second;
      if(dy >= d) break;
      d = min(d,(dx * dx + dy * dy));
    }
    b.push_back(a[i]);
  }
  return d;
}

void solve() {
  sort(A,A + N);
  printf("%d\n", closest_pair(A,N));
}

int main() {
  scanf("%d",&N);
  for(int i = 0; i < N; i++) {
    int x, y;
    scanf("%d %d",&x,&y);
    A[i] = P(x,y);
  }
  solve();

}

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

int main(){
    char mymap[101][101];
    int x, y;
    int px = 0; int py = 0; int step = 0;
    while (1){
	cin >> x >> y;
	if (!x && !y) break;
	for (int i = 0; i < x; i++){
	    for (int j = 0; j < y; j++){
		cin >> mymap[i][j];
	    }
	}
/*	for (int i = 0; i < x; i++){
	for (int j = 0; j < y; j++){
	cout << mymap[i][j];
	}
	cout << endl;
	}
*/
	step = px = py = 0;
	while (mymap[px][py] != '.' && step <= x*y){
	    switch (mymap[px][py]){
		case '>':
		    py++; break;
		case 'v':
		    px++; break;
		case '<':
		    py--; break;
		case '^':
		    px--; break;
		default: break;
	    }
	    step++;
	}
	if (step <= x*y)
	    cout << py << " " << px << endl;
	else
	    cout << "LOOP" << endl;
    }
}

Measured memory_bytes: 0
#!/usr/bin/env python
# coding: utf-8
#

def main(a, b, c, x, y):

    # min(a * A + b * B + c * C)
    # A + C/2 >= x
    # B + C/2 >= y
    m = []
    # 全部AとB
    m.append(a * x + b * y)
    # 全部C
    m.append(c * max(x, y) * 2)
    # xの方が多くて途中からA
    if x >= y: m.append(c * min(x, y) * 2 + a * (x - y))
    if x < y: m.append(c * min(x, y) * 2 + b * (y - x))
    print(min(m))
    


if __name__ == '__main__':
    try:
        a, b, c, x, y = list(map(int, input().strip().split(' ')))
        main(a, b, c, x, y)
    except EOFError:
        pass


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

#define ll long long
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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 main()
{
    int X;
    cin >> X;

    while(true)
    {
        bool flag = true;
        rep(i,sqrt(X)-2)
        {
            if( X%(i+2) == 0 )
            {
                flag = false;
                break;
            }
        }
        if(flag)
        {
            cout << X << endl;
            return 0;
        }
        X++;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int m;
	cin>>m;
	while(m--){
		int money,year,n,max=0;
		cin>>money>>year>>n;
		while(n--){
			int type,cost,remain=money;
			double riritu;
			cin>>type>>riritu>>cost;
			if(type){
				for(int i=0;i<year;++i){
					remain=remain+remain*riritu-cost;
				}
			}else{
				int risoku = 0;
				for(int i=0;i<year;++i){
					risoku+=remain*riritu;
					remain=remain-cost;
				}
				remain=remain+risoku;
			}
			if(max<remain) max=remain;
		}
		cout<<max<<endl;
	}
	return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

typedef double MT;
typedef vector<MT> Array;
typedef vector<Array> Matrix;

Array GaussJordan(Matrix A, Array b)
{
  int n = A.size();
  Matrix B(n, Array(n + 1));
  rep(i, n) rep(j, n) B[i][j] = A[i][j];
  rep(i, n) B[i][n] = b[i];
  rep(i, n){
    int p = i;
    rrep(j, i, n) if(abs(B[j][i]) > abs(B[p][i])) p = j;
    swap(B[i], B[p]);
    if(abs(B[i][i]) < EPS) return Array();
    erep(j, i + 1, n) B[i][j] /= B[i][i];
    rep(j, n) if(i != j) erep(k, i + 1, n) B[j][k] -= B[j][i] * B[i][k];
  }
  Array x(n);
  rep(i, n) x[i] = B[i][n];
  return x;
}

int n, s, t;
int q[111];
double a[111][111];
double d[111];

int main(int argc, char *argv[])
{
  while(cin >> n >> s >> t, n){
    s -= 1;
    t -= 1;
    rep(i, n) cin >> q[i];
    rep(i, n) rep(j, n) cin >> a[i][j];

    rep(i, n) d[i] = INF;
    d[t] = 0.0;
    priority_queue<pair<double, int>, vector<pair<double, int> >, greater<pair<double, int> > > que;
    que.push(mp(0.0, t));
    while(!que.empty()){
      pair<double, int> top = que.top();  que.pop();
      double cost = top.first;
      int v = top.second;
      if(cost > d[v]) continue;
      rep(i, n) if(a[v][i] && minup(d[i], d[v] + a[v][i])) que.push(mp(d[i], i));
    }
    if(d[s] >= INF){
      puts("impossible");
      continue;
    }
    Matrix A(n, Array(n));
    Array b(n);
    rep(i, n) if(i != t){
      double m = 0.0;
      if(q[i]){
        rep(j, n) if(a[i][j] && d[i] == a[i][j] + d[j]){
          A[i][j] = -1.0;
          m += 1;
          b[i] += a[i][j];
        }
        A[i][i] = m;
      }
      else{
        rep(j, n) if(a[i][j]){
          A[i][j] = -1.0;
          m += 1;
          b[i] += a[i][j];
        }
        A[i][i] = m;
      }
    }
    A[t][t] = 1.0;
    printf("%.15f\n", GaussJordan(A, b)[s]);
  }
  
  return 0;
}

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

int main(){
  string p;
  cin>>p;
  int a=0;
  int b=0;
  int c=0;

for(int i = 0;i<p.size();i++){
  if(p[i]>='a'&&p[i]<='z')a=1;
  if(p[i]>='A'&&p[i]<='Z')b=1;
  if(p[i]>='0'&&p[i]<='9')c=1;
}

  if(p.size()>=6&&a&&b&&c){
    cout << "VALID"<<endl;
  }else{
    cout <<"INVALID"<<endl;
  }
}

Measured memory_bytes: 3224
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  int ans=0;
  for(int i=0;i<N;i++){
  	int x;
    cin >> x;
    ans+=min(x,K-x);
  }
  cout << 2*ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;


int Main(int N, int K, int R, int S, int P, string T)
{
    int ans = 0;
    string perfect = "";
    unordered_map<char, char> win;
    win['p'] = 's';
    win['s'] = 'r';
    win['r'] = 'p';
    REP(i, N) {
        perfect.push_back(win[T[i]]);
    }
    REP2(i, K, N) {
        if(perfect[i] == perfect[i-K]) {
            perfect[i] = 'x';
        }
    }
    unordered_map<char, int> score;
    score['p'] = P;
    score['r'] = R;
    score['s'] = S;
    score['x'] = 0;
    REP(i, N) ans += score[perfect[i]];
    return ans;
}

int main(void){
    int N, K, R, S, P;
    string T;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    cout << Main(N, K, R, S, P, T) << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    char s[101];

    scanf("%s", s);

    int len = strlen(s);

    printf("%c%d%c\n", s[0], len-2, s[len-1]);

    return 0;
}

Measured memory_bytes: 1724
use std::io::stdin;
#[allow(dead_code)]
fn input() -> String {
    let mut s = String::new();
    stdin() .read_line(&mut s) .unwrap();
    s.trim().to_string()
}
#[allow(dead_code)]
fn get_value<T: std::str::FromStr>() -> T {
    input().parse().ok().unwrap()
}
#[allow(dead_code)]
fn get_values_for<T: std::str::FromStr>(times: u64) -> Vec<T> {
    (0..times).map(|_| get_value()).collect()
}
#[allow(dead_code)]
fn get_vector<T: std::str::FromStr>() -> Vec<T> {
    input().split_whitespace().map(|v| v.parse().ok().unwrap()).collect()
}
#[allow(dead_code)]
fn get_vectors_for<T: std::str::FromStr>(times: u64) -> Vec<Vec<T>> {
    (0..times).map(|_| get_vector()).collect()
}

fn main() {
    let input = input();
    let sls = input.chars().collect::<Vec<_>>();

    let len = input.len();
    let mut center = len / 2;
    let (mut f,mut l) = (center, center);

    let temp = sls[f];
    if len % 2 == 0 {
        f -= 1;
        center -= 1;
        if sls[f] != temp {
            println!("{}", len / 2);
            return;
        }
    }

    for i in 1..center+1 {
        if sls[f - i] != temp || sls[l + i] != temp {
            println!("{}", len - f + i - 1);
            return;
        }
    }
    println!("{}", len);
}


Measured memory_bytes: 4352
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def calc_distance(x, y, D):
    distance = 0
    for i in range(D):
        distance += (x[i] - y[i])**2
    distance = np.sqrt(distance)
    return distance

def main():
    N, D = map(int, input().split())
    X = []
    for _ in range(N):
        line = [int(i) for i in input().split()]
        X.append(line)
    
    num = 0
    for i in range(N):
        for j in range(i + 1, N):
            distance = calc_distance(X[i], X[j], D)
            if isinstance(distance, int) or distance.is_integer():
                num += 1
    print(num)




    



if __name__ == '__main__':
    main()

Measured memory_bytes: 21764
import sys

input = sys.stdin.readline

n, m= map(int, input().split())

links = [[] for x in range(n + 1)]
sums = [0 for x in range(n + 1)]
adds = [0 for x in range(n + 1)]

links[0].append(1)

buf = [map(int, input().split()) for _ in range(n - 1)]

for link in buf:
  a, b= link
  links[a].append(b)
  links[b].append(a)


buf = [map(int, input().split()) for _ in range(m)]
for px in buf:
  p, x = px
  adds[p] += x

que = [0,[1]]
checked = [0 for x in range(n+1)]

que = [[-1, [0]]]

while que:
  link = que.pop()
  par = link[0]
  childs = link[1]

  for child in childs:
    if checked[child] != 1:
      sums[child] = sums[par] + adds[child]
      que.append([child, links[child]])
      checked[child] = 1

  
print(*sums[1:])

Measured memory_bytes: 159096