akhauriyash/Code-Regression huggingface dataset:
n = int(input())
XY = []
ans = 0
for i in range(n):
  a = int(input())
  XY.append([])
  for j in range(a):
    XY[i].append(list(map(int,input().split())))
for i in range(2**n):
  i = format(i, 'b')
  i = i.zfill(n)
  temp = i.count("1")
  temp2 = 0
  for j in range(n):
    if i[j] == "1":
      for k in range(len(XY[j])):
        if str(XY[j][k][1]) != i[XY[j][k][0]-1]:
          temp2 = 1
          break
  if temp2 == 0:
    if ans < temp:
      ans = temp
print(ans)

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


#define mod                1000000000000000007
#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define pii                pair < int , int >
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define forn(i,n)          for(i = 0 ; i < n ; i++)
#define deb(x)             cout << #x << " " << x << endl;
#define vecsum(v)          accumulate(v.begin(), v.end(), 0)
#define T(t)               cout << "Case " << t <<": ";
#define fast_cin           ios_base::sync_with_stdio(false);cin.tie(NULL)






vector < ll > a,b;
int n , m , k ;
int main() {



     cin >> n >> m >> k ;
     vector< ll >sumA(n+1),sumB(m+1);

     for( int i = 0 ; i < n ; i++ ){
         ll x;
         cin >> x;
         a.pb(x);
     }
     for( int i = 0 ; i < m  ; i++ ){
         ll x;
         cin >> x;
         b.pb(x);
     }

     for( int i = 0 ; i < n ; i++ ){
         sumA[i+1] = sumA[i] + a[i];
     }
     for( int i = 0 ; i < m ; i++ ){
         sumB[i+1] = sumB[i] + b[i];
     }

     ll mx = 0 ;
     ll total = 0 ;

     for( ll i = 0 ; i <= n ; i++ ){
          ll rem = k - sumA[i];

          if( rem < 0 )continue;

          int j = lower_bound(sumB.begin(),sumB.end(),rem)-sumB.begin();
          if( j > m || sumB[j] > rem){
             j--;
          }
          total = max( total , i + j );
     }

     cout << total << endl;








    return 0;
}

Measured memory_bytes: 11120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;

priority_queue<ll> pq;

