akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <unordered_map>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;

vector<int> posMap[26];

int main(int argc, char** argv) {
  string s, t;
  cin >> s;
  cin >> t;

  // For Debug
  // cout << s << endl;
  // cout << t << endl;
  int s_len = s.size();
  rep(i, s_len) {
    int c = s[i] - 'a';
    posMap[c].push_back(i);
    posMap[c].push_back(i + s_len); // To check the cycle case.
  }
  rep(i, 26) {
    sort(all(posMap[i]));
  }

  int p = -1;
  ll ans = 0;
  int t_len = t.size();
  rep(i, t_len) {
    int c = t[i] - 'a';
    if (posMap[c].size() == 0) { // Impossible
      cout << -1 << endl;
      return 0;
    }

    p = *upper_bound(all(posMap[c]), p);
    if (p >= s_len) { // If p is larger than first s_len values in posMap[c], we have to cycle.
      p -= s_len;
      ans += s_len;
    }
  }
  ans += p;
  cout << ans + 1 << endl;
}


Measured memory_bytes: 1724
use std::io;
use std::io::BufRead;

fn main() {
    let mut sc = Scanner::new(std::io::stdin());
    let n: usize = sc.next().unwrap();
    let a: i64 = sc.next().unwrap();
    let b: i64 = sc.next().unwrap();
    let c: i64 = sc.next().unwrap();
    let d: i64 = sc.next().unwrap();
    for i in 0..n {
        let i = i as i64;
        let j = n as i64 - 1 - i;
        let l1 = a + i * c;
        let r1 = a + i * d;
        let l2 = b + j * c;
        let r2 = b + j * d;
        let l = std::cmp::max(l1, l2);
        let r = std::cmp::min(r1, r2);
        if l <= r {
            println!("YES");
            return;
        }
    }
    println!("NO");
}

/// Scanner
///
/// # Example
/// ```
/// use contest::io::scanner;
/// let mut sc = scanner::Scanner::new("1 2 \n\n \r\t \n 3.5".as_bytes());
/// assert_eq!("1".to_string(), sc.next::<String>().unwrap());
/// assert_eq!(2, sc.next().unwrap());
/// assert_eq!(3.5, sc.next().unwrap());
/// assert_eq!(None, sc.next::<i32>());
/// ```

pub struct Scanner<R: io::Read> {
    br: io::BufReader<R>,
    // Read tokens are stored in reversed order per line.
    buf: Vec<String>,
}

impl<R: io::Read> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner {
            br: io::BufReader::new(r),
            buf: vec![],
        }
    }
    #[inline]
    pub fn next<T>(&mut self) -> Option<T>
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        self.next_string().map(|s| s.parse::<T>().expect("Parse failed: "))
    }
    fn next_string(&mut self) -> Option<String> {
        self.buf.pop().or_else(|| match self.update() {
            true => self.next_string(),
            false => None,
        })
    }
    #[inline]
    fn update(&mut self) -> bool {
        let mut s = String::new();
        let res = self.br.read_line(&mut s);
        match res.expect("I/O error.") {
            0 => false,
            _ => {
                self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                true
            }
        }
    }
}


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

vector<int>g[5000];
int dis[5000];
int ans = 0;
int n, k;

