akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;


public class Main {

	static int n;
	static Scanner sc = new Scanner(System.in);
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		while(read())	solve();
	}
	
	public static boolean read() {
		if(sc.hasNext()) {
			n = sc.nextInt();
			return true;
		} else {
			return false;
		}
	}
	public static void solve() {
		int ans = 0;
		for(int a=0 ; a<10 ; a++) {
			for(int b=0 ; b<10 ; b++) {
				for(int c=0 ; c<10 ; c++) {
					for(int d=0 ; d<10 ; d++) {
						if(a+b+c+d==n) ans++;
					}
				}
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 12000
#D
S = list(str(input()))
N = len(S)

U = []
for i in range(N):
    U.append(int(S[N-i-1]))


DP = [-1]*(N+1)
DP[0] = 0
now = 0
pnow = 1
for i,u in enumerate(U):
    pnow*=10
    pnow%=2019
    now+=int(u)*pnow
    now%=2019
    DP[i+1] = now
    
#print(DP)
tyo = [0]*2019
for dp in DP:
    tyo[dp]+=1

ans = 0
for t in tyo:
    ans+=(t*(t-1))//2
    
print(ans)




Measured memory_bytes: 19640
#include <bits/stdc++.h>
#define Ganesha ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define lli long long int
using namespace std;
int main(){
    Ganesha
    lli n,m;
    cin>>n>>m;
    if(n>=1&&n<=9&&m>=1&&m<=9) return cout<<n*m,0;
    cout<<-1;
    return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <string>
#include <vector>
#include <cmath>
#include <tuple>
#include <queue>
#include <map>
using namespace std;
// ----------------------------------------------- Union FInd Query -------------------------------------

int group[1000009], num[1000009], size_, cnts; vector<int>GR[1000009];
void init() {
	for (int i = 0; i < size_; i++) { group[i] = i; num[i] = i; GR[i].push_back(i); }
	cnts = size_;
}
void unite(int p1, int p2) {
	int z1 = group[p1], z2 = group[p2]; if (z1 == z2)return;
	if (GR[z1].size() < GR[z2].size())swap(z1, z2);
	for (int i = 0; i < GR[z2].size(); i++) {
		GR[z1].push_back(GR[z2][i]); group[GR[z2][i]] = z1;
	}
	GR[z2].clear(); num[z1] = cnts; cnts++;
}
int Size(int p1) {
	return GR[group[p1]].size();
}
bool same(int p1, int p2) {
	if (group[p1] == group[p2])return true;
	return false;
}

// ----------------------------------------------- Main ------------------------------------------------

long long n, a[100009], b[100009], w[100009], p[300009];
vector<tuple<int, int, int>>V; vector<int>G, x[300009];

int main() {
	cin >> n;
	for (int i = 1; i <= n - 1; i++) {
		cin >> a[i] >> b[i] >> w[i]; V.push_back(make_tuple(w[i], a[i], b[i]));
	}
	sort(V.begin(), V.end(), greater<tuple<int, int, int>>());
	size_ = n + 1; init();
	for (int i = 0; i < V.size(); i++) {
		long long a1 = get<1>(V[i]), a2 = get<2>(V[i]), a3 = get<0>(V[i]);
		long long C1 = Size(a1), C2 = Size(a2);
		long long D1 = num[group[a1]], D2 = num[group[a2]];
		unite(a1, a2); x[cnts - 1].push_back(D1); x[cnts - 1].push_back(D2);
		p[D1] += a3*C2; p[D2] += a3*C1;
	}
	for (int i = cnts; i >= 0; i--) {
		for (int j = 0; j < x[i].size(); j++)p[x[i][j]] += p[i];
	}
	for (int i = 1; i <= n; i++) {
		cout << p[i] << endl;
	}
	return 0;
}

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

#define ll long long 
#define all(x) (x).begin(),(x).end()
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define f(i,x,z) for(ll i=x;i<z;i++)
#define debug(x) cout<<'DEBUG------> '<<x<<endl
#define srt(v) sort(v.begin(), v.end())
#define clr(x) memset(x, 0, sizeof(x)) 
#define mi map<int,int>
#define mod 1000000007
//  for (auto &a : A)
//cin >> a;
//for (auto m : map) {

int main()
{
//   freopen('input.txt', 'r', stdin);
//   freopen('output.txt', 'w', stdout);
    ios::sync_with_stdio(0);// Input and output clearance
    cin.tie(0);
    ll a,co=0;
    cin>>a;
    f(i,1,a)
    {
        
            co+=((a-1)/i);
        
    }
    cout<<co;
   return 0;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e - a <= k){
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
}


Measured memory_bytes: 256
import Control.Applicative

main :: IO ()
main = do
    ns <- map read . lines <$> getContents
    mapM_ print $ solve ns

solve :: [Int] -> [Int]
solve [] = []
solve (n':ns) = (solve' n'):(solve ns)
    where
        solve' :: Int -> Int
        solve' n = length $ takeWhile (\x -> x <= n) primes

primes = 2:3:[x|i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x]
    where
        isPrime n = null [i|i<-takeWhile (\x -> x*x <= n) primes, rem n i == 0]

Measured memory_bytes: 10060
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Restrictive Filesystem
// 2013/05/13
public class Main{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

	int n;
	String[] ss;

	void run(){
		try{
			for(;;){
				n=Integer.parseInt(br.readLine());
				if(n==0){
					break;
				}
				ss=new String[n];
				for(int i=0; i<n; i++){
					ss[i]=br.readLine();
				}
				solve();
			}
		}catch(Exception e){}
	}

	void solve(){
		ArrayList<Mem> list=new ArrayList<Mem>();
		boolean[] removed=new boolean[10010];
		int[] ids=new int[10010];
		HashMap<Integer, Integer> rev=new HashMap<Integer, Integer>();

		list.add(new Mem(0, (int)1e9+10));
		removed[0]=true;
		ids[0]=-1;
		rev.put(-1, 0);

		StringBuilder sb=new StringBuilder();
		for(String s : ss){
			String[] ss=s.split(" ");
			if(ss[0].equals("W")){
				int id=Integer.parseInt(ss[1]), len=Integer.parseInt(ss[2]);
				ids[rev.size()+1]=id;
				rev.put(id, rev.size()+1);
				id=rev.get(id);
				for(int i=0, size=list.size(); i<size; i++){
					Mem m=list.get(i);
					if(removed[m.id]){
						if(len>=m.len){
							m.id=id;
							len-=m.len;
						}else if(len<m.len){
							int right=m.len-len;
							m.id=id;
							m.len=len;
							list.add(i+1, new Mem(0, right));
							len=0;
						}
					}
					if(len==0){
						break;
					}
				}
			}else if(ss[0].equals("D")){
				int id=Integer.parseInt(ss[1]);
				removed[rev.get(id)]=true;
			}else{
				int at=Integer.parseInt(ss[1]);
				int tot=0;
				for(int i=0, size=list.size(); i<size; i++){
					Mem m=list.get(i);
					if(tot+m.len>at){
						int id=m.id;
						sb.append(removed[id]?-1:ids[id]).append('\n');
						break;
					}
					tot+=m.len;
				}
			}
		}
		println(sb.toString());
	}

	class Mem{
		int id, len;

		Mem(int id, int len){
			this.id=id;
			this.len=len;
		}
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 59728
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define INF (2e9)
const int maxv=100000+10;
const int maxe=500000+10;
int V,E,S;
struct Edge{int from, to,cost;};
int d[maxv];
Edge es[maxe];
 
void bellman_ford(int s)
{
    for(int i=0;i<V;i++) d[i]=INF;
    bool bUpdate=true;
    d[s]=0;
    while(true)
    {
        bUpdate=false;
        for(int i=0;i<E;i++)
        {
            Edge &e=es[i];
            if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost)
            {
                d[e.to]=d[e.from]+e.cost;
                bUpdate=true;
            }
        }
        if(!bUpdate) break;
    }
    for(int i=0;i<V;i++)
    {
        if(d[i]!=INF)  printf("%d\n",d[i]);
        else printf("INF\n");
 
 
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    scanf("%d%d%d",&V,&E,&S);
    int u,v,dd;
    for(int i=0;i<E;i++)
    {
        scanf("%d%d%d",&u,&v,&dd);
        es[i].from=u;
        es[i].to=v;
        es[i].cost=dd;
    }
    bellman_ford(S);
 
    return 0;
}


Measured memory_bytes: 9272
N = int(input())
strlist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']


ans = [['a']]
for i in range(1, N):
  ans.append([])
  for s in ans[i-1]:
    n = len(set(s))
    for j in range(n+1):
      ans[i].append(s+strlist[j])

ans.sort()
print(*ans[-1], sep='\n')

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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n,x,t;
    cin >> n >> x >> t;
    int ans = n/x+((n%x)>0);
    print(ans*t);    
    return 0;
}

Measured memory_bytes: 3596
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

char o[55], e[55];
int main()
{
  scanf("%s%s", o, e);
  for (int i = 0; i < MAX(strlen(o), strlen(e)); i++)
  {
    putchar(o[i]);
    if (e[i] == 0)
      break;
    putchar(e[i]);
  }
  puts("");
  return 0;
}

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

using namespace std;

int main(){
  int N;
  long long int K;
  cin >> N >> K;
  vector<int> A(N);
  vector<int> already(N,-1);

  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    A[i]=a;
  }

  //今いる街
  int current=0;
  //ジャンプした回数
  int count=0;
  //通ったことのある街に再度訪れるまで
  while(already[current]==-1){
    //何回ジャンプしてたどり着いたか保存
    already[current]=count;
    //街を移動
    current=A[current]-1;
    count++;
  }
  // cout << count-already[current] << endl;
  int shuuki = count-already[current];
  long long int nokori = K;
  if(K<already[current]){
    current = 0;
  }else{
    nokori = (K-already[current])%shuuki;
  }
  for(long long int i=0;i<nokori;i++){
    current=A[current]-1;
  }

  cout << current+1 << endl;
}


Measured memory_bytes: 4808
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	static int n,m;
	static int a[200010],x[200010],y[200010];
	scanf("%d%d",&n,&m);
	rep1(i,n)scanf("%d",&a[i]);
	rep1(i,m)scanf("%d%d",&x[i],&y[i]);
	
	static int cnt[200010] = {};
	rep1(i,n){
		cnt[a[i]] ++;
	}
	static int d[400010] = {};
	rep1(i,n){
		d[i+1-cnt[i]+n] ++;
		d[i+1+n] --;
	}
	rep1(i,400000)d[i] += d[i-1];
	
	//rep1(i,n)cout << d[i+n] << " ";
	//cout << endl;
	
	int ret = 0;
	rep1(i,n)if(d[i+n] == 0)ret ++;
	//cout << ret << endl;
	rep1(i,m){
		cnt[a[x[i]]] --;
		d[a[x[i]]-cnt[a[x[i]]]+n] --;
		if(d[a[x[i]]-cnt[a[x[i]]]+n] == 0 && 1 <= a[x[i]]-cnt[a[x[i]]] && a[x[i]]-cnt[a[x[i]]] <= n)ret ++;
		cnt[y[i]] ++;
		d[y[i]+1-cnt[y[i]]+n] ++;
		if(d[y[i]+1-cnt[y[i]]+n] == 1 && 1 <= y[i]+1-cnt[y[i]] && y[i]+1-cnt[y[i]] <= n)ret --;
		a[x[i]] = y[i];
	//rep1(j,n)cout << d[j+n] << " ";
	//cout << endl;
		printf("%d\n",ret);
	}
}



Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main(){
    string s;
    cin>>s;
    int c[26]={};
    bool ans=true;
    for(int i=0;i<s.size();i++)c[s[i]-'a']++;
    for(int i=0;i<26;i++){
        if(c[i]>1)ans=false;
    }
    if(ans==true)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    return 0;
}



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

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

    //百の位
    //((N % 1000) - (N % 100)) / 100
    //十の位
    //((N % 100 ) - ( N % 10)) / 10

  if (((N % 1000) - (N % 100)) / 100 == ((N % 100 ) - ( N % 10)) / 10) {
      if ( ((N % 100 ) - ( N % 10)) / 10 == N / 1000) {
          cout << "Yes" << endl;
      }
      else if( ((N % 100 ) - ( N % 10)) / 10 == N % 10) {
          cout << "Yes" << endl;
      }
      else {
          cout << "No" << endl;
      }
    }

  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
int a[100000];
map<int, int> cnt;
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	LL sum = 0;
	for (auto p : cnt) {
		if (p.first <= p.second) sum += p.second - p.first;
		else sum += p.second;
	}
	cout << sum << endl;
}

Measured memory_bytes: 5120
A = [int(x) for x in input().split()]

A.sort()
reg = 0
diff_1 = (A[2] - A[0]) // 2
reg += diff_1
diff_2 = (A[2] - A[1]) // 2
reg += diff_2
A[0] += 2 * diff_1
A[1] += 2 * diff_2

A.sort()
if A[0]==A[1]==A[2]:
    print(reg)
elif A[0]==A[1]:
    print(reg+1)
else:
    print(reg+2)

Measured memory_bytes: 3064
# B - Ordinary Number

N = int(input())
P = [int(p) for p in input().split()]

cnt = 0
for i in range(1, N - 1):
    if P[i - 1] < P[i] < P[i + 1] or P[i + 1] < P[i] < P[i - 1]:
        cnt += 1

print(cnt)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main (void)
{
    int group[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};

    int x, y;
    cin >> x >> y;

    cout << ((group[x] == group[y])? "Yes": "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    int N;
    int a[105];

    cin >> N;
    for (int j = 0; j < N; ++j) {
        cin >> a[j];
    }

    int ret[205];
    fill(ret, ret + 205, 0);

    for (int j = 0; j <= 200; ++j) {
      for (int k = 0; k < N; ++k) {
        int offset = a[k] - (j - 100);
        ret[j] += offset * offset;
      }
    }

    int ans = 100000000;
    for (int j = 0; j <= 200; ++j) {
        ans = min(ans, ret[j]);
    }

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


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

int main() {
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  
  int i = 0;
  int p = 1;
  
  while (i < N) {
    if (a[i] == p) {p++;}
    i++;
  }
  if (p == 1) {cout << -1 << endl;}
  else {cout << N - p + 1 << endl;}
}

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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define INF 1e16
#define mod 1e9+7


int main() {
  ll r,d,a;
  cin>>r>>d>>a;
  ll ans=a;
  FOR(i,0,10){
    ans=ans*r-d;
    co(ans);
  }
}
  

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll M, D;
    cin >> M >> D;
    ll res = 0;

    for(int i=1;i<=M;i++){
    	for(int j=1;j<=D;j++){
    		ll d1 = j%10;
    		ll d2 = j/10;
    		if(d1 >= 2 && d2 >= 2 && d1 * d2 == i) res++;
    	}
    }
    cout << res <<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef pair<pair<int,int>,bool> piib;

const ll N=1001;
const int MOD=1e9+7;

string s,t;

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

	//freopen("mosalah.in","r",stdin);

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

	cin >> s >> t;
	int ans = 0;

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

	return 0;
}


Measured memory_bytes: 3808
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
import Data.Array.IArray
--import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
dictCompare :: [a -> a -> Ordering] -> a -> a -> Ordering
dictCompare [] _ _ = EQ
dictCompare (f:fs) x y = let c = f x y in if c==EQ then dictCompare fs x y else c
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
-- end of templete

f [] = []
f (x:xs) = f' 1 x xs
f' n _ [] = [n]
f' n x ya@(y:ys)
  | x==y = n : f ya
  | otherwise = f' (n+1) y ys

g (x:xs@(y:z:zs)) = max (x+y+z) $ g xs
g _ = 0

main = do
    n <- getInt
    s <- getInts
    let seqs = f s
    print $ if length seqs <= 3 then n else g seqs


Measured memory_bytes: 15304
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int n ,d,x;
	cin >> n >> d >> x;
	vector<int > a(n);
	cinf(n,a);
	int cnt=0;
	for(int i=0;i<n;i++){
		for(int j=1;j<=d;j+=a[i]){
			cnt ++;
		}
	}
	cout << x+cnt << endl;


}

Measured memory_bytes: 256
#define P(x) cout << #x " = " << x << endl
#define PP(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define PPP(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl

#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;
int n;

int main()
{
    cin >> n;
    cout << n * (n - 1) / 2 - n / 2 << endl;
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            if (i + j == n / 2 * 2 + 1) continue;
            cout << i << " " << j << endl;
        }
    }
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

struct UnionFind {
  // 要素に対応する値は自分の根。根は要素数の-1倍したものを代入する。
  // 根ならそのグループの要素数(負)が、子であれば親の番号が入る。初期値-1。
  vector<int> uni;
  UnionFind(){
    uni = vector<int>(100100, -1);
  }

  // 頂点aの所属するグループを調べる。
  int root(int a)
  {
    // uni[a]が負の値なら親はa自身
    if (uni[a] < 0) return a;
    // 正の値であれば、親ルートを調べ戻り値で根に直接つなぐ。
    else {
      uni[a] = root(uni[a]);
      return uni[a];
      // return uni[a] = root(uni[a]);
    }
  }

  // 頂点aとbをつなぐ、もともと同じグループの場合falseを返す。
  bool connect(int a, int b)
  {
    a = root(a);
    b = root(b);
    if (a == b) return false;

    // aを大きなグループにしたいので、逆であれば入れ替える。
    if (uni[a] > uni[b])
    {
      int hoge = a;
      a = b;
      b = hoge;
    }

    //aとbを結合し、bをaの親とする。
    uni[a] += uni[b];
    uni[b] = a;
    return true;
  }

  //  頂点a, bが同じグループか
  bool isConnect(int a, int b)
  {
    return root(a) == root(b);
  }

  // 頂点aを含むグループの頂点数を調べる
  int size(int a)
  {
    return -uni[root(a)];
  }

};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  vector<int> y(m);
  vector<int> z(m);
  UnionFind uni;
  for (int i = 0; i < m; i++) {
    int tmp;
    int x, y;
    cin >> x >> y >> tmp;
    uni.connect(x, y);
  }
  set<int> s;

  for (int i = 1; i <= n; i++) {
    s.insert(uni.root(i));
  }

  cout << s.size() << endl;

}


Measured memory_bytes: 6528
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 3223372036854775807
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
//#define leng length()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<Pll,ll> a,pair<Pll,ll> b){
        return a.fi.se>b.fi.se;
}
ll cmp2(pair<Pll,ll> a,pair<Pll,ll> b){
        return a.se<b.se;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //------------------------------
    ll n;cin>>n;
    for(ll h=1;h<=3500;h++){
        for(ll w=1;w<=3500;w++){
            ll up  = n*h*w;
            ll down = 4*h*w-n*h-n*w;
            if(down<=0)continue;
            if(up%down!=0)continue;
            cout<<h<<" "<<w<<" "<<up/down<<endl;
            return 0;
        }
    }
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //------------------------------- 
    return 0;
}
//----------------------------------------------------------------------


















































