akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int a, b;
int main() {
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) { cout << "Possible" << endl; }
	else { cout << "Impossible" << endl; }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int N=1e5+10,INF=0x3f3f3f3f;
int main()
{
    int n,ans,x,ans1;
    while(~scanf("%d",&n)){
        ans=0;
        ans1=0;
        for(int i=1;i<=n;i++){
            scanf("%d",&x);
            if(x==i)
                ans1++;
            if(x!=i||i==n){
                if(ans1>1) ans+=((ans1+1)/2);
                else ans+=ans1;
                ans1=0;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
import math

A = input().split()

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

x = int(A[0])
y = int(A[1])

if x > 1 and y > 1:
  print(combinations_count(x, 2) + combinations_count(y, 2))
else:
  if x > 1 and y <= 1:
    print(combinations_count(x, 2))
  else:
    if x <= 1 and y > 1:
      print(combinations_count(y, 2))
    else:
      print(0)

Measured memory_bytes: 3064
# test
class Union:
  def __init__(s, num):
    s.T = [-1 for i in range(num)]
 
  def root(s, x):
    if s.T[x] < 0: return x, -s.T[x]
    t, k = s.root(s.T[x])
    s.T[x] = t
    return t, k
 
  def merge(s, x, y):
    an, am = s.root(x)
    bn, bm = s.root(y)
    if an == bn: return False
    if am < bm: an, bn  = bn, an
    s.T[an] += s.T[bn]
    s.T[bn] = an
    return True
 
  def size(s, x):
    return s.root(x)[1]

  def same(s, x, y):
    return s.root(x)[0] == s.root(y)[0]


N, Q = list(map(int, input().split()))
tuv = [list(map(int, input().split())) for _ in range(Q)]

uni = Union(N)

for t, u, v in tuv:
  if t == 0:
    uni.merge(u, v)
  else:
    if uni.same(u, v):
      print(1)
    else:
      print(0)


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

using namespace std;

int main(){

  int n,k;

  cin>>n>>k;

  vector<int>ok(n);

  

  for(int i=0;i<n;i++){

  	cin>>ok[i];  }

  sort(ok.begin(),ok.end());

  int ans=0;

  for(int i=0;i<k;i++){

  	ans+=ok[i];

  }

  cout<<ans<<'\n';

  	

  

    

}

Measured memory_bytes: 3624
#include <stdio.h>

#define MAX 100000
#define INFTY 2000000000

typedef struct{
  char mark;
  int value;
} Card;

void merge(Card *, int, int, int, int);
void mergeSort(Card *, int, int, int);
void quicksort(Card *, int, int);
int partition(Card *, int, int);

Card L[MAX], R[MAX];
int n, count=0;
 

int main()
{
  int i;
  Card A[MAX], a[MAX];
  int judge = 1;
  
  scanf("%d", &n);

  for( i = 0 ; i < n ; i++ ){
    scanf(" %c%d", &A[i].mark, &A[i].value);
    a[i] = A[i];
  }

  mergeSort(A, n, 0, n);
  quicksort(a, 0, n-1);

  for( i = 0 ; i < n ; i++ ) if( A[i].mark != a[i].mark ) judge = 0;
  
  if( judge == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  
  for( i = 0 ; i < n ; i++ )
    printf("%c %d\n", a[i].mark, a[i].value);

  return 0;
}

void merge(Card S[], int n, int left, int mid, int right)
{
    int n1, n2, i, j, k;
    
    n1 = mid - left;
    n2 = right - mid;
    
    for( i = 0 ; i < n1 ; i++ ) L[i] = S[left+i];
    for( i = 0 ; i < n2 ; i++ ) R[i] = S[mid+i];
    
    L[n1].value = R[n2].value = INFTY;
    
    i = j = 0;
    
    for( k = left ; k < right ; k++ ){
        count++;
        if( L[i].value <= R[j].value ){
            S[k] = L[i];
            i++;
        }
        else {
            S[k] = R[j];
            j++;
        }
    }
}

void mergeSort(Card S[], int n, int left, int right)
{
    int mid;
    
    if( left+1 < right ){
        mid = (left + right)/2;
        mergeSort(S, n, left, mid);
        mergeSort(S, n, mid, right);
        merge(S, n, left, mid, right);
    }
}

void quicksort(Card A[], int p, int r)
{
  int q;

  if( p < r ){
    q = partition(A, p, r);
    quicksort(A, p, q-1);
    quicksort(A, q+1, r);
  }
}

int partition(Card A[], int p, int r)
{
  int i, j, x;
  Card tmp;
  
  x = A[r].value;
  i = p-1;
  
  for( j = p ; j < r ; j++ ){
    if( A[j].value <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  
  return i+1;
}

Measured memory_bytes: 2952
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    a, b = (int(_) for _ in input().split())
    if a*b %2 ==0:
        print('Even')
    else:
        print('Odd')
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
H,W,K=map(int,input().split())
c=[list(input()) for i in range(H)]
count=0
for bit_h in range(1<<H):
    for bit_w in range(1<<W):
        black=0
        for h in range(H):
            for w in range(W):
                if c[h][w]=="#" and (bit_h>>h)&1 and (bit_w>>w)&1:
                    black+=1
        if black==K:
            count+=1
print(count)

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

int main() {
    int n;
    cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        cin >> u[i];
    }
    double ans = 0;
    for (int i = 0; i < n; i++) {
        if (u[i] == "JPY") {
            ans += x[i];
        } else {
            ans += x[i] * 380000;
        }
    }
    cout << ans << endl;
}


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


int main(){
    string s;
    cin >> s;
    int ans;

    if(s == "SAT"){
        ans = 1;
    }
    else if (s == "SUN")
    {
        ans = 7;
    }
    else if (s == "MON")
    {
        ans = 6;
    }
    else if (s == "TUE")
    {
        ans = 5;
    }
    else if (s == "WED")
    {
        ans = 4;
    }
    else if (s == "THU")
    {
        ans = 3;
    }
    else if (s == "FRI")
    {
        ans = 2;
    }
    cout << ans;
    
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.Math;

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

        int N = scan.nextInt(); long D = scan.nextInt();

        int ans = 0;
        for(int i = 0; i < N; i++) {
            long X = scan.nextInt();
            long Y = scan.nextInt();
            if(X*X+Y*Y <= D*D) ans++;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 59280
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        for (int i = a; i <= b; i++) {
            if (i % k == 0) {
                System.out.println("OK");
                return;
            }
        }
        System.out.println("NG");
    }
}

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

int W,H;

struct RECT{int height,pos;};

int solve(int data[]){
	int ret = 0;
	data[W] = 0;
	RECT t;
	stack<RECT> S;
	for(int i=0;i<=W;i++){
		t.height = data[i];
		t.pos = i;
		if(S.empty()){
			S.push(t);
		}else{
			if(data[i] > S.top().height){
				S.push(t);
			}else if(data[i] < S.top().height){
				int here = i-1;
				while( !S.empty() && S.top().height > data[i]){
					RECT s = S.top(); S.pop();
					t.pos = s.pos;
					int width = here-s.pos+1;
					ret = max(ret,width*s.height);
				}
				S.push(t);
			}
		}
	}
	
	return ret;
}

int main(){
	while(cin >> H >> W, H){
		string s;
		getline(cin,s);
		int ret = 0;
		
		int dp[501][501]={{0}};
		for(int i=1;i<=H;i++){
			getline(cin,s);
			rep(j,s.length()){
				if(s[j] == '.')dp[i][j] = dp[i-1][j] + 1;
			}
		}
		for(int i=1;i<=H;i++){
			ret = max(solve(dp[i]),ret);
		}
		cout << ret << endl;
	}

}

Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)
typedef long long ll;

int main(){
	string S;
	cin >> S;

	cout << S.at(0) <<S.at(1) <<S.at(2) << endl;
}

Measured memory_bytes: 3632
a, b, c = (int(x) for x in input().split())
k = int(input())

ans = 'No'

for i in range(k):

    if c <= b : 
        c = c * 2
    else :
        if b <= a :
            b = b * 2

    # print("A : {0}".format(a))
    # print("B : {0}".format(b))
    # print("C : {0}".format(c))

    if a < b < c :
        ans = 'Yes'
        break

print(ans)

Measured memory_bytes: 9184
#include <stdio.h>

int cnt=0;
int m=0;
int G[1000000]={};

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


void shell(int N,int a[]){
    int i;
    
    G[0]=1;
    
    for(m=1;m<15;m++){
        G[m]=G[m-1]*3+1;
        if(G[m]>N)break;
    }
    
    for(i=m-1;i>=0;i--){
        insertion(N,a,G[i]);
    }
    
}

int main(void){
    int i,N,a[1000000]={};
    
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    
    shell(N,a);
    
    printf("%d\n",m);
    for(i=m-1;i>=0;i--){
        printf("%d",G[i]);
        if(i==0)puts("");
        else printf(" ");
    }
    printf("%d\n",cnt);
    
    for(i=0;i<N;i++){
        printf("%d\n",a[i]);
    }
    
    return 0;
}

Measured memory_bytes: 4536
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/



int main() {
	string S;
	lint K;
	cin >> S >> K;
	lint Z = S.size();
	if (S[0] != '1') {
		cout << S[0] << endl;
	}
	else {
	lint I = 0;
	char a;
	rep(i, Z) {
		if (S[i] != '1') {
			I = i;
			a = S[i];
			break;
		}
	}
	K--;
	if (I == 0) {
		cout << '1' << endl;
	}
	else if (K < I) {
		cout << '1' << endl;
	}
	else {
		cout << a << endl;
	}
	}
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>
struct card{char suit, value;} ;
void bubblesort(struct card a[],int n){
    for(int i=0;i<n;i++){
        for(int j=n-1;j>=i;j--){
            if(a[j].value<a[j-1].value){
               struct card t=a[j];a[j]=a[j-1];a[j-1]=t;
            }
        }
    }
}
void selection(struct card a[],int n){
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if(a[j].value<a[minj].value)
                minj=j;
    }
        struct card t=a[i];a[i]=a[minj];a[minj]=t;
}
}
void print(struct card a[],int n){
    for(int i=0;i<n;i++){
        if(i>0)printf(" ");
        printf("%c%c",a[i].suit,a[i].value);
    }
    printf("\n");
}

bool isstable(struct card c1[],struct card c2[],int n){
    for(int i=0;i<n;i++)
        if(c1[i].suit!=c2[i].suit)
            return false;
    return true;
}

int main(){
    struct card c1[100],c2[100];
    int n;
    int i;
    char copy,copy2;
   
    scanf("%d\n",&n);
  
    for(i=0;i<n;i++){
        scanf(" %c%c",&copy,&copy2);
        c1[i].suit=copy;
        c1[i].value=copy2;
       
    }
    for(i=0;i<n;i++)
        c2[i]=c1[i];
    bubblesort(c1,n);
    selection(c2,n);
    
    print(c1,n);
    printf("Stable\n");
    print(c2,n);
    if(isstable(c1,c2,n))
        printf("Stable\n");
    else
        printf("Not stable\n");
  
    }
       
        
    


Measured memory_bytes: 2100
using System;

namespace AtC154
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int len = S.Length;
            string ans = "";
            for (int i = 0; i < len; i++) ans = ans + "x";
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
from collections import Counter

S = input()

removeAC = S.replace("A","").replace("C","")

C = Counter(S)

if S[0]=="A" and "C" in S[2:len(S)-1] and C["A"]==1 and C["C"]==1 and removeAC.islower():
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
double h[1100];
double t;
double n;
double mb;
int main()
{
	  cin>>n>>t>>mb;
	  for(int i=1;i<=n;i++)
	    cin>>h[i];
	  int daan;
	  double cz=999999999;
	  for(int i=1;i<=n;i++)
	  {
	  	  if(cz>abs(t-h[i]*0.006-mb))
	  	    cz=abs(t-h[i]*0.006-mb),daan=i;
	  }
	  cout<<daan;
	  return 0;
}

Measured memory_bytes: 256
import sys
import heapq
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def shortest_path(s, n, w, es):
    d = [float("inf")]*n
    d[s] = 0
    while True:
        update = False
        for p,q,r in es:
            if d[p] != float("inf") and d[q] > d[p] + r:
                d[q] = d[p] + r
                update = True
        if not update:
            break
    return d

def main():
    n = int(input())
    es = list()
    cnt = 0
    ps = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
    ps.sort()
    for i in range(n+1):
        for j in ps:
            if i + j <= n:
                es.append([i, i+j, 1])
                cnt += 1
            else:
                break

    reslut = shortest_path(0,n+1, cnt, es)
    print(reslut[n])
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 145620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

int main() {
  int x, y;
  cin >> x >> y;
  bool can = false;
  rep(i, x+1) {
    int a = i;
    int b = x - i;
    if(2*a + 4*b == y) {
      can = true;
      break;
    }
  }
  if(can) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,M;
int a[100011];
int b[100011];
vector<int>G[100011];
int Q;
int v[100011];
int d[100011];
int c[100011];

int dp[11][100011];
int color[11][100011];

int main(){
        REP(i,11){
            REP(j,100011){
                dp[i][j]=-1;
                color[i][j]=0;
            }
        }
	cin>>N>>M;
	REP(i,M){
	    cin>>a[i]>>b[i];
	    G[a[i]].push_back(b[i]);
	    G[b[i]].push_back(a[i]);
	}
	cin>>Q;
	REP(i,Q){
	    cin>>v[i]>>d[i]>>c[i];
	    dp[d[i]][v[i]]=i+1;
	    color[d[i]][v[i]]=c[i];
	}
	for(int i=10;i>0;i--){
	    REP(j,100011){
	       if(dp[i-1][j]<dp[i][j]){
	          dp[i-1][j]=dp[i][j];
	          color[i-1][j]=color[i][j];
	       }
	       REP(k,G[j].size()){
	           if(dp[i-1][G[j][k]]<dp[i][j]){
	              //cout<<"aa"<<endl;
	              dp[i-1][G[j][k]]=dp[i][j];
	              color[i-1][G[j][k]]=color[i][j];
	           }
	       }
	    }
	}
	/*
	REP(i,11){
	    REP(j,20){
	        cout<<dp[i][j]<<" ";
	    }
	    cout<<endl;
	}
	*/
	REP(i,N){
	    cout<<color[0][i+1]<<endl;
	}
	return(0);
}

Measured memory_bytes: 17016
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int x, y;
    int maxv = 0;

    cin >> x >> y;

    if (x > y) {
        maxv += x;
        x--;
    } else {
        maxv += y;
        y--;
    }

    if (x > y) {
        maxv += x;
        x--;
    } else {
        maxv += y;
        y--;
    }

    cout << maxv << endl;

    return 0;
}



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

using namespace std;

int main() {
  int X, A;
  cin >> X >> A;
  if (X < A)
    cout << 0 << endl;
  else
    cout << 10 << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()

if len(s) % 2 == 1:
    s = s[:-1]
else:
    s = s[:-2]
while True:
    middle_index = len(s) // 2
    if s[:middle_index] == s[middle_index:]:
        print(len(s))
        exit()
    else:
        s = s[:-2]

Measured memory_bytes: 3060
s = set(list(input()))

if "N" in s:
  if "S" not in s:
    print("No")
    exit()
if "S" in s:
  if "N" not in s:
    print("No")
    exit()
if "W" in s:
  if "E" not in s:
    print("No")
    exit()
if "E" in s:
  if "W" not in s:
    print("No")
    exit()

print("Yes")

Measured memory_bytes: 3060
def get_list(L,i): return L[i] if len(L) > i else None
def print_key(key_name,val): print(key_name,"key = {0},".format(val), end=" ")
H = int(input())
hp = list(map(int,input().split()))
if H > 0:
    print_key("node 1:", hp[0])
    l = get_list(hp,1)
    r = get_list(hp,2)
    if l: print_key("left",l)
    if r: print_key("right",r)
    print("")
if H > 1:
    for i in range(2,H+1):
        print_key("node {0}:".format(i), hp[i-1])
        print_key("parent", hp[i//2-1])
        l = get_list(hp,i*2 -1)
        r = get_list(hp,i*2   )
        if l: print_key("left",l)
        if r: print_key("right",r)
        print("")

Measured memory_bytes: 7752
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#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;
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<double,int,double> 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;}
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 n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)cin>>in[i];
	sort(all(in));
	int sum=0;
	rep(i,m)sum+=in[n-1-i];
	cout<<sum<<endl;
}








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

signed main() {
	int N;
	string S;
	cin >> N >> S;
	vector<vector<int>> dp(N + 1, vector<int>(N + 1, 0));
	int ans = 0;
	for(int i=N-1;i>=0;i--) {
		for(int j=N-1;j>i;j--) {
			if(S[i] == S[j]) dp[i][j] = max(dp[i][j], dp[i+1][j+1] + 1);
			else dp[i][j] = 0;
			ans = max(ans, min(j - i, dp[i][j]));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 98176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int d[MAXn];
vector<int> odd;
vector<int> a;
int main(){
    IOS();
    int n,m;
    cin >> n >> m;
    REP (i,m) {
        cin >> d[i];
        if (d[i]&1) odd.eb(i);
    }
    if (m == 1 && n > 1) {
        cout << n << endl;
        cout << 2 << endl;
        cout << 1 << ' ' << n-1 << endl;
        return 0;
    }
    else if (m == 1 && n == 1) {
        return cout << "1\n1\n1\n",0;
    }
    if (SZ(odd) > 2) return cout << "Impossible" << endl,0;

    if (SZ(odd) >= 1) a.eb(d[odd[0]]);
    REP (i,m) {
        if (d[i]&1) continue;
        a.eb(d[i]);
    }
    if (SZ(odd) == 2) a.eb(d[odd[1]]);

    vector<int> b;
    int cur = 0;
    REP (i,m) {
        if (cur == n) break;
        if (!i) {
            b.eb(a[i]+1);
            cur += (a[i]+1);
        }
        else if (i == m-1) b.eb(a[i]-1);
        else {
            b.eb(a[i]);
            cur += a[i];
        }
    }

    REP (i,m) cout << a[i] << " \n"[i==m-1];
    cout << SZ(b) << endl;
    REP (i,SZ(b)) cout << b[i] << " \n"[i==SZ(b)-1];
}


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

int main() {
  char S;
  cin >> S;
    
  if(S=='a'||S=='i'||S=='u'||S=='e'||S=='o'){
   cout<< "vowel"<<endl;
 }else{
   cout<<"consonant"<<endl;
}
}


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> A(M);
  
  for (int i=0; i<M; i++) {
    cin >> A.at(i);
    N=N-A.at(i);
  }
  
  if (N>=0) {
    cout << N << endl;
  }
  else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3664
#include<stdio.h>
int mat[100][100];
int ret[100][100];
int tmp[100][100];
int s[100];
int t[100];
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		c--;
		for(int i=0;i<100;i++)
			for(int j=0;j<100;j++)
				mat[i][j]=ret[i][j]=0;
		for(int i=0;i<b;i++){
			int d,e;
			scanf("%d%d",&d,&e);
			d--;e--;
			s[2*i]=d;
			t[2*i]=e;
			s[2*i+1]=e;
			t[2*i+1]=d;
		}
		b*=2;
		for(int i=0;i<b;i++){
			for(int j=i+1;j<b;j++){
				if(t[i]==s[j]&&i/2!=j/2)mat[i][j]=1;
				if(s[i]==t[j]&&i/2!=j/2)mat[j][i]=1;
			}
		}
		for(int i=0;i<b;i++)ret[i][i]=1;
		while(c){
			if(c&1){
				for(int i=0;i<b;i++)
					for(int j=0;j<b;j++)
						tmp[i][j]=0;
				for(int i=0;i<b;i++)
					for(int j=0;j<b;j++)
						for(int k=0;k<b;k++)
							tmp[i][j]|=(ret[i][k]&mat[k][j]);
				for(int i=0;i<b;i++)
					for(int j=0;j<b;j++)
						ret[i][j]=tmp[i][j];
			}
			for(int i=0;i<b;i++)
				for(int j=0;j<b;j++)
					tmp[i][j]=0;
			for(int i=0;i<b;i++)
				for(int j=0;j<b;j++)
					for(int k=0;k<b;k++)
						tmp[i][j]|=(mat[i][k]&mat[k][j]);
			for(int i=0;i<b;i++)
				for(int j=0;j<b;j++)
					mat[i][j]=tmp[i][j];
			c/=2;
		}
		bool Ret=false;
		for(int i=0;i<b;i++){
			if(t[i]==a-1){
				for(int j=0;j<b;j++)if(s[j]==0&&ret[j][i])Ret=true;
			}
		}
		if(Ret)printf("yes\n");else printf("no\n");
	}
}

Measured memory_bytes: 1128
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define FORN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define FORR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll a, b, c;
	cin >> a >> b >> c;

	if(a == b && b == c) puts("Yes");
	else puts("No");

	return 0;
}


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

using namespace std;

struct Perm
{
    vector<int> x;
};

const int MAXN = 8;
bool used[MAXN + 1];
vector<Perm> perms;

bool cmp(Perm &a, Perm &b)
{
    for (int i = 0; i < (int) a.x.size(); i++)
    {
        if (a.x[i] != b.x[i])
            return a.x[i] < b.x[i];
    }
    return false;
}

void gen(int n, int index, vector<int> &v)
{
    if (index < n)
    {
        for (int i = 1; i <= n; i++)
        {
            if (!used[i])
            {
                used[i] = true;
                v.push_back(i);
                gen(n, index + 1, v);
                used[i] = false;
                v.pop_back();
            }
        }
    }
    else
    {
        Perm p;
        p.x = v;
        perms.push_back(p);
    }
}

bool same(Perm &a, Perm &b)
{
    for (int i = 0; i < (int) a.x.size(); i++)
        if (a.x[i] != b.x[i])
            return false;
    return true;
}

int main()
{
    int n;
    cin >> n;
    vector<int> v;
    Perm a, b;
    for (int i = 0; i < n; i++)
    {
        int y;
        cin >> y;
        a.x.push_back(y);
    }
    for (int i = 0; i < n; i++)
    {
        int y;
        cin >> y;
        b.x.push_back(y);
    }
    gen(n, 0, v);
    sort(perms.begin(), perms.end(), cmp);
    int num1, num2;
    for (int i = 0; i < (int) perms.size(); i++)
    {
        if (same(a, perms[i]))
            num1 = i;
        if (same(b, perms[i]))
            num2 = i;
    }
    cout << abs(num1 - num2) << endl;
    return 0;
}


Measured memory_bytes: 3256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[4] = {0,0,1,-1}, dy[4] = {1,-1,0,0};
const int INF = 1e9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    ch--; cw--; dh--; dw--;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    vector<vector<int>> dp(h, vector<int>(w, INF));
    rep(i,h)rep(j,w){
        if(s[i][j] == '#') dp[i][j] = -1;
    }
    queue<P> que, que2;
    que.push(P(ch, cw));
    dp[ch][cw] = 0;
    while(!que.empty()){
        int y = que.front().first;
        int x = que.front().second;
        que.pop();
        que2.push(P(y, x));
        rep(i,4){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(ny < 0 || h <= ny) continue;
            if(nx < 0 || w <= nx) continue;
            if(s[ny][nx] == '#') continue;
            if(dp[ny][nx] <= dp[y][x]) continue;
            dp[ny][nx] = dp[y][x];
            que.push(P(ny, nx));
        }
        if(que.empty()){
            while(!que2.empty()){
                int y = que2.front().first;
                int x = que2.front().second;
                que2.pop();
                for(int i = -2; i <= 2; ++i){
                    int ny = y + i;
                    if(ny < 0 || h <= ny) continue;
                    for(int j = -2; j <= 2; ++j){
                        int nx = x + j;
                        if(nx < 0 || w <= nx) continue;
                        if(s[ny][nx] == '#') continue;
                        if(dp[ny][nx] <= dp[y][x]+1) continue;
                        dp[ny][nx] = dp[y][x] + 1;
                        que.push(P(ny, nx));
                    }
                }
            }
        }
    }
    if(dp[dh][dw] == INF) cout << -1 << endl;
    else cout << dp[dh][dw] << endl;
    return 0;
}


Measured memory_bytes: 8672
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, k; ll l;
    cin >> n >> k >> l;
    int ok = 0, ng = n+1;
    vector<int> v(n), u(n);
    for (auto &&i : v) scanf("%d", &i);
    while(ng-ok > 1){
        int X = (ok+ng)/2;
        for (int i = 0; i < n; ++i) u[i] = v[i] < X;
        int lcur = 0, rcur = 0, cnt = 0;
        ll val = 0;
        while(rcur < n){
            cnt += u[rcur++];
            while(cnt >= k) cnt -= u[lcur++];
            if(rcur >= k) val += min(rcur-k+1, lcur);
        }
        if(val < l) ok = X;
        else ng = X;
    }
    cout << ok << "\n";
    return 0;
}


Measured memory_bytes: 4348
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var line = cin.ReadLine;
			Console.WriteLine(line[2]==line[3]&&line[4]==line[5]?"Yes":"No");
		}
	}
	static class ExtendClass {
		public static void Swap<T>(this T[] A, int x, int y) {
			var tmp = A[x];
			A[x]=A[y];
			A[y]=tmp;
		}
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		public static IEnumerable<int> Indices<T>(this T[] X) => Enumerable.Range(0, X.Length);
		public static IEnumerable<int> Indices<T>(this T[,] X, int dim)
			=> Enumerable.Range(0, X.GetLength(dim));
		public static string Join<T>(this T[,] X, string separatorD2 = ",", string separatorD1 = "\n")
			=> X.Indices(0).Select(
				i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2)
			).Join(separatorD1);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}
}

