akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
  
public class Main
{ 
    //By shwetank_verma
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    static int mod=1000000007;
    static boolean primes[]=new boolean[1000007];
    
    static boolean seive(int n){
        Arrays.fill(primes,true);
        primes[0]=primes[1]=false;
        for(int i=2;i*i<=n;i++){
            if(primes[i]==true){
                for(int p=i*i;p<=n;p+=i){
                    primes[p]=false;
                }
            }
        }
        if(n<1000007){
            return primes[n];
        }
        return false;
        
    }
    static int gcd(int a,int b){
        if(b==0)
        return a;
        return gcd(b,a%b);
    }
    static long GCD(long a,long b){
        if(b==0)
        return a;
        return GCD(b,a%b);
    }
    
  
    public static void main(String[] args) 
    { 
        FastReader sc=new FastReader(); 
        try{
           
                
                int n=sc.nextInt();
                
                long ans=n+n*n+n*n*n;
                
                System.out.println(ans);
                
        
                
           
            
        }catch(Exception e){
            return;
        }
    } 
}


Measured memory_bytes: 33712
#include <iostream>
#include <bits/stdc++.h>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <utility>
using namespace std;
using ll = long long int;
int main() {
  ll x,n;
  cin>>n>>x;
  vector<ll> a(n);
  ll sum=0;
  ll min=pow(10,9);
  for (ll i=0;i<n;i++) {
	cin>>a.at(i);
	sum+=a.at(i);
	if (a.at(i)<min) min=a.at(i);
  }
  sort(a.begin(), a.end());
  
  if (x>sum) cout<<n-1;
  else if (x<min) cout<<0;
  else {
	ll cnt=0;
	ll acc=0;
	for (ll i=0;i<n;i++){
	  acc+=a.at(i);
	  if (acc<=x) cnt++;
	}
	cout<<cnt;
  }
}

Measured memory_bytes: 256
n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
xyh=sorted(xyh, key=lambda x:x[2], reverse=True)

for xi in range(101):
    for yi in range(101):
        hi=0
        flag=True
        for i in range(n):
            x=xyh[i][0]
            y=xyh[i][1]
            h=xyh[i][2]
            if i==0:
                hi=abs(xi-x)+abs(yi-y)+h
            if max(hi-abs(xi-x)-abs(yi-y),0)!=h:
                flag=False
        if flag:
            print(xi, yi, hi)
            break
    else:
        continue
    break

Measured memory_bytes: 9212
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cctype>

using namespace std;
#define N 100
#define INF 10000
int main()
{
    int n, m, s;
    int hanako[N];
    int taro[N];
    while (true) {
        cin >> n >> m;
        if (n == 0 && m == 0) {
            break;
        }
        for (int i = 0; i < n; i++) {
            cin >> taro[i];
        }
        for (int i = 0; i < m; i++) {
            cin >> hanako[i];
        }
        int sum_taro = 0;
        int sum_hanako = 0;
        for (int i = 0; i < n; i++) {
            sum_taro += taro[i];
        }
        for (int i = 0; i < m; i++) {
            sum_hanako += hanako[i];
        }
        int ans_t = INF, ans_h = INF;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                int tmp1 = sum_taro + hanako[j] - taro[i];
                int tmp2 = sum_hanako + taro[i] - hanako[j];
                if (tmp1 != tmp2) {
                    continue;
                }
                if (taro[i] + hanako[j] < ans_t + ans_h) {
                    ans_t = taro[i];
                    ans_h = hanako[j];
                }
            }
        }
        if (ans_t == INF) {
            cout << -1 << endl;
        }
        else {
            cout << ans_t << " " << ans_h << endl;
        }
    }
    return 0;
}

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



