akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
const int INF = 1<<29;
const int MAX_V = 110;
const int MAX_E = 1100;

int N, M;
int a[MAX_E], b[MAX_E], c[MAX_E]; // 各辺
int dist[MAX_V][MAX_V]; // Floyd-Warshall 用

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

    // Floyd-Warshall でよくやる初期化
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            dist[i][j] = INF;
        }
        dist[i][i] = 0; // ここがポイント
    }

    // 入力
    for (int i = 0; i < M; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        --a[i], --b[i];
        dist[a[i]][b[i]] = c[i];
        dist[b[i]][a[i]] = c[i];
    }

    // Floyd-Warshall
    for (int k = 0; k < N; ++k)
        for (int i = 0; i < N; ++i)
            for (int j = 0; j < N; ++j)
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

    // 集計
    int res = 0;
    for (int i = 0; i < M; ++i) {
        if (c[i] > dist[a[i]][b[i]]) ++res;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P);
P dequeue(void);


int main(){
  int elaps = 0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n+1;
  
  while(head != tail){
    if(Q[head].t<=q){
      elaps += Q[head].t;
      u=dequeue();
      printf("%s %d\n",u.name,elaps);
    }else{
      elaps += q;
      Q[head].t -= q;
      enqueue(Q[head]);
      dequeue();
    }
  }  

 
  return 0;
  
}

void enqueue(P x){ 
  Q[tail]=x;
  if(tail==LEN){
    tail = 1;
  }else{
    tail++;
  }
}

P dequeue(){
  P x;
  x = Q[head];
  if(head == LEN){
    head = 1;
  }else{
    head++;
  }
  return x; 
}

Measured memory_bytes: 10756
mod = 10**9 + 7

def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

#####################################################ライブラリ集ここまで

def main():
    K, N = iip()
    A = iip()
    A.sort()

    dis = []
    cur = -(K - A[-1])
    for i in A:
        d = i - cur
        cur = i
        dis.append(d)

    md = max(dis)
    print(K-md)


    pass

if __name__ == "__main__":
    main()

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

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

    // 入力
    double X, t;
    cin >> X >> t;

    // 処理
    // 出力
    cout << X / t << endl;

    return 0;
}


Measured memory_bytes: 764
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		long N = long.Parse(str);
		long[] C = new long[N-1];
		long[] S = new long[N-1];
		long[] F = new long[N-1];
		long[] A = new long[N];
		long[] B = new long[N];
		for(var i=0;i<N-1;i++){
			string[] str2 = Console.ReadLine().Split();
			C[i] = long.Parse(str2[0]);
			S[i] = long.Parse(str2[1]);
			F[i] = long.Parse(str2[2]);
		}
		for(var i=0;i<N;i++){
			long ct = 0;
			for(var j=i;j<N-1;j++){
				if(ct <= S[j]){
					ct = S[j] + C[j];
				} else if(ct % F[j] == 0){
					ct = ct + C[j];
				} else {
					ct = ct + (F[j] - (ct - S[j]) % F[j]) + C[j];
				}
			}
			Console.WriteLine(ct);
		}
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[200001],op=0,s=0;
	char x;
	cin>>n;
	for(int i=1;i<=n+1;i++){
		x=getchar();
		if(x=='R'){
			a[i-1]=0;
			s++;
		}
		if(x=='W') a[i-1]=1;
	}
	for(int i=1;i<=s;i++){
		if(a[i]==1) op++; 
	}
	cout<<op<<endl;
	return 0;
}

Measured memory_bytes: 4384
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e18+1e18;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

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

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll N;
	cin >> N;
	vll a(N + 1);
	repn(i, N) cin >> a[i];

	ll mx = 1;
	ll mn = 1;

	repn(i, N) {
		if (a[i] > a[mx]) { mx = i; }
		if (a[i] < a[mn]) { mn = i; }
	}

	cout << 2 * N - 2 << endl;
	if (a[mx] + a[mn] >= 0) {
		repn(i, N) {
			if (i == mx) { continue; }
			cout << mx << " " << i << endl;
		}
		repn(i, N - 1) {
			cout << i << " " << i + 1 << endl;
		}
	}
	else {
		repn(i, N) {
			if (i == mn) { continue; }
			cout << mn << " " << i << endl;
		}
		for (ll i = N; i >= 2; i--) {
			cout << i << " " << i - 1 << endl;
		}
	}

	
}

Measured memory_bytes: 3612
import itertools as ite
import math
import random
import sys

INF = 10 ** 18
MOD = 10 ** 9 + 7

sys.setrecursionlimit(1000000)

N, M = map(int, raw_input().split())
E = [[] for i in range(N + 1)]
for i in range(M):
    x, y = map(int, raw_input().split())
    E[x].append(y)