Measured memory_bytes: 11220
//JSD
#include<limits.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#define ll long long
#define Mod 1000000007
using namespace std;
ll modular_exponentiation(ll a,ll b){
	if(b==0){
		return 1;
	}
	if(b==1){
		return a%Mod;
	}
	ll x=modular_exponentiation(a,b/2);
	x=(x*x)%Mod;
	if(b%2==1){
		x=(x*a)%Mod;
	}
	return x;
}
ll modular_divison(ll a,ll b){
    return (modular_exponentiation(b,Mod-2)*a)%Mod;
}

bool isPrime(ll n){
	if(n<=1) return 0;
	if(n==2 or n==3 ) return 1;
	if(n%2==0 or n%3==0) return 0;
	for(ll i=5;i*i<=n;i+=6){
		if(n%i==0 or n%(i+2)==0)
			return 0;
	}
	return 1;
}
struct primeFactorInfo{
	map<ll,ll> M;
	set<ll> S;
};
primeFactorInfo pfs(ll n){
	primeFactorInfo p;
	for(ll i=2;i<=sqrt(n);i++){
		if(n%i==0){
			p.S.insert(i);
			while(((n%i)==0)){
				p.M[i]++;
				n/=i;
			}
		}
	}
	if(n>1){
		p.M[n]++;
		p.S.insert(n);
	}
	return p;
}
void sieve(ll n,vector<ll>& v){
	bool isComposite[n+1]={0};
	isComposite[0]=isComposite[1]=1;
	for(ll i=2;i*i<=n;i++){
		if(!isComposite[i]){
			v.push_back(i);
			for(int j=2;j*i<=n;j++){
				isComposite[i*j]=1;
			}
		}
	}
}
primeFactorInfo pfsUsingSieve(ll n){
	primeFactorInfo p;
	vector<ll > v;
	sieve(n,v);
	for(auto i: v){
		if(n%i==0){
			p.S.insert(i);
			while(((n%i)==0)){
				p.M[i]++;
				n/=i;
			}
		}
	}
	if(n>1){
		p.M[n]++;
		p.S.insert(n);
	}
	return p;
}
map<ll,ll> dp;
ll n;
ll a[1001],b[1001];	
ll solve(ll H){
	if(H<0)
		return 0;	
	if(dp.find(H)!=dp.end())
		return dp[H];
	ll ans=INT_MAX;
	for(int i=0;i<n;i++){
		ans=min(ans,solve(H-a[i])+b[i]);
	}
	dp[H]=ans;
	return ans;
}
int main(){
	dp[0]=0;
	ll h;
	cin>>h>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i]>>b[i];		
	}
	cout<<solve(h);
	return 0;
}


