akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int mul_count(int k, int n) {
  int count = 0;
  while(1) {
    if(n >= k) break;
    n *= 2;
    count++;
  }
  return count;
}

int main(int argc, char *argv[])
{
  int n, k;
  cin >> n >> k;
  double ans = 0.0;
  for (int i = 1; i <= n; ++i) {
    ans += (1.0 / (double)n * pow(1.0/2.0, (double)mul_count(k, i)));
  }
  cout << fixed;
  cout << setprecision(9);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}


const long long INF = 1LL << 60;

//bucket1
// bool ch[10] = {0};
// bool check(int n){
//     while(n!=0){
//         if(ch[n%10]) return false;
//         n /= 10;
//     }
//     return true;
// }



// --------write my code!!!!!----------//


int main(){
    long long res;
    int x,y; cin >> x >> y;
    res = y*pow(y-1,x-1);
    cout << res << endl;
} 


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

using namespace std;

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

	if (N == 0) {
		cout << X << endl;
		return 0;
	}
	vector < int >p(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}

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

	int leftIndex, rightIndex;
	leftIndex = rightIndex = 0;
	for (int i = 1; i < N; i++) {
		if (abs(p[i] - X) < abs(p[leftIndex] - X)) {
			leftIndex = rightIndex = i;
		}
	}

	for (int i = 0; i <= 100; i++) {
		int smallX = X - i;
		int bigX = X + i;
		if (p[leftIndex] == smallX) {
			leftIndex = max(leftIndex - 1, 0);
		} else {
			cout << smallX << endl;
			break;
		}

		if (p[rightIndex] == bigX) {
			rightIndex = min(rightIndex + 1, N - 1);
		} else {
			cout << bigX << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<int,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	string str;
	while(true){
		getline(cin,str);
		vi num;
		stringstream ss(str);
		int tmp;
		while(ss >> tmp){
			num.PB(tmp);
		}
		if(num[0] == 0)break;
		int one = 0;
		int ans = 0;
		rep(i,num.size()){
			if(num[i]==1){
				ans++;
				one++;
			}
			else{
				if(num[i] > 9){
					ans+=10;
				}
				else{
					ans+=num[i];
				}
			}
		}
		while(one--){
			if(ans+10 < 22){
				ans += 10;
			}
		}
		if(ans >= 22)ans = 0;
		printf("%d\n",ans);
    }
    return 0;
}

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

def solve():
    s = input()
    f, t = s[:2], s[2:]
    YYMM = 0 <= int(f) <= 99 and 1 <= int(t) <= 12
    MMYY = 0 <= int(t) <= 99 and 1 <= int(f) <= 12
    if YYMM and MMYY:
        print('AMBIGUOUS')
    elif YYMM:
        print('YYMM')
    elif MMYY:
        print('MMYY')
    else:
        print('NA')

if __name__=="__main__":
    solve()

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>



using namespace std;
typedef long long ll;
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}

int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}









int main() {
  long long X,Y;
  cin>>X>>Y;
  long long sum=1;
  while(X*2<=Y){
    
      X*=2;
      sum++;
    }

  
  cout<<sum<<endl;

  



  

  


  

    


  

  
  
  
  
}


  

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

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

    ll a,b,c;
    cin>>a>>b;
    c=__gcd(a,b);
    c=(a*b)/c;
    cout<<c<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;


char buf[100];
int main(void) {
  int n;
  scanf("%d", &n);
  double res = 0;
  REP(i, n) {
    double x;
    scanf("%lf%s", &x, buf);
    if(buf[0] == 'J') {
      res += x;
    } else {
      res += x * 380000.0;
    }
  }
  printf("%.10f\n", res);
  return 0;
}


Measured memory_bytes: 888
# -*- coding:utf-8 -*-
n = int(input())
s=''

for i in range(1,n+1):
    if i%3==0 or i%10==3:
        s = s + " " + str(i)
        continue
    else:
        x = i
        while x >0:
            x //= 10
            if x%10==3: 
                s = s + " " + str(i)
                break
print(s)

Measured memory_bytes: 7632
#include <iostream>
#include <cstring>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    bool flag= false;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        if(x%2==0){
            if(x%3!=0 && x%5!=0){
                cout << "DENIED\n";
                flag = true;
                break;
            }
        }
    }
    if(!flag)cout << "APPROVED\n";
}