m = {}
def func(pos):
    if pos in m:
        return m[pos]
    ret = 0
    for to in E[pos]:
        ret = max(ret, func(to) + 1)
    m[pos] = ret
    return ret

print max(func(i) for i in range(1, N + 1))


Measured memory_bytes: 64000
// AGC 017A
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
int main()
{
	int n,p,z;
	LL x,y;
	cin>>n>>p;
	x=1;
	y=0;
	while(n--){
		cin>>z;
		if(z%2){
			x+=y;
			y=x;
		}
		else{
			x+=x;
			y+=y;
		}
	}
	if(p)
		x=y;
	cout<<x<<endl;
	return 0;
}

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

int main() {
		
		int n, k , d;
		cin >> n>> k;
		vector<int> snukes(n,0);
		
		while(k--) {
			int d ; cin >> d;
			
			for(int i=0; i<d; i++) {
				int t ; cin>> t;
				snukes[t-1] = 1;
			}
		}
		
		int count = 0;
		for(int i=0; i<n; i++) {
			if (snukes[i] == 0) count++;
		}
		cout<<count<<endl;
}


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		while(a>0) {
			a=a-1000;
		};
		a=a*-1;
        System.out.println(a);

	}

}


Measured memory_bytes: 35704
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int h[n];
  for(int i=0;i<n;++i){
    cin>>h[i];
  }
  int x=abs(h[n-1]-h[n-2]),y=0;
  for(int i=n-3;i>=0;--i){
    int t=min(x+abs(h[i]-h[i+1]),y +abs(h[i]-h[i+2]));
    y=x;
    x=t;
  }
  cout << x << "\n";
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

	string s, p;
	cin >> s >> p;
	s = s + s;//hutatsu tsunageru
	if (s.find(p) != string::npos)
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
#include <complex>
typedef complex<double> Point;
double dot(Point a, Point b){
  return real(conj(a) * b);
}
double cross(Point a, Point b){
  return imag(conj(a) * b);
}
struct Line : public vector<Point> {
  Line(Point a, Point b){
    push_back(a); push_back(b);
  }
  Point vector() const {
    return back() - front();
  }
};
int ccw(Point a, Point b, Point c){
  b -= a; c -= a;
  if(cross(b, c) > EPS) return 1;
  if(cross(b, c) < -EPS) return -1;
  if(dot(b, c) < 0) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}