Measured memory_bytes: 1664
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    ans = 0
    for hi in h:
        if hi >= k:
            ans += 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 50160
#include <stdio.h>
#include <math.h>
 
int main()
{
    int i, n;
    double x1, x2, x3, y1, y2, y3;
    double a, b, c, d, e, f;
    double X1, Y1, r;
     
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%lf %lf %lf %lf %lf %lf",&x1, &y1, &x2, &y2, &x3, &y3);
        a = 2 * (x2 - x1);
        b = 2 * (y2 - y1);
        c = x1*x1 - x2*x2 + y1*y1 - y2*y2;
        d = 2 * (x3 - x1);
        e = 2 * (y3 - y1);
        f = x1*x1 - x3*x3 + y1*y1 - y3*y3;
         
        X1 = (b*f - e*c) / (a*e - d*b);
        Y1 = (c*d - f*a) / (a*e - d*b);
        r  = sqrt((X1-x1)*(X1-x1) + (Y1-y1)*(Y1-y1));
         
        X1 *= 1000;
        Y1 *= 1000;
        r  *= 1000;
         
        X1 = (int)(X1 > 0.0 ? X1+0.5 : X1-0.5);
        Y1 = (int)(Y1 > 0.0 ? Y1+0.5 : Y1-0.5);
        r  = (int)(r  > 0.0 ? r +0.5 : r -0.5);
         
        X1 = (double)X1/1000;
        Y1 = (double)Y1/1000;
        r  = (double)r /1000;
         
        printf("%.3f %.3f %.3f\n", X1, Y1, r);
         
         
    }
     
    return 0;
}

