akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] idx = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = sc.nextInt() - 1;
            idx[a[i]] = i;
        }

        NavigableSet<Integer> set = new TreeSet<>();
        set.add(-1);
        set.add(n);
        long ans = 0;
        for (int i = 0; i < n; ++i) {
            int m = idx[i];
            int l = set.lower(m);
            int r = set.higher(m);
            ans += (long)(i + 1) * (m - l) * (r - m);
            set.add(m);
        }

        _out.println(ans);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 99972
h,w = map(int,input().split())
s =list()
for i in range(h):
    s.append(list(input()))

print("".join(["#" for _ in range(w+2)]))
for j in range(h):
    s[j].insert(0,"#")
    s[j].append("#")
    print("".join(s[j]))
print("".join(["#" for _ in range(w+2)]))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll w[505][505];
ll dp[505][505];
ll sum[505][505];
ll tot[505][505];
inline ll calc(int a,int b,int c,int d){
	return sum[b][d]-(a==0?0:sum[a-1][d])-(c==0?0:sum[b][c-1])-(a==0||b==0?0:sum[a-1][c-1]);
}
int main(){
//	freopen("park.in","r",stdin);
//	freopen("park.out","w",stdout); 
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			if(i==j) continue;
			scanf("%d",&w[i][j]);
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+w[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			tot[i][j]=tot[i-1][j]+tot[i][j-1]-tot[i-1][j-1]+(i<j?w[i][j]:0);
	for(int i=1;i<=n;i++){
		dp[i][1]=tot[i][i];
		for(int j=2;j<=i;j++){
			dp[i][j]=1e18;
			for(int k=1;k<j;k++)
				dp[i][j]=min(dp[i][j],dp[j-1][k]+tot[i][i]-tot[i][j-1]-tot[j-1][i]+tot[j-1][j-1]+calc(j,i,0,k-1));
		} 
	}		
	ll ans=1e18;
	for(int i=1;i<=n;i++) ans=min(ans,dp[n][i]);
	printf("%lld\n",ans);
	return 0;
} 

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
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;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_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 cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

#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 == 0) {
        v.clear();
        return 0;
    }
    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;
    }
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}


int solve(int N, vi& a) {
    int cnt = 0;
    for(int i=1; i+1<N; ++i){
        if (a[i-1]<a[i] && a[i]<a[i+1]) ++cnt;
        else if (a[i-1]>a[i] && a[i]>a[i+1]) ++cnt;
    }
    return cnt;
}

int main() {
    vi a;
    int N = loadvec(a);
    cout << solve(N,a) << endl;
    return 0;
}


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

int m[5][5];

