akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define mod 1000000007
using namespace std;

bool prime[1000010];
long long dp[1000000];
int q[1000000];

int main(){
	rep(i,1000000)prime[i]=true;
	prime[0]=prime[1]=false;
	loop(i,2,1000000){
		for(int j=2*i;j<1000000;j+=i)prime[j]=false;
	}
	int n;
	cin>>n;
	rep(i,n)cin>>q[i];
	dp[1]=(prime[q[0]]?1:0);
	loop(i,1,n+1){
		dp[i]%=mod;
		if(prime[q[i+1]]&&q[i-1]<q[i+1])dp[i+2]+=dp[i];
		if(prime[q[i]]&&q[i-1]<q[i])dp[i+1]+=dp[i];
	}
	cout<<(dp[n]+dp[n-1])%mod<<endl;
	return 0;
}


Measured memory_bytes: 5240
def gcd(a,b):
    if(a%b==0):
        return b
    else:
        return gcd(b,a%b)
N = int(input())
s = [int(x) for x in input().split()]
tmp = s[0]
for i in s[1:]:
    tmp = gcd(tmp,i)
print(tmp)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;

ll MOD = 1000000007;
ll INF =1<<29;
ll dp[100100];
int main() {
    string n;
    cin >> n;
    char s = n[n.size()-1];
    if (s=='3'){
        cout << "bon" <<endl;
        return 0;
    }
    else if(s=='0'||s=='1'||s=='6'||s=='8'){
        cout << "pon"<<endl;
        return 0;
    }
    else cout << "hon" <<endl;
}

Measured memory_bytes: 3608
# coding: utf-8
# Your code here!
X,Y,A,B,C = [int(i) for i in input().split()]

P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
R = [int(i) for i in input().split()]

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

r_len = min(X+Y, len(R))
V = P[:X] + Q[:Y] + R[:r_len]
V.sort(reverse=True)

print(sum(V[:X+Y]))

Measured memory_bytes: 23340
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int H, W;
int maps[1000][1000];
set<pii> ss[1000][1000];
bool done[1000][1000];
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

bool check(int y, int x) {
	return x >= 0 && x < W && y >= 0 && y < H;
}

