akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

  int n, x, cnt[100100] = {0};
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> x;
    cnt[x]++;
  }

  int ans = 0;
  for (int i = 1; i <= 100000; i++)
  {
    cnt[i] += cnt[i - 1];
    ans += cnt[i] * 2 == n;
  }
  cout << ans << endl;
}


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

int main() {
  int A, B, C, D;
  scanf("%d%d%d%d", &A, &B, &C, &D);

  if (B <= C || A >= D) {
    printf("0");
    return 0;
  }
  if (A <= C && D <= B) {
    printf("%d", D - C);
    return 0;
  } 
  if (C <= A && B <= D) {
    printf("%d", B - A);
    return 0;
  }
  
  if (C < A && A < D) {
    printf("%d", D - A);
  } else if (C < B && B < D) {
    printf("%d", B - C);
  } else if (A < C && C < B) {
    printf("%d", B - C);
  } else if (A < D && D < B) {
    printf("%d", B - D);
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool allow[256];
int main(){
	string input;
	allow['A'] = allow['T'] = allow['C'] = allow['G'] = true;
	cin >> input;
	int ans = 0, nowlen = 0;
	for(int i = 0;i < input.size();++i){
		if(allow[input[i]])++nowlen;
		else{
			ans = max(ans, nowlen);
			nowlen = 0;
		}
	}
	cout << max(ans, nowlen) << '\n';
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define rep(i,n) for (int i=0;i<(n);++i)
#define rep2(i,a,b) for (int i=(a);i<(b);++i)
#define rrep(i,n) for (int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for (int i=a;((c>0)?i<b:i>b);i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

int p, q, a, n;
int b[10];

double sum(int n_) {
  double v = 0;
  rep(i, n_) {
	v += (double)1/b[i];
  }
  return v;
}

bool larger(int n_) {
  double origin = (double)p / q;
  double v = sum(n_);
  return sgn(origin, v) == -1;
}

bool ok(int n_) {
  double origin = (double)p / q;
  double v = sum(n_);
  // {
  // 	rep(i, n_) cerr << b[i] << ' ';
  // 	cerr << endl;
  // }
  if (sgn(origin, v) == 0) {
	if (test) {
	  rep(i, n_) cerr << b[i] << ' ';
	  cerr << endl;
	}
	return true;
  }
  return false;
}

int ans(int a_, int n_, int max_v) {
  int res = 0;
  if (larger(n_)) return 0;
  if (ok(n_)) res++;
  if (n_ == n) return res;
  rep2(i, max_v, a_ + 1) {
	b[n_] = i;
	res += ans(a_ / i, n_ + 1, max(max_v, i));
  }
  return res;
}

void solve() {
  cin >> p >> q >> a >> n;
  if (p == 0) exit(0);
  cout << ans(a, (ll)0, 1) << endl;
}

signed main() {
  int T = (int)1e9;
  rep(i, T) {
  	char s[MAX];
  	if (scanf("%s", s) == EOF) break;
  	rrep(i, strlen(s)) {
  	  ungetc(s[i], stdin);
  	}
  	solve();
  }
  return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
typedef long long ll;
using namespace std;
//�I�[�o�[�t���[�ɋC������您����������
//�m�F�Y���Ȃ您����������

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

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cctype>
#include <cstdio>

int main(){
	char s[11], t[11], w[11];


	scanf("%s %s %s", s, t, w);

	printf("%c%c%c\n", toupper((int)s[0]), toupper((int)t[0]), toupper((int)w[0]));

	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace B_SMTB2019
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            int n = s[0];
            for(int i = 1;i<=50000;i++){
                double tmp = (double)(i*1.08);
                int ntmp = (int)(tmp);
                if(n==ntmp){
                    WriteLine(i);
                    return;
                }
                
            }
            WriteLine(":(");
        }
    }
}


Measured memory_bytes: 13268
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner(s.lock());
    let n: usize = sc.read();

    println!("{}", (n - 1) / 2);
}

pub struct Scanner<R>(R);

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;
const ll INF=(ll)1e18;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF ll(1e18)
#define MOD 1000000007
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	ll a,b,n;cin>>a>>b>>n;
	ll j=min(b-1,n);
    cout<<a*j/b-a*(j/b)<<"\n";
}



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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string[]> cardList = new List<string[]>();
            int tarou = 0;
            int hanako = 0;
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                cardList.Add(Console.ReadLine().Split());
            }

            foreach (string[] cards in cardList)
            {
                if (string.Compare(cards[0], cards[1]) > 0)
                {
                    tarou += 3;
                }
                if (string.Compare(cards[0], cards[1]) < 0)
                {
                    hanako += 3;
                }
                else if (string.Compare(cards[0], cards[1]) == 0)
                {
                    tarou++;
                    hanako++;
                }
            }

            Console.WriteLine("{0} {1}", tarou, hanako);
        }
    }
}

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