bool intersectSP(const Line& s, const Point& p){
  return ccw(s[0], s[1], p) == 0;
}
bool intersectSS(const Line& s, const Line& t){
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 && 
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
Point projection(const Line& l, const Point& p){
  double t = dot(p - l[0], l.vector()) / norm(l.vector());
  return l[0] + t * l.vector();
}
double distanceSP(const Line& s, const Point& p){
  const Point r = projection(s, p);
  if(intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const Line& s, const Line& t){
  if(intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
int main(){
  int N;
  while(cin >> N && N){
    Point sp, gp;
    cin >> sp.real() >> sp.imag();
    cin >> gp.real() >> gp.imag();
    Line l(sp, gp);
    vector<double> bx(N), ex(N), by(N), ey(N), h(N);
    REP(i, N) cin >> bx[i] >> by[i] >> ex[i] >> ey[i] >> h[i];
    double ans = 1e8;
    REP(i, N){
      double d = 1e8;
      Point p[4] = { Point(bx[i], by[i]), 
                     Point(ex[i], by[i]),
                     Point(ex[i], ey[i]),
                     Point(bx[i], ey[i]) };
      REP(j, 4) d = min(d, distanceSS(l, Line(p[j], p[(j + 1) % 4])));
      REP(j, 2){
        if(bx[i] <= l[j].real() && l[j].real() <= ex[i] &&
            by[i] <= l[j].imag() && l[j].imag() <= ey[i]  ){
          d = 0.0;
        }
      }

      if(h[i] >= d) ans = min(ans, d);
      else ans = min(ans, h[i] / 2.0 + d * d / (2.0 * h[i]));
    }
    printf("%.12f\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int tmp[6];
	int n;
	while (cin >> n && n != 0) {
		int dice[] = {1,2,3,4,5,6};
		string vec;
		int ans=1;
		for (int i=0; i<n; i++) {
			cin >> vec;
			if (vec=="North") {
				tmp[0] = dice[1]; tmp[1] = dice[5]; tmp[2] = dice[2]; // 123456->263415
				tmp[3] = dice[3]; tmp[4] = dice[0]; tmp[5] = dice[4];
				for (int j=0; j<6; j++) {
					dice[j] = tmp[j];
				}
				ans += dice[0];
			} else if (vec=="East") {
				tmp[0] = dice[3]; tmp[1] = dice[1]; tmp[2] = dice[0]; // 123456->421653
				tmp[3] = dice[5]; tmp[4] = dice[4]; tmp[5] = dice[2];
				for (int j=0; j<6; j++) {
					dice[j] = tmp[j];
				}
				ans += dice[0];
			} else if (vec=="West") {
				tmp[0] = dice[2]; tmp[1] = dice[1]; tmp[2] = dice[5]; // 123456->326154
				tmp[3] = dice[0]; tmp[4] = dice[4]; tmp[5] = dice[3];
				for (int j=0; j<6; j++) {
					dice[j] = tmp[j];
				}
				ans += dice[0];
			} else if (vec=="South") {
				tmp[0] = dice[4]; tmp[1] = dice[0]; tmp[2] = dice[2]; // 123456->513462
				tmp[3] = dice[3]; tmp[4] = dice[5]; tmp[5] = dice[1];
				for (int j=0; j<6; j++) {
					dice[j] = tmp[j];
				}
				ans += dice[0];
			} else if (vec=="Left") {
				tmp[0] = dice[0]; tmp[1] = dice[3]; tmp[2] = dice[1]; // 123456->142536
				tmp[3] = dice[4]; tmp[4] = dice[2]; tmp[5] = dice[5];
				for (int j=0; j<6; j++) {
					dice[j] = tmp[j];
				}
				ans += dice[0];
			} else if (vec=="Right") {
				tmp[0] = dice[0]; tmp[1] = dice[2]; tmp[2] = dice[4]; // 123456->135246
				tmp[3] = dice[1]; tmp[4] = dice[3]; tmp[5] = dice[5];
				for (int j=0; j<6; j++) {
					dice[j] = tmp[j];
				}
				ans += dice[0];
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
using namespace std;
int main()
{ 
	int a, b;
	string op;
	while (true)
	{
		cin >> a >> op >> b;
		if (op == "+")cout << a + b << endl;
		else if (op == "-")cout << a - b << endl;
		else if (op == "*")cout << a*b << endl;
		else if (op == "/")cout << a / b << endl;
		else break;
	}

	return 0;
}

Measured memory_bytes: 1204
import Control.Monad
import Control.Applicative
import Data.List

helper n a b =
  if n == 1
    then "Hello World"
    else show (a + b)

readInt :: IO Int
readInt = readLn

main :: IO ()
main = do
  n <- readInt
  if n == 1
    then putStrLn "Hello World"
    else do
      a <- readInt
      b <- readInt
      print $ a + b

Measured memory_bytes: 508
var
 n,m,i,j:longint;
 s1:string;
 s:array[0..10001] of string;
begin
 readln(n,m);
 for i:=1 to n do
  readln(s[i]);
 for i:=1 to n-1 do
  for j:=i+1 to n do
   if s[i]>s[j] then
    begin
     s1:=s[i]; s[i]:=s[j]; s[j]:=s1;
    end;
 for i:=1 to n do
  write(s[i]);
 writeln;
end.

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

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

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

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

	return 0;
}

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

int main()
{
  int N, K;
  int a;
  cin >> N >> K;
  vector<int> d1(K);
  vector<vector <int>> vec(K);
  for(int i = 0; i < K; i++){
    cin >> d1.at(i);
    for(int j = 0; j < d1.at(i); j++){
      cin >> a;
      vec.at(i).push_back(a);
    }
  }
  int count = 0;
 
  for(int k = 1; k < N+1; k++){
    bool finished = false;
    for(int i = 0; i < K; i++){
      for(int j = 0; j < d1.at(i); j++){
        if(k == vec.at(i).at(j)){
          finished = true;
        }
      }
    }
    if(!finished){
        count++;
      }
  }
  cout << count << endl;
}


Measured memory_bytes: 3684
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
import numpy as np
def main():
    N = int(input())
    V = np.array(input_nums())
    C = np.array(input_nums())
    D = V - C
    D = D[D>0]
    print(np.sum(D))



if __name__ == '__main__':
    main()


Measured memory_bytes: 12492
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskB {
        public static int div(int n) {
            int res = 0;
            while (n % 2 == 0) {
                res++;
                n = n / 2;
            }
            return res;

        }

        public void solve(int testNumber, Scanner sn, PrintWriter out) {
            int n = sn.nextInt();
            int res = 0;
            int m = 1;
            int i = 2;
            for (; i <= n; i++) {
                if (res < div(i)) {
                    res = div(i);
                    m = i;
                }
            }
            out.println(m);
        }

    }
}



Measured memory_bytes: 23636
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Data.Array

solve :: (Array Int Int) -> Int -> Int -> Int
solve arr idx count
    | count > length(arr) = -1
    | arr!idx == 1 = count
    | otherwise = solve arr (arr!idx) (count + 1)

main :: IO()
main = do
    n <- (fst . fromJust . B.readInt) <$> B.getLine
    a <- replicateM n (((flip (-) 1) . fst .fromJust . B.readInt) <$> B.getLine)
    let arr = listArray (0,n-1) a
    print $ solve arr 0 1


Measured memory_bytes: 21884
n = gets.to_i

ans = 1

if n == 2
  puts ans
  exit
end

n_half = (n-1) / 2

ans += n - 2
2.upto(n-1) do |i|
  1.upto(n_half) do |j|
    ans += 1 if i * j <= n-1
    break if i * j > n-1
  end  
end

puts ans


Measured memory_bytes: 14324
import functools
"""最大公約数"""
def gcd(a,b):
    import fractions
    return fractions.gcd(a,b)

"""最小公倍数"""
def lcm(a,b):
    f = gcd(a,b)
    return a*b//f

def m(nums):
    return functools.reduce(lcm, nums)

def main():
    n = int(input())
    A = list(map(int,input().split()))
    mod = 10**9+7
    l = m(A)
    res = 0
    print(sum(l// i for i in A) % mod)

if __name__ == '__main__':
    main()

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

const int maxn = 3005;
int N, a[maxn];
ll dp[2][maxn][maxn];

ll f(int t, int l, int r) {
    if (dp[t][l][r] != -1) return dp[t][l][r];
    if (l > r) return dp[t][l][r] = 0;
    if (t == 0) {
        return dp[t][l][r] = max(f(!t,l+1,r) + a[l],
                                 f(!t,l,r-1) + a[r]);
    }
    else {
        return dp[t][l][r] = min(f(!t,l+1,r) - a[l],
                                 f(!t,l,r-1) - a[r]);
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> a[i];
    memset(dp,-1,sizeof dp);
    ll ans = f(0,1,N);
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 141568
package main

import (
	"fmt"
	"math"
)

func main() {
	var n,counter int
	counter = 0
	fmt.Scan(&n)
	for i := 0; i <= n ; i++ {
		if i % 2 == 0 {
			continue
		}
		ncounter := 0
		j := int(math.Floor(math.Sqrt(float64(i))))
		
		for k := 1; k <=j ; k +=2  {
			if i % k == 0 {
				ncounter ++
			}
		}

		if ncounter == 4 {
			counter++ 
		}
	}
	fmt.Println(counter)
}



Measured memory_bytes: 512
c[1<<23],*p,n=5e6;main(a,b){for(;++a<n;)for(b=++a/2;(b+=a)<n;)c[b]=1;for(;scanf("%d",&n)*n;printf("%d\n",n))for(;p=c+n/2-4,~n&1|p[4]|p[3]|p[1]|*p;n--);}

Measured memory_bytes: 19000
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007

using namespace std;

ll dp[100001][101];

ll knapsack(ll wt[],ll val[],ll w,ll n,ll cur_index)
{
    if(dp[w][cur_index]!=-1)
        return dp[w][cur_index];
    if(cur_index==n)
        return (ll)0;
    if(wt[cur_index]<=w)
        return dp[w][cur_index] = max(val[cur_index]+knapsack(wt,val,w-wt[cur_index],n,cur_index+1)
                                      ,knapsack(wt,val,w,n,cur_index+1));
    else
        return dp[w][cur_index] = knapsack(wt,val,w,n,cur_index+1);
}

int main()
{
    IOS
    memset(dp,-1,sizeof(dp));
    ll n,w;
    cin>>n>>w;
    ll wt[n],val[n];
    for(ll i=0;i<n;i++)
        cin>>wt[i]>>val[i];
    cout<<(ll)knapsack(wt,val,w,n,0);
    return 0;
}


Measured memory_bytes: 79232
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  double mountain[55]={};
  int i=0,j;
  while(scanf("%lf",&mountain[i])!=EOF)
    i++;
  double high=0.0,low=1000000.0;
  rep(j,i){
    high=max(high,mountain[j]);
    low=min(low,mountain[j]);
  }
  printf("%.1f\n",high-low);
}

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

int main()
{
  int n;
  cin>>n;
  int A[210];
  for(int i=0;i<n;i++) cin>>A[i];
  
  int res=0;
  
  while(true){
   	bool exist_odd=false;
    for(int i=0;i<n;i++){
     	 if(A[i]%2!=0) exist_odd=true;
    }
    if(exist_odd) break;
    
    for(int i=0;i<n;i++){
     	A[i]/=2; 
    }
    res++;
  }
  
  cout<<res<<endl;
  
}
  

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#define int long long
using namespace std;
int test[12], uiop[12];
signed main() {
	int n, a = 0, b = 0, c = 1, d = 0, sum = 1, ans = 1; cin >> n;
	for (int h = 1; h < n; h++) {
		c *= h;
	}
	for (int h = 0; h < n; h++) {
		cin >> a; test[a]++; int e = a;
		for (int h = 1; h <= a; h++) {
			if (test[h] == 1) { e--; }
		}
		if (h < n - 2) {
			sum += (e - 1) * c;
		}
		if (h == n - 2) { d = a; }
		if (h == n - 1) {
			if (d > a) { sum++; }
		}
		if (h < n - 2) {
			c /= (n - 1 - h);
		}
	}
	for (int h = 1; h < n; h++) {
		c *= h;
	}
	for (int h = 0; h < n; h++) {
		cin >> b; uiop[b]++; int e = b;
		for (int h = 1; h <= b; h++) {
			if (uiop[h] == 1) { e--; }
		}
		if (h < n - 2) {
			ans += (e - 1) * c;
		}
		if (h == n - 2) { d = b; }
		if (h == n - 1) {
			if (d > b) { ans++; }
		}
		if (h < n - 2) {
			c /= (n - 1 - h);
		}
	}
	cout << abs(sum - ans) << endl;
}

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

int n;
string s;
string dp[51][51];

string f(string a,string b){
  if(a=="invalid")return b;
  if(b=="invalid")return a;
  if(a.size()>b.size())return a;
  if(a.size()<b.size())return b;
  return max(a,b);
}

string calc(int l,int r){
  bool flg=true;
  for(int i=l;i<=r;i++){
    if(s[i]=='?')continue;
    if(s[i]<'0'||'9'<s[i])flg=false;
  }
  if(!flg)return "invalid";
  if(s[l]=='0'&&l<r)return "invalid";
  string res="";
  for(int i=l;i<=r;i++){
    if(s[i]=='?')res.push_back('9');
    else res.push_back(s[i]);
  }
  return res;
}

string solve(int l,int r){
  if(dp[l][r]!="")return dp[l][r];
  string res=calc(l,r);
  if(r-l+1>=6){
    if(s[l]=='?'||s[l]=='L'||s[l]=='R'){
      if(s[l+1]=='?'||s[l+1]=='('){
        if(s[r]=='?'||s[r]==')'){
          for(int i=l+3;i+2<=r;i++){
            if(s[i]!='?'&&s[i]!=',')continue;
            string L=solve(l+2,i-1);
            string R=solve(i+1,r-1);
            if(L=="invalid"||R=="invalid")continue;
            if(s[l]=='L'||s[l]=='?')res=f(res,L);
            if(s[l]=='R'||s[l]=='?')res=f(res,R);
          }
        }
      }
    }
  }
  return dp[l][r]=res;
}


int main(){
  cin>>s;
  n=s.size();
  cout<<solve(0,n-1)<<endl;
  return 0;
}

Measured memory_bytes: 1284
#include<stdio.h>
#include<math.h>
int main(void){
  int i,n,s[1000],sum;
  double ave,dev;
  for( ; ; ){
    sum = 0;
    dev = 0;
  scanf("%d",&n);
  if(!n){break;}
  for(i=0;i<n;i++)
    {
      scanf("%d",&s[i]);
	sum += s[i];
    }
  ave=(double)sum/(double)n;
  for(i=0;i<n;i++){
    dev+=((double)s[i]-ave)*((double)s[i]-ave)/(double)n;
  }
  printf("%f\n",sqrt(dev));
  }
  return 0;
}

Measured memory_bytes: 636
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                   0.000000000000001
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define endl                 '\n'
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[200010],vis(200010,0),dis(200010,inf),fin(200010,0),col(200010,0),par(200010,0);
int myrandom (int i) { return std::rand()%i;}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    int maxi=0,cnt=0;
    for(int i=2;i<=n;i++)
    {
        if(arr[i]<=arr[i-1])
            cnt++;
        else
            cnt=0;
        maxi=max(maxi,cnt);
    }
    cout<<maxi<<endl;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100050;
int fa[maxn*2];
int find(int x) {
	return x==fa[x]?x:(fa[x]=find(fa[x]));
}
void join(int x,int y,int& blk) {
	x=find(x),y=find(y);
	if(x!=y) --blk,fa[x]=y;
}
pair<int,int> data[maxn*2];
vector<int> G[maxn];
int vis[maxn];
bool flag;
void dfs(int x,int col) {
	if(vis[x]) {
		if(vis[x]!=col) flag=false;
		return;
	}
	vis[x]=col;
	for(auto v:G[x]) {
		dfs(v,3-col);
	}
}
int main() {
	int n,m;
	scanf("%d%d", &n,&m);
	for(int i = 0; i < m; ++i) {
		int x,y;
		scanf("%d%d", &x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
		data[i]={x,y};
	}
	int u=0,v=0;
	for(int i = 1; i <= n; ++i) {
		if(G[i].size()) ++u;
		else ++v;
	}
	iota(fa,fa+n*2+1,0);
	int blk1=u*2;
	for(int i = 0; i < m; ++i) {
		int x=data[i].first,y=data[i].second;
		join(x,y+n,blk1);
		join(x+n,y,blk1);
	}
	int blk2=blk1;
	for(int i = 0; i < m; ++i) {
		int x=data[i].first,y=data[i].second;
		join(x,y,blk2);
	}
	ll ans=0;
	for(int i = 1; i <= n; ++i) {
		if(!G[i].size() || vis[i]) continue;
		flag=true;
		dfs(i,1);
		if(flag) ans+=blk1;
		else ans+=blk2;
	}
	ans+=((ll)v*n+(ll)u*v);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 11392
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main(void) {
    ll N, K;
    cin >> N >> K;

    vector<ll> cnt(N + 2);
    cnt[1] = N + 1;
    ll upper = 0, lower = 0;
    for (ll i = 1; i <= N+1; i++) {
        upper += (N - i + 1);
        upper %= DIV;
        lower += (i-1);
        lower %= DIV;
        cnt[i] = upper - lower + 1;
        if (cnt[i] < 0)
            cnt[i] += DIV;
        cnt[i] %= DIV;

    }

    ll ans = 0;
    for (int i = K; i <= N + 1; i++) {
        ans += cnt[i];
        ans %= DIV;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4844
def main():
    import sys
    input = sys.stdin.buffer.readline
    W, H, N = (int(i) for i in input().split())
    XYA = [[int(i) for i in input().split()] for j in range(N)]
    seen = [[True]*W for _ in range(H)]
    for x, y, a in XYA:
        if a == 1:
            for h in range(H):
                for w in range(x):
                    seen[h][w] = False
        elif a == 2:
            for h in range(H):
                for w in range(x, W):
                    seen[h][w] = False
        elif a == 3:
            for h in range(y):
                for w in range(W):
                    seen[h][w] = False
        elif a == 4:
            for h in range(y, H):
                for w in range(W):
                    seen[h][w] = False
    ans = 0
    for h in range(H):
        for w in range(W):
            if seen[h][w]:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40688
from collections import deque

n, q = map(int, input().split())
p = deque()
for i in range(n):
    name, t = input().split()
    time = int(t)
    p.append((name, time))
elapsed = 0
while len(p) > 0:
    name, time = p.popleft()
    elapsed += min(q, time)
    if time > q:
        p.append((name, time - q))
    else:
        print(name, elapsed)



Measured memory_bytes: 12528
s = str(input())
l = len(s)
s = list(s)
for i in range (l):
    if 97 <= ord(s[i]) <= 122:
        s[i] = chr(ord(s[i]) - 32)
    elif 65 <= ord(s[i]) <= 90:
        s[i] = chr(ord(s[i]) + 32)
s = "".join(s)
print(s)


Measured memory_bytes: 5572
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 100000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long
/* define/include */

int main(){
  //まっぷ　に　つっこんで　えい！ｗ
  set<int> se;
  int N;
  cin >> N;
  LOOP(i,N){
    int t;
    cin >> t;
    if(se.count(t)){
      se.erase(t);
    }else{
      se.insert(t);
    }
  }
  cout << se.size();
}


Measured memory_bytes: 4864
#include<stdio.h>

int main(){
	
	int i;
	int ii;
	
	for (i = 1 ; i < 10 ; i++)
	{
		
		for (ii = 1 ; ii < 10 ; ii++)
		{
		
		printf("%dx%d=%d\n", i , ii , i * ii);
		
		}
		
	}
	
    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int x;
    cin >> x;

    if(x < 1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,m;ll l;cin>>n>>m>>l;
    vvll d(n+1,vll(n+1,INF));
    vin a(m),b(m);vll c(m);
    rep(i,m){
        cin>>a[i]>>b[i]>>c[i];
        d[a[i]][b[i]]=c[i];
        d[b[i]][a[i]]=c[i];
    }
    rep(i,n+1)d[i][i]=(ll)0;
    rep2(k,1,n+1)rep2(i,1,n+1)rep2(j,1,n+1)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    vvin oil(n+1,vin(n+1,inf));
    rep2(i,1,n+1)rep2(j,i+1,n+1){
        if(d[i][j]<=l){
            oil[i][j]=1;
            oil[j][i]=1;
        }
        oil[i][i]=0;
    }
    rep2(k,1,n+1)rep2(i,1,n+1)rep2(j,1,n+1)oil[i][j]=min(oil[i][j],oil[i][k]+oil[k][j]);
    int q,s,t;cin>>q;
    vin ans(q);
    rep(i,q){
        cin>>s>>t;
        ans[i]=(oil[s][t]!=inf)?oil[s][t]-1:-1;
    }
    rep(i,q)cout<<ans[i]<<endl;
}

Measured memory_bytes: 5324
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class B
{
	public static void Main()
	{
		int N = Int32.Parse(Console.ReadLine());
		List<int> a = new List<int>(N);
		string[] args = Console.ReadLine().Split(' ');
		for(int i = 0; i < N; i++)
			a.Add(Int32.Parse(args[i]));
		a.Sort((x,y) => y - x);

		int Alice = 0;
		for(int i = 0; i < N; i+=2)
			Alice += a[i];

		int Bob = 0;
		for(int i = 1; i < N; i+=2)
			Bob += a[i];

		Console.WriteLine(Alice - Bob);
	}	
}





Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
using namespace std;

int main()
{
	int n;
	string str;

	cin >> n;

	while (n--)
	{
		cin >> str;

		int Min = 0, Max = 0;

		sort(str.begin(), str.end());
		for (int i = 0; i < 8; i++) Max += pow(10, i) * (str[i] - '0');

		sort(str.begin(), str.end(), greater<int>());
		for (int i = 0; i < 8; i++) Min += pow(10, i) * (str[i] - '0');

		cout << Max - Min << endl;
	}

	return 0;
}

Measured memory_bytes: 1264
using System;
using System.Linq;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var allcards = new int[52];
            for (int i = 0; i < allcards.Length; i++)
            {
                allcards[i] = i + 1;
            }

            var num = int.Parse(Console.ReadLine());
            var findingcards = new int[num];
            for (int i = 0; i < num; i++)
            {
                var inputs = Console.ReadLine().Split(' ');
                findingcards[i] = ChangeStringToCard(inputs[0], inputs[1]);
            }

            Array.Sort(findingcards);
            var missingCards = allcards.Except(findingcards);
            foreach (var item in missingCards)
            {
                Console.WriteLine(ChangeCardToString(item));
            }
        }
        public static int ChangeStringToCard(string suit, string rank)
        {
            switch (suit)
            {
                case "S":
                    return int.Parse(rank);
                case "H":
                    return int.Parse(rank) + 13;
                case "C":
                    return int.Parse(rank) + 13*2;
                case "D":
                    return int.Parse(rank) + 13*3;
                default:
                    return 0;
            }
        }
        public static string ChangeCardToString(int card)
        {
            if (card <= 13) return string.Format("S {0}", card);
            else if ((13 < card) && (card <= (13 * 2))) return string.Format("H {0}", card - 13);
            else if ((13 * 2 < card) && (card <= (13 * 3))) return string.Format("C {0}", card - 13 * 2);
            else if ((13 * 3 < card) && (card <= (13 * 4))) return string.Format("D {0}", card - 13 * 3);
            else return null;
        }
    }
}

Measured memory_bytes: 16360
def main():
    num = int(input())
    data = list(map(int, input().split()))
    a = data[0::2]
    b = data[1::2]
    if num % 2 == 0:
        ans = b[::-1] + a
    else:
        ans = a[::-1] + b
    print(' '.join(list(map(str, ans))))




if __name__ == '__main__':
    main()


Measured memory_bytes: 119252
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>

using namespace std;

int min(vector<int> p)
{
  	sort(p.begin(),p.end());
    return p[0];
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h;
    for(int  i = 0 ; i < n ; i++ )
    {
      	int l;
        cin >> l;
      	h.push_back(l);
    }

    vector<int> dp;
    dp.push_back(0);

    for(int i = 1 ; i < n ; i++)
    {
      vector<int> possible;
      int sum;
      int x = 1;
      while((i - x) >= 0 && x <= k)
      {
          int pos = abs(h[i] - h[i-x]) + dp[i-x];
          possible.push_back(pos);
          x += 1;
      }
      sum = min(possible);
      dp.push_back(sum);
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1400
import sys
n = int(input())
A = [int(e)for e in sys.stdin]
cnt = 0
G = [int((2.1**i-1)/1.1)for i in range(18,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')


Measured memory_bytes: 53324
n,k=map(int,input().split())
s=list(input())
if s[k-1]=='A': s[k-1]='a'
elif s[k-1]=='B': s[k-1]='b'
if s[k-1]=='C': s[k-1]='c'
s=''.join(s)
print(s)


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

constexpr int64_t mod = 998244353;

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

    vector<int> d(n);
    for(int i = 0; i < n; i++) cin >> d[i];

    if(d[0] != 0) {
        cout << "0" << endl;
    } else {
        sort(d.begin(), d.end());
        
        int64_t ans = 1;
        vector<int> d_num(d[n - 1] + 1, 0);
        for(int i = 0; i < n; i++) {
            d_num[d[i]]++;
        }

        if(d_num[0] > 1) ans = 0;

        for(int i = 1; i < d[n - 1]; i++) {
            for(int j = 0; j < d_num[i + 1]; j++) {
                ans *= d_num[i];
                ans %= mod;
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
#define int            		long long
#define x              		first
#define y              		second
#define all(aaa)       		(aaa).begin(),(aaa).end()
#define REP(i,sss,eee) 		for(int i=sss;i<=eee;++i)
#define pb             		push_back
#define pii            		pair<int,int>
#define vi             		vector<int>
#define speed          		ios_base::sync_with_stdio(0);cin.tie(0);
#define N              		1000000007
#define inf					1000000000000000000
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
int,
null_type,
less_equal<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;//for multiset use less_equal above

signed main()
{
    int n,k;cin>>n>>k;
    std::vector<int> inp(n),sor;
    for (int i = 0; i < n; ++i)
    {
    	cin>>inp[i];
    }
    sor=inp;
    std::vector<int> forw(n),tot(n);
    sort(sor.begin(),sor.end());
    ordered_set st;
    int ct=n-1;
    int ans=0;
    int fact=((k*(k-1))/2);fact%=N;
    for(auto it=inp.rbegin();it!=inp.rend();++it)
    {
    	forw[ct]=st.order_of_key(*it);
    	tot[ct]=(lower_bound(sor.begin(),sor.end(),*it)-sor.begin());
    	ans+=(forw[ct]*k);ans%=N;
    	ans+=(fact*tot[ct]);ans%=N;
    	--ct;st.insert(*it);
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 384
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	bool h=true;
	rep(i,a+b+1)if(i==a&&s[i]!='-'||i!=a&&!isdigit(s[i]))h=false;
	if(h)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}











Measured memory_bytes: 256
from collections import Counter

n,m = list(map(int, input().split()))
ls = []
for i in range(n):
  a = list(map(int, input().split()))
  del a[0]
  for j in range(len(a)):
    ls.append(a[j])
#print(ls)

c = Counter(ls)
b = [k[0] for k in c.items() if k[1] == n]
#print(b)
print(len(b))

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

const int M = 26;
const int N = 2e5+2;

int pen[2][N];
void update(int *p,int ind,int add) {
   while(ind<N) {
      p[ind]+= add;
      ind += ind&(-ind);
   }
}
int query(int *p,int ind) {
   int ret = 0;
   while(ind>0) {
      ret += p[ind];
      ind = ind&(ind-1);
   }
   return ret;
}
vector<int> pos[M];
int l[M],r[M];
void solve() {
   string s;
   cin>>s;
   for(int i=0;i<s.size();++i) {
      int c = s[i]-'a';
      pos[c].push_back(i+1);
   }
   int numOfOdd = 0;
   for(int i=0;i<M;++i) {
      l[i] = 0;
      r[i] = pos[i].size()-1;
      if(pos[i].size()&1) {
         ++numOfOdd;
      }
   }
   if(numOfOdd>1) {
      printf("-1\n");
      return;
   }
   int cc = s.size()/2;
   int tmp = 0;
   ll ret = 0;
   while(cc--) {
      int al = -1, minSwapNum = 1e9;
      for(int i=0;i<M;++i) {
         if(l[i]<r[i]) {
            int leftPos = pos[i][l[i]];
            int rightPos = pos[i][r[i]];
            int tmpSwap = leftPos -1 - query(pen[0],leftPos) + (s.size() - rightPos - (tmp - query(pen[1],rightPos)) );
            if(tmpSwap<minSwapNum) {
               al = i;
               minSwapNum = tmpSwap;
            }
         }
      }
      assert(al!=-1);
      int leftPos = pos[al][l[al]];
      int rightPos = pos[al][r[al]];
      ++l[al];
      --r[al];

      update(pen[0],leftPos,1);
      update(pen[0],rightPos,1);
      update(pen[1],leftPos,1);
      update(pen[1],rightPos,1);
      tmp += 2;
      ret += minSwapNum;
   }
   printf("%lld\n", ret);
}

int main() {
   //freopen("input.txt","r",stdin);
   solve();
}

Measured memory_bytes: 3068
n=int(input())
a,b=map(int,input().split())
p=list(map(int,input().split()))
one=0
two=0
three=0
for i in range(n):
    if p[i]<=a:
        one+=1
    elif b+1>p[i]>a:
        two+=1
    else:
        three+=1
print(min(one,two,three))


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

using namespace std;

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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

    int n, m, a, b;
    cin>>n>>m;
    vi estados;
    vi cant;
    estados.assign(n,0);
    cant.assign(n,1);
    estados[0] = 1;

    for (int i = 0; i < m; ++i) {
        cin>>a>>b;
        a--; b--;
        if (estados[a]) { estados[b] = 1; }
        cant[a]--;
        cant[b]++;
        if(!cant[a]) { estados[a] = 0; }
    }

    int sol = 0;
    for (int i = 0; i < n; ++i) { sol += estados[i]; }
    cout<<sol<<endl;

    return 0;
}


Measured memory_bytes: 1024