akhauriyash/Code-Regression huggingface dataset:
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

import math

r = ni()

print(2 * r * math.pi)

Measured memory_bytes: 9232
a, b = map(int, input().split())
y = []
p = 0
#w = []
for i in range(1, 1000):
    p += i
    y.append(p)
    #w.append(1)
c = b - a
for i in range(1, 999):
    if y[i] - y[i - 1] == c:
        print(y[i] - b)
        break
"""z = []
for i in range(499500):
    z.append([])
for i in range(499500):
    z[i] = list(map(lambda k: k - i - 1, y))"""
"""for x in range(1, 499501):
    for i in range(1, 999):
        if y[i] == b + x and y[i - 1] == a + x:
            print(x)
            break
    else:  # 内側のforのelse節は内側ループが全部まわり切ったら実行される、つまり前の行のbreakで抜けた場合ここは実行されない
        continue  # 外側のforに対応するcontinue文、ここが実行されたら次の行のbreakには処理がいかず、外側のforの次のループにジャンプする
    break  # 外側のforを抜ける"""

"""for h in range(1, 499501):
    y = [y1 - w1 for (y1, w1) in zip(y, w)]
    x = 100 if a > 50 else 0
    k = min(y)
    for i in range(999):
        if i != 0:
            if b == y[i] and a == y[i - 1]:
                print(h)
                break
    else:  # 内側のforのelse節は内側ループが全部まわり切ったら実行される、つまり前の行のbreakで抜けた場合ここは実行されない
        continue  # 外側のforに対応するcontinue文、ここが実行されたら次の行のbreakには処理がいかず、外側のforの次のループにジャンプする
    break  # 外側のforを抜ける"""

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,K;cin >> N >> K;
  int ans = K;
  rep(i,N-1)ans*=(K-1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#Solver:Rute
n,m,x = map(int,input().split())
money = []
#データ入力
ls = []
costmin = 10**18
for i in range(n):
  ls.append(list(map(int,input().split())))
#bit全探索
for i in range(2**n+1):
  cost = 0
  #print(now)
  #理解度のリスト
  f = "{{:0{}b}}".format(n)
  now = f.format(i)
  understand = [0]*m
  for j in range(len(now)):
    if now[j] == "1":
      cost += ls[j][0]
      for k in range(m):
        understand[k] += ls[j][k+1]
  #print(understand)
  if min(understand) >= x:
    money.append(cost)
if len(money) == 0:
  print(-1)
else:
  money.sort()
  print(money[0])

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
#define pb push_back

/*int pare(int en,int start,int par[])
{
	if(par[en]==start)
	{
		return en;
	}
	pare(par[en],start,par);
}*/


int main()
{
    int t=1;
    //scanf("%d",&t);
    while(t--)
    {
		long double n,mm,i,z=0,r=0,mx=1e18,f=1,o=0;
		cin >> n;
		for(i=0;i<n;i++)
		{
			cin >> mm;
			f*=mm;
			if(f>mx || f<0)
			{
				r=1;
			}
			if(mm==0)
			{
				z=1;
			}
			if(mm>mx)
			{
				o=1;
			}
		}
		if(z)
		{
			cout << 0 << endl;
		}
		else if(r || o)
		{
			cout << "-1" << endl;
		}
		else
		{
			ll aans=(ll)f;
			cout << aans << endl;
		}
    }
    return 0;
}


Measured memory_bytes: 3780
import java.util.*;
import java.io.*;
 
public class Main{
    public static void main(String[] args){
        Main m = new Main();
        m.input();
    }
 
    public void input(){
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int p = sc.nextInt();
        int n = sc.nextInt();
        ArrayList<Integer> parkList = new ArrayList<Integer>();
        for(int i = 0; i < p; i++){
            parkList.add(sc.nextInt());
        }
        int zero = 0;
        int max = 0;
        Collections.sort(parkList);
        for(int i = 0; i < n; i++){
            if(parkList.contains(i)){
                zero++;
            }
        }
        for(int i = m; i > n; i--){
            if(parkList.contains(i)){
                max++;
            }
        }
        System.out.println(Math.min(zero,max));
        sc.close();
    }
    

}

Measured memory_bytes: 25172
use std::io::{ stdin, stdout, BufRead, Write };

const SP   : u8 = b' ';
const LF   : u8 = b'\n';
const ZERO : u8 = b'0';

#[inline(always)]
fn uitoa(mut n: usize, buf: &mut Vec<u8>) {
  buf.clear();
  if n == 0 {
    buf.push(ZERO);
    return;
  }

  while n > 0 {
    buf.push((n % 10) as u8 + ZERO);
    n /= 10;
  }

  buf.reverse();
}

#[inline(always)]
fn atoui(s: &[u8]) -> usize {
  let mut n = 0;
  for b in &s[..] { n = n * 10 + (b - ZERO) as usize; }
  n
}

#[inline(always)]
fn vec_write_with(buf: &mut Vec<u8>, s: &mut Vec<u8>, b: u8) {
  s.push(b);
  buf.write(s).unwrap();
}

macro_rules! input {
  ($stdin:ident, $delim:expr, $buf:ident) => {
    {
      $buf.clear();
      let len = $stdin.read_until($delim, &mut $buf).unwrap();
      $buf.truncate(len - 1);
      atoui(&$buf)
    }
  };
}

macro_rules! subroutine {
  ($buf:ident, $ans:ident, $odd:ident, $n:ident, $i:ident, $j:ident, $x:ident, $y:ident, $num:ident) => {
    if $odd != 0 {
      uitoa($y + 1, &mut $num);
      vec_write_with(&mut $ans, &mut $num, SP);

      uitoa($x + 1, &mut $num);
      vec_write_with(&mut $ans, &mut $num, SP);

      uitoa($i + 1, &mut $num);
      vec_write_with(&mut $ans, &mut $num, SP);

      uitoa($j + 1, &mut $num);
      vec_write_with(&mut $ans, &mut $num, LF);

      $n += 1;
    }
    $odd ^= $buf[$j * 2] & 1;
    $y = $i;
    $x = $j;
  };
}

fn main() {
  let stdin = stdin();
  let mut stdin = stdin.lock();

  let mut buf = Vec::with_capacity(500 * 2);
  let h = input!(stdin, SP, buf);
  let w = input!(stdin, LF, buf);

  let mut num = Vec::with_capacity(4);
  let mut ans = Vec::with_capacity(8 * 500);
  let mut n   = 0;

  let mut odd = 0;
  let mut x   = 0;
  let mut y   = 0;

  for i in 0..h {
    buf.clear();
    stdin.read_until(LF, &mut buf).unwrap();

    if i % 2 == 0 {
      for j in 0..w {
        subroutine!(buf, ans, odd, n, i, j, x, y, num);
      }
    } else {
      for mut j in 0..w {
        j = w - 1 - j;
        subroutine!(buf, ans, odd, n, i, j, x, y, num);
      }
    }
  }

  let stdout = stdout();
  let mut stdout = stdout.lock();

  uitoa(n, &mut buf);
  buf.push(LF);
  stdout.write(&buf).unwrap();

  stdout.write(&ans).unwrap();
  stdout.flush().unwrap();
}


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

const int N = 3e5 + 10, mod = 1e9 + 7;
int f[N], n, m, k, tot, ans;

int sum(int a, int b){
	int c = a + b;
	if(c >= mod)
		c -= mod;
	if(c < 0)
		c += mod;
	return c;
}
int mul(int a, int b){
	return 1LL * a * b % mod;
}
int pow(int n, int k){
	int res = 1;
	for (; k; k /= 2){
		if(k % 2 == 1)
			res = mul(res, n);
		n = mul(n, n);
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> n >> m >> k;
  	int a1 = 1LL * n * (n - 1) / 2 % mod, a2 = 1LL * m * (m - 1) / 2 % mod;
  	tot = sum(mul(a1, m), mul(a2, n));
	f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = mul(f[i - 1], i);
	int r = mul(f[n * m - 2], mul(pow(f[k - 2], mod - 2), pow(f[n * m - k], mod - 2)));

	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			if(j != 1 || i != 1)
				if(j == 1)
					tot = sum(tot, mod - mul(m, n - i + 1));
				else
					tot = sum(tot, sum(mul(n - i, j - 1), mod - mul(n - i + 1, m - j + 1)));
			
			ans = sum(ans, mul(r, tot));
		}
	}
	cout << ans;
}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll a[200010], ans;
bool visited[200010];
int main()
{
    int i, v, u, edges, nodes;
    cin  >> nodes >> edges;
    for(i=1;i<=nodes;i++)
    {
        cin >> a[i];
        visited[i] = true;
    }
    for(i=1;i<=edges;i++)
    {
        cin >> u >> v;
        if(a[u]==a[v])
        {
            visited[u] = false;
            visited[v] = false;
        }
        else if(a[u]>a[v])
        {
            visited[v] = false;
        }
        else{
            visited[u] = false;
        }
    }
    for(i=1;i<=nodes;i++)
        ans += visited[i];
    cout << ans << endl;
    return 0;
}
/*8 9
1 2
1 3
2 5
2 4
4 5
5 6
6 8
6 7
3 7*/