Measured memory_bytes: 3640
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int a, b, c;

	cin >> a >> b >> c;

	//cout << max(c, (b / a > c ? c: b/a)) << endl;
	cout << min(c,  b / a) << endl;


	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	int H,W;
	cin >> H >> W;
	string S[52];
	string Sc[52];
	vector<int> a={ 0, 1, 0,-1,-1, 1, 1,-1};//x
	vector<int> b={-1, 0, 1, 0,-1, 1,-1, 1};//y
	int cnt=0;
	REP(i,H){
		cin >> S[i];
		Sc[i]=S[i];
	}
	REP(i,H)REP(j,W){//S[i][j]
		cnt=0;
		if(S[i][j]=='.'){
			REP(k,8) if(S[i+a[k]][j+b[k]]=='#') cnt++;
			Sc[i][j] = cnt + '0';
		}
	}
	REP(i,H) cout << Sc[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    if (A == B && A != C) {
        cout << "Yes" << endl;
    } else if (B == C && B != A) {
        cout << "Yes" << endl;
    } else if (C == A && C != B) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 888
<?php

while (true) {
    fscanf(STDIN, '%f %f %f %f %f %f %f %f', $xa1, $ya1, $xa2, $ya2, $xb1, $yb1, $xb2, $yb2);
    if (feof(STDIN)) {
        break;
    }
    if ($xb2 < $xa1 || $xb1 > $xa2 || $yb2 < $ya1 || $yb1 > $ya2) {
        echo 'NO';
    } else {
        echo 'YES';
    }
    echo PHP_EOL;
}

Measured memory_bytes: 6564
S = input()


def judge():
    L = len(S)
    keyence = 'keyence'
    if S[0] != 'k':
        if S[-7:] != 'keyence':
            return False
        else:
            return True
    else:
        for i in range(8):
            if S[0:i] == keyence[0:i] and S[L-(7-i):L] == keyence[i:7]:
                return True
        return False


def main():
    if judge():
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define SZ(x) (long long)x.size()
#define endl '\n'
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define tc                                                                     \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
bool comp(pair<int, int> v, int val) { return v.ff < val; }
inline int read() {
  int t = 0;
  char c;
  while ((c = getchar_unlocked()) != '\n' && c != ' ' && c != EOF) {
    t = t * 10 + c - 48;
  }
  return t;
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
bool checkValidity(int a, int b, int c) {
  if (a + b <= c || a + c <= b || b + c <= a)
    return false;
  else
    return true;
}

int32_t main() {
  FAST;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("output.txt", "w", stderr);
#endif
  int n = read();
  vector<int> v(n);
  int ans = 0;
  REP(i, 0, n) v[i] = read();
  REP(i, 0, n) {
    REP(j, i + 1, n) {
      REP(k, j + 1, n) {
        if (v[i] == v[j] || v[j] == v[k] || v[k] == v[i])
          continue;
        if (checkValidity(v[i], v[j], v[k])) {
          ans++;
        }
      }
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3664
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;
 
const long long MOD = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;
 
#define itn int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int p,q,r,s,t; //2,4,14,24,74
void solve(int n){
   //75 = 5*5*3
   map<int,int> m;
   for(int j = 1;j <= n;j++){
      int k = j;
      for(int i = 2;i * i <= j;i++){
        while(k % i == 0){
            ++m[i];
            k /= i;
        }
      }
      if(k != 1) m[k]++;
   }
   
   
   for(auto i : m){
      //cout << i.first << " " << i.second << endl;
      int k = i.second;
      if(k >= 74) t++;
      if(k >= 24) s++;
      if(k >= 14) r++;
      if(k >= 4) q++;
      if(k >= 2) p++;
   }
   //cout << t << " " << s << " " << r << " " << q << " " << p << endl; 
   int ans = 0;
   ans += t;
   ans += s*(p - 1);
   ans += r*(q - 1);
   ans += q*(q - 1)*(p - 2)/2;
   cout << ans << endl;
}
int main(void){
   int n;cin >> n;
   solve(n);
   return 0;
}

Measured memory_bytes: 256
// AOJ CGL_4_B Diameter of a Convex Polygon
// 2018.5.3 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct { double x, y; } PP;
typedef struct { PP s, e; } SEG, LINE;

#define INF			1e8
#define EPS			1e-8
#define EQ(a,b)		(fabs((a)-(b))<EPS)
#define PPeQ(a,b)	(EQ(a.x,b.x)&&EQ(a.y,b.y))

int dcmp(double x) { if (fabs(x) < EPS) return 0; return x <= 0 ? -1 : 1; }
PP vset(double x, double y) { PP r; r.x = x, r.y = y; return r; }
PP vadd(PP p1, PP p2) { PP r; r.x = p1.x + p2.x, r.y = p1.y + p2.y; return r; }
PP vsub(PP p1, PP p2) { PP r; r.x = p1.x - p2.x, r.y = p1.y - p2.y; return r; }
PP vsmul(PP p, double k) { PP r; r.x = p.x * k, r.y = p.y * k; return r; }
PP vmul(PP p1, PP p2) { PP r;
	r.x = p1.x * p2.x - p1.y * p2.y, r.y = p1.x * p2.y + p1.y * p2.x; return r; }
double vabs(PP a) { return hypot(a.x, a.y); }
double dist(PP p1, PP p2) {	return hypot(p1.x-p2.x, p1.y-p2.y); };
double cross(PP a, PP b) { return a.x * b.y - a.y * b.x; }
double dot(PP a, PP b) { return a.x * b.x + a.y * b.y; }
double norm(PP a) { return a.x * a.x + a.y * a.y; }

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

double dbl()
{
	int minus = 0;
	double x, y;
	int n = 0, c = gc();
	if (c == '-') minus = 1, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');

	if (c == '.') {
		x = 0;
		y = 1, c = gc();
		do y *= 0.1, x += y * (c & 0xf), c = gc(); while (c >= '0');
		x += n;
	} else x = n;
	if (minus) x = -x;
	return x;
}

int cmp(PP *a, PP *b) {
	if (EQ(a->y, b->y)) return dcmp(a->x - b->x);
	return                     dcmp(a->y - b->y);
}

int convex_hull(int n, PP *ps, PP *po)
{
	int i, k, j = 0;

	qsort(ps, n, sizeof(PP), cmp);
	for (i = 0; i < n; i++) {
		while (j > 1 && cross(vsub(po[j-1], po[j-2]), vsub(ps[i], po[j-1])) <= 0) j--;
		po[j++] = ps[i];
	}
	k = j;
	for (i = n - 2; i >= 0; i--) {
		while (j > k && cross(vsub(po[j-1], po[j-2]), vsub(ps[i], po[j-1])) <= 0) j--;
		po[j++] = ps[i];
	}
	return j-1;
}

PP pp[80005], poly[80005];

int main()
{
	int n, i, j;
	double ans, t;

	n = in();
	for (i = 0; i < n; i++) pp[i].x = dbl(), pp[i].y = dbl();
	n = convex_hull(n, pp, poly);
	ans = 0;
	for (i = 0; i < n; i++) {
		for (j = i+1; j < n; j++) {
			t = dist(poly[i], poly[j]);
			if (t > ans) ans = t;
		}
	}
	printf("%.10lf\n", ans);
	return 0;
}



Measured memory_bytes: 3628
N = int(input())
L = list(map(int,input().split()))

L.sort()

import bisect
ans = 0

for i in range(N-2):
    for j in range(i+1,N-1):
        a = L[i] 
        b = L[j] 
        
        insert_index = bisect.bisect_left(L,a+b)
        #print(insert_index,a,b,a+b)
        
        if i < insert_index:
            ans += insert_index - j - 1
            #print(i,j,insert_index)
        
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = gcd(a[0], a[1]);
  for (int i = 2; i < n; i++) {
    ans = gcd(ans, a[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 

#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

const int N =1e3;

int mod= 1e9+7;
int dx[4]={0,0,+1,-1};
int dy[4]={+1,-1,0,0};



void solve(){
 int n,k;
 cin>>n>>k;
 vi v(n,0),dp(n,1e9);

 rep(i,0,n)
	  cin>>v[i];

 dp[0]=0;
 rep(i,1,n){
	 if(i<=k){
		dp[i]=abs(v[i]-v[0]);		
	 }
		  
   for(int j=i;j<=i+k && j<n;j++){
	 dp[j]=min(dp[i]+abs(v[i]-v[j]),dp[j]);
   }
 }

 cout<<dp[n-1]<<endl; 

// rep(i,0,n)
//	 cout<<dp[i]<<" ";
}



int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
		solve();


	return 0;	   
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
long a[501][501];
long b[250001][5];

int main(){long H, W;
cin >> H >> W;
erep(i, H){
    erep(j, W) cin >> a[i][j]; 
}
bool odd = true; bool hold = false; int k = 1;
long tmp;
erep(j, W){
    if(odd == true){
        erep(i, H){
            if(hold == false){
                if(a[i][j] % 2 == 1){
                    b[k][1] = i;
                    b[k][2] = j;
                    hold = true;
        tmp = k;
                }
            }
            else{//hold = true
                if(a[i][j] % 2 == 1){
                    b[k][3] = i;
                    b[k][4] = j;
                    k++;
                    hold = false;
                }
                else{
                    b[k][3] = i;
                    b[k][4] = j;
                    k++;
                    b[k][1] = i;
                    b[k][2] = j;
                    
                }
            }
        }
        odd = false;
    }
    else{
        for(long i = H; i >= 1; i--){
            if(hold == false){
                if(a[i][j] % 2 == 1){
                    b[k][1] = i;
                    b[k][2] = j;
                    hold = true;
                    tmp = k;
                }
            }
            else{
                if(a[i][j] % 2 == 1){
                    b[k][3] = i;
                    b[k][4] = j;
                    k++;
                    hold = false;
                }
                                else{
                    b[k][3] = i;
                    b[k][4] = j;
                    k++;
                    b[k][1] = i;
                    b[k][2] = j;
                    
                }

            }
        }
        odd = true;
    }
}
if(hold == true) k = tmp;
cout <<  k - 1 << endl;
erep(i, k - 1){
    cout << b[i][1] << ' ' << b[i][2] << ' ' << b[i][3] << ' ' << b[i][4] << endl;
}


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




Measured memory_bytes: 11776
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <utility>
using namespace std;


int main() {
	int K, A, B;
	scanf("%d", &K);
	scanf("%d %d", &A, &B);
	bool flag = false;
	for (int i=A; i <= B; i++) {
		if (i % K == 0) {
			flag = true;
		}
	}
	if (flag) {
		printf("%s\n", "OK");
	} else {
		printf("%s\n", "NG");
	}
	
	return 0;
}

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

int main() {
  int N, L;
  cin >> N >> L;
  
  int apple = 0;
  int sum = 0;
  int taste = 1000;
  
  for (int i = 1; i <= N; i++) {
    sum += L+i-1;
    if (abs(L+i-1) < taste) {
      apple = i;
      taste = abs(L+i-1);
    }
  }
  
  cout << sum - (L+apple-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    int a[6]={0, 1, 2, 3, 4, 5};

    if(x<100){
        cout << 0 << endl;
        return 0;
    }
    if(x%100==0){
        cout << 1 << endl;
        return 0;
    }
    int count = x/100;
    int sita = x-(count*100);

    rep(i, count+1){
        rep(j, count+1-i){
            if(count-i-j < 0) break;
            rep(k, count+1-i-j){
                if(count-i-j-k < 0) break;
                rep(h, count+1-i-j-k){
                    if(count-i-j-k-h < 0) break;
                    rep(l, count+1-i-j-k-h){
                        if(count-i-j-k-h-l < 0) break;
                        if(sita == i+2*j+3*k+4*h+5*l){
                            cout << 1 << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
import collections


if __name__ == "__main__":
    S_num = int(input())
    S = collections.Counter(set(map(lambda x: int(x), input().split())))
    T_num = int(input())
    T = list(map(lambda x: int(x), input().split()))

    print(f"{sum(map(lambda x: S[x], T))}")



Measured memory_bytes: 16548
program main
    implicit none
    integer(8) x
    integer(8) i,j
    integer(8) a,b,a5,b5
    real(8) t
    read(*,*) x

    do i = -1000,1000
        b = i
        b5 = b*b*b*b*b
        t = dble(x + b5)
        t = t**0.2
        a = int(t)
        a5 = a*a*a*a*a
        if(a5-b5 == x) then
            write(*,*) a, b
            exit
        end if
    end do


end program

Measured memory_bytes: 3140
#include<iostream>
using namespace std;
    
int S[10000];
int T[500];
    
int main() {
  int N, Q, sum;
  cin >> N;
  for ( int i = 0; i < N; i++ ) cin >> S[i];
  cin >> Q;
  for ( int i = 0; i < Q; i++ ) cin >> T[i];
    
  sum = 0;
  for ( int i = 0; i < Q; i++ ) {
    for ( int j = 0; j < N; j++ ) {
      if ( S[j] == T[i] ) {
        sum++;
        break;
      }
    }
  }
    
  cout << sum << endl;
  return 0;
}


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

using namespace std;

struct Taste {
    long long hi;
    vector<long long> ds;
    Taste(): hi(0), ds(0) {}
    void add(long long d) {
        ds.push_back(d);
        hi = max(hi, d);
    }
    bool operator<(const Taste& o) const {
        return hi > o.hi;
    }
};

struct TopK {
    int k;
    multiset<long long> xs;
    long long sum;
    TopK(int k): k(k), sum(0) {}
    void insert(long long x) {
        xs.insert(x);
        sum += x;
        minimize();
    }
    void minimize() {
        while (xs.size() > k) {
            sum -= *xs.begin();
            xs.erase(xs.begin());
        }
    }
    void decrease_k() {
        --k;
        minimize();
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<Taste> tastes(n);
    for (int i = 0; i < n; ++i) {
        int t, d;
        cin >> t >> d;
        --t;
        tastes[t].add(d);
    }
    sort(tastes.begin(), tastes.end());
    for (auto& taste : tastes) {
        sort(taste.ds.begin(), taste.ds.end(), [](int i, int j) { return i > j; });
    }
    long long best = 0;
    long long sum = 0;
    long long x = 0;
    TopK top_k(k);
    for (auto& taste : tastes) {
        if (taste.hi > 0 && x < k) {
            top_k.decrease_k();
            ++x;
            sum += taste.hi;
            for (int i = 1; i < (int) taste.ds.size(); ++i) {
                top_k.insert(taste.ds[i]);
            }
            best = max(best, sum + x*x + top_k.sum);
        }
    }
    cout << best << endl;
    return 0;
}


Measured memory_bytes: 7168
#include <stdio.h>

#define N 8

int main(void){
    char buf[N+1];
    char ptn[N][N];
    
    for (int y=0; y<N; y++){
        scanf("%s", buf);
        for (int x=0; x<N; x++){
            ptn[x][y]=buf[x];
        }
    }
    
    puts("90");
    for (int y=0; y<N; y++){
        for (int x=0; x<N; x++){
            printf("%c",ptn[y][N-1-x]);
        }
        printf("\n");
    }
    puts("180");
    for (int y=0; y<N; y++){
        for (int x=0; x<N; x++){
            printf("%c",ptn[N-1-x][N-1-y]);
        }
        printf("\n");
    }
    puts("270");
    for (int y=0; y<N; y++){
        for (int x=0; x<N; x++){
            printf("%c",ptn[N-1-y][x]);
        }
        printf("\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 948
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
  int up = 0;
  int low = 100000;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < 5; j++) {
      int a;
      cin >> a;
      sum += a;
    }
    up = max(up, sum);
    low = min(low, sum);
  }
  cout << up << " " << low << endl;
}
  return 0;
}

Measured memory_bytes: 0
<?php
    # 1. Aに窓の長さを与えられる
    # 2. Bにカーテンの長さを与えられる
    # 3. A <= B の場合はカーテンが隠れるため出力結果は 0
    # 4. A > B の場合はカーテンが隠れないため出力結果は 差分
    fscanf(STDIN, "%d %d", $a, $b);

    $b = $b * 2;
    if($a <= $b){
        echo 0;
    } else{
        echo $a - $b;
    }
?>

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


Measured memory_bytes: 2076