int main(){
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    auto win = [&](char c, int h) {
        if ( c == 'r' ) {
            return ( h == 2 ) ? p : 0;
        }
        if ( c == 's' ) {
            return ( h == 0 ) ? r : 0;
        }
        if ( c == 'p' ) {
            return ( h == 1 ) ? s : 0;
        }
        return 0;
    };
    int ans = 0;
    vector<vector<int>> dp(125252, vector<int>(3));
    rep(sh, k) {
        string tt;
        int it = sh;
        while(it<n){
            tt += t[it];
            it += k;
        }
        int m = tt.size();
        rep(i, m+1)rep(j, 3){
            dp[i][j] = -(1<<30);
        }
        rep(j, 3)dp[0][j] = 0;
        rep(i, m) {
            rep(j, 3) {
                rep(jj, 3) {
                    if ( j != jj ) {
                        dp[i+1][jj] = max(dp[i+1][jj], dp[i][j] + win(tt[i], jj));
                    }
                }
            }
        }
        ans += *max_element(dp[m].begin(), dp[m].end());
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7424
import itertools,math
N=int(input())
T=[list(map(int,input().split())) for i in range(N)]
D=0
U=[]
def f(U):
  d=((U[0][0]-U[1][0])**2+(U[0][1]-U[1][1])**2)**0.5
  return d

#print(T)
for i in list(itertools.permutations(range(1,N+1))):
  for j in range(1,N):
    U+=[T[i[j-1]-1],T[i[j]-1]]
#    print('U:',U)
    D+=f(U)
#    print('D:',D)
    U=[]
print(D/math.factorial(N))


Measured memory_bytes: 7972
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long
const int N=1e6+5;

int call[N];


void Sieve(ll n) 
{ 
    bool prime[n+1];
	for(ll i=0;i<n+1;++i){
		prime[i]=true;
		call[i]=i;
		
	}
    for (ll p=2;p*p<=n;++p) 
    {
        if (prime[p] == true) 
        {  
            for (ll i=2*p; i<=n; i += p) 
                {
                    if(prime[i]==true)
                    {
                        prime[i]=false;
                        call[i]=p;   
                    }
                } 
        } 
    }  
    
}


void solve()
{
    Sieve(N);
    int n;
    cin>>n;
    int a[n];
    for(auto &x:a)cin>>x;
    int f=0;
    set<int>s;
    
    for(int i=0;i<n;i++)
    {
        int x=a[i];
      //  cout<<call[x]<<" ";
        set<int>t;
        while(x!=1)
        {
            t.insert(call[x]);
            x/=call[x];
        }
        
        for(auto x:t)
        {
            if(s.count(x))
            {
                f=1;
                break;
            }
            s.insert(x);
        }
        if(f)break;
    }
    
    
    
    if(!f)
    {
        cout<<"pairwise coprime";return;
    }
    int g=0;
    for(int i=0;i<n;i++)
    {
        g=__gcd(g,a[i]);
    }
    
    if(g==1)
    {
        cout<<"setwise coprime";
    }
    else cout<<"not coprime";
    
    
    
}

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--)solve();
	    
  
}