Measured memory_bytes: 4488
#include<iostream>
#include<vector>
#include<map>
using namespace std;
long long n,a[200100],s[200100],k,ans;
map<int,vector<int> > m;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]--;
	}	
	for(int i=1;i<=n;i++)
	{
		s[i]=s[i-1]+a[i];
		s[i]%=k;
		m[s[i]].push_back(i);
	}			 	
	for(int i=0;i<n;i++)
	{
		if(m[s[i]].size()==0)
			continue;	
		int l=0,r=m[s[i]].size(),w,w1;
		while(r-l!=1)
		{
			w=(l+r)/2;
			if(m[s[i]][w]>i+k)
				r=w;
			else 
				l=w;	
		}
		w=(l+r)/2;
		if(w==m[s[i]].size()-1 && m[s[i]][w]<=i)
			continue;
		if(m[s[i]][w+1]<i+k && w+1!=m[s[i]].size())	
			w++;
		else if(m[s[i]][w]>=i+k)	
			w--;
		l=0,r=m[s[i]].size();
		while(r-l!=1)
		{
			w1=(l+r)/2;
			if(m[s[i]][w1]>i)
				r=w1;
			else 
				l=w1;	
		}
		w1=(l+r)/2;
		if(m[s[i]][w1]>i)
			w1--;
		if(m[s[i]][w1]<i && m[s[i]][w1+1]<i && w1+1!=m[s[i]].size())
			w1++;	
		ans+=w-w1;
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 27264
#include <iostream>
#include <vector>

using namespace std;

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

  int cnt = 1;
  for (int i = 0; i < n-1; i++) {
    if (s[i] != s[i+1]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

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


int main() {
  long n,m;
  cin>>n>>m;
  if(m>=n*2&&m<=n*4&&m%2==0){ 
    cout<<" Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}



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

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int main() {  // TODO
  int N, X;
  cin >> N >> X;
  vector<int> L(N + 1);
  rep(i, N) cin >> L[i + 1];

  int ans = 0;
  int d = 0;
  if (d <= X) ans++;
  if (N == 1) {
    cout << ans << endl;
    return 0;
  }
  for (int i = 2; i <= N + 1; i++) {
    d = d + L[i - 1];
    if (d <= X) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

const ll C = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> men(N, 0);
    for(int i=0; i<N; i++) {
        int x;
        cin >> x;
        men[x]++;
    }

    ll count = 1;

    //奇数個
    if(N % 2 == 1 && men[0] != 1) {
        cout << 0 << endl;
        return 0;
    }

    if(N % 2 == 1) {
        for(int i=2; i<N; i += 2) {
            if(men[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
            else {
                count *= 2;
                count %= C;
            }
        }
        cout << count << endl;
        return 0;
    }

    //偶数個
    if(N % 2 == 0) {
        for(int i=1; i<N; i += 2) {
            if(men[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
            else {
                count *= 2;
                count %= C;
            }
        }
        cout << count << endl;
        return 0;
    }
}

Measured memory_bytes: 3752
#include<stdio.h>
#include<string.h>
main(){
  char n[1000]={0},n_new[1000]={0},initial[1000]={0};
  int m,h,i,j,k,count;
  while(1){
    scanf("%999s",n);
    if(n[0]=='-')
      break;
    scanf("%d",&m);
    count=strlen(n);
    for(k=0;k<m;k++){
      scanf("%d",&h);
      for(i=h,j=0;i<count;i++,j++)
        n_new[j]=n[i];
      for(i=0;i<h;i++,j++)
        n_new[j]=n[i];
      strcpy(n,n_new);
    }   
    for(i=0;i<count;i++)
      printf("%c",n_new[i]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2028
#include <stdio.h>

int main()
{
    int a, b, c, d, result = 0;
    scanf("%d%d%d%d", &a, &b, &c, &d);

    if (a > b) {
        result += b;
    } else {
        result += a;
    }

    if (c > d) {
        result += d;
    } else {
        result += c;
    }

    printf("%d\n", result);
    return 0;
}

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

typedef long long int int64;
static const int64 mod = 1000000007LL;

int n;
bool p[603];
bool used[603];
int dp[2][303][303];
int main()
{
	scanf("%d",&n);
	int64 ans = 1;
	int cntfree = 0;
	for(int i = 0;i < n;++i) {
		int a,b;
		scanf("%d%d",&a,&b);
		if(a >= 0) --a;
		if(b >= 0) --b;
		if(a >= 0 && b >= 0) {
			p[a] = p[b] = true;
		} else if(a >= 0) {
			used[a] = true;
		} else if(b >= 0) {
			used[b] = true;
		} else {
			++cntfree;
			ans = ans * cntfree % mod;
		}
	}
	dp[0][0][0] = 1;
	int k = 0;
	for(int i = 2*n-1;i >= 0;--i) if(!p[i]) {
		memset(dp[k^1],0,sizeof(dp[k^1]));
		for(int a = 0;a <= n;++a) {
			for(int b = 0;b <= n;++b) {
				if(used[i]) {
					dp[k^1][a][b+1] = (dp[k^1][a][b+1]+dp[k][a][b])%mod;
					if(a > 0) dp[k^1][a-1][b] = (dp[k^1][a-1][b]+dp[k][a][b])%mod;
				} else {
					dp[k^1][a+1][b] = (dp[k^1][a+1][b]+dp[k][a][b])%mod;
					if(a > 0) dp[k^1][a-1][b] = (dp[k^1][a-1][b]+dp[k][a][b])%mod;
					if(b > 0) dp[k^1][a][b-1] = (dp[k^1][a][b-1]+(int64)dp[k][a][b]*b%mod)%mod;
				}
			}
		}
		k ^= 1;
	}
	printf("%lld\n", ans * dp[k][0][0] % mod);
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <complex>

using namespace std;

typedef complex<double> Point;

const double EPS = 1e-8;

int n;
Point data[300];

int calc(Point a, Point b){
  int res = 0;
  double d = abs(b - a) / 2.0;
  Point ab = (b - a) / (2.0 * d);
  if(d < 1){
    Point o = ab * d;
    d = sqrt(1.0 - d * d);
    o += Point(d * ab.imag() + a.real(), -d * ab.real() + a.imag());
    for(int i=0;i<n;i++){
      if(abs(o - data[i]) < 1.0 + EPS) res++;
    }
  }
  return res;
}

main(){
  while(cin >> n && n){
    for(int i=0;i<n;i++){
      cin >> data[i].imag() >> data[i].real();
    }
    int ans = 1;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        ans = max(ans, calc(data[i], data[j]));
        ans = max(ans, calc(data[j], data[i]));
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 984
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
//assert(q==w) если q!=w --> runtime error
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=5e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};
int a[maxn];
int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string s;
    cin>>s;
    s="#"+s;
    int n=s.size();
    int cntr=0;
    ll ans=0;
    for(int i=1;i<=n;i++){
        a[i]=-1;
    }
    for(int i=n;i>=1;i--){
        if(s[i]=='>'){
            cntr++;
            if(a[i+1]<cntr){
                a[i+1]=cntr;
            }
        }
        else{
            cntr=0;
        }
    }
    for(int i=1;i<=n;i++){
        if(s[i]=='<'){
            cntr++;
            if(a[i+2]<cntr){
                a[i+2]=cntr;
            }
        }
        else{
            cntr=0;
        }
    }
    for(int i=2;i<=n+1;i++){
        if(a[i]!=-1){
            ans+=a[i];
        }
    }
    cout<<ans;
	exit(0);
}


Measured memory_bytes: 2864
import           Control.Monad (replicateM)

main :: IO ()
main = do
  n <- readLn
  amounts <- replicateM n $ do
    [x, u] <- words <$> getLine
    pure $ toAmount x u
  print $ solve amounts

data Amount = JPY Int | BTC Double

toAmount :: String -> String -> Amount
toAmount x "JPY" = JPY $ read x
toAmount x "BTC" = BTC $ read x
toAmount _ _     = error "unkwoun currency"

solve :: [Amount] -> Double
solve = sum . map toYen

toYen :: Amount -> Double
toYen (JPY n) = fromIntegral n
toYen (BTC x) = x * yenPerBTC

yenPerBTC :: Double
yenPerBTC = 380000.0


Measured memory_bytes: 636
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;

#define INF 2000000000
typedef pair<int, int> seg;
seg dat[1 << 18 + 1];
int ans[1 << 17];

int n, N, R, L;


void update(int i, seg x)
{
  i += n - 1;
  dat[i] = x;
  while(i > 0)
  {
    i = (i - 1) / 2;
    dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
  }
}

void init()
{
  n = 1;
  while(n < N) n *= 2;
  n *= 2;
  for(int i = 0; i < n * 2 - 1; i++)
    dat[i] = make_pair(INF, INF);
  for(int i = 0; i < N; i++)
    update(i, make_pair(0, i));
}

seg query(int a, int b, int k, int l, int r)
{
  if(a >= r || b <= l)
    return make_pair(INF, INF);
  if(a <= l && b >= r)
    return dat[k];
  seg vr = query(a, b, k, (l + r) / 2, r);
  seg vl = query(a, b, k, l, (l + r) / 2);
  return min(vr, vl);
}


void output()
{
  int m = 0;
  for(int i = 0; i < N; i++)
  {
//    cout << ans[i] << " ";
    m = max(m, ans[i]);
  }
  for(int i = 0; i < N; i++)
  {
    if(ans[i] == m)
    {
      cout << i + 1 << endl;
      return;
    }
  }
}


int main()
{
  int old_t = 0;

  cin >> N >> R >> L;
  init();
  for(int i = 0; i < R; i++)
  {
    int d, t, x;
    cin >> d >> t >> x;
    d--;
    ans[query(0, N, 0, 0, n).second] += t - old_t;
    
    seg s = dat[d + n - 1];
    update(d, make_pair(s.first - x, s.second));
    old_t = t;
  }
  ans[query(0, N, 0, 0, n).second] += L - old_t;

  output();
}

Measured memory_bytes: 5648
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register ll i=(a);i<=(b);i++)
#define For(i,a,b) for (register ll i=(a);i>=(b);i--)
#define mem(i,j) memset(i,j,sizeof(i))
#define GO(u) for (register ll j=f[u];j!=-1;j=nxt[j])
#define fi first
#define se second
#define pb push_back
#define pii pair<ll,ll>
#define MP make_pair
using namespace std;
typedef long long ll;
const ll N=1e6+5;
const ll mod=1e9+7;
ll n,ans=0,dp[N],pre[N];
inline ll read()
{
	ll x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
inline void write(ll x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
	return;
}
int main()
{
	n=read();
	dp[0]=1;
	dp[1]=1;
	pre[1]=2;
	FOR(i,2,n)
	{
		dp[i]=(pre[i-1]-dp[i-2]+mod)%mod;
		pre[i]=(pre[i-1]+dp[i])%mod;
	}
	dp[0]=1;
	FOR(i,0,n-2) ans=(ans+dp[i]*n%mod*(n-1)%mod)%mod;
	ans=(ans+dp[n-1]*(n-1)%mod)%mod;
	ans=(ans+1)%mod;
	write(ans);
	return 0;
}


Measured memory_bytes: 15872
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
   
public class Main{
   
  public static void main(String [] args)throws IOException{
       
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int [] num = new int[51];
    for(int a = 0; a <= 9; a++)
      for(int b = 0; b <= 9; b++)
        for(int c = 0; c <= 9; c++)
          for(int d = 0; d <= 9; d++) 
             num[a+b+c+d]++;
    String ln ="";
    while((ln = br.readLine())!= null)
      System.out.println(num[Integer.parseInt(ln)]);    
          
       
    }
       
}  

Measured memory_bytes: 24072
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n; string s;
    cin>>n>>s;
    s+=s[0];
    rep(p,0,2){
        rep(q,0,2){
            string ans;
            ans+=(p==0?'S':'W');
            ans+=(q==0?'S':'W');
            
            rep(i,2,n+2){
                if((s[i-1]=='o'&&ans[i-1]=='S') || (s[i-1]=='x'&&ans[i-1]=='W')) ans+=ans[i-2];
                else ans+=(ans[i-2]=='S' ? 'W' : 'S');
            }
            if(ans[0]!=ans[n]) continue;
            if(ans[1]!=ans[n+1]) continue;
            cout<<ans.substr(0,n)<<endl;
            return 0;
        }
    }
    
    cout<<-1<<endl;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var charCount = int.Parse(Console.ReadLine());

            var A = Console.ReadLine();
            var B = Console.ReadLine();
            var C = Console.ReadLine();


            var result = 0;

            for (int i = 0; i < charCount; i++)
            {
                var tmp = new HashSet<char>();

                tmp.Add(A[i]);
                tmp.Add(B[i]);
                tmp.Add(C[i]);

                result += tmp.Count - 1;
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13396
// I am Varun Das from Jadavpur University
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define mod 1000000007
#define ll long long
#define dbg(x) cerr << #x << " = " << x << endl
#define INF LLONG_MAX
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) for(int i=a;i>=b;i--)
#define nax 503405
using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout<<fixed<<setprecision(12);
int n;
  cin >> n;
  int b[n-1];
  for(int i=0;i<n-1;i++)cin >> b[i];
  int res = b[0];
  for(int i = 1;i < n - 1;i++){
    res += min(b[i],b[i-1]);
  }
  res = res + b[n-2];
  cout<<res;
// cout<<s;


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }


    // int N = Integer.parseInt(scanner.nextLine());
    // int N = scanner.nextInt(), M = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    static void solve(Scanner scanner) {
        String S = scanner.nextLine();
        int[] right = new int[S.length()], left = new int[S.length()];
        right[0] = 0;
        for (int i = 1; i < S.length(); i++) {
            if (S.charAt(i) == 'R') {
                right[i] = i;
            } else {
                right[i] = right[i - 1];
            }
        }
        left[S.length() - 1] = S.length() - 1;
        for (int i = S.length() - 2; i >= 0; i--) {
            if (S.charAt(i) == 'L') {
                left[i] = i;
            } else {
                left[i] = left[i + 1];
            }
        }

        int ans[] = new int[S.length()];
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == 'R') {
                int diff = left[i] - i;
                if (diff % 2 == 0) {
                    ans[left[i]]++;
                } else {
                    ans[left[i] - 1]++;
                }
            } else {
                int diff = i - right[i];
                if (diff % 2 == 0) {
                    ans[right[i]]++;
                } else {
                    ans[right[i] + 1]++;
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        for (int n: ans) {
            sb.append(n);
            sb.append(' ');
        }

        System.out.println(sb.toString().trim());
    }

}


Measured memory_bytes: 30584
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <cassert>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;

typedef long long ll;

const int N = 200005;

struct node
{
        int a, b, c;
} v[N];
bool cmp1(node a, node b)
{
        return a.a < b.a;
}
bool cmp2(node a, node b)
{
        return a.b < b.b;
}

int main()
{
//        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int n;  scanf("%d",&n);
        for(int i = 1; i <= n; ++i) scanf("%d",&v[i].a),  v[i].b = i;
        sort(v+1,v+1+n,cmp1);
//        for(int i = 1; i <= n; ++i) cerr << v[i].a << ' ' << v[i].b << ' ' << v[i].c << endl;
        for(int i = 1; i <= n; ++i)
        {
                if(i <= n/2) v[i].c = v[(n+2)/2].a;
                else v[i].c = v[n/2].a;
        }
        sort(v+1,v+1+n,cmp2);
        for(int i = 1; i <= n; ++i) printf("%d\n",v[i].c);
        return 0;
}


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

int main()
{
	int n,m,i;
	cin>>n;
	int a[n+1];
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	int ans=0;
	for(i=0;i<n-2;i++)
	{
		for(int j=i+1;j<n-1;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(((a[i]+a[j])>a[k]) && (a[i]!=a[j]) && (a[j]!=a[k]) && (a[k]!=a[i]))
					ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int ary[1400][1400];

int main(){
	int maxWidth = 0;
	int w, h;
	cin >> h >> w;

	for (int y = 0; y < h; y++){
		for (int x = 0; x < w; x++){
			cin >> ary[x][y];
			ary[x][y] = !ary[x][y];
			maxWidth = max(ary[x][y], maxWidth);
		}
	}

	for (int y = 1; y < h; y++)
	{
		for (int x = 1; x < w; x++)
		{
			if (ary[x][y] == 0) continue;
			ary[x][y] = min({ ary[x - 1][y], ary[x][y - 1], ary[x - 1][y - 1] }) + 1;
			maxWidth = max(ary[x][y], maxWidth);
		}
	}

	cout << maxWidth * maxWidth << endl;

	return 0;
}

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


int main() {

    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    double res = (double)(w)*h/2;
    cout << fixed << setprecision(10) << res << " ";
    if (w == 2*x && h == 2*y) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

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

int N;
int A[212345], p[212345];

int main() {
	cin >> N;
	REP(i, N) scanf("%d", A + i);
	
	memset(p, -1, sizeof(p));
	for (int i = N - 1; i >= 0; i--) {
		if (A[i] == 0) {
			if (p[i + 1] == -1) p[i] = i;
			else p[i] = p[i + 1];
		}
	}
	
	ll ans = 0;
	
	REP(i, N) {
		int cur = 0;
		FOR(j, i, N) {
			if (A[j] == 0) {
				ans += p[j] - j + 1;
				j = p[j];
			}
			else if ((cur & A[j]) == 0) {
				ans++;
				cur |= A[j];
			}
			else break;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }




int main() {
	int n;
	cin >> n;
	vector<int> w(n);
	rep(i, n) {
		cin >> w[i];
	}
	int ans = INF;
	FOR(t, 1, n) {
		int a=0, b=0;
		rep(i, t) {
			a += w[i];
		}
		FOR(i, t, n) {
			b += w[i];
		}
		ans = min(ans, abs(a - b));
	}
	cout << ans << endl;
}



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

using namespace std;
int main()
{
    int n;
    cin >> n;
    unordered_set<string> h;
    string t="";
    vector<string> ss(n);
    for(int i = 0; i < n; i++){
        cin >> ss[i] ;
    }
    t = ss[0];
    h.insert(t);
    for(int i = 1; i< n; i++){
        string s;

        s = ss[i];
        if(t[t.size() -1 ]!=s[0]){
            cout << "No" << endl;
            return 0;
        }
        if(h.count(s) > 0){
            cout << "No" << endl;
            return 0;
        }
        h.insert(s);
        t = s;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
if n>m:
    n,m=m,n
if m>n+1:
    print(0)
else:
    num1=1
    mod=10**9+7
    for i in range(1,m+1):
        num1=(num1*i)%mod
    num2=1
    for i in range(1,n+1):
        num2=(num2*i)%mod
    ans=(num1*num2)%mod
    if m==n:
        ans=(ans*2)%mod        
    print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string w;
    cin >> w;
    bool f = true;

    string tmp;
    for (int i = 0; i < w.size(); ++i) {
        if (tmp.find(w[i]) == string::npos) {
            tmp += w[i];
            int cnt = count(w.begin(), w.end(), w[i]);
            if (cnt % 2) {
                f = false;
                break;
            }
        }
    }

    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define BOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int who(char c){
    if(c=='a')return 0;
    if(c=='b')return 1;
    return 2;
}

char whoc(int n){
    if(n==0)return 'A';
    if(n==1)return 'B';
    return 'C';
}

int main(){
    
    string S[3];
    REP(i,3)cin>>S[i];
    
    int turn = 0;
    while(true){
        if(S[turn].size()==0){
            cout<<whoc(turn)<<endl;
            return 0;
        }
        char c=S[turn][0];
        S[turn].erase(S[turn].begin());
        turn=who(c);
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
const int MAXN = (1 << 20);

int n, m;
vector<int> G[MAXN];

void read()
{
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
}

deque<int> ans;
bool used[MAXN];

void back_dfs(int u)
{
    used[u] = 1;
    ans.push_back(u);
    for(int v: G[u])
        if(!used[v])
        {
            back_dfs(v);
            return;
        }
}

void front_dfs(int u)
{
    used[u] = 1;
    for(int v: G[u])
        if(!used[v])
        {
            ans.push_front(v);
            front_dfs(v);
            return;
        }
}
void solve()
{
    front_dfs(1);
    back_dfs(1);

    cout << ans.size() << endl;
    while(!ans.empty())
    {
        cout << ans.front() << " ";
        ans.pop_front();
    }

    cout << endl;
}

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

	read();
	solve();
	return 0;
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    map<int, int> ab;
    REP(i, 6) {
        int tmp;
        cin >> tmp;
        ab[tmp]++;
    }

    int maxi = 0;
    for (auto x : ab) {
        maxi = max(maxi, x.second);
    }

    if (maxi == 2) cout << "YES" << '\n';
    else cout << "NO" << '\n';
    return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2
#include <deque>

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> V(N);
  rep (i, N) cin >> V[i];

  deque<ll> treasures;
  rep (i, N) treasures.push_back(V[i]);
  ll ans = numeric_limits<ll>::min();
  for (ll numpop = min(N, K); numpop >= 0; numpop--) {
    ll numpush = K - numpop;
    for (ll numpopL = 0; numpopL < numpop + 1; numpopL++) {
      ll numpopR = numpop - numpopL;
      vector<ll> mytreasures;
      rep (i, numpopL) {
        mytreasures.push_back(treasures.at(i));
        // cerr <<"L"<< mytreasures.back() << endl;
      }
      rep (i, numpopR) {
        mytreasures.push_back(treasures.at(N - i - 1));
        // cerr <<"R"<< mytreasures.back() << endl;
      }
      ll sum = 0;
      for (const auto mytreasure : mytreasures) {
        sum += mytreasure;
      }
      sort(mytreasures.begin(), mytreasures.end());
      for (ll i = 0; i < mytreasures.size() && i < numpush && mytreasures.at(i) < 0;
             ++i) {
        sum -= mytreasures.at(i);
      }
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <complex>

using namespace std;
using pii = pair<int, int>;
using ll = long long;

int n, u, v;
vector<vector<int>> adj;
vector<int> parent;
vector<int> lv;
vector<int> maxlv;
vector<bool> leaf;
vector<int> ind;

void maketree(vector<vector<int>>& adj, vector<int>& parent, int now, int prv)
{
	parent[now] = prv;
	bool isleaf = true;
	for (int nxt : adj[now]) {
		if (nxt == prv) continue;
		isleaf = false;
		lv[nxt] = lv[now] + 1;
		maketree(adj, parent, nxt, now);
	}
	if (isleaf) {
		leaf[now] = true;
		maxlv[now] = lv[now];
	}
}

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

	cin >> n >> u >> v;
	u -= 1;
	v -= 1;
	adj.resize(n);
	parent.resize(n, -1);
	lv.resize(n);
	maxlv.resize(n);
	leaf.resize(n);
	ind.resize(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		adj[a - 1].push_back(b - 1);
		adj[b - 1].push_back(a - 1);
	}
	for (int i = 0; i < n; i++) ind[i] = ((i == v) ? adj[i].size() : adj[i].size() - 1);
	maketree(adj, parent, v, -1);
	queue<int> q;
	for (int i = 0; i < n; i++) if (leaf[i]) q.push(i);
	while (!q.empty()) {
		int now = q.front();
		q.pop();
		if (parent[now] == -1) continue;
		ind[parent[now]] -= 1;
		maxlv[parent[now]] = max(maxlv[parent[now]], maxlv[now]);
		if (ind[parent[now]] == 0) q.push(parent[now]);
	}
	int tmp = 0;
	int gap = lv[u] - lv[v];
	int answer = 0;
	while (gap > 0) {
		answer = max(answer, maxlv[u] - lv[u] + gap - 1 + tmp);
		u = parent[u];
		gap -= 2;
		tmp += 1;
	}
	cout << answer;

	return 0;
}


Measured memory_bytes: 13824
import java.util.*;
import javax.lang.model.util.ElementScanner6;
//import java.lang.Math;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 入力
        //long x = sc.nextLong();
        String s = sc.next();

        // 処理
        String out = "ABC";
        if(s.equals("ABC")){
            out = "ARC";
        }

        // 出力
        System.out.println(out);
    }
}

Measured memory_bytes: 35624
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back

using namespace std;

struct e
{
    int u, v, w;
    e(int u, int v, int w) : u(u), v(v), w(w) {}
    e():u(0), v(0), w(0) {}
    bool operator < (const e& x) const
    {
        return w < x.w;
    }
};

const long long mod = 1e9 + 7;

long long binpow(int n)
{
    long long res = 1;
    long long a = 2;
    while (n)
    {
        if (n & 1) res *= a;
        a *= a;
        res %= mod;
        a %= mod;
        n >>= 1;
    }
    return res;
}

vector <int> p;
vector <vector <pair <int, int> > > g;
vector <vector <long long> > path;

void initialize_dsu(int n)
{
    p.resize(n);
    for (int i = 0; i < n; i++)
        p[i] = i;
}

int get_parent(int x)
{
    if (p[x] == x) return x;
    return p[x] = get_parent(p[x]);
}

bool check(const e& x)
{
    int _u = get_parent(x.u);
    int _v = get_parent(x.v);
    if (_u == _v) return false;
    p[_u] = _v;
    return true;
}

int mainV;
void dfs(int v, long long l = 0, int p = -1)
{
    if (p == -1) mainV = v;
    path[mainV][v] = l;
    for (auto e : g[v])
    {
        if (e.X == p) continue;
        dfs(e.X, max(l, (long long)e.Y), v);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    long long x;
    cin >> x;

    vector <e> edges(m);
    for (int i = 0; i < m; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        u--, v--;
        edges[i] = {u, v, w};
    }
    sort(edges.begin(), edges.end());

    initialize_dsu(n);
    g.resize(n);
    long long s = 0;
    for (int i = 0; i < m; i++)
    {
        if (check(edges[i]))
        {
            g[edges[i].u].pb({edges[i].v, edges[i].w});
            g[edges[i].v].pb({edges[i].u, edges[i].w});
            s += edges[i].w;
        }
    }

    long long d = x - s;
    if (d < 0)
    {
        cout << 0 << '\n';
        return 0;
    }

    path.resize(n, vector <long long>(n, 0));
    for (int i = 0; i < n; i++)
    {
        dfs(i);
    }


    for (int v = 0; v < n; v++)
    {
        for (auto e : g[v])
        {
            path[v][e.X] = e.Y + 1;
        }
    }

    int eq = 0, gr = 0;
    for (int i = 0; i < m; i++)
    {
        long long this_path = path[edges[i].v][edges[i].u];
        eq += (edges[i].w - this_path) == d;
        gr += (edges[i].w - this_path) > d;
    }
    long long ans = 0;
    ans += (((2 * ((binpow(eq) - 1 + mod) % mod)) % mod) * (binpow(gr)));
    if (d == 0)
    {
        ans += (((binpow(n - 1) - 2 + mod) % mod) * (binpow(m - n + 1))) % mod;
    }
    ans %= mod;
    cout << ans;
    return 0;
}


Measured memory_bytes: 8316
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int n;
typedef long long LL;
int main() {
	while(~scanf("%d", &n)) {
		int a = n % 10;//个位
		int b = (n % 100) / 10;//十位
		int c = (n % 1000) / 100;//百位
		int d = n / 1000;//千位
		if((a == b && b == c) || (b == c && c == d) || (a == b == c == d)) puts("Yes");
		else puts("No");
	}
	return 0;
}

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

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple

#define N 311111
#define A 1111111
#define BLOCK 555 // ~sqrt(N)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int INF = 1e9 +5;
const int nax = 1e5 +5;

int dp[nax];
int visited[nax];
int in_degree[nax];
vector<int> edges[nax];

void dfs(int a){
	visited[a]=true;
	for(int b : edges[a]){
		in_degree[b]--;
		dp[b] = max(dp[b], dp[a]+1);
		if(in_degree[b]==0){
			dfs(b);
		}
	}	
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t;
	// cin>>t;
	t = 1;
	while(t--){
		int n,m;
		int ans = 0;
		cin>>n>>m;
		for(int i=0;i<m;i++){
			int x,y;
			cin>>x>>y;
			edges[x].PB(y);
			in_degree[y]++;
		}

		for(int i=1;i<=n;i++){
			if(in_degree[i]==0 && !visited[i]){
				dfs(i);
			}
		}
		for(int i=1;i<=n;i++){
			ans = max(ans,dp[i]);
		}

		cout<<ans<<endl;
	}
}

Measured memory_bytes: 9984
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll n, L;
ll a[100005];
ll x;

int main()
{
    scanf("%lld%lld", &n, &L);
    for(ll i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
        if(i > 1 && a[i] + a[i - 1] >= L) x = i - 1;
    }
    if(x == 0)
    {
        cout<<"Impossible"<<endl;
        return 0;
    }
    cout<<"Possible"<<endl;
    for(ll i = 1; i < x; i++) cout<<i<<endl;
    for(ll i = n - 1; i >= x; i--) cout<<i<<endl;
    return 0;
}


Measured memory_bytes: 1536
import java.io.*;
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
import java.math.*;
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader()
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next()
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine();
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
   public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        int t=1;//sc.nextInt();
        while(t-->0)
        {
            char c=sc.next().charAt(0);
            if(Character.isUpperCase(c))
            pw.println("A");
            else pw.println("a");
        }
           pw.close();
    }
}
  

Measured memory_bytes: 35796
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
pll bug[300001];

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;++i) cin>>bug[i].first>>bug[i].second;
    sort(bug,bug+n);
    priority_queue<pll,vector<pll>,greater<pll> > pq;
    int ans=0;
    ll exs=0,sz=0;
    for(int i=0;i<n;++i){
        exs +=bug[i].first;
        pq.push(make_pair(bug[i].second,bug[i].first));++sz;
        while(sz*pq.top().first<exs&&!pq.empty()){
            exs -=pq.top().second;pq.pop();--sz;
        }
        ans=max(ans,(int)sz);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15900
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

ll D;
vi c;
vvi s;

ll value(vi t)
{
    ll S = 0;
    vi last(26);
    REP(i, t.size())
    {
        ll k = t[i];
        last[k] = i + 1;
        S += s[i][k];
        REP(j, 26)
        {
            S -= c[j] * (i + 1 - last[j]);
        }
    }
    return S;
}

int main()
{
    ll t_begin = clock();
    cin >> D;
    c.resize(26);
    REP(i, 26)
    {
        cin >> c[i];
    }
    s.assign(D, vi(26));
    REP(i, D)
    {
        REP(j, 26)
        {
            cin >> s[i][j];
        }
    }

    vi t;
    REP(i, D)
    {
        ii opt = {0, 0};
        REP(j, 26)
        {
            t.push_back(j);
            ll res = value(t);
            t.pop_back();
            if (res > opt.first)
            {
                opt = {res, j};
            }
        }
        t.push_back(opt.second);
    }
    ll opt = value(t);
    while (1. * (clock() - t_begin) / CLOCKS_PER_SEC < 1.9)
    {
        ll i = rand() % D;
        ll j = rand() % 26;
        ll old = t[i];
        t[i] = j;
        ll res = value(t);
        if (res < opt)
        {
            t[i] = old;
        }
    }
    FOR(x, t)
    {
        OUT(x + 1);
    }
}

Measured memory_bytes: 3752
#include<iostream>
using namespace std;
int a[25];
int main(){
  int n,i,sum=0,mx=0;
  cin>>n;
  for(i=1;i<=n;i++)
  {
    cin>>a[i];
    if(a[i]>=mx)
    {
      sum++;
      mx=a[i];
    }
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256