akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 

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

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int m, f, r, cnt;
    vector<vector<int>> grades;

    cnt = 0;
    while (m!=-1||f!=-1||r!=-1) {
        cin>>m>>f>>r;
        if (m==-1 && f==-1 && r==-1) break;
        vector<int> mfr(3);
        mfr[0] = m; mfr[1] = f; mfr[2] = r;
        grades.push_back(mfr);
        cnt++;
    }
    rep(i, cnt) {
        m = grades[i][0]; f = grades[i][1]; r = grades[i][2];
        if (m == -1 || f == -1) cout<<"F"<<endl;
        else if (m + f >= 80) cout<<"A"<<endl;
        else if (m + f >= 65) cout<<"B"<<endl;
        else if ((m + f >= 50) || (m + f >= 30 && r >= 50)) cout<<"C"<<endl;
        else if (m + f >= 30) cout<<"D"<<endl;
        else cout<<"F"<<endl;
    }
}


Measured memory_bytes: 3144
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<math.h>
#include<set>
#include<iomanip>
#include<stdio.h>
#include<deque>
#include<stack>
#include<map>
#include<queue>
#include<cstring>
#define M 1000000007
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;cin>>n>>k;
	int h[n],i,o=0;
	for(i=0;i<n;i++)
	{
		cin>>h[i];
		if(h[i]>=k)
			o++;
	}
	cout<<o<<endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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

        int m, f, r;

        while (true) {

            m = sc.nextInt();
            f = sc.nextInt();
            r = sc.nextInt();

            if (m == (-1) && r == (-1) && f == (-1)) {
                break;
            }

            //?????¶????????????????¨??????????????¨????????????????????¬????????????´???????????? F???
            if (m == (-1) || f == (-1)) {
                System.out.println("F");
            } //?????¶????????????????¨???¨??????????¨????????¨??????°??? 80 ??\???????????°????????? A ???
            else if ((m + f) >= 80) {
                System.out.println("A");
            } //?????¶????????????????¨???¨??????????¨????????¨??????°??? 65 ??\??? 80 ??????????????°????????? B???
            else if ((m + f) < 80 && (m + f) >= 65) {
                System.out.println("B");
            } //?????¶????????????????¨???¨??????????¨????????¨??????°??? 50 ??\??? 65 ??????????????°????????? C???
            else if ((m + f) < 65 && (m + f) >= 50) {
                System.out.println("C");
            } //?????¶????????????????¨???¨??????????¨????????¨??????°??? 30 ??\??? 50 ??????????????°????????? D???
            //???????????????????¨?????????°??? 50 ??\???????????°????????? C???
            else if ((m + f) < 50 && (m + f) >= 30) {
                if (r >= 50) {
                    System.out.println("C");
                } else if (r < 50) {
                    System.out.println("D");
                }
            } //?????¶????????????????¨???¨??????????¨????????¨??????°??? 30 ??????????????°????????? F???
            else if ((m + f) < 30) {
                System.out.println("F");
            }
        }
    }
}

Measured memory_bytes: 26472
using System;

class Program {
    static void Main(string[] args) {
        string input = Console.ReadLine();
        int a = int.Parse(input.Substring(0, 1));
        int b = int.Parse(input.Substring(1, 1));
        int c = int.Parse(input.Substring(2, 1));
        int result = 0;
        if (a == 1) {
            result++;
        }
        if (b == 1) {
            result++;
        }
        if (c == 1) {
            result++;
        }
        Console.WriteLine(result);

    }
}


Measured memory_bytes: 13140
def examA():
    D,T,S = LI()
    if (D-1)//S<T:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)
    return

def examB():
    S = SI()
    T = SI()
    s = len(S)
    t = len(T)
    ans = t
    for i in range(s-t+1):
        cnt = 0
        for j in range(t):
            if S[i+j]!=T[j]:
                cnt += 1
        ans = min(ans,cnt)

    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examB()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 10556
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    int cnt = 0;
    for(int i = 0; i < n - 2; i++) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
            cnt++;
        }
    }
    cout << cnt << endl;
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    int n;
    cin >> n;

    vll a(n);
    rep(i,0,n) cin >> a[i];
    sort(all(a));
    if(count(all(a),0)) {
        cout << 0 << endl;
    } else {
        __int128_t x = 1;
        __int128_t MAXA = 1e18;
        rep(i,0,n) {
            x *= a[i];
            if(x < 0 || x > MAXA) {
                cout << -1 << endl;
                return 0;
            }
        }
        if(x > MAXA) cout << -1 << endl;
        else cout << (ll)x << endl;
    }
    return 0;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