void solve(){
	int w[5][5] = {0};
	int h[5][5] = {0};
	int s[5][5] = {0};
	int a[5][5] = {0};
	int b[5][5] = {0};
	int ans = 0, cnt = 0;

	for(int y=0 ; y < 5 ; y++ ){
		for(int x=0 ; x < 5 ; x++ ){
			// m[y][x] Ì 1 ð¦é
			cnt += m[y][x];
			// 1*1 1*2 1*3 1*4 1*5 ð¦é
			if( y == 0 && m[y][x] ){
				h[y][x] = 1;
				ans = max( ans , h[y][x] );
			}
			if( y != 0 && m[y][x] ){
				h[y][x] = h[y-1][x] + 1;
				ans = max( ans , h[y][x] );
			}
			// 1*1 2*1 3*1 4*1 5*1 ð¦é
			if( x == 0 && m[y][x] ){
				w[y][x] = 1;
				ans = max( ans , w[y][x] );
			}
			if( x != 0 && m[y][x] ){
				w[y][x] = w[y][x-1] + 1;
				ans = max( ans , w[y][x] );
			}
			if( x != 0 && y != 0 ){
				// 2*2 ð¦é
				if( m[y-1][x-1] && m[y-1][x] && m[y][x-1] && m[y][x] ){
					s[y][x] = 4;
					ans = max( ans , s[y][x] );
				}
				// 3*2 ð¦é
				if( s[y][x-1] >= 4 && m[y-1][x] && m[y][x] ){
					a[y][x] = 6;
					ans = max( ans , a[y][x] );
				}
				// 2*3 ð¦é
				if( s[y-1][x] >= 4 && m[y][x-1] && m[y][x] ){
					b[y][x] = 6;
					ans = max( ans , b[y][x] );
				}
				// 4*2 ð¦é
				if( a[y][x-1] >= 6 && m[y-1][x] && m[y][x] ){
					a[y][x] = 8;
					ans = max( ans , a[y][x] );
				}
				// 5*2 ð¦é
				if( a[y][x-1] >= 8 && m[y-1][x] && m[y][x] ){
					a[y][x] = 10;
					ans = max( ans , a[y][x] );
				}
				// 2*4 ð¦é
				if( b[y-1][x] >= 6 && m[y][x-1] && m[y][x] ){
					b[y][x] = 8;
					ans = max( ans , b[y][x] );
				}
				// 2*5 ð¦é
				if( b[y-1][x] >= 8 && m[y][x-1] && m[y][x] ){
					b[y][x] = 10;
					ans = max( ans , b[y][x] );
				}
				// 3*3 ð¦é
				if( a[y-1][x] >= 6 && w[y][x] >= 3 ){
					s[y][x] = 9;
					ans = max( ans , s[y][x] );
				}
				// 4*3 ð¦é
				if( s[y][x-1] >= 9 && h[y][x] >= 3 ){
					a[y][x] = 12;
					ans = max( ans , a[y][x] );
				}
				// 5*3 ð¦é
				if( a[y][x-1] >= 12 && h[y][x] >= 3 ){
					a[y][x] = 15;
					ans = max( ans , a[y][x] );
				}
				// 3*4 ð¦é
				if( s[y-1][x] >= 9 && w[y][x] >= 3 ){
					b[y][x] = 12;
					ans = max( ans , b[y][x] );
				}
				// 3*5 ð¦é
				if( b[y-1][x] >= 12 && w[y][x] >= 3 ){
					b[y][x] = 15;
					ans = max( ans , b[y][x] );
				}
				// 4*4 ð¦é
				if( a[y-1][x] >= 12 && w[y][x] >= 4 ){
					s[y][x] = 16;
					ans = max( ans , s[y][x] );
				}
				// 5*4 ð¦é
				if( s[y][x-1] >= 16 && h[y][x] >= 4 ){
					a[y][x] = 20;
					ans = max( ans , a[y][x] );
				}
				// 4*5 ð¦é
				if( s[y-1][x] >= 16 && w[y][x] >= 4 ){
					b[y][x] = 20;
					ans = max( ans , b[y][x] );
				}
			}
		}
	}
	// 5*5 ª·×Ä1Å Á½Æ«
	if( cnt == 25 )
		ans = 25;
	cout << ans << endl;
}

int main(){
	int n;
	cin >> n;
	for(int i=0 ; i < n ; i++ ){
		for(int y=0 ; y < 5 ; y++ ){
			for(int x=0 ; x < 5 ; x++ ){
				cin >> m[y][x];
			}
		}
		solve();
	}
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;

namespace easy_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal[] AB = Array.ConvertAll(Console.ReadLine().Split(),decimal.Parse);
            Console.WriteLine(Math.Floor(AB[0]*AB[1]));
        //     Console.WriteLine(AB[0]*AB[1]);
        }   
            // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // long N = NK[0];
            // long K = NK[1];
            // long K = long.Parse(Console.ReadLine());
            // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // string S = Console.ReadLine();
            // int x = int.Parse(Console.ReadLine());
            // int b = int.Parse(Console.ReadLine());
            // int N = int.Parse(Console.ReadLine());
            // float N = float.Parse(Console.ReadLine());
            // string c = Console.ReadLine();
            // string B = Console.ReadLine();
            // string[] s = Console.ReadLine().Split();
            // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), Console.ReadLine() }).Select(float.Parse);
            // float[] a = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // var X = Console.ReadLine();
            // int[,] abcd = new int[NMQ[2],4];
            // int[] A = new int[NMQ[0]];
            // int[] A_num = new int[NMQ[0]];
            // long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // var hs=new Dictionary<long,long>();
            // for(int i=0;i<s[0];i++){
            //     long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            //     if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
            //     else{hs.Add(q[0],q[1]);}
            // }
        
        // //最小公倍数
        // static long Lcm(long a, long b)
        // {
        //     return a/Gcd(a,b)*b;
        // }

        // //最大公約数
        // static long Gcd(long m, long n)
        // {
        //     if(n==0)return m;
        //     return Gcd(n,m%n);
        // }
    }
}


Measured memory_bytes: 27532
from sys import stdin
from itertools import repeat
def main():
    n, m = map(int, stdin.readline().split())
    q = int(stdin.readline())
    a = map(int, stdin.readline().split(), repeat(10, q))
    a = [x - 1 for x in a]
    l = [[] for i in xrange(m)]
    la = []
    for i in xrange(q - 1, -1, -1):
        x = a[i]
        if not l[x]:
            la.append(x)
        l[x].append(i)
    ok = 1
    b = [q] * n
    f = [0] * m
    xt = 0
    for i, x in enumerate(la):
        j = 0
        for y in l[x]:
            if j < n and y < b[j]:
                b[j] = y
                j += 1
        if j < n:
            ok = 0
            b[j] = -1
        if not ok:
            while f[xt]:
                  xt += 1
            if x != xt:
                print "No"
                return
            f[xt] = 1
        else:
            f[x] = 1
    print "Yes"