Measured memory_bytes: 1092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007


int main() {
  string s;
  cin >> s;
  int a = s.size();
  ll res = 0;
  rep(i, (1 << (a - 1))) {
    ll num = s[0] - '0';
    rep(j, a - 1) {
      if (i & (1 << j)) {
        res += num;
        num = 0;
      }
      num = 10 * num + s[j + 1] - '0';
    }
    res += num;
  }
  cout << res << endl;

}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;


public class Main {


    static void solve() {
        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        for(int i=a;i<=b;i++) {
            if(i>=k && i%k == 0) {
                System.out.println("OK");
                return;
            }
        }

        System.out.println("NG");
//        for (int i = 0; i < t; i++) {
//            int x = scan.nextInt();
////            int res = scase(n);
////            System.out.println(res);
////            solveCase(i, x,y,s);
//        }
    }


    static void solveCase(int t, int x, String s) {

    }


//    static int scase(int n) {
//
//    }

    public static void main(String[] args) {

//
        solve();

        //        Main m = new Main();
        //        Scanner scan = new Scanner(System.in);

        //        long n = scan.nextLong();
        //        long r = scan.nextLong();
        //        List<Long> list = new ArrayList<>();
        ////        int[] arr = new int[n];
        //        for (long i=0;i<n;i++){
        //            list.add(scan.nextLong());
        //        }
//            System.out.println(ch);
        //        solve(n, arr);
        //        scan.close();
    }


//
//    class Counter extends HashMap<Integer, Integer> {
//        public int get(int k) {
//            return containsKey(k) ? super.get(k) : 0;
//        }
//
//        public void add(int k, int v) {
//            put(k, get(k) + v);
//        }
//    }


//    static class Node {
//        int val;
//        Node next;
//        Node random;
//
//        public Node(int val) {
//            this.val = val;
//            this.next = null;
//            this.random = null;
//        }
//    }

//    static class Node {
//        int key;
//        int data;
//        Node next;
//        Node prev;
//
//        Node(int key, int data) {
//            this.key = key;
//            this.data = data;
//        }
//    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }
}