long long a[1 << 20], R[1 << 20];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i <= n; i++) cin >> a[i];
	if (n == 0) {
		if (a[0] == 1) cout << 1 << endl;
		else cout << -1 << endl;
		return 0;
	}
	R[0] = 1;
	for (int i = 1; i <= n; i++) {
		R[i] = (R[i - 1] - a[i - 1]) * 2;
		if (R[i] > 1LL << 60) {
			for (int j = i + 1; j <= n; j++) R[j] = R[i];
			break;
		}
	}
	long long ans = 0;
	for (int i = n; i >= 0; i--) {
		if (a[i] > R[i]) {
			cout << -1 << endl;
			return 0;
		}
		ans += a[i];
		if (i) {
			if (a[i - 1] + (a[i] + 1) / 2 > R[i - 1]) {
				cout << -1 << endl;
				return 0;
			}
			a[i - 1] = min(a[i - 1] + a[i], R[i - 1]);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 5160
#include<iostream>
     int main()
         {
             int x, y;
                 while(true) {
                     std::cin >> x >> y;
                         if (x == 0 && y == 0) {
                             break;
                         } else if(x <= y) {
                             std::cout << x << " " << y << std::endl;
                         } else {
                             std::cout << y << " " << x << std::endl;
                         }
                 }
         return 0;
         }

Measured memory_bytes: 3052
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> X = new ArrayList<>();
        for(int i=0;i<N;i++){X.add(sc.nextInt());}
        System.out.println(IntStream.rangeClosed(0, 100).map(p->
                X.stream().map(
                        x->(x-p)*(x-p)
                ).collect(Collectors.summingInt(Integer::intValue))
        ).min().getAsInt());
    }

}


Measured memory_bytes: 26956
#include <iostream>
#include<vector>
#include<cstdio>
#define MAX 1000000

using namespace std;

int l;
long long cnt;
vector<int> G;

void insertionSort(int A[],int n,int g)
{
    for(int i = g;i < n;i++) {
        int v = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void shellSort(int A[], int n)
{
    for(int h = 1;;) {
        if(h > n) break;
        G.push_back(h);
        h = 3*h+1;
    }
    for(int i = G.size()-1;i >= 0;i--) {
        insertionSort(A,n,G[i]);
    }

}

int main()
{
    int n;
    int A[MAX];

    cin >> n;
    for(int i = 0;i < n;i++)
        scanf("%d",&A[i]);
    cnt = 0;

    shellSort(A,n);

    cout << G.size() << endl;
    for(int i = G.size() - 1;i >= 0;i--) {
        printf("%d",G[i]);
        if(i) printf(" ");
    }
    printf("\n");
    printf("%d\n",cnt);

    for(int i = 0;i < n;i++)
        printf("%d\n",A[i]);

    return 0;
}



Measured memory_bytes: 7172
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
struct revran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { --i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr revran(const i64 e) noexcept: b(0), e(e) {}
  constexpr revran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(e - 1); }
  constexpr iter end() const noexcept { return iter(b - 1); }
};

struct ran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { ++i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr ran(const i64 e) noexcept: b(0), e(e) {}
  constexpr ran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(b); }
  constexpr iter end() const noexcept { return iter(e); }
  constexpr revran rev() const noexcept { return revran(b, e); }
};

constexpr ran rin(const i64 e) noexcept { return ran(1, e + 1); }
constexpr ran rin(const i64 b, const i64 e) noexcept { return ran(b, e + 1); }

int main() {
  i64 x;
  cin >> x;
  vector<string> vec(7);
  vec[0] = "sat";
  vec[1] = "sun";
  vec[2] = "mon";
  vec[3] = "tue";
  vec[4] = "wed";
  vec[5] = "thu";
  vec[6] = "fri";
  cout << vec[(((x - 9) % 7) + 7) % 7] << endl;
}



Measured memory_bytes: 3212
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}

int main()
{
int a[100]={0};
for(int i=0;i<5;i++)
{
cin>>a[i];
	
}
sort(a,a+5);
int ans=1e8;
do
{
	int sum=0;
 	for(int i=0;i<4;i++)
 	{
 	//	printf("%d ",a[i]);
 		sum+=a[i];
 		if(sum%10!=0)
 		sum+=(10-(sum%10));
	 }
	// printf("\n");
	sum+=a[4];
//	 printf(" %d\n",sum);
	 ans=min(ans,sum);
}while(next_permutation(a,a+5));
cout<<ans;
}



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

double sum(int n){
    if(n==1) return 1;
    else return n+sum(n-1);
}