int main() {
	cin >> H >> W;
	REP(i, H) REP(j, W) scanf("%d", &maps[i][j]);
	
	priority_queue<pip> pq;
	REP(i, H) REP(j, W) {
		bool ng = false;
		REP(k, 4) {
			int nx = j + dx[k], ny = i + dy[k];
			if (!check(ny, nx)) continue;
			if (maps[i][j] > maps[ny][nx]) { ng = true; continue; }
		}
		if (ng) continue;
		
		done[i][j] = true;
		REP(k, 4) {
			int nx = j + dx[k], ny = i + dy[k];
			if (!check(ny, nx)) continue;
			ss[ny][nx].insert(pii(i, j));
			pq.push(pip(-maps[ny][nx], pii(ny, nx)));
		}
	}
	
	while (!pq.empty()) {
		int x = pq.top().se.se, y = pq.top().se.fi;
		pq.pop();
		
		if (done[y][x]) continue;
		done[y][x] = true;
		
		REP(i, 4) {
			int nx = x + dx[i], ny = y + dy[i];
			if (!check(ny, nx) || done[ny][nx] || maps[y][x] > maps[ny][nx]) continue;
			
			for (set<pii>::iterator it = ss[y][x].begin(); it != ss[y][x].end(); ++it) {
				if (ss[ny][nx].size() >= 2) break;
				ss[ny][nx].insert(*it);
			}
			
			pq.push(pip(-maps[ny][nx], pii(ny, nx)));
		}
	}
	
	int ans = 0;
	REP(i, H) REP(j, W) if (ss[i][j].size() >= 2) ans++;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 139416
#include<bits/stdc++.h>
     
using namespace std;
     
int main(){
     
  int d,n;
     
  cin>>d>>n;
     
  int ans=1;
      
  for(int i=0;i<d;i++){
    ans*=100;
  }


  if(n==100){

    cout<<ans*(n+1)<<endl;

  }else{
    
    cout<<ans*n<<endl;

  }
    		     
  return 0;
     
      
}


Measured memory_bytes: 764
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxn = 3e5 + 5;

int n, x;
ll aoki;
ll sum[maxn];

class Test{
public:
	int b, l, r;
	ll v;
	bool operator <(const Test &another)const{return v < another.v;}
}t[maxn];

bool check(ll md){
	ll ret = 0, rem = md % x, quo = md / x;
	REP(i, 1, n){
		ll res = 0;
		if(rem >= t[i].b)
			res += 1ll * t[i].b * t[i].l + (rem - t[i].b) * t[i].r;
		else
			res += rem * t[i].l;
		//printf("md = %lld i = %d res = %lld\n", md, i, res);
		if(i > quo)
			res += sum[quo];
		else
			res += sum[quo + 1] - t[i].v;
		//printf("md = %lld i = %d res = %lld\n", md, i, res);
		if(res + aoki >= 0)
			return true;
	}
	if(sum[quo] + aoki >= 0)
		return true;
	return false;
}

int main(){
	scanf("%d%d", &n, &x);
	REP(i, 1, n){
		scanf("%d%d%d", &t[i].b, &t[i].l, &t[i].r);
		t[i].v = 1ll * t[i].b * t[i].l + 1ll * (x - t[i].b) * t[i].r;
		aoki -= 1ll * t[i].b * t[i].l;
	}
	//printf("%d\n", aoki);
	sort(t + 1, t + n + 1);
	reverse(t + 1, t + n + 1);
	REP(i, 1, n + 1)
		sum[i] = sum[i - 1] + t[i].v;
	ll lb, rb;
	for(lb = -1, rb = 1ll * n * x + 1; lb + 1 < rb;){
		ll md = lb + rb >> 1;
		if(check(md))
			rb = md;
		else
			lb = md;
	}
	printf("%lld\n", rb);
	return 0;
}



Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=s.length();

    string s1=s;
    reverse(s.begin(),s.end());
    string s2;
    string s3;
    string s4;
    string s5;
    if(s==s1)
    {
      s3=s.substr (0,((n-1)/2)); 
       s4=s3;
       reverse(s3.begin(),s3.end());
       if(s4==s3)
       {
            s4=s.substr ((n+3)/2-1,n); 
           s5=s4;
            reverse(s4.begin(),s4.end());
       }
       else{
           cout<<"No";
           return 0;
       }
       if(s4==s5)
       {
          cout<<"Yes";
          return 0;
       }
       else{
           cout<<"No";
           return 0;
       }
    }
    else{
       cout<<"No";
    }
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val k = sc.nextInt()
    val s = sc.next()

    val ans = if (s.length <= k) s else s.take(k) + "..."

    println(ans)
  }

  //region

  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
    Console.err.flush()
  }

  def printExecTime(process: => Unit): Unit = {
    val start = System.currentTimeMillis
    process
    debug("処理時間： " + (System.currentTimeMillis - start) + " ミリ秒")
  }

  def bitSearch[T](n: Int, choice: Vector[T]): Vector[Vector[T]] = {
    @tailrec
    def bitSearchLogic(n: Int,
                       choice: Vector[T],
                       acc: Vector[Vector[T]]): Vector[Vector[T]] = {
      if (n == 0) acc
      else {
        val newAcc =
          acc.flatMap(vec => {
            choice.map(c => vec :+ c)
          })
        bitSearchLogic(n - 1, choice, newAcc)
      }
    }

    val firstAcc = choice.map(i => Vector(i))
    bitSearchLogic(n - 1, choice, firstAcc)
  }
  //endregion
}


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

ll n,q;
vector<vector<ll>>paths;
vector<ll>sc;

void dfs(int v, int p) {
    sc.at(v) += sc.at(p);
    for (int e : paths.at(v)) if (p != e) dfs(e, v);
}