#define hell 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long 
#define pi 3.14159265358979323846
using namespace std;
const ll N=5e5;
ll pr(ll a,ll b,ll c)
{
	if(b==0)
	return 1LL;
	ll ans=1;
	while(b>0)
	{
		if(b%2)
		ans=((ans%c)*(a%c))%c;
		a=((a%c)*(a%c))%c;
		b/=2;
		a%=c;
		ans%=c;
	}
	return ans;
}

void solve()
{ll k,n,m,x,h,l,r,a,b,c,d,w,mini,maxi=INT_MAX,prev,res;
   cin>>n>>m;
   cout<<n*m;
}

  
int main()
{
  fast
  //for(ll i=0;i<=9;i++)
  //cal(1,3234566667,i);
  //sort(v.begin(),v.end());
  //pre();
ll t=1;
//chk();
//cin>>t;
//SieveOfEratosthenes();
//cout<<"ok";
while(t--)
{ //cout<<"ok";

solve();
 //cout<<ma<<endl;
}
return 0;}
/*
ll pr(ll a,ll b,ll c)
{
	if(b==0)
	return 1LL;
	ll ans=1;
	while(b>0)
	{
		if(b%2)
		ans=((ans%c)*(a%c))%c;
		a=((a%c)*(a%c))%c;
		b/=2;
		a%=c;
		ans%=c;
	}
	return ans;
}
vector<ll> fact(N+1);
void pre()
{
	fact[0]=1;
	for(ll i=1;i<=N;i++)
	fact[i]=fact[i-1]*i,fact[i]%=hell;
	
}
*/

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

int main() {
  int N , A , B;
  cin >> N >> A;
  B = N % 500;
  
  if (B == 0) {
    cout << "Yes" << endl;
  }
  else if (B < A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  

}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;
using ll = long long;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int N, K;
ll x[51], y[51];
vector<pair<ll, ll>> p;

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
        p.push_back({x[i], y[i]});
    }
    sort(p.begin(), p.end());

    ll mn = 1e22;

    for (int i = 0; i < N - 1; i++) {
        for (int k = i + 1; k < N; k++) {
            ll dx = p[k].first - p[i].first;
            vector<pair<ll, ll>> xContain;
            vector<ll> ys;
            for (int v = 0; v < N; v++) {
                if (p[v].first >= p[i].first && p[v].first <= p[k].first) {
                    xContain.push_back(p[v]);
                    ys.push_back(p[v].second);
                }
            }
            sort(ys.begin(), ys.end());

            if (ys.size() < K) continue;
            for (int le = 0; le <= ys.size() - K; le++) {
                ll dy = ys[le + K- 1] - ys[le];
//                cout << p[i].first << " " << p[k].first << " " << ys[le] << " " << ys[le+K-1] << " " << le << " " << le + K << endl;
                mn = min(mn, dx * dy);
            }
        }
    }

    cout << mn << endl;

    return 0;
}


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

using namespace std;

int main()
{
    int n ,result = 8888888;
    cin >> n ;
    int arr[n];
    for(int i=0 ; i<n ; i++)
        cin >> arr[i];

    for(int i= -100 ; i<101 ; i++){
        int sum = 0 ;
        for(int j=0 ; j<n ; j++){
            sum += (arr[j] - i) * (arr[j] - i) ;
        }
        if(sum < result){
            result = sum;
        }
    }

    cout << result ;
    return 0;
}


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