double expec(int n){
    return sum(n)/n;
}

int main(){
    int n,k;
    cin>>n>>k;
    double a[n];
    int b;
    for(int i=0;i<n;i++) {
        cin >> b;
        a[i]=expec(b);
    }
    double tmp=0;
    for(int i=0;i<k;i++) tmp+=a[i];
    double max=tmp;
    for(int i=1;i<=n-k;i++){
        tmp-=a[i-1];
        tmp+=a[i+k-1];
        if(tmp>max) max=tmp;
    }
    printf("%.12f",max);
}

Measured memory_bytes: 1792
x,y=map(int,input().split())

def arrange(x,y):
    if x>y:
        x,y=y,x
    if y-x>1:
        return 0

    ans=1
    mod=10**9+7
    for i in range(1, x+1):
        ans*=i
        ans%=mod
    for i in range(1, y+1):
        ans*=i
        ans%=mod
    if x==y:
        ans*=2
        ans%=mod
    return ans

print(arrange(x,y))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

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

struct edge
{
    int to, cost;
};

int n;
vector<edge> g[112345];
int dis[112345];

void dijkstra(int s)
{
    priority_queue<P, vector<P>, greater<P>> que;
    fill(dis, dis + n + 1, INT_MAX);
    dis[s] = 0;
    que.push(P(0, s));

    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        int n_ = p.second;
        if (dis[n_] < p.first)
            continue;
        for (int i = 0; i < g[n_].size(); i++)
        {
            edge e = g[n_][i];
            if (dis[e.to] > dis[n_] + e.cost)
            {
                dis[e.to] = dis[n_] + e.cost;
                que.push(P(dis[e.to], e.to));
            }
        }
    }
}