main()

Measured memory_bytes: 23220
//
//AtCoder Beginner Contest 094
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> x(n);
    vector<int> xp(n);
    REP(i, n) {
        cin >> x[i];
        xp[i]=x[i];
    }

    sort(ALL(xp));

    REP(i,n){
        int idx = lower_bound(ALL(xp), x[i])-xp.begin();
        int ans;
        if (idx<n/2) ans=xp[n/2];
        else ans=xp[n/2-1];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4824
import java.util.Scanner;

public class Main {
	final int MAX_N = 2000000;
	final int K = 10000;
	
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		int[] a = new int[MAX_N + 1];
		for (int j = 1; j <= n; j++)
			a[j] = scan.nextInt();
		
		int[] c = new int[K + 1];
		for (int i = 1; i <= n; i++)
			c[a[i]] += 1;
		
		for (int i = 1; i <= K; i++)
			c[i] += c[i - 1];
		
		int[] b = new int[n + 1];
		for (int j = n; j >= 1; j--) {
			b[c[a[j]]] = a[j];
			c[a[j]]--;
		}
		
		StringBuilder builder = new StringBuilder();
		for (int i = 1; i <= n; i++)
			builder.append(b[i] + (i == n ? "\n" : " "));
		System.out.print(builder);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 578980
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {

    public static void main(String args[]) throws IOException {
        FastReader in = new FastReader();
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        Task.solve(in, out);
        out.close();
    }

    static class Task {

        public static void solve(FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int sum=0,max = Integer.MIN_VALUE;
            for(int i=0;i<n;i++){
                int x = in.nextInt();
                sum+=x;
                max = Math.max(max,x);
            }
            sum-=max;
            if(sum>max){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 23380
N = list(input())

if N[0] == N[1]:
    if N[1] == N[2]:
        ans = 'Yes'

    else:
        ans = 'No'

elif N[-1] == N[-2]:
    if N[-2] == N[-3]:
        ans = 'Yes'
    else:
        ans = 'No'

else:
    ans = 'No'

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a[200005];
map<ll,ll>p;
bool check(ll x){
    p.clear();
    for(int i=1;i<n;i++){
        ll b=a[i-1],c=a[i];
        if(b>=c){
            if(x==1)return false;
            p.erase(p.upper_bound(c),p.end());
            while(1){
                if(c==0)return false;
                if(++p[c]<x)break;
                p.erase(c);
                c--;
            }
        }
    }
    return true;
}
int main(void){
    scanf("%lld",&n);
    for(int i=0;i<n;i++)scanf("%lld",a+i);
    ll l=0,r=n;
    while(r-l>1){
        ll m=(l+r)/2;
        if(check(m))r=m;
        else l=m;
    }
    printf("%lld\n",r);
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	int[] b = new int[n];
	for (int i=0; i<n; i++) {
	    a[i] = sc.nextInt();
	    b[i] = a[i];
	}
	Arrays.sort(b);
	StringBuilder sb = new StringBuilder();
	for (int i=0; i<n; i++) {
	    if (b[n-1] == a[i]) sb.append(b[n-2]+"\n");
	    else { sb.append(b[n-1]+"\n"); }
	}
	System.out.print(sb.toString());
    }
}


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

const int MOD = 1000*1000*1000+7;
int main(){

  int N; cin >> N;
  vector<long long> v(N);
  for(int i=0; i<N; i++) cin >> v[i];

  vector<long long> cum(N+1,0);
  for(int i=0; i<N; i++) cum[i+1] = (cum[i] + v[i]) % MOD;

  long long ans = 0;
  for(int i=0; i<N-1; i++){
    ans += v[i] * (cum[N]-cum[i+1] + MOD) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6440
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	string s;
	cin >> s;
	if (s == "SUN") {
		cout << 7;
		return 0;
	}
	if (s == "MON") {
		cout << 6;
		return 0;
	}
	if (s == "TUE") {
		cout << 5;
		return 0;
	}
	if (s == "WED") {
		cout << 4;
		return 0;
	}
	if (s == "THU") {
		cout << 3;
		return 0;
	}
	if (s == "FRI") {
		cout << 2;
		return 0;
	}
	if (s == "SAT") {
		cout << 1;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
# 2019/03/24
# AtCoder Beginner Contest 122 - A

# Input
b = input()

# Calc
if b == "A":
    ans = "T"
elif b == "C":
    ans = "G"
elif b == "G":
    ans = "C"
elif b == "T":
    ans = "A"

# Output
print(ans)

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

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

	string s;
	cin >> s;

	int result = n;
	for(auto i = 1; i < n; ++i) {
		if(s[i - 1] == s[i]) {
			--result;
		}
	}

	cout << result << endl;
}



Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int n, i, j;
	int sum = 0;
	int d[101];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &d[i]);
	}

	//体力の回復量の合計を求める
	for (i = 0; i < n - 1; i++) {
		for (j = i + 1; j < n; j++) {
			sum = sum + d[i] * d[j];
		}
	}

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 128
using System.Linq;
using static System.Console;

public static class Program
{
    const long mod = 1000000007;
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        var aArray = ReadLine().Split(' ').Select(int.Parse).ToArray();
        long sum = 0;

        long jSum = 0;
        for(int j = 0; j < n; ++j)
        {
            jSum += aArray[j];
            jSum %= mod;
        }
        
        for(int i = 0; i < n - 1; ++i)
        {
            jSum -= aArray[i];
            if (jSum < 0) jSum += mod;
            sum += jSum * aArray[i];
            sum %= mod;
        }
        WriteLine(sum.ToString());
    }
}

Measured memory_bytes: 46948
//by yjz
#include<bits/stdc++.h>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
typedef long long ll;
using namespace std;
char s[300111];
const int mod = 998244353;
int ans = 1;

int main()
{
	scanf("%s", s+1);
	scanf("%s", s+1);
	int n = strlen(s+1);
	for (int i=1; i<=n/3; i++) ans = 1ll*ans*i%mod;
	int a[3] = {};
	for (int i=1; i<=n; i++)
	{
		int p = 0;
		if (s[i]=='R') p=0;
		if (s[i]=='G') p=1;
		if (s[i]=='B') p=2;
		int mn = 1e9;
		for (int j=0; j<3; j++)
		{
			if (j!=p&&a[j]>a[p])
			{
				mn = min(mn, a[j]);
			}
		}
		if (mn<=n) ans = 1ll*ans*(mn-a[p])%mod;
		a[p]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>

using namespace std;

int main(){
    int N,M;
    int c =0;
    while(true){
        c++;
        cin >> N >> M;
        if((N|M)==0)break;
        int t=0;
        int ws[M+1];
        memset(ws,0,sizeof ws);
        ws[0] = N;
        while(true){
            t++;
            int nws[M+1];
            memset(nws,0,sizeof nws);
            for(int i=0;i<M;i++){
                nws[i+1]+=ws[i]/2;
                if(ws[i]%2==0)
                nws[0]+=ws[i]-ws[i]/2;
                else{
                    nws[0]+=ws[i]-ws[i]/2-1;
                    nws[i]++;
                }
            }
            for(int i=0;i<=M;i++){
                ws[i] = nws[i];
            }
            if(ws[M]){
                cout << "Case " << c << ":" << " " << t << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    double N; cin >> N;
    double cnt = 0;
    rrep (i, 1, N) {
        int p; cin >> p;
        if (i != p) ++cnt;
    }
    if (cnt/2 <= 1) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce, lru_cache
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

n = INT()
k = INT()

@lru_cache(None)
def F(n, k):
    # n以下で0でないものがちょうどk個ある数字の個数
    if n < 10:
        if k == 0:
            return 1
        if k == 1:
            return n
        return 0
    q, r = divmod(n, 10)
    ret = 0
    if k >= 1:
        ret += F(q, k-1) * r
        ret += F(q-1, k-1) * (9-r)
    ret += F(q, k)
    return ret

print(F(n, k))

Measured memory_bytes: 10524
local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    local cnt = bls(1, i - 1)
    for j = 1, cnt do
      self.stage[i][j] = self.func(self.stage[i + 1][j * 2 - 1], self.stage[i + 1][j * 2])
    end
  end
end
SegTree.create = function(self, n, func, emptyvalue)
  self.func, self.emptyvalue = func, emptyvalue
  local stagenum, mul = 1, 1
  self.stage = {{}}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.stage[stagenum] = {}
  end
  self.stagenum = stagenum
  self.left_stage = {}
  for i = 1, n do
    local sp, sz = 1, bls(1, stagenum - 1)
    while(i - 1) % sz ~= 0 do
      sp, sz = sp + 1, brs(sz, 1)
    end
    self.left_stage[i] = sp
  end
  self.sz_stage = {}
  local tmp, sp = 1, stagenum
  for i = 1, n do
    if tmp * 2 == i then tmp, sp = tmp * 2, sp - 1 end
    self.sz_stage[i] = sp
  end
  for i = 1, mul do self.stage[stagenum][i] = emptyvalue end
  self:updateAll()
end
SegTree.getRange = function(self, left, right)
  if left == right then return self.stage[self.stagenum][left] end
  local stagenum = self.stagenum
  local ret = self.emptyvalue
  while left <= right do
    local stage = mma(self.left_stage[left], self.sz_stage[right - left + 1])
    local sz = bls(1, stagenum - stage)
    ret = self.func(ret, self.stage[stage][1 + brs(left - 1, stagenum - stage)])
    left = left + sz
  end
  return ret
end
SegTree.update = function(self, idx)
  for i = self.stagenum - 1, 1, -1 do
    local dst = brs(idx + 1, 1)
    local rem = dst * 4 - 1 - idx
    self.stage[i][dst] = self.func(self.stage[i + 1][idx], self.stage[i + 1][rem])
    idx = dst
  end
end
SegTree.setValue = function(self, idx, value, silent)
  self.stage[self.stagenum][idx] = value
  if not silent then
    self:update(idx)
  end
end
SegTree.addValue = function(self, idx, value)
  self.stage[self.stagenum][idx] = self.stage[self.stagenum][idx] + value
  self:update(idx)
end
SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

local n, q = io.read("*n", "*n")
local st = SegTree.new(n, function(a, b) return a + b end, 0LL)
for i = 1, n do
  local a = io.read("*n")
  st:setValue(i, a, true)
end
st:updateAll()
for iq = 1, q do
  local a, b, c = io.read("*n", "*n", "*n")
  if a == 0 then
    st:addValue(b + 1, c)
  else
    local ans = st:getRange(b + 1, c)
    ans = tostring(ans):gsub("LL", "")
    print(ans)
  end
end


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

int main() {
  int A;
  cin >> A;
  
  if ( A <= 599 ) cout << 8;
  else if ( 600 <= A && A <= 799) cout << 7;
  else if ( 800 <= A && A <= 999) cout << 6;
  else if ( 1000 <= A && A <= 1199) cout << 5;
  else if ( 1200 <= A && A <= 1399) cout << 4;
  else if ( 1400 <= A && A <= 1599) cout << 3;
  else if ( 1600 <= A && A <= 1799) cout << 2;
  else cout << 1;
  
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

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

    int n;
    cin>>n;
    int a[n];
    for(int i = 0; i<n; i++){
        cin>>a[i];
    }
    int xr = a[0];
    for(int i = 1; i<n; i++){
        xr^=a[i];
    }
    for(int i = 0; i<n; i++){
        cout<<(a[i]^xr)<<" ";
    }
    
}

Measured memory_bytes: 4296
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define MOD 1000000007

int main() {
  ll H, W;

  cin >> H >> W;

  vector<string> map(H, "");

  typedef pair<P, ll> NodeInfo;

  queue<NodeInfo> q;
  vector<vector<bool> > visited(H, vector<bool>(W, false));

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

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (map[i][j] == '.') {
        bool upc = (i >= 1) && map[i - 1][j] == '#';
        bool dnc = (i <= H - 2) && map[i + 1][j] == '#';
        bool ltc = (j >= 1) && map[i][j - 1] == '#';
        bool rtc = (j <= W - 2) && map[i][j + 1] == '#';
        if (upc || dnc || ltc || rtc) {
          q.push(NodeInfo(P(i, j), 1));
          visited[i][j] = true;
        }
      }
    }  // j
  }    // i

  ll ans = 0;
  while (!q.empty()) {
    NodeInfo tmp = q.front();
    q.pop();
    ll tmp_y = tmp.first.first;
    ll tmp_x = tmp.first.second;
    ll tmp_n = tmp.second;
    map[tmp_y][tmp_x] = '#';
    ans = tmp_n;
    if (tmp_y >= 1 && !visited[tmp_y - 1][tmp_x] && map[tmp_y - 1][tmp_x] == '.'){
      q.push(NodeInfo(P(tmp_y - 1, tmp_x), tmp_n + 1));
      visited[tmp_y - 1][tmp_x] = true;
    }
    if (tmp_y <= H - 2 && !visited[tmp_y + 1][tmp_x] && map[tmp_y + 1][tmp_x] == '.'){
      q.push(NodeInfo(P(tmp_y + 1, tmp_x), tmp_n + 1));
      visited[tmp_y + 1][tmp_x] = true;
    }
    if (tmp_x >= 1 && !visited[tmp_y][tmp_x - 1] && map[tmp_y][tmp_x - 1] == '.'){
      q.push(NodeInfo(P(tmp_y, tmp_x - 1), tmp_n + 1));
      visited[tmp_y][tmp_x - 1] = true;
    }
    if (tmp_x <= W - 2 && !visited[tmp_y][tmp_x + 1] && map[tmp_y][tmp_x + 1] == '.'){
      q.push(NodeInfo(P(tmp_y, tmp_x + 1), tmp_n + 1));
      visited[tmp_y][tmp_x + 1] = true;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 13840
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    a,b,c,d = LI()
    return max(a*b,c*d)


print(main())


Measured memory_bytes: 7880
#include<bits/stdc++.h>
using namespace std;
const int N = 25;

int l, n = 1, m, a[N];
bool b[N];

int main() {
	scanf("%d",&l);
	l--;
	for(int i=1;;i++) {
		if(!l) break;
		n++;
		a[i] = l/2+1;
		b[i] = (l%2);
		m += 2 + !b[i];
		l = (l-1)/2;
	}
	printf("%d %d\n", n, m);
	for(int i=1;i<n;i++) {
		printf("%d %d %d\n", i, i+1, a[i]);
		if(b[i]) {
			printf("%d %d 0\n", i, i+1);
		}
		else {
			printf("%d %d 1\n", i, i+1);
			printf("%d %d 0\n", i, n);
		}
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
using namespace std;

struct S{
	int id,solve,pena;
	bool operator<(S a)const{
		if(solve!=a.solve)return solve>a.solve;
		if(pena!=a.pena)return pena<a.pena;
		return id>a.id;
	}
	bool operator==(S a)const{
		return solve==a.solve&&pena==a.pena;
	}
};
int main(){
	int M,T,P,R;
	S team[50];
	while(cin>>M>>T>>P>>R,M|T|P|R){
		for(int i=0;i<T;i++){
			team[i].id=i+1;
			team[i].solve=team[i].pena=0;
		}
		int wrong[50][10]={};
		for(int i=0;i<R;i++){
			int m,t,p,j;
			cin>>m>>t>>p>>j;
			t--;p--;
			if(j==0){
				team[t].solve++;
				team[t].pena += m+20*wrong[t][p];
			}else{
				wrong[t][p]++;
			}
		}
		sort(team,team+T);
		cout<<team[0].id;
		for(int i=1;i<T;i++){
			if(team[i-1]==team[i])cout<<'=';
			else cout<<',';
			cout<<team[i].id;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1188
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

N = int(input())

def cnt_753(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += cnt_753(s + c)
    return ret

print(cnt_753('0'))

Measured memory_bytes: 14188
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>

using namespace std;

int main() {
	int i, j, k, n, n2;
	int m[100][100] = { 0 };
	int list[400][400] = { 0 };

	cin >> n;
	for (i = 0; i<n; i++) {
		cin >> n2;
		cin >> n2;
		list[i][0] = n2;
		for (j = 1; j <= n2; j++) {
			cin >> list[i][j];
		}
	}
	//cout << endl;
	
	for(i=0; i<n; i++){
		n2=list[i][0];
		for(j=1; j<=n2; j++){
			//cout << list[i][j] << " ";
			m[i][list[i][j] - 1] = 1;
		}
		//cout << endl;
	}
	//cout << endl; cout << endl;
	

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			cout << m[i][j];
			if (j != (n - 1)) cout << " ";
		}
		cout << endl;
	}
	//cout << endl; cout << endl;

	return 0;
}

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

double t, a;

double calc_dis(double x) { return abs(a-(t - x*0.006)); }

int main() {
  int n;
  cin >> n >> t >> a;
  double h[n];
  for ( int i = 0; i < n; i++ ) { cin >> h[i]; }
  int ans = 1;
  double dis = calc_dis(h[0]);
  for ( int i = 1; i < n; i++ ) {
    if ( dis > calc_dis(h[i]) ) { dis = calc_dis(h[i]); ans = i+1; }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {

	string s,t;
	cin >> s >> t;

	int ans =0;
	rep(i,s.size()){
		if(s[i] != t[i])
		ans++;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 3912
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

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

	vector<int>w(n);
	int sum = 0;
	rep(i, 0, n) {
		cin >> w[i];
		sum += w[i];
	}

	int ans = 101010;
	for (int i = 0; i <= n-2;i++) {
		int sum1 = 0;
		for (int j = 0; j <= i; j++) {
			sum1 += w[j];
		}
		int sum2 = sum - sum1;
		ans = min(ans, abs(sum1 - sum2));
	}
	cout << ans << endl;

	
	return 0;
}

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

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

    //freopen("input.txt","r",stdin);

    long long n,i=1,k=7;
    cin>>n;
    while(1){
        if(n%2==0 || n%5==0){cout<<-1<<endl;break;}
        else{
            if(k%n){k=10*(k%n)+7;}
            else {cout<<i<<endl;break;}
            i++;
        }
    }

    return 0;
}





Measured memory_bytes: 3604
<?php
$s = trim(fgets(STDIN));
$s = str_replace(array("\r\n","\r","\n"), '', $s);
$s = explode(" ", $s);

$N = $s[0];


$s = trim(fgets(STDIN));
$s = str_replace(array("\r\n","\r","\n"), '', $s);
$s = explode(" ", $s);

$A = $s;

$ret = array();

$sum = 0;
for ($j = 0; $j < $N; $j++) {
    $a = $A[$j];
    if ($j % 2 == 0) {
        $sum += $a;
    } else {
        $sum -= $a;
    }
}

$ret[0] = $sum;
for ($j = 1; $j < $N; $j++) {
    $ret[$j] = ($A[$j - 1] - ($ret[$j - 1] / 2)) * 2;
}

echo implode(" ", $ret);

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

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int l = in.nextInt();
		int r = in.nextInt();
		int d = in.nextInt();
		int ans = r / d - l / d;
		if (l % d == 0)
			ans++;
		System.out.println(ans);

	}

}


Measured memory_bytes: 35576
N=int(input())
A=list(map(int,input().split()))
S=sum(A)
B=[A[0]]
for j in range(1,N):
    B.append(B[j-1]+A[j])
#print(B)

ans=10000000000
for i in range(N-1):
    ans=min(abs((S-B[i])-B[i]),ans)
print(ans)

Measured memory_bytes: 24824
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int c[40][40];
int sum[40][40];
int sum_all = 0;
int h,w,s;

int get_sum(int x1,int y1,int x2,int y2){
	return sum[x2][y2] + sum[x1 - 1][y1 - 1] - sum[x1 - 1][y2] - sum[x2][y1 - 1];
}

P dp[40][40][40][40];

P rec(int x1,int y1,int x2,int y2){
	if(dp[x1][y1][x2][y2].first != -1) return dp[x1][y1][x2][y2];
	P res = {1 , s - (sum_all - get_sum(x1,y1,x2,y2))};
	for(int i = x1;i < x2;i++){
		if(sum_all - get_sum(x1, y1, i, y2) > s) continue;
		if(sum_all - get_sum(i + 1,y1,x2,y2) > s) continue;
		P l = rec(x1, y1, i, y2);
		P r = rec(i + 1,y1,x2,y2);
		P ans = {l.first + r.first,min(l.second,r.second)};
		res = max(res,ans);
	}
	for(int i =  y1;i < y2;i++){
		if(sum_all - get_sum(x1,y1,x2,i) > s) continue;
		if(sum_all - get_sum(x1,i + 1,x2,y2) > s) continue;
		P l = rec(x1,y1,x2,i);
		P r = rec(x1,i + 1,x2,y2);
		P ans = {l.first + r.first , min(l.second , r.second)};
		res = max(res,ans);
	}

	return dp[x1][y1][x2][y2] = res;
}


int main(){
	while(cin >> h >> w >> s,h || w || s){
		sum_all = 0;
		rep(i,1,h)rep(j,1,w)rep(k,1,h)rep(l,1,w) dp[i][j][k][l].first = dp[i][j][k][l].second = -1;
		rep(i,1,h)rep(j,1,w) sum[i][j] = 0;
		rep(i,1,h)rep(j,1,w) c[i][j] = 0;
		rep(i,1,h)rep(j,1,w) cin >> c[i][j];
		rep(i,1,h)rep(j,1,w) sum_all += c[i][j];
		rep(i,1,h)rep(j,1,w) sum[i][j] = sum[i - 1][j] + c[i][j];
		rep(i,1,h)rep(j,1,w) sum[i][j] += sum[i][j - 1];
		cout << rec(1,1,h,w).first << " " << rec(1,1,h,w).second << endl;;
	}
}



Measured memory_bytes: 27652
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

int main() {

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

	cout << (int)t / a *b << endl;










}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,a,k,m[201],i,b[200],c[200],j;
	scanf("%d%d",&n,&k);
	for(i=1;i<=2*n;i++)m[i-1]=i;
	for(i=0;i<k;i++){
		scanf("%d",&a);
		if(!a){
			for(j=0;j<n;j++){
				b[j]=m[j];
				c[j]=m[j+n];
			}
			for(j=0;j<n*2;j+=2){
				m[j]=b[j/2];
				m[j+1]=c[j/2];
			}
		}
		else{
			for(j=0;j<a;j++)b[j]=m[j];
			for(j=a;j<n*2;j++)c[j-a]=m[j];
			for(j=0;j<n*2-a;j++)m[j]=c[j];
			for(j=n*2-a;j<n*2;j++)m[j]=b[j-(n*2-a)];
		}
	}
	for(i=0;i<n*2;i++)printf("%d\n",m[i]);
	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
//input power
int n;
int X[100100];
int main(){
	cin >> n; 
	int a[n];
	int ans = 0;
	rep(i,n){
		cin>>a[i];
	}
	rep(i,n){
		int A =a[i];
		rep(j,3){
			if(A-1+j!=0){
			X[A-1+j] ++;
			chmax(ans,X[A-1+j]);
			}
		}
	}
	cout << ans <<endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var An = Sarray().OrderByDescending(x => x).ToArray();
            long ans = 0;
            var t = N-1;
            for(var i=0;i<N;i++)
            {
                var lim = 2;
                if (i == 0) lim = 1;
                for(var j=0;j<lim;j++)
                {
                    if(t>0)
                    {
                        ans += An[i];
                        t--;
                    }
                }
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 46116
#include<iostream>

using namespace std;

int main() {
	char x[10];
	int i;

	for (i = 0; i < 10; i++) {
		cin >> x[i];
	}

	x[3] = '8';

	for (i = 0; i < 10; i++) {
		cout << x[i];
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define drng(i,a,b) for(int i=int(a);i>int(b);i--)
typedef long long LL;
 
 
void test_case(){
 
}
int main() {
    fastio
    int h, w;
    cin >> h >> w;
    
    char matrix[h+1][w+1];
    rng(i,1,h+1){
        string s;
        cin>>s;
        rng(j,1,w+1){
            char c = s[j-1];
            // cin >> c;
            matrix[i][j] = c;
        }
    }
    LL dp[h+1][w+1] = {};
    
    dp[0][1] = 1;
    rng(i,1,h+1){
        rng(j,1,w+1){
            if(matrix[i][j] == '#')
                dp[i][j] = 0;
            else{
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
                dp[i][j] = dp[i][j] % mod;
            }
        }
    }

    cout<<dp[h][w]<<endl;
    return 0;
}

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

void solve() 
{
    int x,y;cin>>x>>y;
    if(y%2){cout<<"No"<<endl;return;}
    cout<<(x>=((y+2)/4)&&x<=y/2?"Yes":"No")<<endl;
}

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

Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

class Main{
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] Args) throws IOException{
        final int n = Integer.parseInt(br.readLine());
        for(int i = 1; i<=n; i++){
            int x = i;
            if(x%3==0){
                out.print(" "+i);
                continue;
            }
            do{
                if(x%10==3){
                    out.print(" "+i);
                    break;
                }
                x /= 10;
            }while(x!=0);
        }
        out.println();
        out.flush();
    }
}

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

public class Main {
    public static void main(String[] args) {Main instance = new Main();sc = instance.new Scanner();instance.solve();}
    private class Scanner {String[] s = new String[0];String regex = " ";int i = 0;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));public String next() {try {if (i < s.length) { return s[i++];}String st = br.readLine();while ("".equals(st)) { st = br.readLine(); }s = st.split(regex, 0);i = 0;return s[i++];} catch (IOException e) { return null; }}public int nextInt(){return Integer.parseInt(next());}}        
    private static Scanner sc;

    private void solve() {
        int N = sc.nextInt();
        String[] S = new String[N];
        String ans = "Three";
        for (int i = 0; i < N; i++) {
            if ("Y".equals(sc.next())) {
                ans = "Four";
            }
        }
        System.out.println(ans);
    }
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code
LL gcd(LL a,LL b) {
	LL bigger = max(a,b);
	LL smaller = min(a,b);
	if (smaller == 0) return bigger;
	if (smaller < 0) {
		cerr << "smaller of gcd is negative number" << endl;
		return 1;
	}
	if (bigger % smaller != 0) {
		return gcd(smaller,(bigger % smaller));
	}
	return smaller;
}

int main(int argc, char const* argv[])
{
	LL a,b,c,d;
	cin >> a >> b >> c >> d;
	LL num_c = b / c - a / c + (a%c == 0 ? 1 : 0);
	LL num_d = b / d - a / d + (a%d == 0 ? 1 : 0);
	LL glm_cd = c*d/gcd(c,d);
	LL num_cd = b / glm_cd - a / glm_cd + (a%glm_cd== 0 ? 1 : 0);
	cout << b-a-num_c-num_d+num_cd+1 << endl;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    while (true) {
        val n = readLine()!!.toInt()
        
        if (n == 0) break

        val a = readLine()!!.split(' ').map{ it.toInt() }

        val avg = a.sum() / n

        val sum = a.count{ it <= avg }

        println(sum)
    }
}



Measured memory_bytes: 46860