Measured memory_bytes: 256
n, m, c = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
a = [[int(_) for _ in input().split()] for i in range(n)]
sum = 0
cnt = 0
for i in range(n):
  sum = 0
  for j in range(m):
    sum += a[i][j] * b[j]
  if sum + c > 0:
    cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    cout << n*(n-1)/2<< endl;
}

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

int main(){
  int n,d,x;
  cin >> n >> d >> x;
  vector<int> A(n);
  rep(i,n) cin >> A[i];
  int ans = x;
  rep(i,n){
    ans += ((d-1) / A[i]) + 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int y=sc.nextInt();
		int ans10=-1;
  		int ans5=-1;
  		int ans1=-1;
  		
		for(int c=n;c>=0;c--){
          for(int d=n-c;d>=0;d--){
            int e=n-c-d;
    		if((c*10000+d*5000+e*1000)==y){
            ans10=c;
            ans5=d;
            ans1=e;
           break;
            }
          }
            if(ans10!=-1){
            break;
            }
    	}
  

    	System.out.println(ans10);
          System.out.println(ans5);
          System.out.println(ans1);
    }
}


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

using ll = long long int;
typedef long double ld;
typedef pair<ll,ll> pll;

#define sz(v) (ll)v.size()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll a;
	bool f=1;
	for(ll i=0;i<n;i++)
	{
		cin>>a;
		if(!f)continue;
		if(a%2==0)
		{
			if(!(a%3==0 or a%5==0))
				f=0;
		}
	}
	if(f)cout<<"APPROVED\n";
	else cout<<"DENIED\n";
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

counter = 0

for i in range(N):
    if B_list[i] <= A_list[i]:
        # B_list[i] = B_list[i] - A_list[i]
        counter += B_list[i]
    
    else:
        if B_list[i] <= A_list[i] + A_list[i+1]:
            A_list[i+1] = A_list[i+1] - (B_list[i] - A_list[i])
            counter += B_list[i]

        else:
            counter += A_list[i] + A_list[i+1]
            A_list[i+1] = 0

print(counter)


Measured memory_bytes: 18476
#define p(b,c)printf("%d %d %d ",i,b,c)
i;L;a;main(l){for(scanf("%d",&L);L>>l;)a+=L>>l++-1&1;printf("%d %d ",l,l*2-2+a);for(;++i<l;)p(i+1,0),p(i+1,a=1<<i-1),L&a&&p(l,L-=a);}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

int arr[200005];
int n, k;

bool check(int cuts) {
    int req = 0;
    for(int i = 0; i < n; i++) {
        req += ((arr[i] + cuts - 1) / cuts - 1);
    }
    return  req <= k;
}