int main()
{   
    int N;
    cin>>N;
    int a[N],b[N];
    for(int i=0;i<N;i++) cin>>a[i];
    for(int i=0;i<N;i++) cin>>b[i];
    for(int i=1;i<N;i++){
        a[i]=a[i]+a[i-1];
    }
    reverse(b,b+N);
    for(int i=1;i<N;i++) b[i]=b[i]+b[i-1];
    int ans=0;
    for(int i=0;i<N;i++){
        int tmp=a[i]+b[N-1-i];
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a,b,c,min;
	
	scanf("%d %d %d",&a,&b,&c);
	min=a+b;
	if(min>b+c) min=b+c;
	if(min>c+a) min=c+a;
	printf("%d\n",min);
	return 0;
}


Measured memory_bytes: 128
#include<iostream> 
using namespace std; 
int main(){ 
int h,w; 
while(cin >> h >> w && h||w){ 
for(int i=0;i<h;i++){ 
for(int j=0;j<w;j++) cout << "#"; cout << endl;
 } 
cout << endl; 
}
 }


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
map<char,string> table;
map<string,char> table2;

void make_table (void )
{
	table.clear();
	table[' ']="101";
	table['\'']="000000";
	table[',']="000011";
	table['-']="10010001";
	table['.']="010001";
	table['?']="000001";
	table['A']="100101";
	table['B']="10011010";
	table['C']="0101";
	table['D']="0001";
	table['E']="110";
	table['F']="01001";
	table['G']="10011011";
	table['H']="010000";
	table['I']="0111";
	table['J']="10011000";
	table['K']="0110";
	table['L']="00100";
	table['M']="10011001";
	table['N']="10011110";
	table['O']="00101";
	table['P']="111";
	table['Q']="10011111";
	table['R']="1000";
	table['S']="00110";
	table['T']="00111";
	table['U']="10011100";
	table['V']="10011101";
	table['W']="000010";
	table['X']="10010010";
	table['Y']="10010011";
	table['Z']="10010000";

	table2.clear();
	table2["00000"]='A';
	table2["00001"]='B';
	table2["00010"]='C';
	table2["00011"]='D';
	table2["00100"]='E';
	table2["00101"]='F';
	table2["00110"]='G';
	table2["00111"]='H';
	table2["01000"]='I';
	table2["01001"]='J';
	table2["01010"]='K';
	table2["01011"]='L';
	table2["01100"]='M';
	table2["01101"]='N';
	table2["01110"]='O';
	table2["01111"]='P';
	table2["10000"]='Q';
	table2["10001"]='R';
	table2["10010"]='S';
	table2["10011"]='T';
	table2["10100"]='U';
	table2["10101"]='V';
	table2["10110"]='W';
	table2["10111"]='X';
	table2["11000"]='Y';
	table2["11001"]='Z';
	table2["11010"]=' ';
	table2["11011"]='.';
	table2["11100"]=',';
	table2["11101"]='-';
	table2["11110"]='\'';
	table2["11111"]='?';
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.the_code_a_doctor_loved", "r", stdin );
	make_table();
	string str = "";
	while (getline (cin, str ) ){
		int n = str.length();
		string ans = "";
		rep (i, n ){
			ans += table[str[i]];
		} // end rep
		if (ans.length() % 5 != 0 ){
			ans += string (5 - (ans.length() % 5 ), '0' );
		} // end if
		string res = "";
		for (int i = 0; i < ans.length(); i += 5 ){
			 res += table2[ans.substr (i, 5 )];
		} // end for
		cout << res << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1216
// I/O
#include <iostream>
#include <iomanip>

// data structures
#include <set>
#include <queue>
#include <vector>

// manipulations
#include <algorithm>

#define rep(i,n) for(int i=0;i< (n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define for_lowercase(c) for(int c='a';c<='z';++c)
#define for_uppercase(c) for(int c='A';c<='Z';++c)
#define ALL(a) (a).begin(),(a).end()
using LLI = long long int;
LLI GCD(LLI a,LLI b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LLI LCM(LLI a,LLI b){ return (a/GCD(a,b))*b; }
using VI  = std::vector<LLI>;
using PI  = std::pair<LLI,LLI>;
using VVI = std::vector<VI>;
using VPI = std::vector<PI>;
template<class T> bool is_odd (T x){ return   x%2 ; }
template<class T> bool is_even(T x){ return !(x%2); }
LLI combination(LLI n,LLI k,bool reset=false){
    static VVI C;
    static LLI n_hashed = -1;

    if(n<0){
        std::cout << "n must be non-negative in combination()" << std::endl;
        exit(1);
    }

    if(n_hashed<n || reset){
        C.clear();
        C.resize(n+1);
        for(int i=0;i<=n;++i){
            C[i].clear();
            C[i].resize(i+1,1); // filled with 1
        }
        for(int i=1;i<=n;++i){
            for(int j=1;j<i;++j){
                C[i][j] = C[i-1][j-1] + C[i-1][j];
            }
        }

        n_hashed = n;
    }

    // std::cout << "C[" << n << "][" << k << "]" << C[n][k] << std::endl;
    return C[n][k];
}

int main() {
    std::ios::sync_with_stdio(false);

    LLI N,A,B;
    std::cin >> N >> A >> B;
    VI v(N);
    rep(i,N)
        std::cin >> v[i];

    std::sort(ALL(v),std::greater<LLI>()); // descending order

    double max_average = 0.;
    rep(i,A){
        max_average += v[i];
    }
    max_average /= A;

    std::cout << std::fixed << std::setprecision(6) << max_average << std::endl;

    LLI min = v[A-1];
    LLI num_min = 0;
    rep(i,N)
        if(v[i]==min)
            ++num_min;

    LLI num_fixed;
    for(num_fixed=0;v[num_fixed]>min;++num_fixed);

    A -= num_fixed;
    B -= num_fixed;

    // sum of (num_min choose i) for i in [A,B]
    LLI result = 0;
    for(int i=A;i<=std::min(B,num_min);++i){
        result += combination(num_min,i);
        if(min!=v[0]) break;
    }

    std::cout << result << std::endl;

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n, x, d = map(int, input().split())

if d == 0:
    if x == 0:
        ans = 1
    else:
        ans = n + 1
else:
    if d < 0:
        x, d = -x, -d

    intervals = defaultdict(list)
    for i in range(n + 1):
        # [l, r]
        l = i * (i - 1) // 2
        r = i * (2 * n - i - 1) // 2

        a = (x * i) % d
        b = (x * i) // d
        intervals[a].append((l + b, r + b))  # [l, r]
    # print(intervals)

    ans = 0
    for interval in intervals.values():
        interval.sort()

        l, r = interval[0]
        ans += r - l + 1
        for i in range(1, len(interval)):
            li, ri = interval[i]
            if ri <= r:
                continue
            elif li <= r:
                ans += ri - (r + 1) + 1
                l, r = li, ri
            else:
                ans += ri - li + 1
                l, r = li, ri

print(ans)


Measured memory_bytes: 72184
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    var ans = 0L
    val map = mutableMapOf<String, Long>()
    for (i in 0 until n) {
        val s = sc.nextLine().toCharArray().sorted().joinToString("")
        if (!map.containsKey(s)) {
            map[s] = 0
        }
        ans += map[s]!!
        map[s] = map[s]!! + 1
    }
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 66372
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n;
pair<ll,ll>a[100005];
int32_t main(){
CODE_START;
cin>>n;
for(ll i=0;i<n;i++)
{
    cin>>a[i].f;
    a[i].s=i;
}
sort(a,a+n);
for(ll i=0;i<n;i++)
cout<<a[i].s+1<<' ';
}


Measured memory_bytes: 2432
#define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX_N = 5000;
const long long MIN = -1000000000000;
long long d[MAX_N][MAX_N]; //距離表
int n,m;

void init(){
	REP(i,n){
		REP(j,n){
			if (i == j)	d[i][j] = 0;
			else d[i][j] = MIN;
		}
	}
}

void warshall_floyd(){
	REP(k,n){
		REP(i,n){
			REP(j,n){
				d[i][j] = max(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
}

int main(){
	cin >> n >> m;
	init();
	REP(i,m){
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		d[a][b]=c;
	}

	warshall_floyd();
	
	if(d[0][0] > 0) cout << "inf" << endl;
	else cout << d[0][n-1] << endl;
}

Measured memory_bytes: 39808
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vi A(N), B(N);
    ll sm = 0, mi = LLONG_MAX;
    rep(i, N) {
        cin >> A[i] >> B[i];
        sm += A[i];
        if (A[i] > B[i])smin(mi, (ll)B[i]);
    }
    if (mi == LLONG_MAX)cout << 0 << endl;
    else cout << sm - mi << endl;
}

Measured memory_bytes: 512
import java.util.*;
 
public class Main{
  	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long ans = 0;
      for(int i = 1 ; i < n ; i++){
        ans += i;
      }
      System.out.println(ans);
      return;
    }
}

Measured memory_bytes: 21844
n, k=map(int,input().split())

mod=[n//k]*k
if n%k!=0:
    for i in range(1, n%k+1):
        mod[i]+=1

ans=0
for a in range(k):
    a_mod=a%k
    if a_mod==0:
        b_mod=0
        c_mod=0
    else:
        b_mod=k-a_mod
        c_mod=k-a_mod
    if (b_mod+c_mod)%k==0:
        ans+=mod[a_mod]*mod[b_mod]*mod[c_mod]
print(ans)


Measured memory_bytes: 4596
s=input()
if s[0]=='W':
    ans=s.count('WB')
elif s[0]=='B':
    ans=s.count('BW')
if s[0]==s[len(s)-1]:
    a=1
else:
    a=0
    
if ans==0:
    print(0)
else:
    #print(ans)
    print(ans*2-1+a)


Measured memory_bytes: 3188
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	int N, M;
	cin >> N >> M;

	for (int i = 0; i < M; i++)
	{
		int a;
		cin >> a;

		N -= a;
	}

	if (N < 0) cout << -1;
	else cout << N;

	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
using namespace std;
 
typedef vector<int> vi;
#define loop(i,a,b) for(int i=(a); i<int(b);i++)
#define rep(i,b) loop(i,0,b)
 
int main(){
    int n,m;
    while(cin >>n>>m){
        if(n==0&&m==0)break;
        vector<bool> in(n,true);
        int num=-1;
        for(int i=0;i<n-1;i++){
            rep(j,m){
                num++;
                if(num>=n)num=0;
                if(!in[num]){j--;continue;}
            }
            // cout<<num<<endl;
            in[num]=false;
        }
 
        // cout << "end" << endl;
        rep(i,n){
            if(in[i]){
                cout << i+1 << endl;
            }  
        }
    }
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,a,b)       for(i=a;i<=b;i++)
#define FOR(i,a,b)       for(i=a;i>=b;i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define sz(v)           (int)v.size()
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
const int inf =         1e18;
const int mod =         1e9+7;
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p) {int ans=1;x%=mod;while(p>0){if(p&1)ans=(ans*x)%mod;p=p>>1;x=(x*x)%mod;}return ans;}
int inv(int x){return po(x,mod-2)%mod;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=================================================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r,f,q;








void sol()
{ 
  cin>>n;
  in1(a,n);
  c=0;
  fo1(i,n)
  {
      if(a[i]&1 && i&1)c++;
  }
  
  
  
  cout<< c <<endl;
}





int32_t main()
{ 
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //pre();
  //sp(10);
//   w(t)
  sol();
  return 0;
}  

Measured memory_bytes: 3616
#pragma GCC optimize("Ofast,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma G++ optimize(2)
#pragma GCC optimize(3)
#pragma G++ optimize(3)
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#include<bits/stdc++.h>
#define ll long long
//#define int ll
using namespace std;
const int md=1000000007;
const int mxn=200005;
int n,m,mx,ans,dp[mxn],f[mxn];
char s[mxn];
inline void add(int&x,int y){
	x+=y;
	if(x>=md)x-=md;
}
signed main(){
	int i,j,t;
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for(i=1;i<=m;++i)if(s[i]!=s[1])break;mx=i-1;
	if(mx==m){
		dp[0]=f[i]=ans=1;
		for(int i=0;i<=n;++i){
			if(i>=2)dp[i]=f[i-2];
			f[i]=(f[i-1]+dp[i])%md;
			if(n-i>1)add(ans,(ll)dp[i]*(n-i)%md);
		}
		printf("%d\n",ans);
		return 0;
	}
	if(n&1)return 0*puts("0");
	if(!(mx&1))++mx;
	for(t=0;i<=m;++i){
		if(s[i]==s[1])++t;
		else{
			if(t&1)mx=min(mx,t);
			t=0;
		}
	}
	n>>=1,mx=mx+1>>1;
	dp[0]=f[0]=1;
	for(i=0;i<=n;++i){
		if(i){
			dp[i]=(md+f[i-1]-(i-mx-1>=0?f[i-mx-1]:0))%md;
			f[i]=(f[i-1]+dp[i])%md;
		}
		if(n-i<=mx) add(ans,(ll)(n-i)*dp[i]*2ll%md);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 2048
#abc 045 C
import itertools
s= input() # e.g 125
n = len(s)
zentan = itertools.product([0,1],repeat = n-1)
output = 0
for i in zentan: #e.g  i = (0,1)
    total_i = 0
    ln = s[0]
    for j,k  in enumerate(i): # j= 0~ len(n)-1, k = i[?]
        if k == 0:
            ln +=s[j+1]
        elif k == 1:
            total_i += int(ln)
            ln = s[j+1]
    total_i += int(ln)
    output += total_i
    
print(output)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ll n, *l;
    cin >> n;
    l = new ll[n];
    for (int i = 0; i < n; i++)
        cin >> l[i];

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i] && max(l[i]-l[j], l[j]-l[i]) < l[k] && l[k] < l[i] + l[j])
                    ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
// Author := Abhishek Giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vector<(type)>
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)
#define el "\n"

/*##################################################################################*/


int prime[1000000] ;
vector < int > pr;
void calculateprime()
{
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; i <= 1000000 ; i++)
    {
        if(prime[i] == 0)
        {
            pr.pb(i);
            for(ll j = i*2 ; j <= 1000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}


void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool isprime(ll n)
{
    for(ll i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

ll fib(int n)
{
  ll a = 0, b = 1, c, i;
  if( n == 0)
    return a;
  for (i = 2; i <= n; i++)
  {
    c = (a + b);
    a = b;
    b = c;
  }
  return b;
}


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

ll extendedgcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extendedgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

ll findgrouplcm(vector<int> &arr, int n)
{
    ll ans = arr[0];

    for (ll i = 1; i < n; i++)
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));

    return ans;
}


ll powerwithmod(ll x, unsigned ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}


bool comp(const pair<int,int> &a , const pair<int,int> &b){
    return a.first < b.first;
    if(a.first == b.first)  return a.second < b.second;
}


void solve(){
    int n,x;
    in(n)>>x;
    int arr[n];
    f(i,n){
        in(arr[i]);
    }
    int cur = 0 , cnt = 1;
    f(i,n){
        cur += arr[i];
        if(cur > x)    break;
        ++cnt;
    }
    out(cnt);
}


int main() {
    fast();
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3572
// -*- coding:utf-8-unix -*-

use std::cmp::*;
use std::collections::*;
use std::fs::File;
use std::io::prelude::*;
use std::io::*;
use std::vec;

const INF: i64 = 1223372036854775807;
const MEM_SIZE: usize = 202020;
const MOD: i64 = 1000000007;
use std::cmp::*;
use std::collections::*;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(unused_macros)]
macro_rules! p {
    ([$($x:expr), *]) => {{
        let mut f = true;
        $(
            print!("{}{}", if f {""} else {" "}, $x);
            f = false;
        )*
78786    print!("\n");
    }};
    ($x:expr) => {{
        let mut f = true;
        for a in $x.iter() {
            print!("{}{}", if f {""} else {" "}, a);
            f = false;
        }
        print!("\n");
    }};
}
#[allow(dead_code)]
fn readii() -> (i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}
#[allow(dead_code)]
fn readuu() -> (usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn solve() {
    let mut n: usize = read();
    let mut zma = -1 * INF;
    let mut zmi = INF;
    let mut wma = -1 * INF;
    let mut wmi = INF;
    for i in 0..n {
        let (x, y) = readii();
        zma = max(zma, x + y);
        zmi = min(zmi, x + y);
        wma = max(wma, x - y);
        wmi = min(wmi, x - y);
    }
    println!("{}", max(zma - zmi, wma - wmi));

    return;
}
fn main() {
    solve()
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)
#define ll LL
#define st f
#define nd s
#define pb PB
#define mp MP
#define eb emplace_back
#define siz(c) SIZ(c)
const int inf = 1e9+7;
const ll INF = 1e18L+7;

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

const int MXN = 1e5+5;
int h[MXN];
VI V[MXN];
int main()
{
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  FOR(i, 1, n)cin >> h[i];
  FOR(i, 1, m)
    {
    int a, b;
    cin >> a >> b;
    V[a].PB(b);
    V[b].PB(a);
    }
  int res = 0;
  FOR(i, 1, n)
    {
    bool ok = 1;
    for(auto j: V[i])
      if(h[j] >= h[i])ok = 0;
    res += ok;
    }
  cout << res << endl;
}


Measured memory_bytes: 9088
<?php
list($x,$y)=explode(" ",trim(fgets(STDIN)));
$a = array(4,6,9,11);
if($x == 2 || $y == 2 || $x == 11){
    echo "No";
}elseif(in_array($x,$a)){
    if(in_array($y,$a)){
        echo "Yes";
    }else{
        echo "No";
    }
}else{
    if(in_array($y,$a)){
        echo "No";
    }else{
        echo "Yes";
    }
}
?>


Measured memory_bytes: 3828
#include<stdio.h>
int main(void){
	int x,y;
	int i,tmp;
	for(i=0;i<3000;i++){
		scanf("%d %d",&x,&y);
		if(x==0 && y==0){
			break;
		}
		if(x>y){
			tmp=y;
			y=x;
			x=tmp;
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {

    int x; cin >> x;

    while(!IsPrime(x)) {
        x++;
    }

    cout << x << endl;
}

Measured memory_bytes: 256
// Problem : C - Same Integers
// Contest : AtCoder Regular Contest 094
// URL : https://atcoder.jp/contests/arc094/tasks/arc094_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
#define size(x) (int)x.size()
using ll = long long;
using namespace std;

const int N = 1e6 + 1, mod = 1e9 + 7;

int a, b, c, ans = 0;

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> a >> b >> c;
	int t[3] = {a, b, c};
	sort(t, t + 3), a = t[0], b = t[1], c = t[2];
	while (b < c) {
		ans++;
		a++;
		b++;
	}
	ans += (c - a) / 2;
	if ((c - a) & 1) {
		ans += 2;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int i,n,num,digit,ans=0;
    cin>>n;
    for(i=1; i<=n; i++){
        num=i;
        digit=0;
        while(num>0){
            num/=10;
            digit++;
        }
        if(digit%2==1)  ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  double N;
  double P;
  cin >> N >> P;
  double n = pow(P,1/N);
  long int p = P;
  long int x = N;
  for(long int i = n + 10;i>0;i--){
    long int m = pow(i,x);
    if(p % m == 0){
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
import collections
import sys
input = sys.stdin.readline

N = int(input())

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

l = collections.Counter(A)

l24 =list([int(l1[0]) for l1 in l.items() if l1[1]>=2])

l24.sort(reverse=True)

if l24==[]:print(0)
elif l[l24[0]]>=4:print(l24[0]**2)
elif len(l24)>=2:print(l24[0]*l24[1])
else:print(0)


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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)2e5 + 5;
const dbl pi = acos(-1);

int n;
ll a[maxn];
map <ll, ll> pref;

int main() {
//	fin("t.in");
	sync;
	cin >> n;
	pref[0] = 1;
	ll s = 0;
	ll ans = 0;
	F(i, 0, n) {
		cin >> a[i];
		s += a[i];
		ans += pref[s];
		++pref[s];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14336
s = raw_input()
if len(s) == 1:
    print -1, -1
    exit()
if len(s) == 2:
    if s[0] == s[1]:
        print 1, 2
    else:
        print -1, -1
    exit()
for i in xrange(len(s)-2):
    if s[i] == s[i+1] or s[i] == s[i+2] or s[i+1] == s[i+2]:
        print i+1, i+3
        exit()
print -1, -1


Measured memory_bytes: 10864
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T>
struct BIT{
    //1-index
    //0-indexで取ると無限ループする
    private:
    V<T> arr;
    int n;

    public:
    BIT(int siz){
        n=siz;
        arr.assign(n+1,0);
    }
    //一点更新 aにvを加える
    void add(T a,T v){
        //x+=(x&-x) 初項a,それ以降a<=2^Nが列挙
        for(T x=a;x<=n;x+=(x&-x)){
            arr[x]+=v;
        }
    }
    T sum(T a){
        // 1からaまでの区間和
        T ret=0;
        for(T x=a;x>0;x-=(x&-x))ret+=arr[x];
        return ret;
    }
    T lower_bound(T w){// 区間和がw以上となる最小のindを返す
        if(w<=0)return 0;
        T x,r=1;//xは横の位置,rはrank
        while(r<n)r<<=1;
        for(T k=r;k>0;k>>=1){
            if(x+k<=n&&arr[x+r]<w){
                w-=arr[x+r];
                x+=k;
            }
        }
        return x+1;
    }
    T get(T x){//x番目に大きい数
        if(x<=0) return 0;
        T N=1;
        while(N*2<=n)N*=2;
        T v=0;
        for(T i=N;i>0;i/=2){
            if(v+i<=n&&arr[v+i]<x){
                x-=arr[v+i];
                v+=i;
            }
        }
        return v+1;
    }
    T query(int l,int r){
        return sum(r)-sum(l);
    }
};
ll n;
V<ll> a;
V<ll> sum;
V<P> dat;
ll solve(ll x){
    BIT<ll> bit(n+1);
    sum.assign(n+1,0);
    dat.clear();
    for(int i=0;i<n;i++){
        ll add;
        if(a[i]>=x)add=1;
        else add=-1;
        sum[i+1]=sum[i]+add;
    }
    for(int i=0;i<=n;i++)dat.emplace_back(sum[i],i);
    sort(all(dat),greater<P>());
    ll res=0;
    for(int i=0;i<=n;){
        int j=i;
        while(j<=n&&dat[i].fi==dat[j].fi){
            res+=bit.sum(dat[j].se);
            j++;
        }
        j=i;
        while(j<=n&&dat[i].fi==dat[j].fi){
            bit.add(dat[j].se+1,1);
            j++;
        }
        i=j;
    }
    return res;
}
int main(){
    cin>>n;
    a.resize(n);
    V<ll> d(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll l=0,r=(1e10);
    while(r-l>1){
        ll mid=(l+r)/2;
        ll c=solve(mid);
        if(c>(n+1)*n/2/2)r=mid;
        else l=mid;
    }
    cout<<r-1<<"\n";
}

Measured memory_bytes: 5620
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
    for (int i = n - 1; i >= 0; i--){
        for (int j = n - 1; j >= 0; j--){
            if (s[i] != s[j]) dp[i][j] = 0;
            else chmax(dp[i][j],dp[i+1][j+1]+1);
        }
    }
    ll ans = 0;
    rep(i,n){
        rep(j,n){
            chmax(ans,min(dp[i][j],abs(i-j)));
        }
    }
    PRINT(ans);
}    


Measured memory_bytes: 195840
import kotlin.math.*

fun main(){
    val t = readLine()!!.toInt()
    val inputList = Array(t){ readLine()!!.split(" ").map(String::toLong) }
    inputList.forEach { input ->
        val (n, a, b, c, d) = input
        val memo = mutableMapOf<Long, Long>()
        val array = arrayOf(Pair(2L, a), Pair(3L, b), Pair(5L, c))

        fun search(now: Long): Long{
            if(now == 0L){
                return 0
            }else if(now == 1L){
                return d
            }else if(memo.containsKey(now)){
                return memo[now]!!
            }else{
                var res = Long.MAX_VALUE
                if(now < res / d) res = now * d
                array.forEach {
                    val l = (now / it.first) * it.first
                    val r = ((now + it.first - 1L) / it.first) * it.first
                    res = min(res, d * abs(l - now) + it.second + search(l/it.first))
                    res = min(res, d * abs(r - now) + it.second + search(r/it.first))
                }
                memo[now] = res
                return res
            }
        }
        println(search(n))
    }
}

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

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i=1; i<=n; i++){
    int count = 0;
    if(i%2 == 1){
      for(int j=1; j<=i; j++){
        if(i%j == 0){
          count++;
          //cout << j << endl;
        }
      }
    }
    if(count == 8){
      ans++;
      //cout << i << endl;
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h,w;cin>>h>>w;
  vector<vector<char>>ss(h,vector<char>(w));
  rep(i,h)rep(j,w)cin>>ss[i][j];
  vector<vector<char>>res(h*2,vector<char>(w*2));
  rep(i,h*2){
    rep(j,w)cout<<ss[i/2][j];
    cout<<endl;
  }





  return 0;

}


Measured memory_bytes: 384
#入力
D=int(input())
c=list(map(int,input().split()))
l=[0]*26
#リスト初期化
s=[]
for i in range(D):
  s.append(list(map(int,input().split())))
ans=[]
#変数初期化

for d in range(D):
  maxScore=-99999999
  maxI=0
  score=0
  sumdegScore=0
  for i in range(26):
    sumdegScore-=c[i]*((d+1)-l[i])
  for i in range(26):
    score=sumdegScore+c[i]*((d+1)-l[i])-s[d][i]
    if maxScore < score:
      maxScore=score
      maxI=i
  ans.append(maxI+1)
  l[maxI]=d+1

for i in range(D):
  print(ans[i])


Measured memory_bytes: 9420