void input(){
    cin>>n>>q;
    ll a,b;
    sc.resize(n+1,0);
    paths.resize(n+1);
    rep(i,n-1){
        cin>>a>>b;
        paths[a].push_back(b);
        paths[b].push_back(a);
    }

    int x,p;
    rep(i,q){
        cin>>p>>x;
        sc[p]+=x;
    }
}
void src(){
    dfs(1,0);
    repi(j,1,n+1){cout<<sc[j]<<" ";}
    return;
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
} edge;
int main( void ){
	string S; cin >> S;
	int lim = S.size()/2, ans = 0;
	rep(i,1, lim+1){
		bool is_correct = true;
		rep(j,0,i){
			if (S[j] != S[i+j]){
				is_correct = false;
				break;
			}
		}
		if (is_correct && i*2 != S.size())
			ans = i*2;
	}
	cout << ans << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vite ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tst lli T; cin>>T; while(T--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define lli long long int
#define vt vector
#define pb push_back
int main()
{
    vite;
    lli n;
    cin >> n;
    lli a[10001] = {0}, k;
    for (lli x = 1; x <= 100;x++)
    {
        for (lli y = 1; y <= 100;y++)
        {
            for (lli z = 1; z <= 100;z++)
            {
                k = x * x + y * y + z * z + x * y + z * y + z * x;
                if(k<=10000)
                    a[k]++;
            }
        }
    }

    for (lli i = 1; i <= n;i++)
        cout << a[i]<<"\n";
        // cout<<endl<<fixed << 1.0 * clock() / CLOCKS_PER_SEC << setprecision(5);
        return 0;
}

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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  ll n;
  cin>>n;
  
  ll c=0;
  ll i;
  for(i=1;i*i<n;i++)
  {
    if(n%i==0)
      c+=(n/i-i);
    else
      c+=(n/i-i+1);
  }
  i--;
  c*=2;
  cout<<c-i;
  
}
    

Measured memory_bytes: 3588
a,b,c = map(int,input().split())
ans = 0
cache = {(a,b,c):True}
while not(a % 2 or b % 2 or c % 2):
    a, b, c = b // 2 + c // 2, a // 2 + c // 2, a // 2 + b // 2
    if cache.get((a,b,c)):
        ans = -1
        break
    cache[(a,b,c)] = True
    ans += 1
print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr ll INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

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

    int n; cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    multiset<int> st;
    st.emplace(-1);
    st.emplace(1e9+1);

    int ans = 0;
    for(int i=0; i<n; i++){
        auto itr = st.lower_bound(a[i]);
        itr--;

        if(*itr == -1){
            ans++;
        }
        else{
            st.erase(itr);
        }

        st.emplace(a[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 5376
//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Rd(a) (a=rd())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int rd(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=x*10+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (60)
int n,m,s,ans[N]{0,-1},u,v,a,b,c[N],d[N],mx[N];
struct E{int v,a,b;};
vector<E>e[N];
struct Q{int u,m,d;bool operator<(Q b)const{return d>b.d;}}t;
priority_queue<Q>q;
signed main(){
	*ans=Rd(n)-1,Rd(m),q.push({1,rd(),0}),Mst(mx,-1);
	while(m--)Rd(u),Rd(v),s+=Rd(a),Rd(b),e[u].push_back({v,a,b}),e[v].push_back({u,a,b});
	Frn1(i,1,n)Rd(c[i]),Rd(d[i]);
	while(!q.empty()){
		t=q.top(),q.pop(),t.m=min(t.m,s);
		if(mx[t.u]>=t.m)continue;mx[t.u]=t.m;
		if(!ans[t.u]){ans[t.u]=t.d;if(!--*ans)break;}
		q.push({t.u,t.m+c[t.u],t.d+d[t.u]});
		for(E i:e[t.u])if(i.a<=t.m)q.push({i.v,t.m-i.a,t.d+i.b});
	}
	Frn1(i,2,n)wr(ans[i]),Pe;
	exit(0);
}


Measured memory_bytes: 3748
N = int(input())
A = [0] * N
for i in range(N):
  A[i] = int(input())
  
ans = 0  
for i in range(N - 1):
  if A[i] >= A[i + 1]:
    now = int((A[i]) / 2)
    ans += now
    A[i] -= now * 2
    now2 = min(A[i], A[i + 1])
    ans += now2
    A[i + 1] -= now2
    A[i] -= now2
    
  else:
    now = A[i]
    ans += now
    A[i] -= now
    A[i + 1] -= now
  #print(ans)
ans += int(A[-1] / 2)  
#print(A)
print(ans)
  
        
        
        

Measured memory_bytes: 75724
#include<cstdio> 
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
typedef long long ll;
typedef double db;
const int N=2e5+5,mo=1e9+7;
struct rec
{
	int sum,cnt;
}tr[N*4],tmp;
int tag[N*4];
rec operator +(rec a,rec b)
{
	return {(a.sum+b.sum)%mo,a.cnt+b.cnt};
}
int n,a[N],cnt[N],prod,i,x,fac,d[N],ans,rev2;
int tt,b[N],nxt[N],fst[N];
void cr(int x,int y)
{
	tt++;
	b[tt]=y;
	nxt[tt]=fst[x];
	fst[x]=tt;
}
int ksm(int x,int y)
{
	int ret=1;
	while (y)
	{
		if (y&1) ret=1ll*ret*x%mo;
		y>>=1;
		x=1ll*x*x%mo;
	}
	return ret;
}
void dw(int x,int s)
{
	if (tag[x]==1) return ;
	if (!s) tag[x*2]=1ll*tag[x*2]*tag[x]%mo,tag[x*2+1]=1ll*tag[x*2+1]*tag[x]%mo;
	tr[x].sum=1ll*tr[x].sum*tag[x]%mo;
	tag[x]=1;
}
rec get(int x,int l,int r,int i,int j)
{
	if (l==i&&r==j) return tr[x];
	int m=l+r>>1;
	dw(x*2,l==m);
	dw(x*2+1,m+1==r);
	rec ret={0,0};
	if (i<=m) ret=ret+get(x*2,l,m,i,min(m,j));
	if (m<j)  ret=ret+get(x*2+1,m+1,r,max(i,m+1),j);
	return ret;
}
void change(int x,int l,int r,int p,int v)
{
	if (l==r) 
	{
		tr[x].cnt=1,tr[x].sum=v;
		return ;
	}
	int m=l+r>>1;
	dw(x*2,l==m);
	dw(x*2+1,m+1==r);
	if (p<=m) change(x*2,l,m,p,v);
	else change(x*2+1,m+1,r,p,v);
	tr[x]=tr[x*2]+tr[x*2+1];
}
int main()
{
	scanf("%d",&n);
	fo(i,1,n) 
	{
		scanf("%d",a+i);
		cr(a[i],i);
		cnt[a[i]]++;
	}
	fd(i,n,1) cnt[i]+=cnt[i+1];
	prod=1;
	fo(i,1,n) prod=1ll*prod*(cnt[i]-(n-i))%mo;
	fo(i,1,n*4) tag[i]=1;
	rev2=ksm(2,mo-2);
	fd(x,n,1)
	{
		d[0]=0;
		for(int p=fst[x];p;p=nxt[p]) d[++d[0]]=b[p];
		fac=ll(cnt[x]-1-(n-x))*ksm(cnt[x]-(n-x),mo-2)%mo;
		fo(i,1,d[0])
		{
			tmp=get(1,1,n,d[i],n);
			ans=(ans+1ll*tmp.sum*rev2)%mo;
			tmp=get(1,1,n,1,d[i]);
			ans=(ans+1ll*tmp.cnt*prod-1ll*tmp.sum*rev2)%mo;
		}
		ans=(ans+1ll*d[0]*(d[0]-1)/2%mo*prod%mo*rev2)%mo;
		fo(i,1,d[0]) change(1,1,n,d[i],prod);
		tag[1]=1ll*tag[1]*fac%mo;
		dw(1,1==n);
	}
	if (ans<0) ans+=mo;
	printf("%d",ans);
}

Measured memory_bytes: 12544
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int N=3;
  string S;
  cin>>S;
  if(S=="SSS") N=0;
  if(S=="SSR") N=1;
  if(S=="SRR") N=2;
  if(S=="RRR") N=3;
  if(S=="SRS") N=1;
  if(S=="RRS") N=2;
  if(S=="RSR") N=1;
  if(S=="RSS") N=1;
  cout<<N<<endl;
return 0;}


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

#define int long long
typedef pair<int, int> Pii;
const int INF = 1e9;

Pii dist(vector<vector<int> > G, string c, int N, int s) {
  vector<int> dis(N, 0);
  bool used[N] = {0};
  queue<int> Q;
  Q.push(s);
  vector<int> deg(N, 0);
  for ( int i = 0; i < N; i++ ) deg[i] = G[i].size();
  while ( !Q.empty() ) {
    int p = Q.front(); Q.pop();

    if ( used[p] ) continue;
    used[p] = true;

    for ( int v : G[p] ) {
      if ( used[v] ) continue;      
      dis[v] = dis[p]+((deg[v]%2)^(c[v]=='W'));      
      Q.push(v);
    }
  }
   
  int ma = dis[0];
  int id = 0;
  for ( int i = 1; i < N; i++ ) {
    if ( ma <= dis[i] && deg[i] == 1 ) {
      ma = dis[i];
      id = i;
    }
  }

  return Pii(ma, id);
}

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

  vector<vector<int> > G(N);
  string c;
  vector<int> x(N), y(N);
  for ( int i = 0; i < N-1; i++ ) {
    cin >> x[i] >> y[i];
    x[i]--; y[i]--;
    G[x[i]].emplace_back(y[i]);
    G[y[i]].emplace_back(x[i]);
  }
  cin >> c;

  if ( N == 1 ) {
    cout << (int)(c[0]=='W') << endl;
    return 0;
  }

  bool unuse[N] = {0};
  {
    vector<int> deg(N, 0);
    for ( int i = 0; i < N; i++ ) deg[i] = G[i].size();
    queue<int> Q;
    for ( int i = 0; i < N; i++ ) {
      if ( deg[i] == 1 && c[i] == 'B' ) {
	Q.push(i);
	deg[i]--;
      }
    }
    while ( !Q.empty() ) {
      int p = Q.front(); Q.pop();      

      if ( unuse[p] ) continue;
      unuse[p] = true;

      for ( int v : G[p] ) {
	if ( --deg[v] == 1 && c[v] == 'B' ) {
	  Q.push(v);
	}
      }
    }

    for ( int i = 0; i < N; i++ ) G[i].clear();
    for ( int i = 0; i < N-1; i++ ) {
      if ( !unuse[x[i]] && !unuse[y[i]] ) {
	G[x[i]].emplace_back(y[i]);
	G[y[i]].emplace_back(x[i]);
      }
    }
  }

  int n = 0;
  for ( int i = 0; i < N; i++ ) if ( !unuse[i] ) n++;
  if ( n == 0 ) {
    cout << 0 << endl;
    return 0;
  }
  
  vector<int> deg(N, 0);
  for ( int i = 0; i < N; i++ ) deg[i] = G[i].size();
  int ans = 2*(n-1);
  for ( int i = 0; i < N; i++ ) {
    if ( !unuse[i] ) {
      ans += (deg[i]%2)^(c[i]=='W');
    }
  }

  Pii p;
  for ( int i = 0; i < N; i++ ) {
    if ( unuse[i] || c[i]=='B' || deg[i]>=2 ) continue;
    p = dist(G, c, N, i);
    break;
  }

  cout << ans - 2*(dist(G, c, N, p.second).first) << endl;
  
  return 0;
}
    


Measured memory_bytes: 17892
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  double y = abs(y1 - y2);
  double x = abs(x1 - x2);
  cout << fixed << setprecision(10) << sqrt(x * x + y * y) << endl;
}



Measured memory_bytes: 3292
//input.c
#include <stdio.h>
#include<stdlib.h>


int main(void){
  
  long K;
  long A;
  long B;

  scanf("%ld %ld %ld",&K,&A,&B);
 long count = 1;
 for( long i=K;0<i;i-- )
 {
  if( 2<=(B-A) && 2<=i && A<=count)
  {  
    count +=(B-A);
    i--;
  }
else
{
count++;
}
//printf("%d,%d----",i,count);
 }
printf("%ld",count);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner

object Main {
  val sc = new Scanner(System.in)
  def main(args: Array[String]): Unit = {
    val a = sc.nextLong
    val b = sc.nextLong
    val c = sc.nextLong

    val res =
      if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0 ) 0L
      else Seq(a * b, b * c , c * a).min

    println(res)
  }

}

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

using namespace std;
int main(){
    long long int H,N;
    cin >> H >> N;

    vector<long long int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    long long int T = H;
    for(int i = 0; i < N; i++){
        T -= A[i];
    }

    if(T <= 0) cout << "Yes";
    else cout << "No";

 return 0;
}

Measured memory_bytes: 1024
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;


int main()
{

	ll N;
	cin >> N;

	vector<ll> v(N), L(N);
	rep(i, N)
	{
		cin >> L[i];
	}
	ll res = 0;
	sort(L.begin(), L.end());
	for (ll i = 0; i < N; i++)
	{
		for (ll j = i + 1; j < N; j++) {
			ll k = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();
			res += max(k - (j + 1), (ll)0);
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, x int64
	fmt.Scan(&a, &b, &x)
	if a%x != 0 {
		a += x - a%x
	}
	if b%x != 0 {
		b -= b % x
	}
	if a > b {
		fmt.Println(0)
	} else {
		fmt.Println((b-a)/x + 1)
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    string s;
    cin >> s;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]){
        cout << "Bad" << endl;
    }
    else{
        cout << "Good" << endl;
    }
}

Measured memory_bytes: 256
def koch(n, p1, p2):
    if n == 0:
        return

    s_x = p1[0] * 2/3 + p2[0] * 1/3
    s_y = p1[1] * 2/3 + p2[1] * 1/3

    t_x = p1[0] * 1/3 + p2[0] * 2/3
    t_y = p1[1] * 1/3 + p2[1] * 2/3

    u_x = (t_x - s_x) * 1/2 - (t_y - s_y) * 3 ** 0.5 / 2 + s_x
    u_y = (t_x - s_x) * 3 ** 0.5 / 2 + (t_y - s_y) / 2 + s_y

    s, t, u = (s_x, s_y), (t_x, t_y), (u_x, u_y)
    
    koch(n - 1, p1, s)
    print(' '.join(str(i) for i in s))
    koch(n - 1, s, u)
    print(' '.join(str(i) for i in u))
    koch(n - 1, u, t)
    print(' '.join(str(i) for i in t))
    koch(n - 1, t, p2)
    
    
S, G = (0, 0), (100, 0)
print(' '.join(str(i) for i in S))
koch(int(input()), S, G)
print(' '.join(str(i) for i in G))



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

int main(){
    int x,y;
    cin>>x>>y;
    int tmp=y-2*x;
    if(tmp>=0 && tmp%2==0 && x-tmp/2>=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

using namespace std;
typedef long long int ll;
int main() {
	// your code goes here
	
	
	ll n,i,j;
	cin>>n;
	ll a[n];
	for(i=1;i<=n;i++){
	    cin>>j;
	    a[j-1]=i;
	}
	for(i=0;i<n;i++){
	    cout<<a[i]<<" ";
	}
	
    return 0;
}


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

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

long long read(void) {
	long long d;
	cin >> d;
	return d;
}
string readString(void) {
	static char s[4096];
	cin >> s;
	return string(s);
}
void println(void) {
	cout << endl;
}
template <typename T>void print(T t) {
	cout << t;
}
template <typename T>void println(T t) {
	print(t);
	println();
}

class Dice{
public:
	Dice(vector<int> dice): Points_(dice) {
	}
	~Dice() {}
	int Top(void) const { return Points_[0]; }
	Dice& Role(char c){
		switch (c)
		{
		case 'N': RoleN(); break;
		case 'E': RoleE(); break;
		case 'S': RoleS(); break;
		case 'W': RoleW(); break;
		default:
			break;
		}
		return *this;
	}
	Dice& Roles(const string& roles) {
		REP(i, roles.size()) {
			Role(roles[i]);
		}
		return *this;
	}
private:
	vector<int> Points_;
	void RoleN(void) {
		int temp = Points_[0];
		Points_[0] = Points_[1];
		Points_[1] = Points_[5];
		Points_[5] = Points_[4];
		Points_[4] = temp;
		return;
	}
	void RoleE(void) {
		int temp = Points_[0];
		Points_[0] = Points_[3];
		Points_[3] = Points_[5];
		Points_[5] = Points_[2];
		Points_[2] = temp;
		return;
	}
	void RoleS(void) {
		int temp = Points_[0];
		Points_[0] = Points_[4];
		Points_[4] = Points_[5];
		Points_[5] = Points_[1];
		Points_[1] = temp;
		return;
	}
	void RoleW(void) {
		int temp = Points_[0];
		Points_[0] = Points_[2];
		Points_[2] = Points_[5];
		Points_[5] = Points_[3];
		Points_[3] = temp;
		return;
	}
};

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

	vector<int> points(6);
	REP(i, points.size()) {
		points[i] = read();
	}
	Dice dice(points);
	println(dice.Roles(readString()).Top());
	return 0;
}



Measured memory_bytes: 3212
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include<deque>

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
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 (a > b) { a = b; return 1; }
	return 0;
}


int main()
{
	int n;
	int b[101];
	cin >> n;
	REP(i, n) {
		cin >> b[i];
	}
	b[n-1] = INF;

	int ans = b[0];
	//cout << ans << endl;
	REP(i, n-1) {
		ans += min(b[i], b[i + 1]);
		//cout << ans << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a, b, c;
	int d=0;
	scanf("%d %d %d", &a, &b, &c);
	for(int i=1; i<=a; i++){
		int x=i;
		int ttl=0;
		while(x>0){
			ttl+=x%10;
			x/=10;
		}
		if(ttl>=b && ttl<=c){
			d+=i;
		}
	}
	printf("%d", d);
	return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>


int main()
{
    int n;
    std::cin >> n;

    if (n % 10 == n / 100){
        std::cout << "Yes\n";
    }else{
        std::cout << "No\n";
    }
}

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

int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    a[i] -= i + 1;
  }
  sort(a.begin(), a.end());
  long long sum = 0;
  for (long long i = 1; i < n; i++) {
    a[i] -= a[0];
    sum += a[i];
  }
  a[0] = 0;
  priority_queue<long long, vector<long long>, greater<long long>> pq;
  pq.push(sum);
  long long cnt = 1;
  for (long long i = 1; i < n; i++) {
    if (a[i] == a[i - 1]) {
      cnt++;
      continue;
    }
    sum += i * (a[i] - a[i - 1]);
    sum -= (n - i) * (a[i] - a[i - 1]);
    pq.push(sum);
  }
  cout << pq.top() << endl;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

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

    vector<int> arr(n);
    int x = INF;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        int p;
        cin >> p;
        x = min(p, x);
        if (x == p)
            ans++;
    }
    cout << ans << endl;
}

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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
  int n, q;
  while(cin >> n >> q, n+q) {
    int s[100] = {};
    rep(i, n) {
      int m; cin >> m;
      rep(j, m) {
        int d; cin >> d;
        s[d-1]++;
      }
    }

    int  cnt = -1, p;
    rep(i, 100) {
      if(cnt < s[i]) {
        cnt = s[i];
        p = i+1;
      }
    }
    if(cnt >= q) cout << p << endl;
    else cout << 0 << endl;
  }
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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

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

    ll K;
    cin >> K;

    ll ans = 0;
    for (ll a = 1; a <= K; a++) {
        for (ll b = 1; b <= K; b++) {
            for (ll c = 1; c <= K; c++) {
                ll tmp = gcd(a, b);
                tmp = gcd(tmp, c);
                ans += tmp;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

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

int main(){
    int x,n;
    cin >> x >> n;
    vector<bool> flag(110,false);
    int t;
    rep(i,n){
        cin >> t;
        flag[t] = true;
    }
    int num = 1e9;
    int ans = -1;
    rep(i,110){
        if(!flag[i]){
            if(num > abs(x-i)){
                //cout << num << " " << abs(x-i) << endl;
            
                //cout << i << endl;
                ans = i;
                num = abs(x-i);
            }
        }
    }

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

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

class Index {
  public:
  ll a, b, c;

  Index(ll a, ll b, ll c): a(a), b(b), c(c) {}

  bool operator<(const Index& other) const {
    return a < other.a;
  }
};

int main() {
  ll X, Y, Z, K;
  cin >> X >> Y >> Z >> K;

  vector<ll> A(X);
  vector<ll> B(Y);
  vector<ll> C(Z);
  for (ll i = 0; i < X; i++) cin >> A[i];
  for (ll i = 0; i < Y; i++) cin >> B[i];
  for (ll i = 0; i < Z; i++) cin >> C[i];

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  sort(C.begin(), C.end());
  reverse(C.begin(), C.end());

  priority_queue< pair<ll, Index> > pq;
  pq.push(make_pair(A[0] + B[0] + C[0], Index(0, 0, 0)));

  vector<ll> ans;
  set<ll> s;
  while(ans.size() < K) {
    auto v = pq.top();pq.pop();
    ans.push_back(v.first);
    if (v.second.a != X - 1) {
      ll a = v.second.a + 1;
      ll b = v.second.b;
      ll c = v.second.c;
      ll hash = (a << 20) + (b << 10) + (c);
      if (s.find(hash) == s.end()) {
        s.insert(hash);
        pq.push(make_pair(A[a] + B[b] + C[c], Index(a, b, c)));
      }
    }

    if (v.second.b != Y - 1) {
      ll a = v.second.a;
      ll b = v.second.b + 1;
      ll c = v.second.c;
      ll hash = (a << 20) + (b << 10) + (c);
      if (s.find(hash) == s.end()) {
        s.insert(hash);
        pq.push(make_pair(A[a] + B[b] + C[c], Index(a, b, c)));
      }
    }

    if (v.second.c != Z - 1) {
      ll a = v.second.a;
      ll b = v.second.b;
      ll c = v.second.c + 1;
      ll hash = (a << 20) + (b << 10) + (c);
      if (s.find(hash) == s.end()) {
        s.insert(hash);
        pq.push(make_pair(A[a] + B[b] + C[c], Index(a, b, c)));
      }
    }
  }

  for (ll i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}



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

int n, k, x[101010];


int main()
{
    cin >> n >> k;
    rep(i, n) cin >> x[i];

    int res = 1e9;
    rep(i, n - k + 1)
    {
        int l = x[i], r = x[i + k - 1];
        res = min(res, abs(l - r) + min(abs(l), abs(r)));
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#define BLACK 1
#define WHITE 0
#define GRAY -1
#define NUM 100
#define INF 1000000

int main(){
  int i,n,j,a[NUM][NUM],u,k,v,d[NUM],pi[NUM],color[NUM],minv;
  scanf("%d",&n);

  for(i=0;i<NUM;i++){
    for(j=0;j<NUM;j++){
      a[i][j]=INF;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      scanf("%d",&a[u][v]);
    }
  }
  for(v=0;v<n;v++){
    d[v]=INF;
    pi[v]=-1;
    color[v]=WHITE;
  }
  d[0]=0;

  while(1){
    minv=INF;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<minv){
	minv=d[i];
	u=i;
      }
    }
    if(minv==INF){
      break;
    }
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK&&a[u][v]!=INF){
	if(d[u]+a[u][v]<d[v]){
	  pi[v]=u;
	  d[v]=d[u]+a[u][v];
	  color[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]==INF){
      printf("%d\n",-1);
    }else{
      printf("%d\n",d[i]);
    }
  }
  return 0;
}



Measured memory_bytes: 2108
def main():
  n = int(input())
  data = list(map(int, input().split()))
  if 0 in data:
    print(0)
    return
  
  c = 1
  for d in data:
    c *= d
    if c > 10 ** 18:
      print(-1)
      return
  
  print(c)


if __name__ == "__main__":
  main()


Measured memory_bytes: 21792
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var s = ReadText();
            
            var r = "";
            foreach (var item in s)
            {
                switch (item)
                {
                    case '0': r += "0"; break;
                    case '1': r += "1"; break;
                    case 'B':
                        if (!string.IsNullOrEmpty(r))
                        {
                            r = r.Substring(0, r.Length - 1);
                        }
                        break;
                    default:
                        break;
                }
            }
            return r;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 25884
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			double x[] = new double[3];
			double y[] = new double[3];
			String[] str = sc.next().split(",");
			for(int i=0;i<3;i++) {
//				System.out.println(str[2*i] + " " + str[1] + " " + x[i] + " " + y[i]);
				x[i] = Double.parseDouble(str[2*i]);
				y[i] = Double.parseDouble(str[2*i+1]);
//				System.out.println(str[0] + " " + str[1] + " " + x[i] + " " + y[i]);
			}
			double dx = x[1]-x[0];
			double dy = y[1]-y[0];
			double rety = (x[2]-2*x[0]) * dx * dy - (y[2]-2*y[0]) * dx * dx
							+ dy * dx * x[2] + dy * dy * y[2];
			double retx = (y[2]-2*y[0]) * dx * dy - (x[2]-2*x[0]) * dy * dy
							+ dx * dx * x[2] + dx * dy * y[2];
			rety /= dx*dx+dy*dy;
			retx /= dx*dx+dy*dy;
			System.out.println(retx + " " + rety);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;
    sort(_all(a), greater<int>());

    int A = 0, B = 0;
    rep(i, n){
        (i % 2 ? B:A) += a[i];
    }

    cout << A - B << endl;

    return 0;
}


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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;
	vector<int> a(n);
	REPU(i, 0, n) {
		cin >> a[i]; --a[i];
	}
	int ans = 0;
	REPU(i, 0, n) {
		if (a[i] == i) {
			if (i + 1 < n) swap(a[i], a[i + 1]);
			else if (i > 0) swap(a[i], a[i - 1]);
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


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

public class Main{

	public static void main(String[] args) throws IOException {
		String s = read(); int cnt = 700; for(int i = 0; i<s.length(); i++) if(s.charAt(i) == 'o') cnt += 100; println(cnt);
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	public void close() throws IOException {
		if (din == null)
			return;
		din.close();
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


Measured memory_bytes: 21204
#!/usr/bin/env python3
import sys


def solve(N: int, S: "List[str]"):
    count = [0] * 5
    for s in S:
        if s[0] in 'MARCH':
            idx = 'MARCH'.find(s[0])
            count[idx] += 1
    ret = 0
    for i1 in range(5):
        for i2 in range(i1 + 1, 5):
            for i3 in range(i2 + 1, 5):
                ret += count[i1] * count[i2] * count[i3]
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9816