Measured memory_bytes: 19176
#include<iostream>
#include<vector>
int main()
{
	std::vector<bool>result;
	for (double x1, y1, x2, y2, x3, y3, xp, yp; std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp;)
	{
		double k = ((x2 - x3)*(y3 - y1) - (x3 - x1)*(y2 - y3)) / ((x2 - x3)*(yp - y1) - (xp - x1)*(y2 - y3));
		double s = ((x1 - x3)*(yp - y1) - (xp - x1)*(y1 - y3)) / ((x2 - x3)*(yp - y1) - (xp - x1)*(y2 - y3));
		result.push_back(1 < k && 0 < s && s < 1);
	}
	for (auto i : result)
	{
		std::cout << (i ? "YES" : "NO") << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define rep(i,a,n) for(int (i) = (a);(i) < (n);(i)++)
typedef long long ll;

using namespace std;

int main(){
	bool flag = false;
	int memo = 0,ans = 0;
	string s;
	
	cin >> s;
	
	rep(i,0,s.size()){
		if(flag){
			memo++;
			if(s[i] == 'Z'){
				ans = max(ans,memo);
			}
		}
		else if(s[i] == 'A'){
			flag = true;
			memo = 1;
		}
	
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
static const long double pi = 3.14159265358979;

int main() {
    long double A, B, H, M, Hrad, Mrad, min, rad, anspow;
    cin >> A >> B >> H >> M;
    min = H * 60 + M;
    Hrad = 2 * pi / 12 / 60; // rad/min
    Mrad = 2 * pi / 60;      // rad/min
    rad = abs(min * Hrad - min * Mrad);
    anspow = pow(A, 2) + pow(B, 2) - 2 * A * B * cos(rad);
    cout << fixed << setprecision(10) << sqrt(anspow) << endl;

    return 0;
}

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

double memo[305][305][305];

double dp(ll s1,ll s2,ll s3,ll empty,ll full){
    if(s1==0 && s2==0 && s3==0) return 0;
    if(memo[s1][s2][s3]!=-1) return memo[s1][s2][s3];
    
    double ret=0;
    double temp1=0,temp2=0,temp3=0;
    if(s1!=0){
        temp1=(double)s1*dp(s1-1,s2,s3,empty+1,full);
    }
    if(s2!=0){
        temp2=(double)s2*dp(s1+1,s2-1,s3,empty,full);
    }
    if(s3!=0){
        temp3=(double)s3*dp(s1,s2+1,s3-1,empty,full);
    }
    ret=(double)full*(1 + ( temp1 + temp2 + temp3 )/full)/(double)(full-empty);
    
    return memo[s1][s2][s3]=ret;
}

ll sushi[5];
int main(){
    
    for(int i=0;i<=300;i++){
        for(int j=0;j<=300;j++){
            for(int k=0;k<=300;k++){
                memo[i][j][k]=-1;
            }
        }
    }
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        ll num;
        scanf("%lld",&num);
        sushi[num]++;
    }
    double ans=dp(sushi[1],sushi[2],sushi[3],0,n);
    printf("%.12lf\n",ans);
    
    
}

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

int main() {
	int N;
	cin >> N;
	int A[N];
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	
	int ans=0;
	int ok=1;
	while(ok){
		for(int i=0; i<N; i++){
			if(A[i]%2==0){A[i]/=2;}
			else{
				ok=0;
				break;
			}
		}
		ans+=ok;
	}
	cout << ans << endl;
	return 0;
}

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


import datetime


F = "%Y/%m/%d"
C = "2019/04/30"


def str2date(s):
    return datetime.datetime.strptime(s, F)


def is_heisei(s):
    d0 = str2date(C)
    d1 = str2date(s)
    return d1 <= d0


def main():
    print("Heisei" if is_heisei(input()) else "TBD")


if __name__ == "__main__":
    main()

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 3005;

/* ...o(^-^)o... */

int n;
double dp[305][305][305];

double rec(int i, int j, int k){
    if(dp[i][j][k] > 0) return dp[i][j][k];
    if(i==0 && j==0 && k==0) return 0;
    double ans = n;
    if(i>0) ans += (double)i*rec(i-1, j, k);
    if(j>0) ans += (double)j*rec(i+1, j-1, k);
    if(k>0) ans += (double)k*rec(i, j+1, k-1);
    ans /= (double)(i+j+k);

    dp[i][j][k] = ans;
    return ans;
}

int main(){
    cin >> n;
    int c[3]; rep(i, 3) c[i] = 0;
    rep(i, n){
        int a; cin >> a; c[a-1]++;
    }
    setpre(10); out(rec(c[0], c[1], c[2]));
}

Measured memory_bytes: 219392
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll mypow(ll a, ll b) {
    ll ret = 1;
    while (b--) {
        ret *= a;
    }
    return ret;
}

int main() {
    ll r, g, b;
    cin >> r >> g >> b;
    if ((10 * g + b) % 4 == 0) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    srep(i,a,b+1){
        if(c % i == 0)ans++;
    }
    cout << ans << endl;
    return 0;
}
 
 



Measured memory_bytes: 3092
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>

using namespace std;

int r,c;
int ma[11][10100];
int memo[11];
int kokoko;
int tmp,mi;
int ans;

int main()
{
	while(1)
	{
		cin >> r >> c ;
		if(r+c == 0) break;
		for(int i = 0; i < r;i++)
		{
			for(int j = 0;j < c;j++)
			{				
				cin >> ma[i][j];
			}
		}
		int con = pow(2,r);
		for(int i = 0;i < con;i++)
		{
			tmp = 0;
			int s = i;
			for(int j = 0;j < r;j++)
			{
				memo[j] = s %2;s /= 2;
			}
 
			for(int j = 0; j < c;j++)
			{
				kokoko = 0;
				for(int k = 0;k < r;k++)
				{
					kokoko += memo[k] ^ ma[k][j];
				}
				tmp += max(kokoko,r - kokoko);
			}
			mi = max(mi,tmp);
		}
		cout << mi << endl;
	}
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  string s; cin >> s;
  if (s == "ABC") cout << "ARC" << endl;
  if (s == "ARC") cout << "ABC" << endl;


  return 0;
}

// EOF


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <utility>
#include <fstream>
#include <iomanip>
#include <complex>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define IO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const int N = 3e2 + 5, inf = 1e9, mod = 998244353;
using namespace std;

int n, a, freq[4] = {};
ld dp[N][N][N] = {};
bool vis[N][N][N] = {};

ld solve ( int c1 , int c2 , int c3 )
{
    if ( c1 + c2 + c3 == 0 )
        return 0;
    if ( vis[c1][c2][c3] )
        return dp[c1][c2][c3];
    vis[c1][c2][c3] = true;
    ld ret = 1.0, c0 = n - ( c1 + c2 + c3 );
    if ( c1 )
        ret += solve ( c1 - 1 , c2 , c3 ) * ( 1.0 * c1 / n );
    if ( c2 )
        ret += solve ( c1 + 1 , c2 - 1 , c3 ) * ( 1.0 * c2 / n );
    if ( c3 )
        ret += solve ( c1 , c2 + 1 , c3 - 1 ) * ( 1.0 * c3 / n );
    ret /= ( 1 - ( c0 / n ) );
    return dp[c1][c2][c3] = ret;
}

int main()
{
    IO
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        freq[a]++;
    }
    cout << fixed << setprecision(10) << solve( freq[1] , freq[2] , freq[3] ) << '\n';
    return 0;
}

Measured memory_bytes: 228624
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

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

  vector<long long> h(N);
  for (int i = 0; i < N; ++i) cin >> h[i];

  for (int i = 1; i < N; ++i)
  {
    if (h[i] > h[i - 1]) --h[i];
    else if (h[i] < h[i - 1])
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
const int N=200005,M=1000000007;
using namespace std;
int n,b[N],bi[N],
m0=1,m1=1,am[N],ans,ss,tp,al;
struct dat{int x,v;}a[N];
inline int ksm(long long x,int t){
	int y=1;
	for(;t;t>>=1)
	t&1?y=y*x%M:0,x=x*x%M;
	return y;
}
inline void qry(int x){
	for(;x<=n;x+=x&-x)
	ans=(ans-2ll*m1*b[x])%M,(ss+=bi[x])%=M;
}
inline void ins(int x,int v){
	int y=am[x]*v;x=a[x].x;
	(al+=y)%=M;
	for(;x;x-=x&-x)(b[x]+=y)%=M,v>0?bi[x]++:0;
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	scanf("%d",&a[i].v),a[i].x=i+1;
	sort(a,a+n,[](dat x,dat y){
		return x.v<y.v;
	});
	for(int i=0,j=0;i<n;i++){
		if((tp=a[i].v-i)<1)return puts("0"),0;
		ans=(1ll*ans*tp+1ll*m1*al)%M;
		qry(a[i].x);
		m0=1ll*m0*tp%M;
		am[i]=m0*1ll*ksm(m1,M-2)%M;
		if(tp>1)m1=m1*(tp-1ll)%M;
		ins(i,1);
		if(tp==1)
		for(;j<=i;j++)ins(j,-1);
	}
	printf("%d",((ans*1ll*ksm(2,M-2)+1ll*ss*m0)%M+M)%M);
}

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

int main(){
  string S;
  cin >> S;
  int ans=643;
  int s;
  for(int i=0; i<S.size()-2; i++){
    s=(S.at(i)-'0')*100+(S.at(i+1)-'0')*10+S.at(i+2)-'0';
    ans = min(ans, abs(753-s));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    ll n,k; cin >> n >> k;
    ll mn = k*(k+1)/2;
    ll mx = (n+2)*(n+1)/2 - (n-k+1)*(n-k+2)/2;
    ll ans = 0;
    REP(i,k,n+2){
        ans += mx-mn+1;
        mn += i+1;
        mx += n-i+1;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3652
H,W=map(int,input().split())
N = int(input())
A =list(map(int,input().split()))

import numpy as np
res = np.zeros(H*W,dtype=np.int64)

pos = 0
for i in range(N):
    color = i+1
    for j in range(A[i]):
        res[pos+j] = color
    pos += A[i]
res = np.reshape(res,(H,W))
for i in range(H):
    if i%2 == 0:
        pass
    else:
        res[i] = res[i][::-1]
#print(res)

for i in range(H):
    for j in range(W):
        print(res[i][j],end=" ")
    print()

Measured memory_bytes: 13264
n = 26
d = int(input())
c = list(map(int,input().split()))
s = [[] for i in range(d)]
for i in range(d):
    s[i] = list(map(int,input().split()))
a = 0
last = [0]*n
for i in range(d):
    t = int(input())-1
    a += s[i][t]
    last[t] = i+1
    for j in range(n):
        a -= c[j]*(i-last[j]+1)
    print(a)


Measured memory_bytes: 9320
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll x;
  cin >> x;
  cout << 48-x << endl;
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define all(a) a.begin(),a.end()
#define endl '\n'
#define y1 y12312123
#define int ll

using namespace std;

const int N = 3e5 + 3;

int n, d;
vector<int> a[N];

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

    cin >> n >> d;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= d; ++j){
            int x;
            cin >> x;
            a[i].pb(x);
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; ++i){
        for(int j = i + 1; j <= n; ++j){
            int r = 0;
            for(int k = 0; k < d; ++k){
                r += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
            }

            int z = sqrt(r);
            if(z * z == r)ans++;
        }
    }
    cout << ans;
}


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

int main()
{
  long n,t,i,j;
  cin>>n>>t;
  long ans = LONG_MAX;
  for(i=0;i<n;i++)
  {
    long ci,ti;
    cin>>ci>>ti;
    if(ti<=t)
    {
      ans = min(ans,ci);
    }
  }
  if(ans==LONG_MAX)
    cout<<"TLE";
  else
    cout<<ans;
  return 0;
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    int n, k;
    cin >> n >> k;
    cout << ((n*500 >= k) ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int s[30000],t[30000],r[30000];
int p,q,qq;

void push(int x) {
  s[p]=x;
  p++;
}
void push2(int x) {
  t[q]=x;
  q++;
}
void push3(int x) {
  r[qq]=x;
  qq++;
}

int pop() {
  if(p==0) return -1;
  p--;
  return s[p];
}
int pop2() {
  if(q==0) return 0;
  q--;
  return t[q];
}
int pop3() {
  if(qq==0) return -1;
  qq--;
  return r[qq];
}

int main() {
  p=q=qq=0;
  char c[30000];
  scanf("%s",c);
  int i=0,sum=0,j=0,n=0,a[30000];
  while(c[i]=='\\' || c[i]=='/' || c[i]=='_') { 
    if(c[i]=='\\') push(i);
    if(c[i]=='/') {
      int x=pop();
      if(x>=0) {
	int d=0;
	while(1) {
	  int y=pop3();
	  if(y<x) {
	    if(y!=-1) push3(y);
	    break;
	  }
	  d+=pop2();
	}
	d+=i-x;
	push2(d);
	push3(x);
      }
    }
    i++;
  }
  while(1) {
    int x=pop2();
    if(x==0) break;
    sum+=x;
    a[n]=x;
    n++;
  }
  printf("%d\n%d",sum,n);
  for(j=n-1; j>=0; j--) printf(" %d",a[j]);
  printf("\n");
  return 0;
}


Measured memory_bytes: 664
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>

void view(const std::vector<T> &v)
{
#ifndef ONLINE_JUDGE
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
#endif
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    ll leftover = 0;
    rep(i, n)
    {
        ans += (a[i] + leftover) / 2ll;
        if (a[i] == 0)
            leftover = 0;
        leftover = (a[i] + leftover) % 2ll;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4048
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;


int main(){
  int N, M; cin >> N >> M; int a[N][M];
  rep(i, N){
    rep(j, M){
      cin >> a[i][j]; a[i][j]--;
    }
  }
  bool check[M] = {}; int ans = inf;
  rep(k, M){
    int cnt[M] = {};
    rep(i, N){
      rep(j, M){
        if(check[a[i][j]]) continue;
        cnt[a[i][j]]++; break;
      }
    }
    int tmp = 0, maxj;
    rep(j, M){
      tmp = max(tmp, cnt[j]);
      if(tmp==cnt[j]) maxj = j;
    }
    check[maxj] = true;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int h, w;
    int i, j;
    while(1){
        scanf("%d %d", &h, &w);
        if(h + w == 0)
            break;
        for(i = 0; i < h; i++){
            for(j = 0; j < w; j++)
                putchar('#');
            putchar('\n');
        }
        putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 572
#import <stdio.h>
#import <Foundation/Foundation.h>

int main(int argc, char **argv) {
  int N;
  scanf("%d", &N);
  int i;
  BOOL isValid = YES;
  for (i = 0; i < N; i++) {
   	int A;
    scanf("%d", &A);
    if ((A & 1) == 0 && A % 3 != 0 && A % 5 != 0) {
      isValid = NO;
      break;
    }
  }
  printf("%s", isValid ? "APPROVED" : "DENIED");
  return 0;
}

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

int main() {
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  
  int dx = abs(tx-sx);
  int dy = abs(ty-sy);
  
  const char* rightup = "RULDDRULULDR";
  const char* leftdown = "DLURRDLULURD";
  
  const char* ans;
  if(tx > sx) ans = rightup;
  else  ans = leftdown;
  
  for(int i = 0; i < dx; i++) printf("%c",ans[0]);
  for(int i = 0; i < dy; i++) printf("%c",ans[1]);
  for(int i = 0; i < dx; i++) printf("%c",ans[2]);
  for(int i = 0; i < dy; i++) printf("%c",ans[3]);

  printf("%c",ans[4]);
  for(int i = 0; i < dx+1; i++) printf("%c",ans[5]);
  for(int i = 0; i < dy+1; i++) printf("%c",ans[6]);
  printf("%c",ans[7]);
  printf("%c",ans[8]);
  for(int i = 0; i < dx+1; i++) printf("%c",ans[9]);
  for(int i = 0; i < dy+1; i++) printf("%c",ans[10]);
  printf("%c",ans[11]);
  printf("\n");
  fflush(stdout);
  
 return 0; 
}

Measured memory_bytes: 256
//Dream your Code, Code your Dream [Siriuslight -Subham Pal]
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;    typedef long long ll;    typedef long double ld;
const int inf = 1e9, N = 3e5+5;
const ll INF = 1e18, MOD = 1e9+7;;
ll power(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll gcd(ll a,ll b){if(b>a)swap(a,b);if(!b)return a;return gcd(b,a%b);}

int n, east[N], west[N], ans = inf;
string s;

int main(){
    FIO;
    cout << setprecision(10) << fixed;
    cin >> n >> s;
    s = '@' + s;
    for(int i = 1; i <= n; i++){
        west[i] = west[i - 1] + (s[i] == 'W');
    }
    for(int i = n; i >= 1; i--){
        east[i] = east[i + 1] + (s[i] == 'E');
    }
    for(int i = 1; i <= n; i++){
        ans = min(ans, west[i - 1] + east[i + 1]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3056
#include <iostream>
using namespace std;
const int INF = 1000000000;

int main() {
    int N; 
    string S;
    cin >> N >> S;
    int ans = 0;
    for (int i = 0; i <= 999; i++) {
        int dig[3] = {i / 100, i / 10 % 10, i % 10};
        int flag = 0;
        for (int j = 0; j < N; j++) {
            if (S[j] - '0' == dig[flag]) flag++;
            if (flag == 3) break;
        }
        if (flag == 3) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
N, K = map(int, input().split())
ball_count = [0 for _ in range(N)]
for ball in list(map(int, input().split())):
    ball_count[ball-1] += 1

ball_count.sort()
ball_count.reverse()
answer = 0
# 配列の要素で0でないものがK個以下になるまで要素の小さいものを書き換えていきcountを加えていく。
# 種類を減らすためには全てを０にしないとおけない

print(sum(ball_count[K:]))


Measured memory_bytes: 26344
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <sstream>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define LB long double
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const double eps=1e-10;
const int INF=2e9;
const LL LINF=2e16;
const int magic=100;

inline int getint()
{
	char ch;
	while ((ch=getchar())<'0' || ch>'9') {}
	int res=ch-'0';
	while ((ch=getchar())>='0' && ch<='9') res=res*10+ch-'0';
	return res;
}

int n,e,T;
LL a[100048];
priority_queue<pair<LL,int> > q1,q2;
LL dp[100048];

int main ()
{
	int i;
	n=getint();e=getint();T=getint();
	for (i=1;i<=n;i++) a[i]=(LL)getint();
	dp[0]=0;
	a[0]=0;
	q2.push(mp(a[0]-dp[0],0));
	//dp[1]=a[1]+T;
	//q2.push(mp(a[1]-dp[1],1));
	int num1,num2;
	for (i=1;i<=n;i++)
	{
		
		bool f=true;
		while (!q2.empty() && f)
		{
			int num=q2.top().y;f=false;
			if (T-2*a[i]+2*a[num+1]<0)
			{
				q2.pop();f=true;
				q1.push(mp(a[num]+2*a[num+1]-dp[num],num));
			}
		}
		LL ans1=LINF,ans2=LINF;
		if (!q1.empty())
		{
			num1=q1.top().y;
			ans1=dp[num1]+3*a[i]-a[num1]-2*a[num1+1];
		}
		if (!q2.empty())
		{
			num2=q2.top().y;
			ans2=dp[num2]+a[i]-a[num2]+T;
		}
		dp[i]=min(ans1,ans2);
		q2.push(mp(a[i]-dp[i],i));
	}
	//for (i=1;i<=n;i++) cout<<dp[i]<<' ';
	//cout<<endl;
	cout<<dp[n]+(e-a[n])<<endl;
	return 0;
}

Measured memory_bytes: 5492
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    r = 0
    m = map(int, read().split())
    ab = zip(m, m)
    t = 0
    for a, b in ab:
        if a == b:
            t += 1
            if t == 3:
                print('Yes')
                sys.exit()
        else:
            t = 0
    print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
#define PRYES(x) PR((x) ? "Yes" : "No")
const long long INF = numeric_limits<long long>::max();

// 双方向の関係性をグループにまとめられるやつ
// https://atcoder.jp/contests/abc177/tasks/abc177_d
class UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
public:
    vector<ll> datas;
    UnionFind(ll N) : datas(N, -1) {
    }
    // 該当の値が根か
    bool isRoot(ll x) const {
        return datas[x] < 0;
    }
    // 根の情報を更新/取得
    ll root(ll x) {
        if (isRoot(x)) return x;
        // Rootの情報を更新する
        datas[x] = root(datas[x]);
        return datas[x];
    }

    // 値a,bを関連付け
    bool unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (datas[x] > datas[y]) swap(x, y);
        datas[x] += datas[y];
        datas[y] = x;
        return true;
    }

    // 該当の根に相当するデータサイズを取得
    ll size(ll x) {
        return -datas[root(x)];
    }

    // 該当の値の根が同じかを判定
    bool same(ll a, ll b) {
        return root(a) == root(b);
    }

    void Dump() {
#ifdef SOURCE_TEST
        REP(i, datas.size()) {
            if (isRoot(i)) {
                PS("Root:");
                PS(size(i));
            } else {
                cout << datas[i] << ":";
            }

            PR(i);
        }
#endif
    }
};

int main() {
    ll N, M;

    cin >> N >> M;

    vector<ll> values(N);
    REP(i, N) {
        cin >> values[i];
    }

    UnionFind unionFind(N);
    REP(i, M) {
        ll x, y;
        cin >> x >> y;
        unionFind.unite(x - 1, y - 1);
    }

    ll count = 0;
    REP(i, N) {
        if (unionFind.same(i, values[i] - 1)) {
            count++;
        }
    }
    PR(count);
    return 0;
}

Measured memory_bytes: 4776
#include<stdio.h>
int main(){
  int n,i,tmp;
  scanf("%d",&n);
  int p[n],price=0;
    for(i=0;i<n;i++){
      scanf("%d",&p[i] );
    }

    for(i=0;i<n-1;i++){
      if(p[i]>p[i+1]) {
        tmp = p[i];
        p[i] = p[i+1];
        p[i+1] = tmp;
      }
    }

for(i=0;i<n-1;i++) price = price + p[i];
price = price + p[n-1]/2;

printf("%d\n",price);

return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <functional>
#include <algorithm>
#include <string>

using namespace std;

int main (void)
{
	string a,A;
	int n = 0;

	cin >> a;
   //cout << a;
	for (int i = 0;i < a.size(); i++) {
	        a[i] = tolower(a[i]);
	    }

   for (int s = 0; s < 1000 ;s++)
   {
    cin >> A;

    for (int i = 0; i < A.size(); i++)
    {
    	A[i] = tolower(A[i]);
    }
    if (A == "END_OF_TEXT")
    {
	   break;
    }

    if (A == a)
    {

	    n += 1;
    }
    //cout << A;
   }
    cout << n << endl;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll n,a[1005],p[1005];
vector<ll> func(){
	vector<ll> res(1,0);
	for(ll i=1;i<=n;i++)
		if(p[i])
			res[0]+=a[i];
	ll temp=1,i=n;
	while(temp<=n&&p[temp]==0)
		temp++;
	while(i>=1&&p[i]==0){
		res.push_back(i);
		i--;
	}
	while(i>temp){
		ll j=i-3;
		while(j>=1&&p[j+1]==0){
			res.push_back(j+1);
			j-=2;
		}
		i=j+1;
		res.push_back(i+1);
	}
	i=1;
	while(i<temp){
		res.push_back(1);
		i++;
	}
	return res;
}
void solve(){
	cin>>n;
	for(ll i=1;i<=n;i++)
		cin>>a[i];
	ll f=0;
	for(ll i=1;i<=n;i+=2)
		if(a[i]>0)
			p[i]=f=1;
	if(!f){
		ll hi=(-pow(10,9)-5),ind=0;
		for(ll i=1;i<=n;i+=2)
			if(a[i]>hi){
				hi=a[i];
				ind=i;
			}
		p[ind]=1;
	}	
	vector<ll> res=func();
	for(ll i=1;i<=n;i++)
		p[i]=0;
	f=0;
	for(ll i=2;i<=n;i+=2)
		if(a[i]>0)
			p[i]=f=1;
	if(!f){
		ll hi=(-pow(10,9)-5),ind=0;
		for(ll i=2;i<=n;i+=2)
			if(a[i]>hi){
				hi=a[i];
				ind=i;
			}
		p[ind]=1;
	}
	vector<ll> temp=func();
	if(temp[0]>res[0])
		res=temp;
	cout<<res[0]<<"\n"<<sz(res)-1<<"\n";
	for(ll i=1;i<sz(res);i++)
		cout<<res[i]<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 3864
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define INF 1000000000
using namespace std;

int main()
{
    int N;
    int M;
    
    cin >> N;
    cin >> M;
    
     vector<vector<int>> E(N, vector<int>(N));

    for(int i=0; i<M; i++){
        int s;
        int t;
        cin >> s;
        cin >> t;
        E[s-1].push_back(t-1);
    }
    
    vector<double> dp(N);
    
    double min = INF;

    for(int a=0; a<N; a++){
        dp[N-1] = 0;
        for(int i=N-2; i>=0; i--){
            double count = 0;
            double sum = 0;
            double max = 0;
            for(auto e: E[i]){
                if(e!=0){
                    count++;
                    sum += dp[e];
                    if(dp[e] >= max) max = dp[e];
                }
            }
            if(i == a){
                dp[i] = ((sum-max)/(count-1))+1;
            }
            else{
                dp[i] = (sum/count)+1;
            }
            
        }
        if(dp[0] <= min) min = dp[0];
    }
    cout.precision(10);
    cout << min << endl;
    
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <vector>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

struct Dice {
	int top, front, right, left, back, bottom;

	void toN() {
		swap(top, front);
		swap(front, bottom);
		swap(bottom, back);
	}

	void toS() {
		swap(top, back);
		swap(back, bottom);
		swap(bottom, front);
	}

	void toE() {
		swap(top, left);
		swap(left, bottom);
		swap(bottom, right);
	}

	void toW() {
		swap(top, right);
		swap(right, bottom);
		swap(bottom, left);
	}

	bool rotateTo(int toTop, int toFront) {
		if (top == toFront) {
			toS();
		} else if (front == toFront) {
			// noop
		} else if (right == toFront) {
			toW();
			toS();
		} else if (left == toFront) {
			toE();
			toS();
		} else if (back == toFront) {
			toS();
			toS();
		} else if (bottom == toFront) {
			toN();
		} else {
			return false;
		}
		if (top == toTop) {
			// noop
		} else if (right == toTop) {
			toW();
		} else if (left == toTop) {
			toE();
		} else if (back == toTop) {
			return false;
		} else if (bottom == toTop) {
			toE();
			toE();
		} else {
			return false;
		}
		return true;
	}
};

istream& operator>>(istream& in, Dice& dice) {
	in >> dice.top >> dice.front >> dice.right
		>> dice.left >> dice.back >> dice.bottom;
	return in;
}

int main() {

	Dice dice;
	cin >> dice;

	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		int t, f;
		cin >> t >> f;
		dice.rotateTo(t, f);
		cout << dice.right << endl;
	}

	return 0;
}



Measured memory_bytes: 3108
// A - Bichrome Cells

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	int ans = N * N - A;

	cout << ans << endl;

	return 0;
}

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

using namespace std;

void solve() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
        for (int j = 0; j < M; j++)
        {
            cin >> A[i][j];
        }
    }
    

    int ans = -1;
    
    for (int bit = 0; bit < (1<<N); ++bit) {
        vector<int> U(M, 0);
        int m;
        m = 0;

        for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                m += C[i];
                for (int j = 0; j < M; j++)
                {
                    U[j] += A[i][j];
                }
            }
        }

        int flg;
        flg = 1;
        for (int i = 0; i < M; i++)
        {
            if(U[i] < X){
                flg = 0;
            }
        }
        if(flg){
            if(ans == -1){
                ans = m;
            }else{
                ans = min(ans, m);
            }
        }
    }
    cout << ans << endl;
}

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

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

using namespace std;

const int N = 101;


int a, b, u[N][N], v[N][N], n = 70, m = 70;
bool flag;

void dfs(int x, int y){
      v[x][y] = 1;
      if(u[x][y + 1] == u[x][y] && !v[x][y + 1] && y + 1 <= m)
            dfs(x, y + 1);
      if(u[x][y - 1] == u[x][y] && !v[x][y - 1] && y - 1 >= 1)
            dfs(x, y - 1);
      if(u[x + 1][y] == u[x][y] && !v[x + 1][y] && x + 1 <= n)
            dfs(x + 1, y);
      if(u[x - 1][y] == u[x][y] && !v[x - 1][y] && x - 1 >= 1)
            dfs(x - 1, y);
}

int main(){
      cin >> a >> b;
      a --, b --;
      int x = 1, y = 1;

      while(a > 0){
            u[x][y] = 1;
            a --;
            y += 2;
            if(y > m){
                  x += 2;
                  y = 1;
            }
      }

      for(int i = n / 2; i <= n; i ++)
            for(int j = 1; j <= m; j ++)
                  u[i][j] = 1;

      x = n, y = m;
      while(b > 0){
            u[x][y] = 0;
            b --;
            y -= 2;
            if(y <= 0){
                  y = m;
                  x -= 2;
            }
      }

      int cnt = 0, cn = 0;

      for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= m; j ++){
                  if(v[i][j] == 0 && u[i][j] == 1){
                        dfs(i, j), cnt ++;
                  }
            }
      }

      for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= m; j ++){
                  if(v[i][j] == 0 && u[i][j] == 0){
                        flag = 1;
                        dfs(i, j), cn ++;
                        flag = 0;
                  }
            }
      }

//      cout << cnt << " " << cn << endl;
      cout << n << " " << m << endl;

      for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= m; j ++)
                  if(u[i][j])
                        cout << '.';
                  else
                        cout << '#';
            cout << endl;
      }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    ll r=0;
    if(t%1000==0) cout<<"0";
    else{
       r=t%1000;
       int ans=1000-r;
       cout<<ans;
    } 
    return 0;
}

Measured memory_bytes: 3652
x,y = map(int,input().split())
if x == y:
    print(0)
elif x < y:
    if x*y >= 0:
        print(y-x)
    else:
        print(1+abs(abs(x)-abs(y)))
else:
    if x >= 0 and y > 0:
        print(2+abs(x-y))
    elif x >= 0 and y <= 0:
        if x+y >= 0:
            print(1+x+y)
        else:
            print(1+abs(x+y))
    else:
        print(2+x-y)


Measured memory_bytes: 3060
n = input()
p = list(map(int, input().split()))

# print(p)
p_sorted = sorted(p)
# print(p_sorted)

haming = 0
ans = "YES"
for ori_p, sort_p in zip(p, p_sorted):
    if ori_p != sort_p:
        haming += 1
    if haming > 2:
        ans = "NO"
        break

print(ans)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		String x = sc.next();
		int start = 0;
		int goal = 0;
		for(int i = 0; i < x.length(); i++) {
			if(x.charAt(i) == 'A') {
				start = i;
				break;
			}
		}
		for(int i = x.length() - 1; i >= 0; i--) {
			if(x.charAt(i) == 'Z') {
				goal = i;
				break;
			}
		}
		System.out.println(goal - start + 1);
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

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


Measured memory_bytes: 26792
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


vector<int> Sieve(int n){
    vector<int> ret(n + 1, 0);
    vector<int> pr;
    for (int i = 2; i <= n; i++) {
        if (ret[i] == 0) {
            ret[i] = i;
            pr.emplace_back(i);
        }
        for (int j = 0; j < pr.size() && pr[j] <= ret[i] && i*pr[j] <= n; j++) ret[i * pr[j]] = pr[j];
    }
    return ret;
}




int main(){
    auto p = Sieve(1000000);
    int n;cin >> n;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> cnt(2000000, 0);
    for (int i = 0; i < n; i++) {
        auto A = a[i];
        while(A != 1){
            auto P = p[A];
            cnt[P]++;
            while(A % P == 0){
                A /= P;
            }
        }
    }
    bool f = true;
    for (int i = 0; i < cnt.size(); i++) {
        if(cnt[i] > 1){
            f = false;
            break;
        }
    }
    if(f) puts("pairwise coprime");
    else{
        LL aa = a[0];
        for (int i = 0; i < n; i++) {
            aa = gcd(aa, a[i]);
        }
        if(aa == 1) puts("setwise coprime");
        else puts("not coprime");
    }
    return 0;
}


Measured memory_bytes: 22980