akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n:usize,
        x:i64,
        l:[i64;n]
    }
    let mut sum = 0;
    let mut ans = 1;
    for i in 0..n{
        sum+=l[i];
        if sum<=x {
            ans+=1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
import java.util.*;
public class Main{
    
    public static int gcd(int a, int b){
        if ( a == 0 ) return b;
        
        return gcd(b%a, a);
    }
    
     public static void main(String []args){
         Scanner scan = new Scanner(System.in);
         int a = scan.nextInt();
         
         long s = 0;
         for (int i=1;i<=a;i++){
             for (int j=1;j<=a;j++){
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             }
         }
         
         System.out.println(s);
     }
}

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

using namespace std;

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

#define ff first
#define ss second

const int INF = 4e6+10;
const int maxn = 2e5+10;

vector<int> g[maxn];

ll binpow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)
			res*=a;
		a*=a;
		b/=2;
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int x;
	cin >> x;
	for(ll A=-5543;A<5543;++A){
		ll a = (A*A*A*A*A);
		//cout << "a = " << a << '\n';
		if(a == x){
			cout << A << " " << 0 << '\n';
			return 0;
		}
		else if(a < x){
			for(ll B=-5543;B<0;++B){
				ll b = (B*B*B*B*B);
				if(a+(-b)==x){
					cout << A << " " << B << '\n';
					return 0;
				}
			}
		}
		else{
			for(ll B=1;B<5543;++B){
				ll b = (B*B*B*B*B);
				if(a+b==x){	
					cout << A << " " << B << "\n";
					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 8332
#include<stdio.h>
int main(void){
	int a, b, c;
	int s=0, p=0, cnt=0, count=0;
	int i=0;
	int j;
	int t;
	while (scanf("%d%d%d", &a, &b, &c) != EOF){
		if (c > a) t = a, a = c, c = t;
		if (b > a) t = a, a = b, b = t;

		if (a < b + c){
			s++;
			if (a*a == b*b + c*c) p++;
			else if (a*a < b*b + c*c) cnt++;
			else count++;
		}
		else break;
	}
	printf("%d %d %d %d\n", s, p, cnt, count);

	return 0;
}

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

#define INF (1<<21)

int vis[101],M[101][101],d[101],p[101],n;

void dijkstra(){
    int minv,i,j,v;
    for( i = 1; i < n; i++ ){
        d[i] = INF;
        p[i] = -1;
    }
    while(1){
        minv = INF;
        int u = -1;
        for( i = 0; i < n; i++ ){
            if( minv>d[i] && !vis[i] ){
                minv = d[i];
                u = i;
            }
        }
        if( minv == INF ) break;
        vis[u]  = 1;
        for( v = 0; v < n; v++ ){
            if( !vis[i] && M[u][v]!=INF ){
                if( d[v] > d[u] + M[u][v] ){
                    d[v] = d[u] + M[u][v];
                }
            }
        }
    }
    for( i = 0; i < n ; i++ ){
        cout << i << " " << ( d[i]==INF? -1 : d[i] ) << endl;
    }
}

int main(){
    cin >> n;
    int i,j,k,u,v,du,quan;
    k = n;
    for( i = 0; i < n; i++ ){
        for( j = 0; j < n; j++ ){
            M[i][j] = INF;
        }
    }
    while(k--){
        cin >> u >> du;
        for( i = 0; i < du; i++ ){
            cin >> v >> quan;
            M[u][v] =quan;
        }
    }
    dijkstra();
}



Measured memory_bytes: 3120
# include<iostream>
using namespace std;
int main ()
{
	 int n;
	 cin>>n;
	 int A[n+1];
	 for(int i=1;i<=n;i++)
	 {
	 	 int x;
	 	 cin>>x;
	 	 A[x]=i;
	  } 
	  for(int i=1;i<=n;i++)
	  { 
	      cout<<A[i]<<" ";
	  }
	  cout<<endl;
}

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

int main() {
    size_t h, w;
    cin >> h >> w;
    vector<string> v( h );
    for ( size_t i = 0; i < h; ++i ) {
        cin >> v.at( i );
    }
    for ( size_t i = 0, j; i < h; ++i ) {
        for ( j = 0; j < w; ++j ) {
            if ( v.at( i ).at( j ) == '#' )
                break;
        }
        if ( j == w ) {
            for ( size_t j = 0; j < w; ++j ) {
                v.at( i ).at( j ) = '@';
            }
        }
    }
    for ( size_t i = 0,j; i < w; ++i ) {
        for ( j = 0; j < h; ++j ) {
            if ( v.at( j ).at( i ) == '#')
                break;
        }
        if ( j == h ) {
            for ( size_t j = 0; j < h; ++j ) {
                v.at( j ).at( i ) = '@';
            }
        }
    }
    bool f;
    for ( size_t i = 0; i < h; ++i ) {
        f = false;
        for ( size_t j = 0; j < w; ++j ) {
            if ( v.at( i ).at( j ) != '@' ) {
                cout << v.at( i ).at( j );
                f = true;
            }
        }
        if ( f == true )
            cout << "\n"s;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;  //このネームスペースを使う

int main(){
  int N ;
  int i ;

  cin >> N ;

  int p[N];
  int sum,max;
 
  sum=0;
  max=0;
  for(i=0;i<N;i++){
    cin >> p[i] ;
    sum += p[i] ;
    if(max < p[i]){
      max = p[i];
    }
  }
  max /= 2;

  cout << sum-max << endl;
  
  return 0;
}



Measured memory_bytes: 256
import collections

n = int(input())
List = [input() for i in range(n)]
res = []

#c = collections.Counter(List)

c = {}

for i in range(n):
    if List[i] in c.keys():
        c[List[i]] += 1
    else:
        c[List[i]] = 1


m = 0
for v in c.values():
    m = max(m, v)

for k, v in c.items():
    if v == m:
        res.append(k)
    
res.sort()
for i in range(len(res)):
    print(res[i])


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

ll gcd(ll x,ll y) {
	if(x==0||y==0) return 0;
	ll r=0;
	while((r=x%y)!=0) x=y,y=r;
	return y;
}

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

	ll a,b;
	while(cin>>a>>b) {
		ll g=gcd(a,b);
		cout<<g<<' '<<a/g*b<<endl;
	}

	return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int long long int
#define ld long double
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'	
#define setbits(x) (__builtin_popcount(x))
int mod=1000000007;
int INF64=mod*mod+1;

void solve(){
	int k;
	cin>>k;
	while(k--)
		cout<<"ACL";
}

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

	int T;
	// cin>>T;
	T=1;
	for(int i=1;i<=T;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
}

Measured memory_bytes: 3768
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#define MAX_N 200000
#define INF 100000000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
struct edge{
  ll to;
  ll cost;
};
vector<edge> G[MAX_N];
ll d[MAX_N];
signed main(){
  ll n,m,l,r,c;
  priority_queue<P,vector<P>,greater<P>> que;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> l >> r >> c;
    l--;
    r--;
    G[l].push_back({r,c});
    G[r].push_back({l,c});
  }
  for(int i=1;i<n;i++){
    G[i].push_back({i-1,0});
    d[i] = INF;
  }
  d[0]=INF;
  que.push(P(0,0));
  while(!que.empty()){
    P tmp = que.top();
    que.pop();
    ll v,dis;
    v = tmp.second;
    dis = tmp.first;
    if(d[v]<=dis){
      continue;
    }
    d[v] = dis;
    for(int i=0;i<G[v].size();i++){
      que.push({dis+G[v][i].cost,G[v][i].to});
    }
  }
  if(d[n-1]==INF) d[n-1]=-1;
  cout << d[n-1]<<endl;
}

Measured memory_bytes: 18420
#include <bits/stdc++.h>
using namespace std;
char s[101010];
int main() {
  cin >> s;
  int n = strlen(s);
  if (n % 2) {
    cout << "No";
    return 0;
  }
  bool ok = true;
  for (int i = 0; i < n; ++i) {
    ok &= i % 2 ? s[i] == 'i' : s[i] == 'h';
  }
  cout << (ok ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
import string

def generate(n, res, cur = None, alphabet = None):
    if cur is None:
        cur = []
    if alphabet is None:
        alphabet = list(string.ascii_lowercase)[::-1]
    if n == 0:
        res.append(''.join(cur))
        return
    for i in range(len(cur)):
        cur.append(cur[i])
        generate(n - 1, res, cur, alphabet)
        cur.pop()
    cur.append(alphabet.pop())
    generate(n - 1, res, cur, alphabet)
    alphabet.append(cur.pop())

res = []
generate(int(input()), res=res)
res = sorted(set(res))
for row in res:
    print(row)


Measured memory_bytes: 390300
#include<stdio.h>
#include<string.h>

int main(){
  int n,m,i,max=0,j,cnt=0;
  char s[100][10],t[100][10],x[200][10];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%s",s[i]);
  scanf("%d",&m);
  for(i=0;i<m;i++)
    scanf("%s",t[i]);
  for(i=0;i<n;i++){
    cnt=0;
    for(j=0;j<n;j++){
      if(strcmp(s[i],s[j])==0) cnt++;
    }
    for(j=0;j<m;j++){
      if(strcmp(s[i],t[j])==0) cnt--;
    }
    if(max<cnt) max=cnt;
  }
  printf("%d\n",max);
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int tot = 0, i;
  for (i = 1; tot + i <= n; tot += i, i ++);
  i --;
  int tg = i + 1 - (n - tot);
  for (int j = 1; j <= i; j ++) {
    if (j == tg) printf("%d\n", i + 1);
    else printf("%d\n", j);
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <list>
using namespace std;

int main(){
    int n = 0;
    double sd, avg;
    list<double> lst;
    while(cin >> n){
        if(n == 0) break;
        sd = 0;
        avg = 0;
        double *s = new double[n];
        for(int i = 0; i < n; i++){
            cin >> s[i];
            avg += s[i];
        }
        avg /= n;
        for(int i = 0; i < n; i++){
            sd += pow(s[i] - avg, 2);
        }
        sd = sqrt(sd / n);
        lst.push_back(sd);
    }
    list<double>::iterator itr = lst.begin();
    while(itr != lst.end()){
        printf("%.8f\n", *itr);
        itr++;
    }
}

Measured memory_bytes: 1256
(* Examples *)
(*
stdin.ReadLine()
printfn "%d"
printfn "%s"
*)

(* Library *)
module Library = 
  type Queue<'T> (capacity : int) =
    let data = Array.create (capacity + 1) Unchecked.defaultof<'T>
    let length = capacity + 1
    let mutable head = 0
    let mutable tail = 0

    member internal this.Add x = (x + 1) % length
    member internal this.Delete x = (x - 1) % length

    member this.isEmpty =
      if head = tail then true else false

    member this.isFull =
      if this.Add tail = head then true else false

    member this.Enqueue x =
      if this.isFull then 
        raise(new System.Exception("Capacity over"))
      else
        data.[tail] <- x
        tail <- this.Add tail
        ()
        
    member this.Peek =
      if this.isEmpty then 
        None
      else
        Some data.[head]

    member this.Dequeue =
      if this.isEmpty then 
        None
      else
        let result = Some data.[head]
        head <- this.Add head
        result

    member this.Clear =
      head <- 0
      tail <- 0
      ()

(* Standard Input *)
let readSplit elementFun=
  stdin.ReadLine().Split()
  |> Array.map elementFun

let read elementFun =
  stdin.ReadLine() |> elementFun

let readMap H =
  [|for i in 1..H -> stdin.ReadLine()|]
  |> Array.map(fun line ->
    line.ToCharArray()
  )
  |> array2D

(* Main *)
open Library

let [|H; W|] = readSplit int
let map = readMap H

let Q = Queue<int * int * int>(4000000)
map |> Array2D.iteri(fun i j chr ->
  if chr = '#' then
    Q.Enqueue (i, j, 0)
)

let mutable result = 0

let rec solve () =
  match Q.Dequeue with
  | Some (x, y, c) ->
    if x < 0 || x >= H || y < 0 || y >= W || map.[x, y] = 'b' then 
      solve ()
    else
      map.[x, y] <- 'b'
      Q.Enqueue (x + 1, y, c + 1)
      Q.Enqueue (x, y + 1, c + 1)
      Q.Enqueue (x - 1, y, c + 1)
      Q.Enqueue (x, y - 1, c + 1)
      result <- c
      solve ()
  | _ -> ()

solve ()
result |> printfn "%d"

Measured memory_bytes: 211712
#include <iostream>
int main() {

	int n = 0, a[100];
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	for (int i = n - 1; i >= 0; i--) {
		std::cout << a[i];
		if (i != 0) {
			std::cout << ' ';
		}
		else {
			std::cout << std::endl;
		}
	}
}


Measured memory_bytes: 3064
// Problem : D - Lucky PIN
// Contest : AtCoder - Sumitomo Mitsui Trust Bank Programming Contest 2019
// URL : https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n;
    string s;
    cin>>n>>s;
    int ans = 0;
    for(int a=0;a<=9;a++){
        for(int b=0;b<=9;b++){
            for(int c=0;c<=9;c++){
                int cnt = 0;
                for(char ch : s){
                    if(cnt == 0 && ch-'0' == a) cnt++;
                    else if(cnt == 1 && ch-'0' == b) cnt++;
                    else if(cnt == 2 && ch-'0' == c) cnt++;
                }
                if(cnt == 3) ans++;
            }
        }
    }
    cout<<ans;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <climits>
#include <algorithm>
using namespace std;

int main()
{
    long long int A, B;
    char op;
    cin >> A >> op >> B;
    if (op == '+') {
        cout << (A + B) << endl;
    } else {
        cout << (A - B) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n, k;
	scanf("%d %d",  &n, &k);
	V a(n);
	SCAN(a);

	ll l=0, r=1e9+1;
	while(r-l>1){
		ll mid = (l+r)/2.0;
		ll cnt = 0;
		REP(i, 0, n){
			cnt += (a[i]+mid-1)/mid;
			cnt--;
		}
		
		if(cnt>k) l = mid;
		else r = mid;
	}
	printf("%ld\n", r);
	return 0;
}




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

int main() {

	int N;
	cin >> N;

	int H[100];
	int answer = 1;
	int saidai = 0;

	for (int i = 0;i < N;i++) {
		int X;
		cin >> X;
		H[i] = X;

		if (i == 0) {
			saidai = H[0];
		}

		if (i != 0 && saidai <= H[i]) {
			saidai = H[i];
			answer++;
		}
	}

	cout << answer << endl;

	return 0;
}


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

/*sortの仕方
 * ■ string s の場合
 * 昇順: sort(s.begin(), s.end())
 * 降順:  sort(s.rbegin(), s.rend())
 *
 * ■ int a[N] の場合
 * 昇順: sort(a, a+N)
 * 降順: 不明
 */

int alph2int(char character) {
    int x = character - 'a';
    return x;
}


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

    int c[N], t[N];
    for (int i=0; i<N; i++) {
        cin >> c[i] >> t[i];
    }

    int ans = 1001;
    for (int i=0; i<N; i++) {
        if (t[i] <= T) {
            ans = min(ans, c[i]);
        }
    }

    if (ans == 1001) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
}

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

int main() {
  int k, s;
  cin >> k >> s;
  
  int count = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      int x = s - i - j;
      if (0 <= x && x <= k) count++;
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll modu=1000000007;
const int maxn=1e5+9;

int pl[maxn];
int tp=0;
void era(){
	const int mx=1e5;
	bool benp[mx+9]={0};
	int q=sqrt(mx);
	for(int i=2;i<=q;++i)
	if(!benp[i]){
		for(int j=i*i;j<=mx;j+=i)
		benp[j]=1;
	}
	for(int i=2;i<=mx;++i)
	if(!benp[i])pl[tp++]=i;
}


int idx[maxn];
void add(int p,int id,int f){
	idx[p]+=id*f;
}
//void clearlist(){
//	memset(idx,0,sizeof(int)*tp);
//}
ll getresult(){
//	for(int p=0;p<tp;++p)
//	if(idx[p]!=0){
//		printf("p%d i%d ",p,idx[p]);
//	}
	ll r=1;
	for(int p=0;p<tp;++p){
		while(idx[p]>0){
			idx[p]--;
			r=r*pl[p]%modu;
		}
	}
	return r;
}

void plusf(int x,int f){
	for(int p=0;p<tp;++p){
		if(x==1)break;
		int idx=0;
		while(x%pl[p]==0){
			idx++;
			x/=pl[p];
		}
		add(p,idx,f);
	}
}
ll perm(int r,int n){
//	printf("perm(%d,%d)",r,n);
	if(r>n)return 0;
	//for(int i=1;i<=r;++i)plusf(i,-1);
	for(int i=n;i>=n-r+1;--i)plusf(i,1);
	return getresult();
}


vector <int> edge[maxn];
int n,k,root;
ll rcv(int p,int fa){
//	printf("begin p=%d\n",p);
	ll pi=1;
	int tt=0;
	for(int v:edge[p])
	if(v!=fa){
		pi=pi*rcv(v,p)%modu;
		tt++;
	}
//	printf("pi=%lld*",pi);
	pi=pi*perm(tt,k-1-(p!=root))%modu;
//	printf("end p=%d pi=%lld\n",p,pi);
	return pi;
}
	
	

void solve(){
	root=1;
	cout<<rcv(1,-1)*k%modu;
}


void init(){
	cin>>n>>k;
	for(int i=1;i<n;++i){
		int a,b;cin>>a>>b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	era();
}

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


Measured memory_bytes: 10496
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int N, A, B;
    cin >> N >> A >> B;
    vector<int> X(N);
    for(int i = 0; i < N; ++i)  cin >> X[i];
    ll ans = 0;
    for(int i = 0; i + 1 < N; ++i){
        int d = X[i + 1] - X[i];
        if((ll)A * d >= B)  ans += B;
        else    ans += (ll)A * d;
    }
    cout << ans << endl;
}

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

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

    int N;
    cin >> N;

    vector<int> vi(N);
    rep(i, N) { cin >> vi[i]; }

    for (auto num : vi) {
        if (num % 2 == 0) {
            if (num % 3 != 0 && num % 5 != 0) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a, b):
    return (a * b)//gcd(a,b)

N = int(input())
A = list(map(int,input().split()))

lcm_a = 1

for i in A:
    lcm_a = lcm(lcm_a,i)

ans = 0
for i in A:
    ans +=lcm_a//i 
    
mod = int(1e9+7)
print(ans%mod)

Measured memory_bytes: 4084
#include <stdio.h>

int main(void) {
  int a, b;
  char op;
  while (1) {
    scanf(" %d %c %d", &a, &op, &b);
    switch (op) {
    case '?':
      return 0;
      break;
    case '+':
      printf("%d\n", a + b);
      break;
    case '-':
      printf("%d\n", a - b);
      break;
    case '*':
      printf("%d\n", a * b);
      break;
    case '/':
      printf("%d\n", a / b);
      break;
    }
  }
}



Measured memory_bytes: 1768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector <int> s(4);
    rep(i,4){
        s[3-i] = n%10;
        n /= 10;
    }

    vector <char> ansi(3);
    for(int i=0; i<(1<<3); i++){
        bitset<3> a(i);
        int tmp = s[0];
        for(int j=0; j<3; j++){
            if(a.test(j)){
                tmp += s[j+1];
                ansi[j] = '+';
            }
            else{
                tmp -= s[j+1];
                ansi[j] = '-';
            }
        }
        if(tmp == 7) break;
    }

    rep(i,3){
        cout << s[i] << ansi[i];
    }
    cout << s[3];
    cout << "=7" << endl;



}   



Measured memory_bytes: 3616
#include<iostream>
#include <string> // string, to_string, stoi
#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 <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b=100,c=0;cin>>a;
  while(b<a){
    b+=b/100;
    c++;
  }
  cout<<c;
}


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

int main()
{
    string s;
    cin>>s;
    string t;
    cin>>t;
    bool flag = true;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
        {
            flag = false;
        }
    }

    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7


import heapq
def prim_heap(n, edges):  # n: 最大の頂点番号+1, edges[頂点番号]=[[重み, 行き先],[重み, 行き先],...]. 無向グラフの場合は相方向有向グラフの表記にしておく。
    seen = [False] * n #True:不使用
    edgelist = []  # heapq
    for e in edges[0]:  # 頂点 0 から伸びる辺をすべて heapq に入れる。
        heapq.heappush(edgelist,e)
    seen[0] = True  # 頂点 0 は見たと記録する。
    res = 0
    while len(edgelist) != 0:
        minedge = heapq.heappop(edgelist)  # edgelist から最小の辺を1つ取り出す。
        if seen[minedge[1]]:  # その辺の行き先がすでに見た先だったら棄却して次へ。
            continue
        v = minedge[1]  # 行き先を v とする。
        seen[v] = True  # 頂点 v は見たと記録する。
        for e in edges[v]:  # 頂点 v から伸びる辺すべてについて、もしその行き先を見ていなかったら heapq に追加する。
            if not seen[e[1]]:
                heapq.heappush(edgelist,e)
        res += minedge[0]  # いま使った辺の重みを結果に加える。
    return res  # 最小全域木の全体の重みを出力する。



def main(): 
    N = II()
    pos_li = []
    for i in range(N):
        x,y = LI()
        pos_li.append((x,y,i))
    edges = [[] for _ in range(N)]
    # # すべての頂点を結ぶグラフを作ってその最小全域木を取ると、時間が足りない（二重ループが O(10^10)）。
    # for i in range(N):
    #     for j in range(N):
    #         weight = min(abs(pos_li[i][0] - pos_li[j][0]), abs(pos_li[i][1] - pos_li[j][1]))
    #         edges[i].append([weight, j])
    #         edges[j].append([weight, i])
    # # なので、座標でソートして、最も近い4点のみへ辺を伸ばす。
    pos_li.sort(key=lambda x: x[0])
    for k in range(N-1):
        x1, y1, p1 = pos_li[k]
        x2, y2, p2 = pos_li[k+1]
        weight = abs(x1-x2)
        edges[p1].append([weight, p2])
        edges[p2].append([weight, p1])

    pos_li.sort(key=lambda x: x[1])
    for k in range(N-1):
        x1, y1, p1 = pos_li[k]
        x2, y2, p2 = pos_li[k+1]
        weight = abs(y1-y2)
        edges[p1].append([weight, p2])
        edges[p2].append([weight, p1])

    # print(edges)
    print(prim_heap(N, edges))

main()

Measured memory_bytes: 122460
#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return 
#define endl         "\n" 

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2) 

#define fo(i,a,b)     for(int i = (int)(a); i <= (int)(b); i++)
#define rf(i,a,b)    for(int i = (int)(a); i >= (int)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***




void solve()
{
    int n;rd(n);
    int a[n];read(a,n);
    sort(a,a+n,greater<int>());   
    ll s = 0;
    s = a[0];
    int i = 1;
    int c = 1;
    while(c<n-1){
        s+=a[i];
        c++;
        if(c==n-1)break;
        s+=a[i];
        c++;
        i++;
    }
    pp(s);
}


void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    // cin >> t;
    while(t--)
        solve();

    cout<<"\n";
    return 0;
}

Measured memory_bytes: 4424
Var     n,g,b,l,c,d,y,o,r,u: Longint;
        a: Array[0..1005] Of Longint;

Procedure       Nhap;
Var     i: Longint;
Begin
Readln(n);
For i:=1 to n do
        Read(A[i]);
End;

Procedure       Xuly;
Var     i: Longint;
Begin
g:=0; b:=0; l:=0; c:=0; d:=0; y:=0; o:=0; r:=0; u:=0;
For i:=1 to n do
        Case a[i] of
                1..399: g:=1;
                400..799: b:=1;
                800..1199: l:=1;
                1200..1599: c:=1;
                1600..1999: d:=1;
                2000..2399: y:=1;
                2400..2799: o:=1;
                2800..3199: r:=1;
                3200..4800: Inc(u);
        End;
End;

Procedure       Xuat;
Begin
If (u=g+b+l+c+d+y+o+r+u) Then Writeln(1,' ',u)
Else Writeln(g+b+l+c+d+y+o+r,' ',g+b+l+c+d+y+o+r+u);
End;

Begin
Nhap;
XuLy;
Xuat;
End.

Measured memory_bytes: 128
from collections import Counter
n=int(input())
l=[input() for i in range(n)]
c=Counter(l)
c=c.most_common()
ansl=[]
max_num=c[0][1]
for i in range(len(c)):
    if c[i][1]==max_num:
        ansl.append(c[i][0])
ansl=sorted(ansl)
for i in range(len(ansl)):
    print(ansl[i])

Measured memory_bytes: 49420
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  int n;
  cin>>n;
  int sum = 0;
  bool flag=false;
    for(int i = 0;i*4<=n;i++){
      sum=i*4;
      for(int j = 0;sum<=n; j++){
        if(sum==n) {
          flag = true; 
          break;
        }
        else{
          sum+=7;
        }
      }
    }
  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
    char N[5];
    int i,yn=1;
 
    scanf("%s",N);
 
    for(i=0;i<2;i++){
        if(N[i]!=N[i+1]){
            yn = 0;
            break;
        }
        if(i==1){
            yn = 1;
            printf("Yes\n");
            return 0;
        }
    }
    
    for(i=3;i>1;i--){
        if(N[i]!=N[i-1]){
            yn = 0;
            break;
        }        
        if(i==2){
            yn = 1;
            printf("Yes\n");
            return 0;
        }
    }
 
    printf("No\n");
 
    return 0;
}

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

long merge_sort(vector<int>& A, int l, int r) {
    long cnt = 0;
    if (l >= r) return 0;
    int m = (l + r) / 2;
    cnt += merge_sort(A, l    , m);
    cnt += merge_sort(A, m + 1, r);
    vector<int> B1(m - l + 2);
    for (int i = 0; i < m - l + 1; i++) B1[i] = A[i+l];
    B1[m-l+1] = 1e9 + 1;
    vector<int> B2(r - m + 1);
    for (int i = 0; i < r - m; i++) B2[i] = A[i+m+1];
    B2[r-m] = 1e9 + 1;
    int j1 = 0;
    int j2 = 0;
    for (int i = l; i <= r; i++) {
        if (B1[j1] <= B2[j2]) {
            A[i] = B1[j1++];
        } else {
            A[i] = B2[j2++];
            cnt += m - l + 1 - j1;
        }
    }
    return cnt;
}

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    for (auto& a : A) cin >> a;
    cout << merge_sort(A, 0, n - 1) << endl;
    return 0;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a*n, b) << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

int n, x[110], y[110];
long long h[110];
int main()
{
    std::cin >> n;
    for (int i = 0; i < n; ++i)
        std::cin >> x[i] >> y[i] >> h[i];

    int ansX, ansY;
    long long ansH;
    for (int i = 0; i <= 100; ++i)
        for (int j = 0; j <= 100; ++j)
            for (int k = 0; k < n; ++k)
            {
                if (h[k] == 0)
                    continue;
                long long H = std::abs(x[k] - i) + std::abs(y[k] - j) + h[k];
                bool check = true;
                for (int l = 0; l < n; ++l)
                {
                    auto temp = std::max(H - std::abs(x[l] - i) - std::abs(y[l] - j), 0LL);
                    if (temp != h[l])
                    {
                        check = false;
                        break;
                    }
                }
                if (check)
                {
                    ansX = i;
                    ansY = j;
                    ansH = H;
                    std::cout << ansX << ' ' << ansY << ' ' << ansH << std::endl;
                    return 0;
                }
            }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
 
inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};


signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

     int a, b, c, x, y;
     cin >> a >> b >> c >> x >> y;

     cout << min({max(x, y) * c * 2, x * a + y * b, min(x, y) * c * 2 + (x < y ? b : a) * (max(x, y) - min(x, y))}) << '\n';

    return (0);
}

Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = 3;
        final int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        in.nextLine();
        Arrays.sort(arr);
        int res = 0;
        for (int i = 0; i < n - 1; i++) {
            res += arr[i + 1] - arr[i];
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 35920
#include <bits/stdc++.h>
#define MAXN 100010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const int mod = 1e9 + 7;


int main (){
    ll n, a, dp[55][5000], tmp;
    memset(dp, 0, sizeof dp);

    cin >> n >> a;

    dp[0][0] = 1;

    for (int i=1; i<=n; i++){
        cin >> tmp;
        for (int j=i; j>=1; j--){
            for (int k=0; k<=2500; k++){
                dp[j][k + tmp] += dp[j-1][k];
            }
        }
    }

    ll ans = 0;

    for (int i=1; i<=n; i++) ans+= dp[i][i*a];

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

Measured memory_bytes: 2432
// Ref : https://book.mynavi.jp/ec/products/detail/id=35408

#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
	int key;
	Node *parent, *left, *right;
};

// These pointer adress is NULL until first store (root == NIL).
// NIL adress is permanently NULL for defining empty node.
Node *root, *NIL;

void myInsert(int k) {
	Node *y = NIL; // parent
	Node *x = root; // comparison
	Node *z; // insertion

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}

	z->parent = y;
	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}

void inOrderPrint(Node *n) {
	if (n == NIL) return;
	inOrderPrint(n->left);
	cout << " " << n->key;
	inOrderPrint(n->right);
}

void preOrderPrint(Node *n) {
	if (n == NIL) return;
	cout << " " << n->key;
	preOrderPrint(n->left);
	preOrderPrint(n->right);
}

Node * myFind(Node *n, int k) {
	while (n != NIL && n->key != k) {
		if (k > n->key)	n = n->right;
		else n = n->left;
	}
	return n;
}

int main() {
	int n, x;
	char com[7];
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> com;
		if (com[0] == 'i') {
			cin >> x;
			myInsert(x);
		}
		else if (com[0] == 'p') {
			inOrderPrint(root);
			cout << endl;
			preOrderPrint(root);
			cout << endl;
		}
		else if (com[0] == 'f') {
			cin >> x;
			if(myFind(root, x ) == NIL) cout << "no";
			else cout << "yes";
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 21868
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
	int H, W, ih, iw;

	while (1) {
		cin >> H >> W;

		if (H == 0 && W == 0)
			break;
		for (ih = 0; ih < H; ih++) {
			for (iw = 0; iw < W; iw++) {
				if (ih == 0 || ih == H-1) 
					printf("#");
				else {
					if (iw == 0 || iw == W - 1)
						printf("#");
					else 
						printf(".");
				}
			}
			printf("\n");
		}

		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 3020
import sys
sys.setrecursionlimit(10**6)

N = int(input())

edge = [[] for _ in range(N+1)]


for _ in range(N-1):
  v1,v2,w = [int(x) for x in input().split()]
  if w&1:
    edge[v1].append((v2,-1))
    edge[v2].append((v1,-1))
  else:
    edge[v1].append((v2,1))
    edge[v2].append((v1,1))

color = [None] * (N+1)

def set_color(v,c):
  color[v] = c
  for x,sgn in edge[v]:
    if color[x] is None:
      set_color(x,sgn*c)
      
set_color(1,1)

for x in color[1:]:
  print((x+1)//2)

Measured memory_bytes: 76380
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int MOD = 1e9 + 7;

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

int main() {
	int n;
	cin >> n;
	int a, MAX = 0, MIN = MOD;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		MAX = max(MAX, a);
		MIN = min(MIN, a);
	}
	cout << MAX - MIN << endl;
}

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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1ll<<50;
typedef pair<ll,ll> ii;
const int N=4e3+20;
//题意:n点,m边的有向带权图,问从1出发到n的最大值为?,若可以无穷大 则输出infn,m<=2e3
//把带权的边变号,只要求出最短路并判断是否有负环即可
//注意该图为有向图 负环不一定能达到n 所以有bellmanford判断环上的点 
 
ll d[N],n,m;
vector<ii> e[N];
bool neg[N];
void calc()
{
	fill(d,d+1+n,inf);
	memset(neg,false,sizeof(neg));
	d[1]=0;
	for(int k=1;k<n;k++)//无环 最多经过n-1条边 
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=0;j<e[i].size();j++)
			{
				ll v=e[i][j].first,w=e[i][j].second;
				if(d[i]==inf)
					continue;
				if(d[v]>d[i]+w)
					d[v]=d[i]+w;
			}
		}
	}
	
	
	for(int k=1;k<=n;k++)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=0;j<e[i].size();j++)
			{
				ll v=e[i][j].first,w=e[i][j].second;
				if(d[i]==inf)
					continue;
				if(d[v]>d[i]+w)
				{
					d[v]=d[i]+w;
					neg[v]=true;//标记负环上的点 
				}
				if(neg[i]==true)
					neg[v]=true;
			}
		}
	}
	if(neg[n]==false)
		cout<<-d[n]<<endl;
	else
		puts("inf");	
	
}
int main()
{
	while(cin>>n>>m)
	{
		for(int i=0;i<=n;i++)
			e[i].clear();
		ll u,v,w;
		while(m--)
		{
			cin>>u>>v>>w;
			e[u].push_back(ii(v,-w));	
		}
		calc();	
	}
	return 0;
} 

Measured memory_bytes: 384
#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<P>>
#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;}

int main(){
    ll ans=0,n;cin>>n;
    vector<ll> a(n),c(n-1);
    rep(i,n){
        cin>>a[i];    
        a[i]--;
    }
    rep(i,n){
        ll b;cin>>b;
        ans+=b;
    }
    rep(i,n-1) cin>>c[i];

    rep(i,n-1){
        if(a[i]+1==a[i+1]) ans+=c[a[i]];
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  ll N,K;
  cin>>N>>K;
  VI A(N);
  rep(i,N) cin>>A[i];
  int en;
  int st;
  int st2;
  int now=0;
  VI num(N,-1);
  num[0]=0;
  rep(i,N){
    int nxt=A[now]-1;
    if(num[nxt]!=-1){
      en=i;
      st=num[nxt];
      st2=nxt;
      break;
    }
    num[nxt]=i+1;
    now=nxt;
  }
  int ans=0;
  if(K<=st){
    rep(i,K) ans=A[ans]-1;
  }else{
    ans=st2;
    rep(i,(K-st)%(en-st+1)) ans=A[ans]-1;
  }
  cout<<ans+1<<endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int A, B, M;
    cin >> A >> B >> M;
    vi a(A), b(B);
    int ma=1e10, mb=1e10;
    rep(i, A) {
        cin >> a[i];
        ma = min(ma, a[i]);
    }
    rep(i, B) {
        cin >> b[i];
        mb = min(mb, b[i]);
    }

    int res = ma+mb;
    rep(i, M) {
        int x, y, c;
        cin >> x >> y >> c;
        x--; y--;
        int t = a[x]+b[y]-c;
        res = min(res, t);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1792
S=list(input().split())
A=[int(n) for n in S]
if A[0]<0 and A[1]<0 and A[2]<0 and A[3]<0:
    print(A[0]*A[2])
elif A[0]<=0 and A[1]<=0 and A[2]<=0 and A[3]>=0:
    print(A[0]*A[2])
elif A[0]<=0 and A[1]<=0 and A[2]>=0 and A[3]>=0:
    print(A[1]*A[2])
elif A[0]<=0 and A[1]>=0 and A[2]<=0 and A[3]<=0:
    print(A[0]*A[2])
elif A[0]<=0 and A[1]>=0 and A[2]<=0 and A[3]>=0:
    print(max(A[0]*A[2],A[1]*A[3]))
elif A[0]<=0 and A[1]>=0 and A[2]>=0 and A[3]>=0:
    print(A[1]*A[3])
elif A[0]>=0 and A[1]>=0 and A[2]<=0 and A[3]<=0:
    print(A[0]*A[3])
elif A[0]>=0 and A[1]>=0 and A[2]<=0 and A[3]>=0:
    print(A[1]*A[3])
elif A[0]>=0 and A[1]>=0 and A[2]>=0 and A[3]>=0:
    print(A[1]*A[3])


Measured memory_bytes: 9320
#include<iostream>
#include<sstream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<queue> 
#include<map>
#include<set>
#include<stack>
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll; 
typedef pair<int, int> P;
char mp[25][25], ch[25][25];
int used[25][25];
int n, m, dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
bool check(int x, int y)
{
	if (x >= 0 && x < n && y >= 0 && y < m)	return true;
	return false;
}
int bfs(int x, int y)
{
	int ans;
	memset(used, 0, sizeof(used));
	memcpy(ch, mp, sizeof(ch));
	queue<P> que;
	ch[x][y] = '#';
	que.push(P(x, y));
	while (!que.empty())
	{
		P e = que.front();
		que.pop();
		for (int i = 0; i < 4; i++)
		{
			int xx = e.first + dx[i], yy = e.second + dy[i];
			if (check(xx, yy) && ch[xx][yy] == '.')
			{
				used[xx][yy] = used[e.first][e.second] + 1;
				ans = used[xx][yy];
				ch[xx][yy] = '#';
				que.push(P(xx, yy));
			}
		}
	}
	return ans;
}
int main()
{
	while (~scanf("%d%d", &n, &m))
	{
		int mx = -1;
		for (int i = 0; i < n; i++)
		{
			scanf("%s", mp[i]);
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (mp[i][j] == '.')
				{
					mx = max(mx, bfs(i, j));
				}
			}
		}
		printf("%d\n", mx);
	}
}

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

#define null               ""
#define endl               '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

int n, k;

int main() {
    cin >> n >> k;
    if (k <= (n + 1) / 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


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

using namespace std;

vector<double> xInfo, yInfo, sizeInfo;

double solve() {
	double distW, distH, distX, distY, overlapW, overlapH;

	overlapW = 0;
	overlapH = 0;
	distW = (sizeInfo[0] + sizeInfo[2]) / 2;
	distH = (sizeInfo[1] + sizeInfo[3]) / 2;
	distX = abs(xInfo[0] - xInfo[1]);
	distY = abs(yInfo[0] - yInfo[1]);
	if (distX < distW && distY < distH) {
		overlapW = min(min(sizeInfo[0], sizeInfo[2]), distW - distX);
		overlapH = min(min(sizeInfo[1], sizeInfo[3]), distH - distY);
	}
	//cout << "overlap:" << overlapH*overlapW << endl;
	return overlapH * overlapW;
}

int main() {
	double x, y, w, h, sum;

	sum = 0;
	for (int i = 0; i < 2; ++i) {
		cin >> x >> y >> w >> h;
		sum += w*h;
		xInfo.push_back(x + w / 2);
		yInfo.push_back(y + h / 2);
		sizeInfo.push_back(w);
		sizeInfo.push_back(h);
	}
	//cout << "sum:" << sum << endl;
	cout << int(sum - 2 * solve()) << endl;

	return 0;
}


Measured memory_bytes: 3280