Measured memory_bytes: 27088
n = int(input())
hi = list(map(int, input().split()))
s = 0
for i in range(n):
  if hi[i] > s:
    s = hi[i] - 1
  elif hi[i] == s:
    pass
  elif hi[i] < s:
    print("No")
    quit()
print("Yes")

Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007;
#define pb push_back
#define vi vector<int>
#define  eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()


int32_t main(){
int n;cin>>n;int k;cin>>k;
int a[n+1];for(int i=1;i<=n;i++)cin>>a[i];
vi dp(n+1);
for(int i=0;i<=n;i++)dp[i]=INT_MAX;
dp[0]=0;
dp[1]=0;
for(int i=2;i<=n;i++){
	for(int j=1;j<=k;j++){
	if(i>j)
  dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
  else break;
  //else dp[i]=min(dp[i-]+abs(a[i]-a[i-1]),dp[i]);
}
}
// for(auto it:dp)cout<<it<<" ";
cout<<dp[n];
}




Measured memory_bytes: 1792
// abc048_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    char c;
    cin >> c;

    string s = "aeiou";

    if (count(ALL(s), c) == 0) {
        print("consonant");
    } else {
        print("vowel");
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int x, y;
    cin >> x >> y;
    if(x==1&&y==1){
        cout << 1000000 << endl;
    }else if(x==1&&y==2) {
        cout << 500000 << endl;
    }else if(x==1&&y==3) {
        cout << 400000 << endl;
    }else if(x==2&&y==1) {
        cout << 500000 << endl;
    }else if(x==2&&y==1) {
        cout << 500000 << endl;
    } else if(x==2&&y==2) {
        cout << 400000 << endl;
    } else if(x==2&&y==3) {
        cout << 300000 << endl;
    } else if(x==3&&y==1) {
        cout << 400000 << endl;
    } else if(x==3&&y==2) {
        cout << 300000 << endl;
    } else if(x==3&&y==3) {
        cout << 200000 << endl;
    } else if(x<=3) {
        cout << (4-x)*100000 << endl;
    } else if(y<=3){
        cout << (4-y)*100000 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3556
use std::io::*;
use std::str::FromStr;

fn main() {
	let (n, k): (usize, usize) = (read(), read());
	let mut p: Vec<usize> = Vec::new();
	let mut temp: usize;
	for _ in 0..n {
		temp = read();
		p.push(temp);
	}
	p.sort();
	let mut sum: usize = 0;
	for i in &p[0..k] {
		sum += *i;
	}
	println!("{}", sum);
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 2164
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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);
        HonestOrUnkind2 solver = new HonestOrUnkind2();
        solver.solve(1, in, out);
        out.close();
    }

    static class HonestOrUnkind2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[][] map = new int[n][n];
            for (int[] a : map) {
                Arrays.fill(a, -1);
            }

            for (int i = 0; i < n; i++) {
                int anum = in.nextInt();
                for (int j = 0; j < anum; j++) {
                    int x = in.nextInt() - 1;
                    int y = in.nextInt();
                    map[i][x] = y;
                }
            }

            long result = 0;
            for (int bit = 0; bit < (1 << n); bit++) {
                if (judge(bit, map)) {
                    long c = 0;
                    for (int i = 0; i < n; i++) {
                        if ((bit & (1 << i)) != 0) {
                            c++;
                        }
                    }
                    result = Math.max(result, c);
                }
            }
            out.println(result);
        }

        public boolean judge(int bit, int[][] map) {
            for (int i = 0; i < map.length; i++) {
                if ((bit & (1 << i)) == 0) {
                    continue;
                }
                int[] pair = map[i];
                for (int j = 0; j < pair.length; j++) {
                    if (pair[j] != -1) {
                        if (((bit >> j & 1) ^ pair[j]) == 1) {
                            return false;
                        }
                    }
                }
            }
            return true;
        }

    }
}



Measured memory_bytes: 36872