int32_t main() {

    fast
    cin >> n >> k;

    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    int left = 1, right = (int)1e10 + 5;

    int ans = 0;
    while(left <= right) {
        int mid = (left + right) / 2;
        if(check(mid)) {
            ans = mid;
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }
    cout << ans << endl;



    return 0;
}



Measured memory_bytes: 5136
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
ll process1(ll n){
  ll a = n/500;
  ll b = (n%500)/5;
  // cout<<1000*a+5*b<<endl;
  return 1000*a+5*b;
}
ll process2(ll n){
  ll a = n/5;
  // cout<<5*a<<endl;
  return (5*a);
}
int main(){
  FIO;
  // ifstream cin("input");
  ll n;
  cin>>n;
  cout<<max(process1(n), process2(n))<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<iomanip>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}

int atcoder(){
    int a,b;
    cin>>a>>b;
    cout<<max({2*a-1,a+b,2*b-1})<<ENT;
    return 0;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int K, N;
  cin >> K >> N;
  vector<int> A(N);

  rep(i, N) cin >> A[i];

  int max_dist = A[0] + (K-A[N-1]);

  rep(i, N-1){
    chmax(max_dist, A[i+1] - A[i]);
  }

  cout << K - max_dist << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;


int main(){
  int n, m, X, Y;
  cin >> n >> m >> X >> Y;
  int x[100], y[100];
  rep(i, n) cin >> x[i];
  rep(i, m) cin >> y[i];
  sort(x, x + n);
  sort(y, y + m);
  for(int i = -200; i < 200; i++){
    if(i <= X || Y < i) continue;
    if(i <= x[n-1]) continue;
    if(i > y[0]) continue;
    cout << "No War" <<endl;
    return 0;
  }
  cout << "War" << endl;
}

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


int main() {
    string S;
    cin >> S;
    long long n = S.size();
    long long res = 0;
    long long num = 0;
    for (long long i = 0; i < n; ++i) {
        if (S[i] == 'W') {
            res += num;
        }
        else {
            ++num;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<complex>

using namespace std;

struct res{
	long long int x,y;
};
long long int res=0;

long long int two[80]={1},graph[200][200]={};

void solve(long long int fin[],long long int n,long long int now){
	bool key=true;
	long long int tmp[15];
	for(int i=1;i<=n;i++){
		tmp[i]=fin[i];
	}
	for(int i=1;i<=n;i++){
				
		if(tmp[i]==0){
			key=false;
			tmp[i]=1;
			if(graph[now][i]==1){
			solve(tmp,n,i);
				
			}
			tmp[i]=0;
		}
	}
	if(key){
		res++;
	}
}

const long long int mod=1000000007;
int main(){
	long long int n,m,a[200],b[200],fin[15]={};
		cin>>n>>m;
		for(int i=0;i<m;i++){
			cin>>a[i]>>b[i];
			graph[a[i]][b[i]]=1;
			graph[b[i]][a[i]]=1;
		}
		fin[1]=1;
		solve(fin,n,1);
		cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*
100^3,に100とか
*/
int main(){
  ll N; cin>>N;
  for(ll i=1; i<=N; i++){
    ll ans=0;
    for(ll x=1; x<=100; x++){
      if((x*x+x+4)>i) break;
      for(ll y=1; y<=x; y++){
        if((x*x+y*y+x*y+x+y+1)>i) break;
        for(ll z=1; z<=y; z++){
          ll d=x*x+y*y+z*z+x*y+y*z+z*x;
          if(d>i) break;
          if(d==i){
            if (x==y && y==z) ans++;
            else if (x==y || y==z) ans+=3;
            else ans+=6;
          }
//printf("x:%d,y:%d,z:%d,i:%d\n",x,y,z,i);
        }
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3520
#include<bits/stdc++.h> //Mr_Mandal
#define PI_INT 3.14159265358979323846
#define PI acos(-1.0)
#define LL long long
#define N 100000007
#define MOD 10000007
#define MX numeric_limits<long long>::max();
#define MN numeric_limits<long long>::min();
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define FILL(v, n) fill(v.begin(), v.end(), n);
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define PRINT(v) for(int i=0; i<v.size(); i++) cout<<v[i]<<" "; cout<<endl;
#define SCAN(v) for(int i=0; i<n; i++) { int temp; cin>>temp; v.push_back(temp); }
#define SORT(v) sort(v.begin(), v.end());
#define VECT(v) vector<int>v
#define SCF(f) scanf("%d", &f)
#define PNF(f) printf("%d\n", f)
#define CASEP(v) cout<<"Case "<<c<<": "<<v<<"\n"

using namespace std;

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

    if(line[4]==line[5] && line[2]==line[3])
        cout<<"Yes\n";
    else
        cout<<"No\n";

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        if(n==1){
        out.println("Hello World");
        } 
        else {
        out.println(sc.nextInt()+sc.nextInt());
        }

        // out.println(ans);
        out.flush();
        // out.println(ans);
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  

    static long gcd(long a, long b){
        if(min(a,b) == 0)return max(a,b);
        return gcd(max(a,b) % min(a,b),min(a,b));
    }
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 21076
def calc_sums(tbl):
    """calculate the total sum for each row and column

    >>> calc_sums([[1, 2], [2, 1]])
    [[1, 2, 3], [2, 1, 3], [3, 3, 6]]
    """
    new_tbl = [row + [0] for row in tbl] + [[0] * (len(tbl[0])+1)]

    for i, row in enumerate(tbl):
        for j, val in enumerate(row):
            new_tbl[i][-1] += val
            new_tbl[-1][j] += val

    new_tbl[-1][-1] = sum(new_tbl[-1][:-1])

    return new_tbl


def run():
    n, m = [int(v) for v in input().split()]
    table = []

    for i in range(n):
        table.append([int(v) for v in input().split()])

    for row in calc_sums(table):
        print(" ".join([str(i) for i in row]))


run()



Measured memory_bytes: 5796
main = do
  [n, k] <- map read . words <$> getLine
  let m = n * (n - 1) `div` 2 - k
  if (n - 1) * (n - 2) < 2 * k then print (-1)
  else print m >>
    (mapM_ putStrLn $ take m [show i ++ " " ++ show j | i <- [1 .. n - 1], j <- [2 .. n], i < j])

Measured memory_bytes: 1020
import math

n = int(input())
#a, b, c = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = [input() for i in range(n)]
#s = input()
#list = list(s)
#temp = [[0 for _ in range(13)] for _ in range(13)]

flag = 0

for i in range(n-2,-1,-1) :
    if(list[i] == list[i+1] + 1) :
        list[i] = list[i] - 1
    elif(list[i] > list[i+1] + 1) :
        flag = 1

    if (list[i] < 1) :
        flag = 1

if (flag == 0) :
    print("Yes")
else :
    print("No")

Measured memory_bytes: 14396
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

inline char get(void) {
  static char buf[100000], *S = buf, *T = buf;
  if (S == T) {
    T = (S = buf) + fread(buf, 1, 100000, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
inline void read(int &x) {
  static char c; x = 0; int sgn = 0;
  for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
  for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
  if (sgn) x = -x;
}

int n, T, t;
int ans, lst, res;

inline int Max(int a, int b) {
  return a > b ? a : b;
}

int main(void) {
  read(n); read(T); lst = ans = 0;
  for (int i = 1; i <= n; i++) {
    read(t);
    if (lst <= t) {
      ans += T; lst = t + T;
    } else {
      ans += t + T - lst; lst = t + T;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
from math import gcd

n=int(input())

s = 0

for i in range(1,n+1):
  if i == 1:
    s += n**2
  else:
    for j in range(1,n+1):
      g = gcd(i, j)
      if g == 1:
        s += n
      else:
        for k in range(1,n+1):
          s += gcd(g, k)
print(s)

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/07/23  Problem: AOJ 2005 / Link: https://onlinejudge.u-aizu.ac.jp/challenges/search/volumes/2005  ----- */
/* ------問題------

21XX 年，ついに人類は火星への移住計画を開始させた．火星への移住第一陣に選抜されたあなたは，火星行政中央局（the Administrative Center of Mars）に配属され，火星で起こる様々な問題に対処している．行政中央局の目下の最大の問題は自立した需要供給サイクルの確保である．月からの援助物資が届くまでには数ヶ月単位の時間がかかるため，基本的には火星内の需要は火星内で解決する必要がある．それに加えて，循環システムを確立するまでは資源を極力節約することが求められる．
行政中央局は極地にある氷の採掘を開始した．太陽光でこれを溶かし，水として個々の基地に供給することが最終目標である．最初の段階として，水源のある基地から2つの主要基地までの導水管を敷設することにした．また，現時点ではいくつかの基地とそれらを結ぶ道路以外には開拓されておらず，未開拓のところに導水管を敷設するには多大なるコストと燃料を要するため，道路に沿って導水管を敷設することにした．さらに，技術上の制約のため，彼らの導水管は常に一方向だけに水が流れる．
あなたの仕事は，これらの条件のもとで，導水管の敷設にかかるコストを最小にするプログラムを作成することである．

-----問題ここまで----- */
/* -----解説等-----

日本語が悪いのでSやGiから水が分かれるとも取れる。
×彼らの導水管は常に一方向だけに水が流れる
○頂点を流れる水は常に一方向である
頂点について一方向だと、分岐点を全探索するのみ。

----解説ここまで---- */


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


	int N, M, S, G1, G2;
	while (cin >> N >> M >> S >> G1 >> G2,N) {
		const int intINF = 2e9 / 3;
		VVI dist(N, VI(N,intINF ));
		S--, G1--, G2--;
		FOR(i, 0, N)dist[i][i] = 0;
		FOR(i, 0, M) {
			int a, b, c; cin >> a >> b >> c; a--; b--;
			dist[a][b] = c;
		}
		FOR(k, 0, N)FOR(i, 0, N)FOR(j, 0, N)dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
		int ans = INF;
		FOR(i, 0, N) {
			ans = min(ans, dist[S][i] + dist[i][G1] + dist[i][G2]);
		}
		cout << ans << "\n";

	}

	return 0;
}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    string S, T;
    cin >> S >> T;
    ll ans = 0;
    rep(i, S.size()) {
        if(S[i] != T[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3852
#include<stdio.h>

const int mod = 1e9 + 7;

int main(){
  int N, M; scanf("%d%d", &N, &M);
  int S[N], T[M];
  for(int i = 0; i < N; i++) scanf("%d", S + i);
  for(int j = 0; j < M; j++) scanf("%d", T + j);
  
  long long num[N + 1][M + 1];
  for(int i = 0; i <= N; i++){
    for(int j = 0; j <= M; j++){
      if(i == 0 || j == 0) num[i][j] = 1;
      else num[i][j] = 0;
    }
  }
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++){
      num[i + 1][j + 1] += num[i + 1][j] + num[i][j + 1] % mod;
      if(S[i] != T[j])
        num[i + 1][j + 1] -= num[i][j];
      if(num[i + 1][j + 1] < 0) num[i + 1][j + 1] += mod;
      num[i + 1][j + 1] %= mod;
    }
  }
  
  printf("%lld\n", num[N][M]);
  
  return 0;
}

Measured memory_bytes: 31488
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: i64,
        b: i64
    }
    println!("{}", max(max(a + b, a - b), a * b));
}


Measured memory_bytes: 4352
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/
#include<bits/stdc++.h>
#define mod 1000000007
#define modc 998244353
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define deb(x) cout << #x << " " << x << endl;
#define deb2(x,y) cout << #x << " " << x << " " <<  #y << " " << y << endl
#define deb3(x,y,z) cout << #x << " " << x << " " << #y << " " << y << " " << #z << " "  << z << endl;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using namespace std;
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
bool perfectSq(T n)
{
	if(sqrt(n) == floor(sqrt(n)))
		return true;
	else
		false;
}
void solve()
{
	int i,j;
	ll sum = 0,prod = 1;
	ll s,w;
	cin >> s >> w;
	if(w>=s)
		cout << "unsafe" << endl;
	else
		cout << "safe" << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	while(t--)
	{
		solve();
	}
}


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

typedef long long int ll;
ll n, dist;
string s;
map<string, ll> occ;

int main() {
    cin >> n;
    for(ll i = 0; i < n; ++i) {
        cin >> s;
        occ[s]++;
        if(occ[s] == 1) dist++;
    }

    cout << dist << endl;
    return 0;
}

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


int main()
{
	string s;
	bool flag=false;
	cin>>s;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='7')flag=true;
	}
	if(flag)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<string.h>
#define MAX 100000
#define MOD 1000000007
#define df 0
typedef long int li;



int main(){
  char s[MAX+1];
  scanf("%s",s);
  int i,m=strlen(s)-1;
  li dp[MAX],beki[MAX];
  dp[0]=(s[m]=='0')?1:3;
  beki[0]=1;
  for(i=1;i<=m;i++){
    dp[i]=dp[i-1];
    beki[i]=beki[i-1]*3%MOD;
    if(s[m-i]=='1')dp[i]=(2*dp[i]+beki[i])%MOD;
  }
  if(df){
    for(i=0;i<m;i++){
      printf("%ld\n",dp[i]);
    }
  }
  printf("%ld",dp[m]);
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);

		int i = 1;
		int EndNum = 0;


		//??°?????????
		while(true){
			//Num???????????????
			int x = sc.nextInt();
			//0?????\????????????
			if( EndNum == x){
				break;
			}

			//??¨???
			System.out.println("Case " + i + ": " + x);
			i++;
		}
	}
}

Measured memory_bytes: 44808
//Zory-2018
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
using namespace std;

namespace mine
{
	typedef long long ll;
	const int INF=0x3f3f3f3f;

	const int MAX_N=110000;

	char s[MAX_N];
	int id=0;
	void solve(int x,int siz)
	{
		for(int i=siz-1;i>=1;i--)
		{
			printf("%d %d\n",x,++id);
			if(s[i]=='1')
			{
				solve(id,i);
				break;
			}
		}
	}
	void main()
	{
		scanf("%s",s+1);int n=strlen(s+1);
		for(int i=1;i<=n/2;i++) if(s[i]!=s[n-i]) {puts("-1");return;}
		if(s[1]=='0' or s[n]=='1') {puts("-1");return;}

		solve(++id,n);
	}
}
int main()
{
	mine::main();
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define puts(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);


void solve(void){

	int N;
	cin >> N;

	while(N--)
	{
		int x1, x2, x3, x4, y1, y2, y3, y4;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;

		int dx1 = x2-x1, dy1 = y2-y1, dx2 = x4-x3, dy2 = y4-y3;

		if (dx1*dx2 + dy1*dy2 == 0)
		{
			cout << "1" << endl;
		}
		else if (dx1*dy2-dx2*dy1 == 0)
		{
			cout << "2" << endl;
		}
		else
		{
			cout << "0" << endl;
		}
	}
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 3112
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
data = list(map(int,read().split()))

tot = 0
same = 0
min_b = 10**9
it = iter(data)
for a,b in zip(it,it):
    tot += a
    if(a==b):
        same += 1
    elif(a > b):
        min_b = min(min_b,b)

if(same==n):
    print(0)
else:
    print(tot-min_b)

Measured memory_bytes: 79364
#include <bits/stdc++.h>
using namespace std;
using graph = vector<vector<int>>;

vector<int> topological_sort(const graph& G) {
	int n = G.size();
	vector<int> used(n), idx; idx.reserve(n);
	function<void(int)> dfs = [&](int v) {
		used[v] = true;
		for (int w : G[v]) if (!used[w]) dfs(w);
		idx.push_back(v);
	};
	for (int i = n - 1; i >= 0; i--) {
		if (!used[i]) dfs(i);
	}
	reverse(idx.begin(), idx.end());
	return idx;
}

int main()
{
	int N, M;
	cin >> N >> M;
	graph G(N);
	for (int i = 0; i < N - 1 + M; i++) {
		int A, B;
		cin >> A >> B; --A, --B;
		G[A].push_back(B);
	}
	auto ids = topological_sort(G);
	vector<int> dist(N);
	for (auto id : ids) {
		for (auto to : G[id]) {
			dist[to] = max(dist[to], dist[id] + 1);
		}
	}
	vector<int> res(N);
	for (auto id : ids) {
		for (auto to : G[id]) if (dist[to] == dist[id] + 1) {
			res[to] = id + 1;
		}
	}
	for (int i = 0; i < N; i++) {
		cout << res[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 10744
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

n = int(input())
s = input()

x = 0
ans = 0
for i in range(n):
    if (s[i] == "I"):
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
print(ans)


Measured memory_bytes: 9056
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint N, Q; cin >> N >> Q;
    string s; cin >> s;
    vector<int> vCnt(s.size()+1, 0);
    vector<int> vCS (s.size()+1, 0); // cumulative sum
    
    for(uint i=1; i<s.size(); ++i){
        if(s[i-1]=='A' && s[i]=='C'){ vCnt[i+1] = 1; }
    }
    
    vCS[0] = vCnt[0];
    for(uint i=1; i<vCS.size(); ++i){
        vCS[i] = vCS[i-1] + vCnt[i];
    }
    
    for(uint i=0; i<Q; ++i){
        uint l, r; cin >> l >> r;
        if(s[l-1]=='C'){ ++l; }
        cout << vCS[r] - vCS[l-1] << endl;
    }
    
    return 0;
}
/*
ACACTACG
3 7
2 3
1 8
           A C A C T A C G
vCnt = [ 0 0 1 0 1 0 0 1 0 ]
vCS  = [ 0 0 1 1 2 2 2 3 3 ]
*/


Measured memory_bytes: 1872
#include <stdio.h>
int main(int argc, char const *argv[])
{
  int n;
  scanf("%d",&n);
  int i;
  for(i=1;i<10;i++){
    if(n%i==0){
      if((n/i)<10){
        printf("Yes");
        return 0;
      }
    }
  }
  printf("No");
  return (0);
}

Measured memory_bytes: 128
H, W = gets.split.map(&:to_i)
C = []; 10.times{C << gets.split.map(&:to_i)}
A = readlines.map{|l| l.split.map(&:to_i)}
INF = 1e10.to_i

class Number
  include Comparable
  attr_accessor :id, :power

  def initialize(id, power)
    @id, @power = id, power
  end

  def <=>(other)
    -@power <=> -(other.power)
  end
end

class PriorityQueue
  def initialize
    @q = [nil]
  end

  def bubble_up(i)
    pi = i / 2
    return if i <= 1 || @q[pi] >= @q[i]
    @q[i], @q[pi] = @q[pi], @q[i]
    bubble_up(pi)
  end

  def add(e)
    @q << e
    bubble_up(@q.size - 1)
  end

  def bubble_down(i)
    ci = i * 2
    return if ci > @q.size - 1
    ci += 1 if ci != @q.size - 1 && @q[ci] < @q[ci + 1]
    return if @q[i] >= @q[ci]
    @q[i], @q[ci] = @q[ci], @q[i]
    bubble_down(ci)
  end

  def pop
    @q[1], @q[-1] = @q[-1], @q[1]
    ret = @q.pop
    bubble_down(1)
    ret
  end
end

def dijkstra
  p = Array.new(10, INF)
  q = PriorityQueue.new
  p[1] = 0
  q.add(Number.new(1, 0))
  while nn = q.pop
    n = nn.id
    (0 .. 9).each do |m|
      next if m == n
      p1 = p[n] + C[m][n]
      if p1 < p[m]
        p[m] = p1
        q.add(Number.new(m, p1))
      end
    end
  end
  p
end

mp = dijkstra
puts A.flatten.group_by(&:itself).map{|k, v| [k, v.size]}.inject(0){|s, (n, m)| n == -1 ? s : s + mp[n] * m}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int buil[4][3][10];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    int n; cin >> n;
    rep(i, 0, n) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        b--, f--, r--;
        buil[b][f][r] += v;
    }
    rep(i, 0, 4) {
        rep (j, 0, 3) {
            rep(k, 0, 10) {
                printf(" ");
                printf("%d", buil[i][j][k]);
            }
            printf("\n");
        }
        if (i != 3) printf("####################\n");
    }
    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, m, t;
    cin >> n >> m >> t;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int T = 0, ans = 0;
    bool f = true;
    rep(i, n)
    {
        int len = a[i] - T;
        T = a[i];
        if (f)
            ans += len - m;
        if (a[i + 1] - T >= 2 * m)
            T += m, f = true;
        else
            f = false;
    }
    ans += max(0LL, t - a[n - 1] - m);
    cout << ans << endl;
}


Measured memory_bytes: 3224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		long sum = 0;
		long count = 0;
		for (int i=0;i<s.length();i++) {
			if (s.charAt(i)=='W') {
				sum+=i;
				count++;
			}
		}
		System.out.println(sum-(count*(count-1)/2));
	}

}

Measured memory_bytes: 26636
N, M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1+M)]
inc = [0] * N
out = [list() for _ in range(N)]
ans = [0] * N

for l in AB:
    inc[l[1]-1] += 1
    out[l[0]-1].append(l[1]-1)

S = {i for i, c in enumerate(inc) if c == 0}
#L = []
while S:
    n = S.pop()
    #L.append(n)
    for m in out[n]:
        inc[m] -= 1
        if inc[m] == 0:
            S.add(m)
            ans[m] = n + 1 
print(*ans,sep="\n")

Measured memory_bytes: 49752
import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
ans = 1
if 0 in a:
    print(0)
    sys.exit()
for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        sys.exit()
print(ans)


Measured memory_bytes: 82900
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

int main() {
    int n;
    cin >> n;
    int k=n;
    int sn=0;
    while (k>0) {
        sn+=k%10;
        k/=10;
    }
    if (n%sn==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int long long
signed main() {
	int h, w;
	cin >> h >> w;
	string a[100];
	for (int i = 0; i < h; i++)
		cin >> a[i];
	for (int i = 0; i < w + 2; i++)
		cout << '#';
	cout << endl;
	for (int i = 0; i < h; i++) {
		cout << '#';
		cout << a[i];
		cout << '#';
		cout << endl;
	}
	for (int i = 0; i < w + 2; i++)
		cout << '#';
	cout << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main {
    static int[] wt;
    static int[] val;
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int C = Integer.parseInt(st.nextToken());
        wt = new int[N];
        val = new int[N];

        for (int i=0; i<N; i++){
            st = new StringTokenizer(br.readLine());
            wt[i] = Integer.parseInt(st.nextToken());
            val[i] = Integer.parseInt(st.nextToken());
        }

        long[][] dp = new long[N+1][C+1];
        knapsack(dp, N, C);

//        bottom-up
//        for (int i=1; i<=N; i++){
//            for (int j = 1; j <= C; j++) {
//                dp[i][j] = Math.max(dp[i][j], dp[i-1][j]);
//                if(j-wt[i-1]>=0)
//                    dp[i][j] = Math.max(dp[i][j], dp[i-1][j-wt[i-1]]+val[i-1]);
//            }
//        }
        System.out.println(dp[N][C]);
    }

    public static long knapsack(long[][] dp, int N, int C){
        if (N<=0 || C<=0)
            return 0;
        if(dp[N][C]!=0)
            return dp[N][C];

        long ans = 0;

            long t1 = knapsack(dp, N-1, C);
            long t2 = 0;
            if(wt[N-1]<=C)
                t2 = knapsack(dp, N-1, C-wt[N-1])+val[N-1];
            ans = Math.max(t1,t2);
        return dp[N][C]=ans;
    }
}


Measured memory_bytes: 126676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string X;
  cin >> X;
  vector<int> can (X.size(),0);
  int j = 0;
  for ( int i = 0 ; i < X.size() ; i++ ) {
    if ( X[i] == 'A' || X[i] == 'G' || X[i] == 'C' || X[i] == 'T' ) {
      can[j]++;
    }
    else {
      j++;
    }
  }
  sort (can.begin(),can.end());
  reverse (can.begin(),can.end());
  cout << can[0] << endl;
}


Measured memory_bytes: 256
hoge=input()
flag=0
if(flag==0 and hoge.count("a")==0):
  print("a")
  flag=1

if(flag==0 and hoge.count("b")==0):
  print("b")
  flag=1

if(flag==0 and hoge.count("c")==0):
  print("c")
  flag=1

if(flag==0 and hoge.count("d")==0):
  print("d")
  flag=1

if(flag==0 and hoge.count("e")==0):
  print("e")
  flag=1

if(flag==0 and hoge.count("f")==0):
  print("f")
  flag=1

if(flag==0 and hoge.count("g")==0):
  print("g")
  flag=1

if(flag==0 and hoge.count("h")==0):
  print("h")
  flag=1

if(flag==0 and hoge.count("i")==0):
  print("i")
  flag=1

if(flag==0 and hoge.count("j")==0):
  print("j")
  flag=1

if(flag==0 and hoge.count("k")==0):
  print("k")
  flag=1

if(flag==0 and hoge.count("l")==0):
  print("l")
  flag=1

if(flag==0 and hoge.count("m")==0):
  print("m")
  flag=1

if(flag==0 and hoge.count("n")==0):
  print("n")
  flag=1

if(flag==0 and hoge.count("o")==0):
  print("o")
  flag=1

if(flag==0 and hoge.count("p")==0):
  print("p")
  flag=1

if(flag==0 and hoge.count("q")==0):
  print("q")
  flag=1

if(flag==0 and hoge.count("r")==0):
  print("r")
  flag=1

if(flag==0 and hoge.count("s")==0):
  print("s")
  flag=1

if(flag==0 and hoge.count("t")==0):
  print("t")
  flag=1

if(flag==0 and hoge.count("u")==0):
  print("u")
  flag=1

if(flag==0 and hoge.count("v")==0):
  print("v")
  flag=1

if(flag==0 and hoge.count("w")==0):
  print("w")
  flag=1

if(flag==0 and hoge.count("x")==0):
  print("x")
  flag=1

if(flag==0 and hoge.count("y")==0):
  print("y")
  flag=1

if(flag==0 and hoge.count("z")==0):
  print("z")
  flag=1
  
if(flag==0):
  print("None")

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

int main() {
    ll x; cin >> x;
    ll ans = (x/11) * 2;
    //if(x % 11 == 1) ans += 1;
    ll rem = x % 11;
    if(rem >6){ ans += 2;}
    else if(rem > 0) ans += 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>
using namespace std;

int main(){
    long long a,n,num,ans=100000000000;
    cin>>n;
    for (int i=1;i<=sqrt(n);i++){
        if (n%i==0){
            a=n/i;
            num=to_string(a).size();
            ans=min(ans,num);
        }
    }
    cout<<ans<<endl;
}


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

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

    int tmp;
    vector<int> sub(n);
    for (int i = 0; i < n-1; i++) {
        cin >> tmp;
        sub[tmp-1]++;
    }

    for (int i = 0; i < n; i++) {
        cout << sub[i] << endl;
    }
    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main() {
	ll a;
	string s;
	cin >> a >> s;

	if (a < 3200) cout << "red" << endl;
	else cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll X,Y;
int main()
{
	scanf("%lld%lld",&X,&Y);
	puts(abs(X-Y)<=1?"Brown":"Alice");
	return 0;
}


Measured memory_bytes: 256