int get(int x, int k, int pre) {
    memset(dis, -1, sizeof dis);
    queue<int>q;
    q.push(x);
    dis[x] = 0;
    while(q.size()) {
        int x = q.front();
        q.pop();
        for(auto t: g[x]) {
            if(dis[t] == -1 && t != pre) {
                dis[t] = dis[x] + 1;
                q.push(t);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++) if(dis[i] != -1 && dis[i] > k) ans++;
    return ans;
}

int main() {
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d%d", &a, &b); a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ans = n + 1;
    if(k % 2) {
        for(int i = 0 ; i < n; i++)
            for(auto x: g[i]) {
                ans = min(ans, get(i, k / 2, x) + get(x, k / 2, i));
            }
    }
    else {
        for(int i = 0; i < n; i++)
            ans = min(ans, get(i, k / 2, -1));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
        string s = ReadLine();
        int n = s.Length;

        // dp[s における index, 1/2 文字列の先頭] = k 番目
        long[,] dp = new long[n, 2];

        dp[0,0] = dp[0,1] = 1;

        for (int i = 0; i < n; i++)
        {
            // j == 0, １文字の case
            if (dp[i, 0] > 0)
            {
                if (i + 1 < n && s[i] != s[i+1])
                    dp[i+1, 0] = Math.Max(dp[i+1, 0], dp[i, 0] + 1);
                if (i + 2 < n)
                    dp[i+1, 1] = Math.Max(dp[i+1, 1], dp[i, 0] + 1);
            }
            // j == 1, ２文字の case
            if (dp[i, 1] > 0)
            {
                if (i + 2 < n)
                    dp[i+2, 0] = Math.Max(dp[i+2, 0], dp[i, 1] + 1);

                if (i + 2 < n - 1 && (s[i] != s[i+2] || s[i+1] != s[i+3]))
                    dp[i+2, 1] = Math.Max(dp[i+2, 1], dp[i, 1] + 1);
            }
        }

        WriteLine(Math.Max(dp[n-2, 1], dp[n-1, 0]));
    }
}

Measured memory_bytes: 14816
#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 w, a, b;
    cin >> w >> a >> b;
    if(a > b)   swap(a, b);
    int ra = a + w, rb = b + w;
    if(ra >= b){
        cout << 0 << endl;
        return 0;
    }
    cout << b - ra << endl;
}

Measured memory_bytes: 3632
/*
....................../´¯/)
....................,/¯../
.................../..../
............./´¯/'...'/´¯¯`·¸
........../'/.../..../......./¨¯\
........('(...´...´.... ¯~/'...')
.........\.................'...../
..........''...\.......... _.·´
............\..............(
..............\.............\...
*/


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define ye cout<<"YES";
#define no cout<<"NO";
#define ln cout<<"\n";
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define pi 3.14159265358979323846
// cout<<"Case #"<<ts<<": “;
//priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;


using namespace std;

ll mod(ll x, ll m) {
	return (x % m + m) % m;
}

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

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

	ll t = 1, r, n, a, d, c, b, x, y, sum, cnt, i, j, k, m, l, q, maxx, minn, temp, ans, flag, g, ts;
	ll mod = 1000000007;
	char ch, chh;
	double dans;
	string str, ttr;

	//cin >> t;


	for (ts = 1; ts <= t; ts++)
	{
		flag = 0; sum = 0; cnt = 0; ans = 0; k = 0; maxx = 0; minn = 0; a = 0; b = 0; temp = 0;

		cin >> x >> k >> c;
      	x=abs(x);

		temp = x / c;

		if (k <= temp)
		{
			cout << x - (k * c);
		}
		else
		{
			a = (x - (temp * c));

			k -= temp;
			if (k % 2 != 0)
			{
				cout << abs(a - c);
			}
			else
				cout << abs(a);
		}


		ln
	}
	return 0;
}


Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(10**6)
def main():
    N = int(input())
    V = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = list(map(int, input().split()))
        V[u - 1].append((v - 1, w))
        V[v - 1].append((u - 1, w))

    R = [0] * N
    def color(n, c, f):
        R[n] = c
        for u, w in V[n]:
            if u == f:
                continue
            color(u, (c + w) & 1, n)
    color(0, 0, 0)
    print("\n".join(str(i) for i in R))

main()




Measured memory_bytes: 96492
#include	<stdio.h>
int	main(void)
{
	int a,b;
	scanf("%d%d\n",&a,&b);
	int c,d,e;
	c = a+b;
	d = a-b;
	e = a*b;
	if(c>d){
		if(c>e){
			printf("%d",c);
		}else{
			printf("%d",e);
		}
	}else{
		if(d>e){
			printf("%d",d);
		}else{
			printf("%d",e);
		}
	}
	return 0;
}

Measured memory_bytes: 128
n, m = map(int, input().split())
a = []
# dp = [0]*(n+1)
dp = [None]*(10**5+1)
mod = 10**9+7
dp[0] = 0

for i in range(m):
    ng = int(input())
    a.append(ng)
    dp[ng] = 0

if 1 in a and 2 in a:
    print(0)
    exit()
elif 1 in a and 2 not in a:
    dp[1] = 0
    dp[2] = 1
elif 1 not in a and 2 in a:
    dp[1] = 1
    dp[2] = 0
else:
    dp[1] = 1
    dp[2] = 2

for i in range(3, n+1):
    if dp[i] is None:
        dp[i] = (dp[i-1] + dp[i-2]) % mod

print(dp[n])

Measured memory_bytes: 50520
from collections import Counter
def prime_fact(n):
    a=[]
    while n%2==0:
        a.append(2)
        n //=2
    f=3
    while f**2<=n:
        if n%f==0:
            a.append(f)
            n //=f
        else:f +=2
    if n!=1:a.append(n)
    return a

a,b=map(int,input().split())
a_key=Counter(prime_fact(a))
b_key=Counter(prime_fact(b))
print(len(a_key&b_key)+1)

Measured memory_bytes: 3828
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct Edge {
	int t, w;
};

const int INF = -1;
const int MAX = 100000;
vector<Edge> G[MAX];
int d[MAX];

int maxv = 0;
int tgt = 0;
void bfs(int u) {
	queue<int> Q;
	Q.push(u);
	while (!Q.empty()) {
		int v = Q.front();
		Q.pop();
		for (int i = 0; i < (int) G[v].size(); ++i) {
			Edge edge = G[v][i];
			if (d[edge.t] == INF) {
				Q.push(edge.t);
				d[edge.t] = d[v] + edge.w;
				if (maxv < d[edge.t]) {
					maxv = d[edge.t];
					tgt = edge.t;
				}
			}
		}
	}
}