int main()
{
    int h, w, c[11][11], a[50000];

    cin >> h >> w;

    n = 10;

    REP(i, 10)
    REP(j, 10)
    {
        cin >> c[i][j];

        if (i == j)
            continue;

        g[j].push_back({i, c[i][j]});
    }

    REP(i, h * w)
    cin >> a[i];

    ll res = 0;

    dijkstra(1);

    REP(i, h * w)
    {
        if (a[i] > -1)
            res += dis[a[i]];
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3072
import math

N, M = map(int, input().split())
Q = int(1e9 + 7)

if max(N, M) - min(N, M) > 1:
    print(0)
else:
    if N == M:
        ans = math.factorial(N)
        ans %= Q
        ans *= math.factorial(M)
        ans %= Q
        ans *= 2
        ans %= Q
    else:
        ans = math.factorial(N)
        ans %= Q
        ans *= math.factorial(M)
        ans %= Q
    print(ans)

Measured memory_bytes: 4092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

#define debug(x) cerr<<#x<<'='<<x<<'\n'
#define Int const int &

int main(void) {
	int a, b, c;
	cin>>a>>b>>c;
	if (a==b) {
		cout<<c;
	} else {
		if (a==c) {
			cout<<b;
		} else {
			cout<<a;
		}
	}
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int p[200000];
int main(void) {
    int n, k;
    double maxx = 0.0;

    scanf("%d", &n);
    scanf("%d", &k);
    double x = 0.0;
    for(int i = 0; i < n; i++) {
        int pp;
        scanf("%d", &pp);        
        p[i] = pp;
        x += (pp + 1) / 2.0;
        if(i - k >= 0) {
            x -= (p[i - k] + 1) / 2.0;
        } 
        maxx = maxx > x ? maxx : x;
    }
    printf("%lf\n", maxx);
    return 0;
}

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

int main() {
	int  N, T, A; cin >> N >> T >> A;
	int H[1005];
	T *= 1000;
	A *= 1000;
	for (int i = 0; i < N; i++)
		cin >> H[i];
	for (int i = 0; i < N; i++) {
		H[i] = T - H[i] * 6;
		H[i] = abs(H[i] - A);
	}
	int ans = 1;
	int Min = H[0];
	for (int i = 0; i < N; i++) {
		if (Min > H[i]) {
			Min = H[i];
			ans = i + 1;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=2E9;

int main(){
    int N;
    cin >> N;
    int A[100100]={0};
    int sum=0;
    for(int i=1;i<=N;i++){
        cin >> A[i] ;
        sum += abs(A[i]-A[i-1]); 
    }
    A[N+1]=0;
    sum += abs(A[N+1]-A[N]);
    for(int i=1;i<=N;i++){
        cout << sum-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1])-abs(A[i+1]-A[i]) << endl;
    }
}


Measured memory_bytes: 1664
N = int(input())
a = list(map(int, input().split()))
color = [0,0,0,0,0,0,0,0,0]

for i in range(N):
    if 1 <= a[i] <= 399:
        color[0] = 1
    elif 400 <= a[i] <= 799:
        color[1] = 1
    elif 800 <= a[i] <= 1199:
        color[2] = 1
    elif 1200 <= a[i] <= 1599:
        color[3] = 1
    elif 1600 <= a[i] <= 1999:
        color[4] = 1
    elif 2000 <= a[i] <= 2399:
        color[5] = 1
    elif 2400 <= a[i] <= 2799:
        color[6] = 1
    elif 2800 <= a[i] <= 3199:
        color[7] = 1
    else:
        color[8] += 1
co = color[:8]
zero = co.count(0)
one = co.count(1)
max = one + color[8]

if one == 0 and color[8] > 0:
    min = 1
else:
    min = one

print("{} {}".format(min, max))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
#define SEG_LEN (1 << 18)
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  string s,t;
  cin >> s >> t;
  t.pop_back();
  if(s == t)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}
 

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

int main()
{
  string T;
  cin >> T;
  int tmp = 0, longest = 0;
  // O(文字列Tの大きさ)
  for (int i = 0; i < T.size(); i++)
  {
    if (T.at(i) == 'A' || T.at(i) == 'C' || T.at(i) == 'G' || T.at(i) == 'T')
    {
      tmp++;
    }
    else
    {
      longest = max(longest, tmp);
      tmp = 0;
    }
  }
  longest = max(longest, tmp);
  cout << longest << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef  long long int ll ;
#define inf 9e18
#define mod 1000000007
#define mod1 998244353
long long int power(long long int a,long long int n,long long int m) ;
 long long int power(long long int a,long long int n,long long int m)
{  if(n==0)
   return 1 ;
   long long int x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}


int main()
{ ll n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,a,o;
  ios_base::sync_with_stdio(false);
   cin.tie(NULL);
  cin>>n>>m ;
  vector<ll> v[n+1] ;
  ll arr[n+1];
  for(i=1;i<=n;i++)
    cin>>arr[i] ;
  for(i=0;i<m;i++)
  {
      cin>>x>>y ;
      v[x].push_back(y) ;
      v[y].push_back(x) ;
  }
  bool vis[n+1] ;
  for(i=1;i<=n;i++)
    vis[i]=0 ;
  cnt=0 ;
  for(i=1;i<=n;i++)
  {

      if(vis[i]==1)
        continue ;
       vis[i]=1 ;
       for(j=0;j<v[i].size();j++)
       {
           if(arr[i]>arr[v[i][j]])
           {
               vis[v[i][j]]=1 ;
           }
           else break ;
       }
       if(j==v[i].size())
        cnt++ ;
  } cout<<cnt<<"\n" ;
  return 0; }


Measured memory_bytes: 10392
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}

	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	x := getNextInt(scanner)
	cc := make([]int, n)
	aa := makeInts(n, m)
	for i := 0; i < n; i++ {
		cc[i] = getNextInt(scanner)
		for j := 0; j < m; j++ {
			aa[i][j] = getNextInt(scanner)
		}
	}

	ans := math.MaxInt32
	for i := 0; i < 1<<uint(n); i++ {
		sum := 0
		al := make([]int, m)
		for j := 0; j < n; j++ {
			if i>>uint(j)%2 == 0 {
				continue
			}
			sum += cc[j]
			for k := 0; k < m; k++ {
				al[k] += aa[j][k]
			}
		}
		if master(x, al) == false {
			continue
		}
		if ans > sum {
			ans = sum
		}
	}
	if ans == math.MaxInt32 {
		fmt.Fprintln(writer, -1)
		return
	}
	fmt.Fprintln(writer, ans)
}

func master(x int, al []int) bool {
	for _, a := range al {
		if a < x {
			return false
		}
	}
	return true
}
func makeInts(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}


Measured memory_bytes: 2212
X, Y = map(int,input().split())

if X == Y == 1:
    print(1000000)
    exit(0)

ans = 0
if X == 1:
    ans += 300000
elif X == 2:
    ans += 200000
elif X == 3:
    ans += 100000

if Y == 1:
    ans += 300000
elif Y == 2:
    ans += 200000
elif Y == 3:
    ans += 100000
print(ans)


Measured memory_bytes: 38364
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001

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

    ll h, w;
    cin>>h>>w;
    string s[h];
    loop(i,0,h){
        cin>>s[i];
    }
    ll dp1[h][w], dp2[h][w], dp3[h][w], dp4[h][w];

    ll cnt = 0;
    loop(i,0,h){
        cnt = 0;
        loop(j,0,w){
            dp1[i][j] = cnt;
            if(s[i][j] == '.') cnt++;
            else if(s[i][j] == '#') cnt = 0;
        }
    }
    loop(i,0,h){
        cnt = 0;
        for(ll j = w-1; j >= 0; j--){
            dp2[i][j] = cnt;
            if(s[i][j] == '.') cnt++;
            else if(s[i][j] == '#') cnt = 0;
        }
    }
    loop(j,0,w){
        cnt = 0;
        loop(i,0,h){
            dp3[i][j] = cnt;
            if(s[i][j] == '.') cnt++;
            else if(s[i][j] == '#') cnt = 0;
        }
    }

    loop(j,0,w){
        cnt = 0;
        for(ll i=h-1; i>=0; i--){
            dp4[i][j] = cnt;
            if(s[i][j] == '.') cnt++;
            else if(s[i][j] == '#') cnt = 0;
        }
    }  
    // loop(i,0,h){
    //     loop(j,0,w){
    //         cout<<dp4[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    ll ans = -1;
    for(ll i = 0; i<h; i++){
        loop(j,0,w){
            if(s[i][j] == '.'){
                ll x = dp1[i][j] + dp2[i][j] + dp3[i][j] + dp4[i][j];
                x++;
                ans = max(ans, x);
            }
        }
    }
    print(ans);
    
}



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

int main(){
  int64_t H,W;
  cin>>H>>W;

  int64_t ans=H*W;

  for(int64_t i=1;i<W;++i){
    int64_t j=H/2;
    vector<int64_t> cho(3);
    cho[0]=i*H,cho[1]=(W-i)*j,cho[2]=(W-i)*(H-j);
    sort(cho.begin(),cho.end());
    ans=min(ans,cho[2]-cho[0]);
  }
  for(int64_t i=1;i<H;++i){
    int64_t j=W/2;
    vector<int64_t> cho(3);
    cho[0]=i*W,cho[1]=(H-i)*j,cho[2]=(H-i)*(W-j);
    sort(cho.begin(),cho.end());
    ans=min(ans,cho[2]-cho[0]);
  }
  if(H>=3){
    if(H%3==0) ans=0;
    else ans=min(ans,W);
  }
  if(W>=3){
    if(W%3==0) ans=0;
    else ans=min(ans,H);
  }

  cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int d;
  scanf("%d",&d);
  
  switch(d){
    case 22:
    printf("Christmas Eve Eve Eve\n");
    break;
    case 23:
    printf("Christmas Eve Eve\n");
    break;
    case 24:
    printf("Christmas Eve\n");
    break;
    case 25:
    printf("Christmas\n");
      break;
  }
  return 0;
  }

Measured memory_bytes: 128
use std::io::*;

// pairを保持した。

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let mut n: i64 = itr.next().unwrap().parse().unwrap();
    if n == 0 {
        println!("0",);
        return;
    }

    let mut out = Vec::new();
    while n != 0 {
        let rem = n % (-2);
        if rem > 0 {
            n -= rem;
            n /= -2;
            write!(out, "{}", rem).ok();
        } else {
            n += rem;
            n /= -2;
            write!(out, "{}", -rem).ok();
        }
    }
    out.reverse();
    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 4352
def t118B():
    A, B, K = map(int, input().split())
    while True:
        if K <= 0:
            break
        if A % 2 != 0:
            A -= 1
        A //= 2
        B += A
        K -= 1
        #print(A, B)
        if K <= 0:
            break
        if B % 2 != 0:
            B -= 1
        B //= 2
        A +=  B
        K -= 1
        #print(A, B)
    print(A, B)
t118B()

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

int main(){
  string s;
  int ans;
  cin >> s;
  int len = s.length();
  char c;
  if(len % 2 == 0){
    c = s[len/2];
    ans = len/2;
    for(int i=0;(c == s[len/2-i-1])&&(c == s[len/2+i])&&i<=len/2;i++){
      ans++;
    }
  }else{
    c = s[len/2];
    ans = len/2 + 1;
    for(int i=1;(c == s[len/2-i])&&(c == s[len/2+i])&&i<=len/2;i++){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
unittest
{
	assert( [ "2", "4 8" ].parse.expand.solve == 8 );
	assert( [ "3", "1 1 3" ].parse.expand.solve == 3 );
	assert( [ "3", "4 2 5" ].parse.expand.solve == 5 );
	assert( [ "4", "-100 -100 -100 -100" ].parse.expand.solve == 0 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = 0L;
	auto ave = roundTo!long( cast( real ) as.sum / as.length );
	foreach( a; as )
	{
		ans += ( ave - a ) ^^ 2;
	}
	return ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
#define MOD 1000000007
int main(){
    ll n;
    cin >> n;
    ll i,j;
    ll T0,A0,T1,A1;
    cin >> T0 >> A0;
    ll l,r,t;
    for(i=1;i<n;i++){
        cin >> T1 >> A1;
        l=0;r=1;
        while(T1*r<T0||A1*r<A0){
            r*=2;
        }
        while(r-l>1){
            t=(l+r)/2;
            if(T1*t<T0||A1*t<A0)l=t;else r=t;
        }
        T0=r*T1;
        A0=r*A1;
    }
    cout << T0+A0;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() { 
    
 string s,t; cin >> s >> t;
 int operations = 0;

 for(int i = 0;i<s.size();i++)
 {
   if(s[i]!=t[i]) operations++;
 }
 
 cout << operations << endl;   
  return 0; 
}

Measured memory_bytes: 3920
program main
  implicit none
  integer :: N, X, Y
  integer :: i, j, distance
  integer, allocatable :: npath(:)

  read(*,*) N, X, Y
  allocate(npath(N-1))
  npath(:) = 0

  do j = 1, N-1
    do i = j+1, N
      if(i<=X)then
        distance = i - j
      elseif(j>=Y)then
        distance = i - j
      elseif(j <=X .and. Y<=i)then
        distance = i - j -(Y-X-1)
      elseif(X <=j .and. i<=Y)then
        distance = min(i-j, (j-X)+(Y-i)+1)
      elseif(j<= X .and. X < i .and. i <= Y)then
        distance = (X-j) + min(i-X, Y-i+1)
      else
        distance = (i-Y) + min(Y-j, j-X+1)
      endif
      npath(distance) = npath(distance) + 1
    enddo
  enddo

  do i = 1, N-1
    write(*,*) npath(i)
  enddo

end program main

Measured memory_bytes: 256
#include<cstdio>

const int MAXN=(4*1e5)+5;
int a[MAXN],n;


int main()
{
	scanf("%d",&n);
	int l=2*1e5+2,r=2*1e5+3;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		if(i%2==n%2){//加到前面 
			a[l]=x;
			l--;
		}
		else{//加到后面 
			a[r]=x;
			r++;
		} 
	}
	for(int i=l+1;i<=r-1;i++){
		printf("%d ",a[i]);
	}
	return 0;
}	 


Measured memory_bytes: 2816
import java.util.*;
public class Main {
	public static void main(String[] args) {
		int[] arr= {0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		System.out.println(arr[x]);
	}
}


Measured memory_bytes: 23636
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 105
using namespace std;

int main() {
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  vector<int> X(n);
  vector<int> Y(m);

  for(int i=0;i<n;i++) {
    cin >> X[i];
  }
  for(int i=0;i<m;i++) {
    cin >> Y[i];
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  bool flag=false;
  for(int z=x+1;z<=y;z++) {
    if(X[n-1]<z && Y[0]>=z) {
      flag=true;
      break;
    }
  }
  if(flag) cout << "No War" << endl;
  else cout << "War" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	int ans = 0;
	int rec = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < i; j++) {
			if (H[j] > H[i]) {
				rec++;
				break;
			}
		}
		if (rec == 0) {
			ans++;
		}
		rec = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

from sys import stdin

import time
import numpy as np
import math

############################################

# read data for n sequences.
temp = stdin.readline().split()
N = int(temp[0])+1

out = 0
for i in range(1,N):
    for j in range(1,N):
        part = np.gcd(j,i)
        #for k in range(1,N):       
        out += np.sum(np.gcd(part,np.arange(1,N)))
print(out)

Measured memory_bytes: 27228
from collections import defaultdict

N = int(input())
S = []
for i in range(N):
    S.append(input().rstrip())
    

dic = defaultdict(int)
for i in range(len(S[0])):
    dic[S[0][i]] += 1


for s in S[1:]:
    temp_dic = defaultdict(int)
    for i in range(len(s)):
        temp_dic[s[i]] += 1
        
    for k, v in dic.items():
        dic[k] = min(v, temp_dic[k])
        
ans = ""
for k,v in dic.items():
    ans = ans + k*v

ans = sorted(ans)
print("".join(ans))

Measured memory_bytes: 3436
import bisect
import sys
input = sys.stdin.readline
M = 998244353
def solve():
  N, K = map(int, input().split())
  LR = []
  for _ in range(K):
    l, r = map(int, input().split())
    LR.append((l, r))
  Ss = [0] * K
  steps = [0] * (N+1)
  steps[1] = 1
  for n in range(2, N+1):
    for k in range(K):
      l, r = LR[k]
      # +n-l, -n-r-1
      # print(n-l, n-r)
      if n-l >= 0:
        Ss[k] += steps[n-l]
      if n-r-1 >= 0:
        Ss[k] -= steps[n-r-1]
      Ss[k] %= M
    steps[n] = sum(Ss) % M
    #print(n, steps, Ss)
  print(steps[-1])
      
solve()
  
  
  
  

Measured memory_bytes: 70304
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
	int64_t x;
	mint(int64_t x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
	mint operator+(const mint a) const { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= a;}
	mint pow(int64_t t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}

	//for prime mod
	mint inv() const { return pow(mod-2);}
	mint& operator/=(const mint a) { return *this *= a.inv();}
	mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

//head

string s;
int d;
int rr;
mint dp[110], dpp[110];
mint *now = dp, *pre = dpp;

inline int num(int i) {return (i%d);}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> s >> d;
	int n = s.size();

	rep(i, n) {
		memset(now, 0, sizeof(dpp));
		rep(j, s[i]-'0') {
			now[num(j+rr)] += 1;
		}
		rep(j, 10) {
			rep(k, d) {
				now[num(j+k)] += pre[k];
			}
		}
		rr += s[i]-'0';
		rr %= d;
		swap(now, pre);
	}
	
	cout << pre[0] + !rr - 1 << endl;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <ios>     // std::left, std::right
#include <iomanip> 
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;

int main(){
    int N,T;cin>>N>>T;
    vector<ll> c(N),t(N);
    ll ans = INF;
    REP(i,N){
        cin>>c[i]>>t[i];
        if(t[i]<=T){
            ans = min(ans,c[i]);
        }
    }
    if(ans==INF){
        cout<<"TLE";
        return 0;
    }
    cout<<ans<<endl;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

ll solve(int N, int x, vi& a) {
    ll eaten = 0;
    if (a[0] > x) {
        eaten = a[0] - x; a[0] = x;
    }
    for (int i=1; i<=N-1; ++i) {
        int sum = a[i-1] + a[i];
        if (sum > x) {
            int to_eat = sum - x;
            eaten += to_eat;
            if (a[i] >= to_eat) {
                a[i] -= to_eat;
            } else {
                // a[i] < to_eat
                to_eat -= a[i];
                a[i-1] -= to_eat;
                a[i] = 0;
            }
        }
    }
    return eaten;
}

int main() {
    vi a;
    loadvec(a,2);
    int N=a[0], x=a[1];
    loadvec(a,N);
    cout << solve(N,x,a) << endl;
    // cout << (solve(N,a) ? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;cin>>k;
    cout<<a[k-1];
    return 0;  
} 





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <cmath>
using namespace std;
const int maxn=1e6+5;
vector<string> mp;
vector<int> vis[maxn],a[maxn];
set<int> lfr[maxn],lfc[maxn];
set<int>::iterator it;
int n,m;
int sx,tx,sy,ty;
inline void init(){
	for (int i=1;i<=m;i++) a[0].push_back(0);
	for (int i=1;i<=n;i++){
		a[i].push_back(0);
		for (int j=1;j<=m;j++){
			a[i].push_back((mp[i][j]=='@')+a[i][j-1]+a[i-1][j]-a[i-1][j-1]);
		}
	}
}
inline int qsum(int x1,int y1,int x2,int y2){
	return abs(a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1]);
}
queue<pair<int,int> > q;
int k;
int main(){
	cin>>n>>m>>k;
	cin>>sx>>sy>>tx>>ty;
	mp.push_back("");
	for (int i=1;i<=n;i++){
		string s;
		cin>>s;
		s=" "+s;
		mp.push_back(s);
	}
	for (int i=1;i<=n;i++){
		vis[i].push_back(0);
		for (int j=1;j<=m;j++){
			vis[i].push_back(-1);
			if (mp[i][j]=='@') continue;
			lfr[i].insert(j);
			lfc[j].insert(i);
		}
	}
//	cout<<"pass 1"<<endl;
	init();
//	cout<<"pass 2 "<<endl;
	vis[sx][sy]=0;
	lfr[sx].erase(sy);
	lfc[sy].erase(sx);
	q.push(make_pair(sx,sy));
	while(!q.empty()){
		int x=q.front().first,y=q.front().second;
		q.pop();
	//	cout<<"print bfs "<<x<<' '<<y<<endl;
		if (x==tx&&y==ty){
			cout<<vis[x][y]<<endl;
			return 0;
		}
		int t=vis[x][y];
		vector<pair<int,int> >mem;
		if (!lfr[x].empty()){
			it=lfr[x].lower_bound(y);
			for (;it!=lfr[x].end();it++){
				int tp=(*it);
				if (abs(tp-y)>k) break;
				if (qsum(x,y,x,tp)==0){
					vis[x][tp]=t+1;
					mem.push_back(make_pair(x,tp));
				}
				else break;
			}
			it=lfr[x].lower_bound(y);
			if (it!=lfr[x].begin()){
				it--;
				for (;;it--){
					int tp=(*it);
					if (abs(tp-y)>k) break;
					if (qsum(x,y,x,tp)==0){
						vis[x][tp]=t+1;
						mem.push_back(make_pair(x,tp));
					}
					else break;
					if (it==lfr[x].begin()) break;
				}
			}
		}
		if (!lfc[y].empty()){
			it=lfc[y].lower_bound(x);
			for (;it!=lfc[y].end();it++){
				int tp=(*it);
				if (abs(tp-x)>k) break;
				if (qsum(x,y,tp,y)==0){
					vis[tp][y]=t+1;
					mem.push_back(make_pair(tp,y));
				}
				else break;
			}
			it=lfc[y].lower_bound(x);
			if (it!=lfc[y].begin()){
				it--;
				for (;;it--){
					int tp=(*it);
					if (abs(x-tp)>k) break;
					if (qsum(x,y,tp,y)==0){
						vis[tp][y]=t+1;
						mem.push_back(make_pair(tp,y));
					}
					else break;
					if (it==lfc[y].begin()) break;
				}
			}
		}
		for (int i=0;i<mem.size();i++){
			int x1=mem[i].first,y1=mem[i].second;
			q.push(make_pair(x1,y1));
			lfr[x1].erase(y1);
			lfc[y1].erase(x1);
		}
	}
	cout<<"-1"<<endl;
	return 0;
}

Measured memory_bytes: 252032
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef vector <int> vi;
vi SIEVES,PRIMES;
vi sieve(int n){
    vi s;
    int i,j,m,x,h;
    for (i=1;i<n+2;i+=2) s.push_back(i);
    m=int(pow(n,0.5))+1;
	h=(int)s.size();
    s[0]=0;
    for (i=0;i<h;i++){
        x=s[i];
        if (x>m) break;
        if (x&&x+i<h)
            for (j=i+x;j<h;j+=x) s[j]=0;
    }
    return s;
}
vi prime(int n){
    vi p;
	SIEVES=sieve(n);
	p.clear();
	p.push_back(2);
    for (int i=0;i<n/2;i++)
        if (SIEVES[i]!=0) p.push_back(SIEVES[i]);
	return p;
}
int main(void){
	PRIMES=prime(105000);
	int n,s;
	while (true){
		s=0;
		cin>>n;
		if (n==0) break;
		for(int i=0;i<n;i++)
			s+=PRIMES[i];
		cout<<s<<"\n";
	}
} 

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

using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0;i < n;i++){
          cin >> h[i];
    }
    
    for(int i = h.size() - 1; i > 0;i--){
          if(h[i] < h[i - 1]){
                if(h[i] == h[i - 1] - 1){
                      h[i - 1]--;
                }else{
                      cout << "No" << endl;
                      return 0;
                }
          }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 3784
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
A = LI()

for i in range(N):
    if A[i] == 0:
        print(0)
        exit()


ans = 1
for i in range(N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        exit()

print(ans)

Measured memory_bytes: 84628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace IPT1_2C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] StringArray = Console.ReadLine().Split(' ');
            int[] NumArray = Array.ConvertAll(StringArray, new Converter<string, int>(s => int.Parse(s)));
 
            Array.Sort(NumArray);
            Console.WriteLine(NumArray[0] + " "
                + NumArray[1] + " "
                + NumArray[2]);
        }
    }
}

Measured memory_bytes: 9308
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	M, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	P, _ := strconv.Atoi(sc.Text())

	edges := make([][]int, M)
	for i := 0; i < M; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())

		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())

		sc.Scan()
		c, _ := strconv.Atoi(sc.Text())

		edges[i] = []int{a - 1, b - 1, c - P}
	}

	scores := make([]int, N)
	scores2 := make([]int, N)
	for i := 0; i < N; i++ {
		scores[i] = math.MinInt64
		scores2[i] = math.MinInt64
	}
	scores[0] = 0
	scores2[N-1] = 0

	for i := 0; i < N; i++ {
		for _, edge := range edges {
			if scores[edge[0]] != math.MinInt64 && scores[edge[1]] < scores[edge[0]]+edge[2] {
				scores[edge[1]] = scores[edge[0]] + edge[2]
			}

			if scores2[edge[1]] != math.MinInt64 && scores2[edge[0]] < scores2[edge[1]]+edge[2] {
				scores2[edge[0]] = scores2[edge[1]] + edge[2]
			}
		}
	}

	for _, edge := range edges {
		if scores[edge[0]] == math.MinInt64 || scores2[edge[1]] == math.MinInt64 {
			continue
		}

		if scores[edge[0]]+edge[2] > scores[edge[1]] {
			fmt.Println(-1)
			return
		}
	}

	if scores[N-1] <= 0 {
		fmt.Println(0)
	} else {
		fmt.Println(scores[N-1])
	}
}


Measured memory_bytes: 1024