int main() {
	ios::sync_with_stdio(false);
	ll n, m, a;
	while(cin >> n >> m) {
		while(!pq.empty()) pq.pop();
		for(int i = 0; i < n; i++) {
			cin >> a;
			pq.push(a);
		}
		for(int i = 0; i < m; i++) {
			ll t = pq.top();
			pq.pop();
			pq.push(t / 2);
		}
		ll ans = 0;
		while(!pq.empty()) {
			ans += pq.top();
			pq.pop();
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int n,x,y;
int main()
{
    cin>>n;
    for (int i=2;i<=n;i+=2)
        x++;
    for (int i=1;i<=n;i+=2)
        y++;
    cout<<x*y;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,x;
map<int,int> mp;
int main() {
    cin >> n;
    for(int i=1;i<=n;++i) {
        cin >> x;
        mp[x]++;
    }
    cin >> m;
    int flag=1;
    for(int i=1;i<=m;++i) {
        cin >> x;
        if(mp[x]) {
            mp[x]--;
        }
        else flag=0;
    }
    if(flag) cout <<"YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

#define int long long
#define INF 9223372036854775807
#define M_PI 3.14159265358979323846
#define double long double

int mod = INF;

int fastPow(int b, int e){int r = 1;while(e){if(e%2 == 1){r*=b;r%=mod;}b*=b;b%=mod;e/=2;}return r;}
int pgcd(int a, int b){ if(a%b == 0) return b; else return pgcd(b, a%b);}
int sign(int a){if(a < 0){ return -1;}if(a == 0) {return 0;}if(a > 0) {return 1;}}
bool isPrime(int a){if(a == 1) {return false;}int f = sqrt(a);for(int i = 2; i<=f; i++){if(a%i == 0){return false;}}return true;}
int toInt(string s){int tot = 0;for(int i = s.size()-1; i >= 0; i--){tot+=((s[i]-'0')%mod)*fastPow(10,i);tot%=mod;}return tot;}
string toString(int a){string s = "";while(a){s = (char)('0'+a%10) + s;a/=10;}return s;}

int n;
vector<int> v;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    v.resize(n);
    int k;
    cin >> k;
    vector<int> dp(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    for(int i = 0; i < n; i++){
        dp[i] = 0;
        if(i) dp[i] = INF;
        for(int j = 1; j <= k; j++){
            if(i >= j){
                dp[i] = min(dp[i], dp[i-j]+abs(v[i]-v[i-j]));
            }
        }
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    List<Integer> list = new ArrayList<>();
    int judge = 1000000000;
    for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    }
    Collections.sort(list);
    for(int i = 0; i < n - k + 1; i++){
        if(list.get(i + k - 1) - list.get(i) < judge){
            judge = list.get(i + k - 1) - list.get(i);
        }
    }
    System.out.println(judge);
    
	}
}

Measured memory_bytes: 58992
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let K: usize = sc.get();
    let S: String = sc.get();
    if S.len() <= K {
        println!("{}", S);
    } else {
        println!("{}...", &S[..K]);
    }
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;

int main()
{
    int n,x;
    cin>>n>>x;
    int64_t l,now=0,c=0;
    REP(i,n)
    {
        cin>>l;
        now+=l;
        
        if(now>x)break;  
        c++;
    }
    c++;
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
int main(){
  int n;
  std::cin >> n;
  int a[21];
  int b[21];
  int c[21];
  int sum=0;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i+1];
  }
  for (int i = 0; i < n; i++) {
    std::cin >> b[i+1];
    sum+=b[i+1];
  }
  for (int i = 0; i < n-1; i++) {
    std::cin >> c[i+1];
  }


  int be;
  int now;
  for (int i = 1; i <= n; i++) {
    if(i!=1)if(a[i-1]+1==a[i]){
      sum+=c[a[i-1]];
    }
  }
  std::cout << sum << '\n';


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
#define INF 1000000000
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t)
{
    std::ostringstream os;
    os << t;
    return os.str();
}
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main()
{
    double a, b;
    cin >> a >> b;
    printf("%.8lf\n", a / b);
    return 0;
}

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


void solve(long long N, std::vector<long long> A){
    long long sum=0,countn=0,countmin=10000000000000;
    for(int i=0;i<N;i++){
        if(countmin>abs(A[i])){
            countmin=abs(A[i]);
        }
        if(A[i]>0){
            sum+=A[i];
        }else if(A[i]<0){
            sum-=A[i];
            countn++;
        }
    }
    if(countn%2==0){
        printf("%lld\n",sum);
    }else{
        printf("%lld\n",sum-countmin*2);
    }

}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
import collections
import itertools
import functools
import math
import scipy.special

if __name__ == "__main__":
    k, s = map(int, input().split())
    res = 0
    mi = min(k, s)
    ma = max(k, s)
    for i in range(mi + 1):
        for j in range(mi + 1):
            if 0 <= s - i - j and s - i - j <= k:
                res += 1
    print(res)

Measured memory_bytes: 14664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String[] lines = in.readLine().split(" ");
      int h = Integer.parseInt(lines[0]);
      int w = Integer.parseInt(lines[1]);
      boolean[][] mat = new boolean[h][w];

      String line;
      for(int y=0; y<h; y++) {
        line = in.readLine();
        for(int x=0; x<w; x++) {
          mat[y][x] = line.charAt(x) == '#' ? true : false;
        }
      }

      int[] rx = {0,0,-1,1};
      int[] ry = {-1,1,0,0};
      boolean result = true;
      boolean isPossible = false;
      for(int y=0; result && y<h; y++) {
        for(int x=0; result && x<w; x++) {
          if(mat[y][x]) {
            for(int i=0; i<4; i++) {
              if(y+ry[i] > -1 && y+ry[i] < h && x+rx[i] > -1 && x+rx[i] < w)
                if(mat[y+ry[i]][x+rx[i]]) {
                  isPossible = true;
                  break;
                }
            }
            if(isPossible) isPossible = false;
            else {
              result = false;
              // System.out.println( y + " " + x);
            }
          }
        }
      }

      String ans = result ? "Yes" : "No";
      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

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

int reverce(int n){
    int reverced_num = 0;
    int digit = pow(10, to_string(n).length()-1);

    while(n){
        reverced_num += (n % 10) * digit;
        n /= 10;
        digit /= 10;
    }
    return reverced_num;
}

int main(){
    int A, B, reverced_num, count = 0;
    cin >> A;
    cin >> B;

    for (int i = A; i <= B; i++){
        reverced_num = reverce(i);
        if(reverced_num == i) count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4052
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
	private static class Pair{
		private int key;
		private int value;
		public Pair(int key,int value)
		{
			this.key=key;
			this.value=value;
		}
		public int getKey()
		{
			return key;
		}
		public int getValue()
		{
			return value;
		}
	}
		public static int boardBfs(char[][] a)
		{
			LinkedList<Pair> q = new LinkedList<Pair>();
			boolean[][] visited = new boolean[a.length][a[0].length];
			Pair[][] prev = new Pair [a.length][a[0].length];
			q.add(new Pair(0,0));
			visited[0][0]=true;
			int[] row = {0,0,1,-1};
			int[] col = {-1,1,0,0};
			
			while(!q.isEmpty())
			{
				Pair p = q.pop();
				int n=(int) p.getKey();
				int m=(int) p.getValue();
				
				if(n==a.length-1 && m==a[0].length-1)
				{
					//finish the bfs
					int count = 0;
					Pair pair = prev[n][m];
					n=(int)pair.getKey();
					m=(int)pair.getValue();
					while(n!=0 || m!=0)
					{
						a[n][m]='#';
					    pair = prev[n][m];
						n = (int)pair.getKey();
						m = (int) pair.getValue();
					}
					//count 
					for(int i=0;i<a.length;i++)
					{
						for(int j=0;j<a[0].length;j++)
						{
							if(a[i][j]=='.')
								count++;
						}
					}
					return count-2;
				}
				for(int i=0;i<row.length;i++)
				{
					if(n+row[i]>=0&&n+row[i]<a.length&&m+col[i]>=0&&m+col[i]<a[0].length&&
							a[n+row[i]][m+col[i]]=='.'&& !visited[n+row[i]][m+col[i]])
					{
						//add to bfs 
						visited[n+row[i]][m+col[i]]=true;
						prev[n+row[i]][m+col[i]]=p;
						q.add(new Pair(n+row[i],m+col[i]));
					}
				}			
			}
			
			return -1;
		}
		
		public static void main(String[] args){
			
			Scanner s = new Scanner(System.in);
			int n=s.nextInt();
			int m=s.nextInt();
			char[][] a = new char[n][m];
			
			for (int i = 0; i < a.length; i++) {
				String str = s.next();
				for (int j = 0; j < a[0].length; j++) 
					a[i][j]=str.charAt(j);
			}
			System.out.println(boardBfs(a));
					
			s.close();
		}		
}


Measured memory_bytes: 23764
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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 ll INF=1e15;

int main()
{
    ll n,T;
    cin >> n >> T;
    vector<ll> t(n);
    rep(i,n){
        cin >> t[i];
    }
    ll ans=0;
    ll st=t[0];
    ll en=T;
    rep(i,n){
        if(i==n-1){
            ans+=en-st;
            break;
        }
        if(en<t[i+1]){
            ans+=en-st;
            st=t[i+1];
            en=t[i+1]+T;
        }
        else{
            en=t[i+1]+T;
        }
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==1) cout<<"Hello World" ;
	else
	{
		int a,b;
		cin>>a>>b;
		cout<<a+b;
	}
	return 0;
}



Measured memory_bytes: 256
X=int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
while len(prime_factorize(X))!=1:
    X+=1
print(X)



        




    









        

    









    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Measured memory_bytes: 9120
#include <iostream>
#define int long long

using namespace std;

const int N = 2e5 + 10;

signed main() {
	int n, d;
	cin >> n >> d;
	
	int ans = 0;
	for (int i = 1, x, y; i <= n; ++i) {
		cin >> x >> y;
		if (x * x + y * y <= d * d) ans++;
	}
	
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 3648
import numpy as np
 
N, T = map(int, input().split())
data = []
for i in range(N):
  a, b = map(int, input().split())
  data.append((a,b))
data.sort()
data = np.array(data)

dp = np.zeros(T)
ans = 0
for a, b in data:
    ans = max(ans,dp[-1]+b)
    if a< T:
        newtable = dp[:T-a] + b
        dp[a:] = np.maximum(dp[a:], newtable)

print(int(ans))

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

using namespace std; 

int main(){ 
  string s;
  cin>>s;
  int c=110;
  int f=-1;
  for(int i=0;i<s.size();i++){
    if(s[i]=='C'){
      c=min(i,c);
    }
    if(s[i]=='F'){
      f=max(i,f);
    }
  }
  if(f<c) cout<<"No";
  else cout<<"Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);	
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll qw(ll x,ll y){ll res = 1;while(y){if(y & 1) res *= x;x = x * x;y >>= 1;}return res;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
string s,t;
bool check(){
	for(int i = 0;i < s.size();i++){
		if(s[i] != t[i]) return 0;
	}
	return 1;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s >> t;
	if(check()) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
//do smt instead of nothing! never give up!


Measured memory_bytes: 3640
n,m = map(int,input().split())

dp = [float("inf")]*(2**n)

p = []
used = [True]*(2**n)

for _ in range(m):
    a,b = map(int,input().split())
    c = tuple(map(int,input().split()))
    jkl = 0
    for e in c:
        jkl += 1 << (e-1)
    p.append(jkl)
    dp[jkl] = min(dp[jkl],a)
    used[jkl] = False

tank = []

while True:
    tank = []
    for e in p:
        for ep in p:
            if dp[e|ep] > dp[e]+dp[ep]:
                dp[e|ep] = dp[e]+dp[ep]
                if used[e|ep]:
                    tank.append(e|ep)
                    used[e|ep] = False

    if len(tank) == 0:
        break
    for e in tank:
        p.append(e)

if dp[-1] == float("inf"):
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 45928
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll N,cnt=0;
  cin>>N;
  vector<pair<ll,ll>> p(N);
  for(ll i=0;i<N;i++) cin>>p[i].first>>p[i].second;
  reverse(p.begin(),p.end());
  for(ll i=0;i<N;i++){
    if((p[i].first+cnt)%p[i].second!=0){
      ll a=p[i].first+cnt,b=p[i].second,c;
      cnt+=b-a%b;
    }
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int>A(n);
	for(int i=0; i<n; i++)
		cin>>A[i];
	int q;
	cin>>q;
	while(q--){
		int b,e;
		cin>>b>>e;
		reverse(A.begin()+b, A.begin()+e);
	}
	for(int i=0; i<n-1; i++)
		cout<<A[i]<<" ";
	cout<<A[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 3116
a, b, k = list(map(int, input().split(' ')))

am = []
for i in range(1, a + 1):
    if a % i == 0:
        am.append(i)

bm = []
for i in range(1, b + 1):
    if b % i == 0:
        bm.append(i)

cm = []
for v in am:
    if bm.count(v) != 0:
        cm.append(v)

print(cm[- k])


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

/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/

using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

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

const int MAX = 15001000;
bool IsPrime[MAX];
int MinFactor[MAX];
vector<int> preprocess(int n = MAX)
{
    vector<int> res;
    for (int i = 0; i < n; ++i)
        IsPrime[i] = true, MinFactor[i] = -1;
    IsPrime[0] = false;
    IsPrime[1] = false;
    MinFactor[0] = 0;
    MinFactor[1] = 1;
    for (int i = 2; i < n; ++i)
    {
        if (IsPrime[i])
        {
            MinFactor[i] = i;
            res.push_back(i);
            for (int j = i * 2; j < n; j += i)
            {
                IsPrime[j] = false;
                if (MinFactor[j] == -1)
                    MinFactor[j] = i;
            }
        }
    }
    return res;
}

vector<int> primes(1000010);

bool prime_factor(int n)
{
    while (n != 1)
    {
        int prime = MinFactor[n];
        int exp = 0;
        while (MinFactor[n] == prime)
        {
            ++exp;
            n /= prime;
        }
        if (primes[prime] == 0)
            primes[prime]++;
        else
            return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto &it : A)
        cin >> it;

    preprocess();
    bool pairwise_coprime = true;
    for (int i = 0; i < N; i++)
    {
        if (!prime_factor(A[i]))
            pairwise_coprime = false;
    }
    if (pairwise_coprime)
    {
        cout << "pairwise coprime" << endl;
        return 0;
    }
    else
    {
        int gcdAll = gcd(A[0], A[1]);
        for (int i = 1; i < N; i++)
        {
            gcdAll = gcd(gcdAll, A[i]);
        }
        if (gcdAll == 1)
            cout << "setwise coprime" << endl;
        else
            cout << "not coprime" << endl;
    }
    return 0;
}


Measured memory_bytes: 88456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s[100];
int main()
{
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++)cin>>s[i];
	vector<string> ans;
	for(int i=0;i<h;i++)
	{
		bool isw = true;
		for(int j=0;j<w;j++)
		{
			if(s[i][j] == '#')
			{
				isw = false;
				break;
			}
		 } 
		if(!isw)
		{
			ans.push_back(s[i]);
		}
	}
	for(int i=0;i<w;i++)
	{
		bool f = true;
		for(int j=0;j<ans.size();j++)
		{
			if(ans[j][i] == '#')
			{
				f =  false;
				break;
			}
		}
		if(f)
		{
			for(int j=0;j<ans.size();j++)
			{
				ans[j][i] = 'A';
			}
		}
	 } 
	for(int i=0;i<ans.size();i++)
	{
		bool canc = true;
		for(int j=0;j<ans[i].size();j++)
		{
			if(ans[i][j] != 'A')
			{
				cout<<ans[i][j];
			}
		}
		cout<<endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Segment tree
//-------------------------------------------------
template<typename T>
class SegmentTree
{
private:
    using F = function<T(T,T)>;
    ::std::vector<T> btree;
    F f, _update;
    T e;
    int n;
public:
    SegmentTree(){}
    SegmentTree(int _n, F f, T e, F g=[](T a,T b){return b;})
         : f(f),e(e),_update(g)
    {
        init(_n);
    }
    SegmentTree(const ::std::vector<T> &v, F f, T e, F g=[](T a,T b){return b;})
         : f(f),e(e),_update(g)
    {
        int _n = v.size();
        init(_n);
        for(int i=0; i<_n; i++) btree[i+n-1] = v[i];
        build();
    }
    void init(int _n){
        n = 1;
        while(_n>n) n<<=1;
        btree.resize(2*n-1, e);
    }
    void build(){
        for(int i=n-2; i>=0; i--) btree[i] = f(btree[2*i+1], btree[2*i+2]);
    }
    void update(int k, T a){
        k += n-1;
        btree[k] = _update(btree[k], a);
        while(k>0){
            --k>>=1;
            btree[k] = f(btree[2*k+1], btree[2*k+2]);
        }
    }
    T query(int a, int b){
        T L=e, R=e;
        a+=n-1; b+=n-1;
        while(a<b){
            if (!(a & 1)) L=f(L, btree[a++]);
            if (!(b & 1)) R=f(btree[--b], R);
            a>>=1; b>>=1;
        }
        return f(L, R);
    }
    T operator[](int k){return btree[k+n-1];}
};

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi a(n);
    rep(i,n) cin>>a[i];
    SegmentTree<int> seg(a,
        [](int x,int y){return max(x,y);},
        0
    );
    rep(i,n){
        cout<<max(seg.query(0,i), seg.query(i+1,n))<<endl;
    }
    return 0;
}


Measured memory_bytes: 4480
n = int(input())
def getDepth(n):
    p = n[0]
    c = 0
    while p != -1:
        c += 1
        p = lst[p][0]

    return str(c)


lst = []
for i in range(n):
    lst.append([-1])
for i in range(n):
    s = list(map(int, input().split()))
    for j in s[2:2+s[1]]:
        lst[j][0] = s[0]
        lst[s[0]].append(j)

for i in range(n):
    k = ', internal node'
    if len(lst[i]) == 1:
        k = ', leaf'

    if lst[i][0] == -1:
        k = ', root'

    print('node ' + str(i) + ': parent = ' + str(lst[i][0]) + ', depth = ' + getDepth(lst[i]) + k + ',', end= ' ')
    print(lst[i][1:])


Measured memory_bytes: 24112
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    int N,A,B;

    std::cin >> N >> A >> B;

    if(B > A*N){
        std::cout << A*N << std::endl;
    }else{
        std::cout << B << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<3;i++)
        if(s[i]=='R')
            ans++;
    if(ans==2)
        if(s[1]=='S')
            ans=1;
    cout<<ans<<endl;
}

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

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

  int a,b;
  cin >> a >> b;

  string u;
  cin >> u;

  if (s == u) printf("%d %d\n",a-1,b);
  if (t == u) printf("%d %d\n",a,b-1);
}

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

int main() {
  int A,B;
  cin >> A >> B;
  int coin;
  if(A > B) {
    coin = A + A - 1;
  }
  else if(A < B) {
    coin = B + B - 1;
  }
  else {
    coin = A + A;
  }
  cout << coin << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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



Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>

using namespace std;

int ans = 1e9;

vector<int> r1(vector<int> cube) {
	for (int i = 0; i < 3; ++i) swap(cube[7 + i], cube[22 + i]);
	swap(cube[13], cube[18]);
	swap(cube[10], cube[12]);
	return cube;
}

vector<int> r2(vector<int> cube) {
	for (int i = 0; i < 3; ++i) swap(cube[3 + i * 3], cube[22 + i * 3]);
	swap(cube[12], cube[19]);
	swap(cube[13], cube[15]);
	return cube;
}

vector<int> r3(vector<int> cube) {
	for (int i = 0; i < 3; ++i) swap(cube[i + 1], cube[28 + i]);
	swap(cube[15], cube[16]);
	swap(cube[19], cube[21]);
	return cube;
}

vector<int> r4(vector<int> cube) {
	for (int i = 0; i < 3; ++i) swap(cube[1 + i * 3], cube[24 + i * 3]);
	swap(cube[10], cube[21]);
	swap(cube[16], cube[18]);
	return cube;
}

bool ok(vector<int> cube) {
	for (int i = 1; i < 9; ++i) if (cube[i] != cube[i + 1]) return false;
	for (int i = 10; i < 12; ++i) if (cube[i] != cube[i + 1]) return false;
	for (int i = 13; i < 15; ++i) if (cube[i] != cube[i + 1]) return false;
	for (int i = 16; i < 18; ++i) if (cube[i] != cube[i + 1]) return false;
	for (int i = 19; i < 21; ++i) if (cube[i] != cube[i + 1]) return false;
	for (int i = 22; i < 30; ++i) if (cube[i] != cube[i + 1]) return false;
	return true;
}

int solve(vector<int> cube) {
	queue<pair<vector<int>,int> > q;
	q.push(make_pair(cube, 0));
	while (!q.empty()) {
		int cnt = q.front().second;
		vector<int> puzzle = q.front().first;
		q.pop();
		if (cnt > 8) continue;
		if (ok(puzzle)) return cnt;
		q.push(make_pair(r1(puzzle), cnt + 1));
		q.push(make_pair(r2(puzzle), cnt + 1));
		q.push(make_pair(r3(puzzle), cnt + 1));
		q.push(make_pair(r4(puzzle), cnt + 1));
	}
	return -1;
}

int main() {
	int n; cin >> n;
	vector<int> puzzle(31);
	while (n--) {
		for (int i = 1; i <= 30; ++i) cin >> puzzle[i];
		cout << solve(puzzle) << endl;
	}

	return 0;
}


Measured memory_bytes: 16740
while True:
    m, f, r = map(int, input().split())
    if m == f == r == -1:
        break

    if m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif m + f >= 65:
        print("B")
    elif m + f >= 50:
        print("C")
    elif m + f >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")



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

int main(){
  int n,m,mx,mn,mn2,mx2;
  int a[100], b[100];
  cin >> n;
  mx = 0;
  mn = 0;
  for(int i=0;i<n;i++){

    cin >> m;

    for(int j=0;j<m;j++) cin >> a[j];

    //   for(int j=1;j<m;j++) b[j-1] = a[j] - a[j-1];

    mx = 0;

    mn = 0;
    
    for(int j=0;j+1<m;j++)
      if(a[j] < a[j+1] )
	mx = max(mx,a[j+1]-a[j]); 
			   
    for(int j=0;j+1<m;j++)
      if(a[j] > a[j+1])
	mn = max(mn,a[j]-a[j+1]);

    //    if(mn<0) mn2 = -mn;

    //    if(mx<0) mx2 = -mx;

    cout << mx << " " << mn << endl;

  }

   
  




  }
  


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)

int a, b, c, d, e, f;
int ans1, ans2;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double mx = 0;
    cin >> a >> b >> c >> d >> e >> f;
    rep(i, f / (100 * a) + 1){
        rep(j, f / (100 * b) + 1) {
            rep(k, f / c + 1) {
                rep(l, f / d + 1) {
                    if (i == 0 && j == 0 && k == 0 && l == 0) continue;
                    if (100 * a * i + 100 * b * j + c * k + d * l > f) continue;
                    int tmp = c * k + d * l;
                    if (tmp * (100 + e)  > e * (c * k + d * l + 100 * a * i + 100 * b * j)) continue;
                    double tmp1 = double(c * k + d * l) / double (c * k + d * l + 100 * a * i + 100 * b * j);
                    if (mx < tmp1) {
                        mx = tmp1;
                        ans1 = 100 * a * i + 100 * b * j + c * k + d * l;
                        ans2 = c * k + d * l;
                    }
                }
            }
        }
    }
    if (ans1 == 0 && ans2 == 0) {
        cout << 100 * a << " " << 0 << endl;
    }
    else cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        int N = cin.Int();
        var a = cin.ArrayInt(N);
        double ave = a.Average();
        var new_a = new double[N];
        for (int i = 0; i < N; i++) {
            new_a[i] = Math.Abs(a[i] - ave);
        }

        Console.WriteLine(Array.IndexOf(new_a, new_a.Min()));

        Console.ReadLine();
    }
}

Measured memory_bytes: 13280
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;

// 最大公約数求める関数
int my_gcd(int n , int m){
  if(n < m){
    int tmp = n;
    n = m;
    m = tmp;
  }
  int l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}

//char⇒int関数
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}



int main(){
int H,N; cin >> H >> N;
int sum , a ;
sum = 0;
rep(i,N) {
cin >> a;
sum += a;
}
if(sum >= H) cout << "Yes" << endl;
else cout << "No" << endl;
  }


Measured memory_bytes: 256
#include<iostream>
//#include<range/v3/all.hpp>
using namespace std;
//using namespace rng = std::ranges;
int main()
{
	int a,b,c,k;
    cin>>a>>b>>c>>k;
    
    if(a >= k)
        cout<<k<<endl;
    else if(k <= a + b){
        std::cout << a;
    }
    else{
        int x = k - a;
        x -= b;
        //cout<<x<<" ";
        if(x==0)
            cout<<a<<endl;
        else{
            cout<<((a) + (-1)*(x));
        }
    }
	return 0;
}

Measured memory_bytes: 3632
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >>= putStrLn . which "YES" "NO" . ( == 0 ) . ( `mod` 4 ) . read . concat . words


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

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

    vector<int> v(m+1);
    for(int i = 0; i < n; i++){
        cin >> k;
        while(k--){
            cin >> a;
            v[a]++;
        }
    }
    int ans = 0;
    for(int i : v) if(i == n) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
l = [int(input()) for i in range(5)]
k = int(input())
flag = 0
for i in range(5):
  for j in range(5):
    if abs(l[i]-l[j]) > k:
      flag = 1
      break
if flag == 1:
  print(':(')
else:
  print('Yay!')

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    if len(set(S)) > 1:
        print("Yes")
    else:
        print("No")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == "__main__":
    main()


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N, K;
    cin >> N >> K;
    int ans = (N - 1 + K - 2) / (K - 1);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ph push
#define ptc putchar
#define enter putchar('\n')
#define mod 998244353
using namespace std;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long lnt;
inline int read(){
	int x = 0;char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + c - '0' , c = getchar();
	return x;
}
inline void write(int x){
	if (!x){
       ptc('0');
       return;
	}
	int dg[20] , len = 0;
	while (x) dg[len++] = x % 10 , x /= 10;
	while (len--) ptc(dg[len]+'0');
}
inline void writeln(int x){
	write(x);
	ptc('\n');
}
inline int add(int x,int y){
	x += y;if (x >= mod) x -= mod;
	return x;
}
inline int sub(int x,int y){
	x -= y;if (x < 0) x += mod;
	return x;
}
inline int qpow(int x,int y){
	int res = 1;
	while (y){
		if (y & 1) res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;y >>= 1;
	}
	return res;
}
const int N = 2e5 + 10;
int n , a[N] , b[N] , res;
int main(){
	scanf("%d",&n);
	for (int i = 1;i <= n;i++){
		scanf("%d",a + i);
		b[a[i]] = i;
	}	
	res = n;
	for (int i = 1;i <= n;i++){
		int j = i;while (j + 1 <= n && b[j + 1] > b[j]) j++;
		res = min(res , n - (j - i + 1));
		i = j;
	}
	
	cout<<res;
	return 0;
}


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

int main(){
    int N,M;
    cin >> N >> M;
    int A[M];
    long sum =0;
    for(int i=0;i<M;i++) {
        cin >> A[i];
        sum += A[i];
    }
    if(N-sum < 0) cout << "-1" << endl;
    else cout << N-sum <<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	Info(){
		to = dist = cost = 0;
	}

	bool operator<(const struct Info &arg) const{
		return dist < arg.dist;
	};
	Info(int arg_to,int arg_dist,int arg_cost){
		to = arg_to;
		dist = arg_dist;
		cost = arg_cost;
	}

	int to,dist,cost;
};

int N,M,min_dist[10001],min_cost[10001];

vector<Info> V[10001];

void func(){

	for(int i = 1; i <= N; i++){
		V[i].clear();
		min_dist[i] = BIG_NUM;
		min_cost[i] = BIG_NUM;
	}

	int from,to,dist,cost;

	for(int i = 0; i < M; i++){
		scanf("%d %d %d %d",&from,&to,&dist,&cost);
		V[from].push_back(Info(to,dist,cost));
		V[to].push_back(Info(from,dist,cost));
	}

	priority_queue<Info> Q;

	min_dist[1] = 0;
	min_cost[1] = 0;

	for(int i = 0; i < V[1].size(); i++){
		min_dist[V[1][i].to] = V[1][i].dist;
		min_cost[V[1][i].to] = V[1][i].cost;
		Q.push(Info(V[1][i].to,V[1][i].dist,V[1][i].cost));
	}

	int min_index;

	while(!Q.empty()){
		if(Q.top().dist > min_dist[Q.top().to] || Q.top().cost > min_cost[Q.top().to]){
			Q.pop();
		}else{
			min_index = Q.top().to;
			Q.pop();

			for(int i = 0; i < V[min_index].size(); i++){
				if(min_dist[V[min_index][i].to] > min_dist[min_index]+V[min_index][i].dist){
					min_dist[V[min_index][i].to] = min_dist[min_index]+V[min_index][i].dist;
					min_cost[V[min_index][i].to] = V[min_index][i].cost;
					Q.push(Info(V[min_index][i].to,min_dist[V[min_index][i].to],min_cost[V[min_index][i].to]));
				}else if(min_dist[V[min_index][i].to] == min_dist[min_index]+V[min_index][i].dist && min_cost[V[min_index][i].to] > V[min_index][i].cost){
					min_cost[V[min_index][i].to] = V[min_index][i].cost;
					Q.push(Info(V[min_index][i].to,min_dist[V[min_index][i].to],min_cost[V[min_index][i].to]));
				}
			}
		}
	}

	int ans = 0;

	for(int i = 2; i <= N; i++)ans += min_cost[i];

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

}

int main(){

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 5060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>
 
using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)

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

    if (a <= 5) { cout << 0 << endl;
    } else if (a <= 12) { cout << b /2 << endl;
    } else {cout << b << endl;
    } 
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

count = 0
mx = 0

for i in range(n-1):
    if h[i] >= h[i+1]:
        count += 1
        if i == n-2:
            if mx < count:
                mx = count
    else:
        if mx < count:
            mx = count
        count = 0

print(mx)

Measured memory_bytes: 14224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static long maxK(int[] weights, int[] values, int W){
        int sum_value = 0;
        for (int i = 0; i < values.length; i++) {
            sum_value += values[i];
        }
        long[] dp = new long[sum_value+1];
        Arrays.fill(dp, (long) 1e18+5);
        dp[0] = 0;
        for (int i = 0; i < weights.length; i++) {
            for (int value_present = sum_value - values[i]; value_present >= 0; value_present--) {
                dp[value_present + values[i]] = Math.min(dp[value_present + values[i]], dp[value_present] + weights[i]);
            }
        }
        long res = 0;
        for (int i = 0; i < sum_value + 1; i++) {
            if (dp[i] <= W){
                res = Math.max(res, i);
            }
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(reader.readLine());
        int N = Integer.parseInt(st.nextToken());
        int W = Integer.parseInt(st.nextToken());
        int[] weights = new int[N];
        int[] values = new int[N];
        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(reader.readLine());
            weights[i] = Integer.parseInt(st.nextToken());
            values[i] = Integer.parseInt(st.nextToken());
        }
        System.out.println(maxK(weights, values, W));
    }
}


Measured memory_bytes: 23124
import math

n = int(input())
l = list(map(int, input().split()))
avg1 = sum(l)//n
avg2 = math.ceil(sum(l)/n)
# print(avg1, avg2)
res1 = 0
res2 = 0
for i in range(n):
    res1 += abs(l[i] - avg1)*abs(l[i] - avg1)
    res2 += abs(l[i] - avg2)*abs(l[i] - avg2)
print(min(res1, res2))



Measured memory_bytes: 9176
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


a, b = [int(sys.stdin.buffer.readline()) for _ in range(2)]
for i in range(1, 4):
    if i not in (a, b):
        print(i)
        break


Measured memory_bytes: 23608
#include<bits/stdc++.h>
#define Mod 998244353
#define Val(x) (((long long)x) % Mod)
#define maxn 400005
using namespace std;
int fac[maxn];
int Pow(int a,int n) {
	int ret = 1;
	int base = a;
	while(n > 0) {
		if(n & 1)	ret = Val(ret * base);
		base = Val(base * base);
		n >>= 1;
	}
	return ret;
}
int inv(int a) {
	return Pow(a,Mod - 2);
}
int C(int n,int m) {
	return Val(Val(fac[n] * inv(fac[m])) * inv(fac[n - m]));
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	fac[0] = 1;
	for(int i=1;i<maxn;i++)
		fac[i] = Val(fac[i - 1] * i);

	int n,m,k;
	cin >> n >> m >> k;
	int ans = 0;
	for(int i=0;i<=k;i++) {
		int now = Val(C(n - 1,i) * m);
		if(i != n - 1)
			now = Val(now * Pow(m - 1,n - 1 - i));
		ans = Val(ans + now);
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  int K;
  cin >> K;
  if (K % 2 == 1){
    cout << (K / 2) * ((K / 2) + 1) << endl;
  }
  else
  {
    cout << (K / 2) * (K / 2) << endl;
  }
  
}

Measured memory_bytes: 3588