int main() {

	int n;
	scanf("%d", &n);

	for (int i = 0; i < n - 1; ++i) {
		int s, t, w;
		scanf("%d %d %d", &s, &t, &w);
		Edge edge;
		edge.t = t;
		edge.w = w;
		G[s].push_back(edge);

		Edge edge2;
		edge2.t = s;
		edge2.w = w;
		G[t].push_back(edge2);
	}

	for (int i = 0; i < n; ++i)
		d[i] = INF;
	d[0] = 0;
	bfs(0);

	for (int i = 0; i < n; ++i)
		d[i] = INF;

	maxv = 0;
	d[tgt] = 0;
	bfs(tgt);

	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 9888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 1000002
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

void solve()
{
    ll n, k, x, y;
    cin>>n>>k>>x>>y;
    if(n <= k)
        cout<<(n * x)<<endl;
    else
        cout<<(k * x + (n-k) * y)<<endl;
}

int main()
{
    FASTIO;
    solve();

    return 0;
}


Measured memory_bytes: 3624
/*author - Ashutosh Chitranshi*/
#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;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod 1000000007
#define ordered_set tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update>
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define mp make_pair
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(),(c).end()
#define nl "\n"
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vi > vvi;
typedef vector< vl > vvl;
typedef pair< int,int > ii;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;
typedef map< int,int> mii;
ll dp[2005];
bool comp(pll a,pll b)
{
    if(a.ff == b.ff)
        return a.ss < b.ss;
    return a.ff < b.ff;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // ll s;
    // cin >> s;
    // dp[3] = 1ll;
    // for(int i=4;i<=s;i++)
    // {
    //     dp[i] = 1ll;
    //     for(int j=3;j<=i;j++)
    //     {
    //         ll rem = i-j;
    //         dp[i] = (dp[i] + (dp[rem]*dp[j])%mod)%mod;
    //     }
    // }
    // cout << dp[s] << nl;
    ll n;
    cin >> n;
    pll ar[n];
    for(int i=0;i<n;i++)
        cin >> ar[i].ff >> ar[i].ss;
    ll val1 = LLONG_MIN;
    ll val2 = LLONG_MAX;
    ll val3 = val1;
    ll val4 = val2;
    for(int i=0;i<n;i++)
    {
        val1 = max(val1,ar[i].ff+ar[i].ss);
        val2 = min(val2,ar[i].ff+ar[i].ss);
        val3 = max(val3,ar[i].ff-ar[i].ss);
        val4 = min(val4,ar[i].ff-ar[i].ss);
    }
    cout << max(abs(val1-val2),abs(val3-val4)) << nl;
    return 0;
}

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

int main()
{
    int num;
    stack<int> s;

    while( cin >> num )
    {
        if( num == 0 )
        {
            cout << s.top() << endl;
            s.pop();
        }
        else
            s.push(num);
    }
    return 0;
}


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

string str;
int ans;

int ruleM (string ex) {
    int num = ex[0] - '0';
    for (int i = 1; i < ex.size(); i += 2) {
        if (ex[i] == '*') {
            num *= ex[i + 1] - '0';
        } else {
            string tmp = string(ex.begin() + i + 1, ex.end());
            num += ruleM(tmp);
            break;
        }
    }

    return num;
}

bool ruleL (string ex) {
    int num = ex[0] - '0';
    for (int i = 1; i < ex.size(); i += 2) {
        if (ex[i] == '+') {
            num += ex[i+1] - '0';
        } else {
            num *= ex[i+1] - '0';
        }
    }

    return num == ans;
}

int main () {
    cin >> str >> ans;

    bool m = ruleM(str) == ans, l = ruleL(str);
    if (!l && m) {
        cout << "M" << endl;
    } else if (!m && l) {
        cout << "L" << endl;
    } else if (m && l) {
        cout << "U" << endl;
    } else {
        cout << "I" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1208
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n,a;
    scanf("%d%d",&n,&a);
    if(n<=a){printf("Yes\n");return 0;}
    int tmp=n%500;
    if(tmp>a){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    llint N, M;
    cin >> N >> M;
    
    llint ans = N*M;
    if(N == 1 || M == 1){
        if(N*M != 1) ans -= 2;
    }else{
        ans = max((llint)0, (N-2)*(M-2));
    }

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

Measured memory_bytes: 256
import sys
import collections
INF = 10**18

def dfs(s,cnt):
    visited = [False]*n
    visited[s] = True
    q = collections.deque([s])
    while q:
        p = q.pop()
        visited[p] = True
        for v in edge[p]:
            if visited[v]:
                continue
            cnt[v] += cnt[p]
            q.append(v)
    return cnt

if __name__ == "__main__":
    n,q = map(int,input().split())
    edge = [[] for i in range(n)]
    for i in range(n-1):
        a,b = map(int,input().split())
        a-=1
        b-=1
        edge[a].append(b)
        edge[b].append(a)
    cnt = [0]*n
    for i in range(q):
        v,x = map(int,input().split())
        v -= 1
        cnt[v] += x
    ans = dfs(0,cnt)
    print(*ans)


Measured memory_bytes: 54860
#include<bits/stdc++.h>
using namespace std;
const int maxn = 10005;
double dp[maxn];
void calc()
{
    dp[1] = 0.5;
    dp[0] = 1;
    for(int i = 2; i < maxn; i++){
        dp[i] = dp[i - 1] * 0.5;
    }
}

int main()
{
    calc();
    int n , k;
    cin >> n >> k;
    double ans = 0.0;
    for(int i = 1; i <= n; i++){
        int cnt = 0;
        int tmp = i;
        while(tmp < k)
        {
            tmp *= 2;
            cnt++;
        }
        //cout << cnt << " "<<dp[cnt]<<endl;
        ans +=(1.0/(double)n) * dp[cnt];
        //cout << ans << endl;
    }
    cout << fixed << setprecision(12)<<ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=300005;
const int mod=1e9+7;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int nxt[8][2]={{1,2},{3,4},{6,7},{3,3},{1,5},{4,4},{1,2},{2,2}};
int f[8][MAXN];char ch[MAXN];
int main()
{
	scanf("%s",ch+1);int n=strlen(ch+1);
	f[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<8;j++)if(f[j][i-1])
		{
			if(ch[i]=='1'||ch[i]=='?')ad(f[nxt[j][0]][i],f[j][i-1]);
			if(ch[i]=='0'||ch[i]=='?')ad(f[nxt[j][1]][i],f[j][i-1]);
		}
	pr2((f[1][n]+f[3][n])%mod);
	return 0;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector <int> d(N, 0);
	for (int ii = 0; ii < N; ++ii){
		cin >> d[ii];
	}

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

	int l = d[N/2 - 1];
	int r = d[N/2];

	cout << r - l << "\n";	

	return 0;
}


Measured memory_bytes: 640
/*
    ThunderClap and Flash
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod) + (b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod) * (b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod) - (b%mod) + mod)%mod;}

ll modexp(ll x, ll n){
    if(n==0){
        return 1;
    }else if(n&1){
        return ((x%mod)*(modexp((x%mod*x%mod),n/2)%mod)%mod)%mod;
    }else{
        return modexp((x%mod*x%mod),n/2)%mod;
    }
}

void Flash(){
    ll n;
    cin>>n;
    ll ans = modexp(10, n);
    ans = sub(ans, mul(2, modexp(9, n)));
    ans = add(ans, modexp(8, n));
    cout<<ans<<"\n";
}

int main(int argc, char const *argv[]){ 
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    ThunderClap;
    ll t = 1;
    //cin>>t;
    for(ll i = 1; i <= t; i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}


Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long
const int dx[4] = { 1,-1,0,0 };
const int dy[4] = { 0,0,1,-1 };
bool OOA(int x, int y, int H, int W) { return (0 <= x && x<H) && (0 <= y && y<W); }

struct UnionFind {
	int V;
	vector<int>ne;
	void init() { for (int i = 0;i<V;i++)ne.push_back(i); };

	int root(int x) {
		if (ne[x] == x)return x;
		return ne[x] = root(ne[x]);
	}
	bool same(int x, int y) { return root(x) == root(y); }
	void unite(int x, int y) {
		if (same(x, y))return;
		if (x>y)swap(x, y);
		ne[ne[y]] = ne[x];
		return;
	}
};

struct Edge{
	int fr,to,val;
	bool operator < (Edge x){
		return (val<x.val);
	}
};

vector<Edge>e;
int n;

int MST() {//最小全域木の重みの総和
	int ret = 0;
	UnionFind uf;
	uf.V = n;
	uf.init();
	sort(e.begin(), e.end());
	for (int i = 0;i<e.size();i++) {
		if (uf.same(e[i].fr, e[i].to))continue;
		ret += e[i].val;
		uf.unite(e[i].fr, e[i].to);
	}
	return ret;
}


int main() {
	cin >> n;
	e = vector<Edge>(n);
	for (int i = 0;i<n;i++) {
		for (int j = 0;j<n;j++) {
			int a;
			cin >> a;
			if (a != -1) e.push_back({ i,j,a });
		}
	}

	cout << MST() << endl;
	return 0;
}



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

int cal(int x, int y, int z){
    return x * x + y * y + z * z + x * y + y * z + z * x;
}

int main(void){
    int n;
    cin >> n;
    vector<int> cnt(n + 1);
    for(int x = 1; x * x <= n; ++x){
        for(int y = 1; y * y + x * x <= n; ++y){
            for(int z = 1;; ++z){
                int v = cal(x, y, z);
                if(v <= n) ++cnt[v];
                else break;
            }
        }
    }
    for(int i = 1; i <= n; ++i) cout << cnt[i] << endl;
    return 0;
}

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


def solve(A: int, B: int, N: int):
    if B > N:
        x = N
    else:
        x = B - 1
    print(A * x // B)


    return


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

if __name__ == '__main__':
    main()


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

int main () {
  int N ;
  cin >> N ;
  
  long long ans = 1 ;
  
  for (int i = 1 ; i <= N ; i++ ){
    ans = ( ans * i ) % 1000000007 ;
  }
  
  cout << ans << endl ;
  
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
using namespace std;
const int num = 100000;
int n, k, w[num];
inline int getp(int p) {
	int  cnt = 0, sum = 0, i = 0, num = 1;
	while (num <= k && i != n) {
		if (sum + w[i] <= p) {
			sum += w[i];
			cnt++;
			i++;
		}
		else {
			num++;
			sum = 0;
		}
	}
	return  cnt;
}
inline int  get(int l, int r) {
	while (l != r - 1) {
		int m = (l + r) / 2;
		if (getp(m) >= n) {
			r = m;
		}
		else { l = m; }
	}
	return r;
}
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}

	int left = 0, right = 1000000000;
	int ans = get(left, right);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3588
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CColon solver = new CColon();
        solver.solve(1, in, out);
        out.close();
    }

    static class CColon {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            double a = in.nextInt();
            double b = in.nextInt();
            double h = in.nextInt();
            double m = in.nextInt();

            double radh = (360 * h / 12) + (30 * m / 60);
            double radm = 360 * m / 60;
            double r = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(Math.toRadians(radh - radm)));

            out.println(r);
        }

    }

    static class Scanner {
        private final InputStream in;
        private final byte[] buffer;
        private int ptr;
        private int buflen;

        public Scanner(InputStream in) {
            this.in = in;
            this.buffer = new byte[1024];
            this.ptr = 0;
            this.buflen = 0;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }

        private byte readByte() {
            if (hasNextByte()) return buffer[ptr++];
            return -1;
        }

        private boolean isPrintableChar(byte c) {
            return '!' <= c && c <= '~';
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
        }

        public boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public int nextInt() {
            if (!hasNext()) throw new NoSuchElementException();
            int n = 0;
            boolean minus = false;
            byte b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



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

#define Int long long int
#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()

int main(){
    int n;
    cin >> n;
    vector<int> a(n+2,0),dif(n+1),bw(n+1);
    int sum=0;
    REP(i,n){
        cin >> a[i+1];
        bw[i]=abs(a[i+1]-a[i]);
        sum+=bw[i];
        if(i>0){
            int bf=bw[i]+bw[i-1];
            int af=abs(a[i+1]-a[i-1]);
            dif[i]=af-bf;
            //cout << bf <<" "<<af << endl;
        }
    }
    bw[n]=abs(a[n+1]-a[n]);
    sum+=bw[n];
    //cout << sum << endl;
    int bbf=bw[n]+bw[n-1];
    int aaf=abs(a[n+1]-a[n-1]);
    dif[n]=aaf-bbf;

    //REP(i,n+1)cout << bw[i] << endl;
    //REP(i,n)cout << dif[i+1] << endl;
    for(int i=1;i<=n;i++){
        cout << sum+dif[i] << endl;
    }
}


Measured memory_bytes: 2432
/*===================*\
|ID : harryPotter_421  |
|      LANG: C++       |
\*====================*/
#include <iostream>
#include<bits/stdc++.h>
#define lli long long int
#define pb push_back
#define INT_MIN -1000000007
#define ld  double
#define pi 3.14159265358979
#define f(j,m,n) for(lli j=m;j<n;j++)
#define harry ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define forn(n) for(i=0;i<n;i++);
using namespace std;
int main()
   {harry
    lli n,k;
    cin>>k;
    string s;
    cin>>s;
    n=s.length();
    for(lli i=0;i<n&&i<k;i++)
         cout<<s[i];
    if(k<n)
         cout<<"...";
     }






















Measured memory_bytes: 3608
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#define ll long long 
using namespace std;
int main()
{
	int a,b,t;
	while(scanf("%d %d %d",&a,&b,&t)!=EOF)
	{
		printf("%d\n",t/a*b);
	}
	return 0;
 } 

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	vector<int> v;
	for(int p = 2; p <= n; p++){
		bool ok = true;
		for(int q = 2; q < p; q++){
			if(p%q == 0){
				ok = false;
				break;
			}
		}
		if(!ok)continue;
		int tmp = n;
		int cnt = 0;
		while(tmp){
			cnt += tmp/p;
			tmp /= p;
		}
		v.push_back(cnt);
	}
	vector<ll> cnt(100, 0);
	for(auto x : v){
		for(int i = 1; i <= x; i++){
			cnt[i]++;
		}
	}
	ll ans = cnt[74];
	ans += cnt[24]*(cnt[2] - 1);
	ans += cnt[14]*(cnt[4] - 1);
	ans += cnt[4]*(cnt[4] - 1)*(cnt[2] - 2)/2;
	cout<<ans<<'\n';

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	vector<int> p(n); for(int i = 0; i < n; i++) cin >> p[i];
	vector<int> a(n), pa(n), b(n), pb(n);
	for(int i = 0; i < n; i++) a[i] = i + 1, b[i] = n - i;
	int mk = 1;
	for(int i = n - 1; i >= 0; i--){
		p[i]--;
		int val = (i + 1) * mk;
		pa[p[i]] += val;
		pb[p[i]] += val;
	}
	for(int i = 0; i < n; i++){
		if(i) pa[i] += pa[i - 1];
		a[i] += pa[i];
	}
	for(int i = n - 1; i >= 0; i--){
		if(i != n - 1) pb[i] += pb[i + 1];
		b[i] += pb[i];
	}
	for(int v : a) cout << v << " "; cout << endl;
	for(int v : b) cout << v << " "; cout << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll k;
    cin>>k;
    ll tmp=7%k;
    rep(0,i,k){
        if(!tmp){
            cout<<i+1;
            return 0;
        }
        tmp=(tmp*10+7)%k;
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	static int INF = 1_000_000_000;
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		while(true){
			String input = sc.next();

			if(input.equals("#")){
				break;
			}

			int n = input.length();
			int dp[][] = new int[n][2];

			for(int i = 1; i < n; i++){
				int c = input.charAt(i) - '0';
				int prev = input.charAt(i - 1) - '0';
//				System.out.println(c+" " + prev + " " +rowNum(c) +" "+ rowNum(prev));

				if(rowNum(c) > rowNum(prev)){
					dp[i][1] = Math.min(dp[i - 1][0], dp[i - 1][1] + 1);
					dp[i][0] = INF;
				}
				else if(rowNum(c) < rowNum(prev)){
					dp[i][0] = Math.min(dp[i - 1][1], dp[i - 1][0] + 1);
					dp[i][1] = INF;
				}
				else {
					dp[i][0] = Math.min(dp[i - 1][0] + 1, dp[i - 1][1]);
					dp[i][1] = Math.min(dp[i - 1][0], dp[i - 1][1] + 1);
				}
			}

			//debug
//			for(int i = 0; i < n; i++){
//				System.out.print(dp[i][0]+" ");
//			}
//			System.out.println();
//			for(int i = 0; i < n; i++){
//				System.out.print(dp[i][1]+" ");
//			}
//			System.out.println();

			System.out.println(Math.min(dp[n - 1][0], dp[n - 1][1]));
		}
	}

	static int rowNum(int c){
		switch (c) {
		case 1:
		case 4:
		case 7:
			return 0;
		case 2:
		case 8:
			return 1;
		default:
			return 2;

		}
	}

}



Measured memory_bytes: 50692
N,K=map(int,input().split())
# numpyを使うと早い操作も単純だから
import numpy as np
H=np.array(list(map(int,input().split())))
INF=10**10
dp=np.array([INF for _ in range(N)])
dp[0]=0
for i in range(N):
    dp[i:i+K+1] = np.minimum(dp[i:i+K+1],dp[i]+np.abs(H[i:i+K+1]-H[i]))
print(dp[N-1])

Measured memory_bytes: 23080
import java.util.Scanner;

public class Main{
    String word[][] = {
	{},
	{".", ",", "!", "?", " "},
	{"a", "b", "c"},
	{"d", "e", "f"},
	{"g", "h", "i"},
	{"j", "k", "l"},
	{"m", "n", "o"},
	{"p", "q", "r", "s"},
	{"t", "u", "v"},
	{"w", "x", "y", "z"}
    };

    Main(){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	
	for(int k = 0; k < n; k++){
	    String str = sc.next();
	    int m = str.length();
	    String st = "";
	    for(int i = 0; i < m; i++){
		String s = str.substring(i, i+1);
		int p = Integer.parseInt(s);
		int q, c = 0;
		if(p == 0){
		    continue;
		} else if(p == 1){
		    q = 5;
		} else if(p == 7 || p == 9){
		    q = 4;
		} else {
		    q = 3;
		}
		i++;
		while(s.equals(str.substring(i, i+1)) && i < m){
		    i++;
		    c++;
		}
		st += word[p][c%q];
	    }
	    System.out.println(st);
	}
    }

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

Measured memory_bytes: 12000
CONNECTED = 1

# Get matrix size
n = gets.to_i

# Initialize matrix
matrix = n.times.map{[0] * n}


STDIN.read.each_line{|line|
  node, _, *nodes = line.split(' ').map(&:to_i)

  nodes.each{|j|
    matrix[node-1][j-1] = CONNECTED
  }
}

# Print matrix
matrix.each{|row|
  puts(row.join(' '))
}



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
typedef pair<int, int> pint;
typedef set<int> si;
typedef set<pint> spi;

main () {
    int n;
    scanf("%d", &n);
    vector<int> A(2 * n);
    for (int i = 0; i < 2 * n; ++i) {
        scanf("%d", &A[i]);
    }
    sort(begin(A), end(A));
    A.insert(A.begin(), -1);
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans = ans + min(A[2 * i - 1], A[2 * i]);
    printf("%d", ans);
}


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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n, m;
    int k[10];
    int s[10][10];
    int p[10];

    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++)
            cin >> s[i][j];
    }
    for (int i = 0; i < m; i++)
        cin >> p[i];

    int cnt = 0;
    for (int i = 0; i < pow(2, n); i++)
    {
        int tmp[10] = {};
        for (int j = 0; j < n; j++)
        {
            for (int kk = 0; kk < m; kk++)
            {
                for (int l = 0; l < k[kk]; l++)
                {
                    if (s[kk][l] == j + 1)
                    {
                        // cout << kk << "," << l << endl;
                        tmp[kk] += (i >> j) & 1;
                    }
                }
            }
        }
        // cout << "-" << endl;
        // for (int j = 0; j < m; j++)
        // cout << tmp[j] << " ";
        // cout << endl;
        bool f = true;
        for (int j = 0; j < m; j++)
        {
            if (tmp[j] % 2 != p[j])
                f = false;
        }
        if (f)
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){

 int n,sum=0;
 cin>>n;
 if (n<10)
    sum=n;
    else if (n>9&&n<100)
        sum=9;
    else if(n>99&&n<1000)
        sum=n-90;
    else if(n>999&&n<10000)
        sum=909;
        else if(n>9999&&n<100000)//10000--99999
            sum=n-9090;
    else sum=90909;
    cout<<sum<<endl;
 }

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

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


int main() {
    int n,x,a,ans;
    cin>>n>>x;
    cin>>ans;
    ans=abs(ans-x);
    for(int i=1;i<n;i++)
    {
        cin>>a;
        ans=gcd(ans,abs(a-x));

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


Measured memory_bytes: 256
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main() {
	int a, b;
  	cin >> a >> b;
  	cout << a * b;
  
    return 0;
}


Measured memory_bytes: 3632
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  A = readInts()
  
  cur = 0
  ans1 = 0
  for i in range(n):
    cur += A[i]
    if i % 2:
      if cur <= 0:
        ans1 += -cur+1
        cur = 1
    else:
      if cur >= 0:
        ans1 += cur + 1
        cur = -1
  cur = 0
  ans2 = 0
  for i in range(n):
    cur += A[i]
    if i % 2:
      if cur >= 0:
        ans2 += cur + 1
        cur = -1
    else:
      if cur <= 0:
        ans2 += -cur + 1
        cur = 1
  print(min(ans1,ans2))
if __name__ == '__main__':
  main()

Measured memory_bytes: 14468
a,b,c,x,y=map(int,input().split())



if a+b<2*c:
    print(a*x+b*y)
else:
    if x>y and a>c*2:
        print(c*2*x)
    elif x>y and a<=c*2:
        print(c*2*y+(x-y)*a)
    elif x<=y and b>c*2:
        print(c*2*y)
    elif x<=y and b<=c*2:
        print(c*2*x+(y-x)*b)
    

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 100'009;

char s[N];
char t[N];
int ne[N][26];

int main() {
  scanf("%s%s", s, t);
  int ns = (int)strlen(s);
  for (int i = 0; i < 26; ++i) {
    ne[ns][i] = -1;
  }
  for (int i = ns - 1; i >= 0; --i) {
    for (int j = 0; j < 26; ++j) {
      ne[i][j] = ne[i + 1][j];
    }
    ne[i][(int)(s[i] - 'a')] = i;
  }
  int nt = (int)strlen(t);
  long long len = 0;
  int j = 0;
  for (int i = 0; i < nt; ++i) {
    int k = (int)(t[i] - 'a');
    if (ne[j][k] != -1) {
      j = ne[j][k] + 1;
    } else {
      if (ne[0][k] == -1) {
        puts("-1");
        return 0;
      }
      len += ns;
      j = ne[0][k] + 1;
    }
  }
  printf("%lld\n", len + j);
}


Measured memory_bytes: 10496
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String input1 = sc.nextLine();
        String input2 = sc.nextLine();
        
        int N = Integer.parseInt(input1);
        String[] ns = input2.split(" ");
        
        boolean[] bools = new boolean[ns.length];
        for (int i = 1; i < ns.length; i++) {
            int a = Integer.parseInt(ns[i - 1]);
            int b = Integer.parseInt(ns[i]);
            if (a >= b) {
                bools[i - 1] = true;
            }
        }
        
        int ans = 0;
        int count = 0;
        for (int i = 0; i < ns.length; i++) {
            if (bools[i]) {
                count++;
            } else {
                ans = Math.max(ans, count);
                count = 0;
                continue;
            }
        }
        ans = Math.max(count, ans);
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 48224
n = int(input())
s = input()

n_e = 0
for ss in s:
    if ss == 'E':
        n_e += 1
n_w = n - n_e

n_change_left = 0
n_change_right = n_e-1 if s[0] == 'E' else n_e
ans = n_change_left + n_change_right
for i in range(1, n):
    if s[i-1] == 'W':
        n_change_left += 1
    if s[i] == 'E':
        n_change_right -= 1
    ans = min(ans, n_change_left+n_change_right)
print(ans)


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define r0 return 0;
#define f(k,i,n,j) for(ll k=i;k<=n;k=k+j)
#define cin(a) cin>>a;
#define loop while(t--)
#define vi vector<int>
#define vii vector<long long int>
#define SORT(v) sort(v.begin(),v.end());
#define mod (1e9+7)
#define crap ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
signed main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int c=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=i+1)
        c++;
    }
    if(c<=2)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main()
{
    int N, M;

    cin >> N >> M;

    //firstは金額、secondは個数
    vector<pair<int, int>> pairs(N);

    for (int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }

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

    long long ans = 0;
    int store = 0;

    for (int i = 0; i < M; i++) //iは買ったドリンクの本数
    {
        pair<int, int> pair = pairs[store];

        int price = pair.first;
        int num = pair.second;

        ans = ans + (long long)price;

        num--;
        pairs[store] = make_pair(price, num);

        if (num == 0)
        {
            store++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
use std::io::Write;

macro_rules! eprintln {
    ($($args:tt)*) => { let _ = writeln!(&mut std::io::stderr(), $($args)*); }
}

fn read_line() -> Vec<String> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).expect("Failed to read line");
    line.trim().split_whitespace().map(|s| s.to_string()).collect()
}

struct Reader { v: Vec<String>, n: usize }

impl Reader {
    fn new() -> Self { Reader { v: read_line(), n: 0 } }
    fn next<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug {
        if self.n == self.v.len() { self.v = read_line(); self.n = 0; }
        self.n += 1;
        self.v[self.n-1].parse().expect(&self.v[self.n-1])
    }
    #[allow(dead_code)]
    fn nexts<T>(&mut self, n: usize) -> Vec<T>
    where T: std::str::FromStr, T::Err: std::fmt::Debug {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n { v.push(self.next()); }
        v
    }
}

fn main() {
    let mut r = Reader::new();
    let a: Vec<usize> = r.nexts(3);
    if a.iter().sum::<usize>() >= 22 {
        println!("bust");
    } else {
        println!("win");
    }
}


Measured memory_bytes: 4352
N,K = map(int,input().split())
S = input()
Hap = 0
NewS = S[0]
def chan(X):
    if X == 'R':
        return 'L'
    else:
        return 'R'
for i in range(1,len(S)):
    strS = S[i]
    strS1 = S[i-1]
    if strS != strS1:
        NewS += strS
    else:
        Hap += 1
while len(NewS) > 1 and K != 0:
    Hap += 2
    NewS = chan(NewS[-1]) + NewS[2:-2] + chan(NewS[0]) 
    K -= 1
if Hap > N-1:
    Hap = N-1
print(Hap)

Measured memory_bytes: 9436
#include <stdio.h>
int main()
{
    int a,b,c,x,t,i,j,k,sum,y,s,z;
    while(scanf("%d %d %d %d",&a,&b,&c,&x)!=EOF)
    {
        sum=0;
            for(i=0;i<=a;i++)
            {
                for(j=0;j<=b;j++)
                {
                    for(k=0;k<=c;k++)
                    {
                        if(500*i+100*j+50*k==x)
                        {
                            sum=sum+1;
                        }
                    }
                }
            }
            printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;

const int N=1e7;

ll v[N+10];

ll a[N+10];


bool compare(string  &a, string &b)
{
     string f=a+b,c=b+a;

     return f<c;
}

int main()
{
    ll a;

    string str;

    cin>>a>>str;

   if(a<3200)cout<<"red"<<endl;

   else cout<<str<<endl;

}








Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>

using namespace std;

int main(void) {
	int a, b;
	cin >> a >> b;
	if (a + b == 15) cout << "+" << endl;
	else if (a * b == 15) cout << "*" << endl;
	else cout << "x" << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <stdint.h>
#include <stdio.h>
#include <deque>
#include <vector>

unsigned readUnsigned() {
    int c;
    do { c = ::getchar_unlocked(); } while (c < '0');
    unsigned result = c - '0';
    while ((c = ::getchar_unlocked()) >= '0') {
        result *= 10;
        result += c - '0';
    }
    return result;
}

void writeUnsignedLn(unsigned x) {
    static const unsigned MAX_DIGITS = 10;
    static const unsigned BUF_SIZE = MAX_DIGITS + 1;
    static char buffer[BUF_SIZE] = {0};
    buffer[BUF_SIZE - 1] = '\n';
    unsigned i = BUF_SIZE - 1;
    do {
        buffer[--i] = x % 10 + '0';
        x /= 10;
    } while (x);
    ::fwrite_unlocked(buffer + i, 1, BUF_SIZE - i, stdout);
}

struct Node {
    unsigned color = 0;
    unsigned colordist = 0;
    std::vector<unsigned> edges;
};

struct Paint {
    unsigned v = 0;
    unsigned color = 0;
    unsigned dist = 0;

    Paint(unsigned v = 0, unsigned color = 0, unsigned dist = 0)
        : v(v), color(color), dist(dist)
    {
    }
};

Node NODE[100 * 1000];

int main() {
    unsigned N = readUnsigned();
    unsigned M = readUnsigned();

    for (unsigned i = 0; i < M; ++i) {
        unsigned x = readUnsigned();
        unsigned y = readUnsigned();
        --x, --y;
        NODE[x].edges.push_back(y);
        NODE[y].edges.push_back(x);
    }
    
    unsigned numPaint = readUnsigned();
    std::deque<Paint> jobs;
    for (unsigned i = 0; i < numPaint; ++i) {
        unsigned v = readUnsigned();
        unsigned dist = readUnsigned();
        unsigned color = readUnsigned();
        jobs.push_front(Paint(v - 1, color, dist + 1));
    }

    while (!jobs.empty()) {
        Paint P = jobs.front();
        jobs.pop_front();
        if (NODE[P.v].colordist >= P.dist) {
            continue;
        }
        if (NODE[P.v].color == 0) {
            NODE[P.v].color = P.color;
        }
        NODE[P.v].colordist = P.dist;
        if (P.dist == 1) {
            continue;
        }
        for (unsigned u : NODE[P.v].edges) {
            if (NODE[u].colordist < P.dist - 1) {
                jobs.push_front(Paint(u, P.color, P.dist - 1));
            }
        }
    }

    for (unsigned i = 0; i < N; ++i) {
        writeUnsignedLn(NODE[i].color);
    }
}


Measured memory_bytes: 9364