akhauriyash/Code-Regression huggingface dataset:
num = int(input())
s = ["".join(sorted(input())) for i in range(num)]

d = dict()

for st in s:
    if st in d:
        d[st]+=1
    else:
        d[st]=1

ans=0

for i in d:
    k=d[i]
    ans+=(k*(k-1))//2

print(ans)

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

int n;
string s;

void solve(){
    cin>>n;
    cin>>s;
    int maxi=0;

    for(int i=0; i<n-1; i++){
        for(int j=i+1; n-j>=j-i; j++){
            string l=s.substr(i,j-i);
            string r=s.substr(j,n-j);
            //cout<<j-i<<' '<<n-j<<endl;
            //cout<<l<<' '<<r<<endl;
            if(maxi<(int)l.size()){
                int ret=r.find(l);
                //cout<<ret<<endl;
                if(ret<(int)r.size() && ret>=0){
                    maxi=(int)l.size();
                }
            }
        }
    }

    cout<<maxi<<endl;
}

int maxi=-100000;

vector<int> zalgo(string s){
    vector<int>A(s.size());
    A[0]=s.size();
    int i=1, j=0;
    while(i<s.size()){
        while(i<s.size() && s[j]==s[i+j]) ++j;
        A[i]=j;
        if(i>=A[i] && A[i]>maxi) maxi=A[i];
        if(j==0){++i; continue;}
        int k=1;
        while(i+k<s.size() && k+A[k]<j){
            A[i+k]=A[k],++k;
            if(i>=A[i] && A[i]>maxi) maxi=A[i];
        }
        i+=k; j-=k;
    }
    return A;
}

vector<int> fkmp(string s){
    
}

void solve1(){
    cin>>n;
    cin>>s;
    maxi=-1000000;
    for(int i=0; i<n; i++){
        vector<int > A=zalgo(s.substr(i,n-i));
        /*
        for(int j=1; j<A.size(); j++){
            if(j>=A[j] && maxi<A[j]){
                maxi=A[j];
            }
        }
        */
    }
    cout<<maxi<<endl;
}

void task(){
    cin>>s;
        vector<int> A=zalgo(s);
        for(auto a:A){
            
            cout<<" ";
        }
}

signed main(){
    //while(1)
    solve1();
}

Measured memory_bytes: 384
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n = I()
s = SR(n)
sc = Counter(s)
most = sc.most_common()[0][1]
ans = []
for s, num in sc.most_common():
    if num == most:
        ans.append(s)
ans.sort()
for x in ans:
    print(x)


Measured memory_bytes: 126728
#include <stdio.h>
#include <stdlib.h>

#define hani2 10000

int main(){
  short *A,*B;
  int C[hani2+1],n, i, j;

  scanf("%d",&n);

  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

  for(i=0;i<=hani2;i++) C[i]=0;

  for(i=0;i<n;i++){
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1;i<=hani2;i++) C[i]=C[i]+C[i-1];

  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 8460
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'

const int N = 2e6 + 11;
const int MOD = 1e9 + 7;
int fact[N], inv[N];

int power(int a, int e) {
    int res = 1ll;
    while (e) {
      if (e & 1) res = (res * a) % MOD;
      a = (a * a) % MOD, e >>= 1;
    }
    return res;
}

void pre() {
    fact[0] = 1;
    inv[0] = power(fact[0], MOD - 2);
    for (int i = 1; i < N; i++) {
      fact[i] = (1ll * fact[i - 1] * i) % MOD;
      inv[i] = power(fact[i], MOD - 2);
    }
}

int nCr(int n, int r) {
    if (r > n) return 0;
    return fact[n] * inv[r] % MOD * inv[n - r] % MOD;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    pre();
    int k; string s;
    cin >> k >> s;
    int ans = 0;
    int n = s.size();
    for (int i = n; i <= n + k; i++) {
      int cur = nCr(n + k, i) * 1ll * power(25, n + k - i) % MOD;
      ans += cur, ans %= MOD;
    }
    cout << ans << endl;
}

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

using namespace std;
const int N=1e5+5;
int a[N];

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    cout<<a[n/2]-a[n/2-1];
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long

int main(void) {
    int n;
    cin >> n;
    if (n % 10 == 0) cout << 10 << endl;
    else {
        int ans = 0;
        while (n > 0) {
            ans += n % 10;
            n /= 10;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
int main(){
  Dice d;
  for(int i=0;i<6;i++) cin >> d.s[i];
  int n;
  cin >> n;
  while(n--){
    int a,b;cin >> a >> b;
    if(d.left()==a) d.roll('E');
    if(d.right()==a) d.roll('W');
    while(d.top()!=a) d.roll('N');
    while(d.front()!=b) d.roll('R');
    cout << d.right() << endl;
  }
  return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
 
using namespace std;
 
using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;
 
#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define LL long long
#define ULL unsigned long long
 
// n개중에서 k 를 고르는 Combination table을 미리 세팅한다.
// C[n][k] -> nCk
ULL Comb[51][51];
void combination_table(int n)
{
    for(int i = 0; i <= n; ++i)
        for(int j = 0; j <= i; ++j)
        {
            if(j == 0 || j == i)
                Comb[i][j] = 1ll;
            else
                Comb[i][j] = Comb[i - 1][j - 1] + Comb[i - 1][j];
        }
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    int N, A, B;
    cin >> N >> A >> B;
 
    VL items(N, 0);
    REP(i, 0, N) cin >> items[i];
 
    combination_table(N);
    sort(items.begin(), items.end(), greater<LL>());
 
    double max_avg = (double)accumulate(items.begin(), items.begin() + A, 0ll) / A;
    
    LL smallest = items[A - 1];
    int numSmallest = count(items.begin(), items.end(), smallest);
 
	cout.precision(10);
    cout << fixed << max_avg << endl;
 
    LL cnt = 0ll;
    // 1. items[0] == items[A - 1] 인 경우    
    if(items[0] == smallest)
        cnt += accumulate(Comb[numSmallest] + A, Comb[numSmallest] + B + 1, 0ll);
    else {
        int numSub = count(items.begin(), items.begin() + A, smallest);
        cnt += Comb[numSmallest][numSub];
    }
 
    cout << cnt << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define MOD 1000000007

int possible_patterns(int N, int K);

int main(void) {
    int N, K;
    
    cin >> N >> K;
    cout << possible_patterns(N, K) << endl;
    
    return 0;
}

int possible_patterns(int N, int K) {
    long k, patterns = 0;
    
    for(k = K; k <= N+1; k++) {
        patterns += k * (N - k + 1) + 1;
        patterns %= MOD;
    }
    
    return patterns;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vi a,b;

int main(){
	cin>>n;
	a=b=vi(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	int res=0;
	for(int i=1;i<n;i++) a[i]+=a[i-1];
	for(int i=n-2;i>=0;i--) b[i]+=b[i+1];
	for(int i=0;i<n;i++){
		res=max(res,a[i]+b[i]);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int h = 0;
    for(int i = 0; i < (int)s.size(); i++){
        if(h == 0 && s[i] == 'C') h++;
        if(h == 1 && s[i] == 'F'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(1, n-1):
    if (p[i-1]<p[i] and p[i]<p[i+1]) or (p[i+1]<p[i] and p[i]<p[i-1]):
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
function main(arg) {
	arg = arg.split("\n").map(e => e.split(" ").map(x => Number(x)).sort((a,b) => a - b))
	// console.log(arg)

	var val_count = [0,0,0,0] 


	var m = []
	for (var i = 0; i < arg.length; i++) {
		if (arg[i][0] === arg[i][1]) {
			console.log("NO")
			return;
		}

		val_count[arg[i][0] - 1]++
		val_count[arg[i][1] -1]++

		m.push(arg[i].join(""))
	}

	m.sort()

	for (var i = 1; i < m.length; i++ ) {
		if (m[i] === m[i-1]) {
			console.log("NO")
			return
		}
	}

	for (var i = 0; i < val_count.length; i++) {
		if (val_count[i] == 0 || val_count[i] > 2) {
			console.log("NO")
			return
		}
	}
	
	console.log("YES")

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main(){
    map<int,int> m;
    int n; cin >> n;
    rep(i,n){
        int a; cin >> a;
        m[a]++;
    }
    for(auto p : m){
        if(p.second >= 2){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int r,g,b,n,an=0;
	cin>>r>>g>>b>>n;
	int a,c,p,q;
	a=n/r;
	for(int i=0;i<=(n/r);i++)
	{
		c=(n-i*r)/g;
		for(int j=0;j<=c;j++)
		{
			p=n-i*r-j*g;
			if(p%b==0)
			an++;
		}
		
	}
	
	cout<<an;
	return 0;
} 


Measured memory_bytes: 256
///******* In the name of Allah *******///

#include <bits/stdc++.h>
using namespace std;

long int verdict[100013];
int main()
{
    long int a,b,c,d,e,f,g,t,i,j,k,l,m,n,r,Max,val[113],sum,ans_1,ans_2,ans_3,cnt_ac = 0,cnt_wa = 0;
    string aa;
    cin>>n>>m;
    for(i=1; i<=m; i++)
    {
        cin>>a>>aa;
        if(aa=="AC")
        {
            if(verdict[a]==0)
            {
                cnt_ac++;
                verdict[a] = -1;
            }
            else if(verdict[a]>0)
            {
                cnt_wa += verdict[a];
                cnt_ac++;
                verdict[a] = -1;
            }
        }
        else if(aa=="WA")
        {
            if(verdict[a]>=0)
            {
                verdict[a]++;
            }
        }
    }
    cout<<cnt_ac<<" "<<cnt_wa<<endl;

    return 0;
}


Measured memory_bytes: 1024
import sys
from collections import namedtuple


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


item = namedtuple("itm", ("w", "v"))
n, W = map(int, input().split())
items = [item(next_int(), next_int()) for i in range(n)]
dic = dict()


def rec_dp(i: int, w: int) -> int:
    if (i, w) in dic:
        return dic[(i, w)]

    result = 0
    if i == n:
        pass
    elif w - items[i].w < 0:
        result = rec_dp(i + 1, w)
    else:
        result = max(
            rec_dp(i + 1, w),
            rec_dp(i + 1, w - items[i].w) + items[i].v
        )
    dic[(i, w)] = result
    return result


def main() -> None:
    print(rec_dp(0, W))


if __name__ == "__main__":
    main()


Measured memory_bytes: 21044
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr uint64_t INF = 1e18;

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

  int N;
  cin >> N;
  int64_t D;
  cin >> D;
  D = D * D;
  int32_t cnt = 0;
  for (int i = 0; i < N; i++) {
    int64_t x,y;
    cin >> x >> y;
    x = x*x;
    y = y*y;
    if (x + y <= D) cnt++;
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<utility>
#include<algorithm>
#include<bitset>
using namespace std;
int n,m,ans;
vector<string> s(100),ss(100);
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>ss[i];
  }
  for(int i=0;i<n;i++){
    if(s[i]!="0"){
      int a=1;
      for(int j=i+1;j<n;j++){
	if(s[j]==s[i]){a++;s[j]="0";}
      }
      for(int j=0;j<m;j++){
	if(ss[j]==s[i]){a--;}
      }
      ans=max(ans,a);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
require 'pp'
require 'prime'

a, b = gets.split.map(&:to_i)

# p [a,b]
# p [a,b].map(&:prime_division)
#
# p a.prime_division.map{|x|x[0]}
# p b.prime_division.map{|x|x[0]}
#
p (a.prime_division.map{|x|x[0]} & b.prime_division.map{|x|x[0]}).size + 1

# 3 4 1


Measured memory_bytes: 4348
#include <stdio.h>

int main()
{
  int N, i, j, k, A[100], v;

  scanf("%d", &N);

  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
  }
    
  for(k = 0; k < N; k++){
    printf("%d", A[k]);
    if(k != N - 1) printf(" ");
  }
  printf("\n");  
  
  for(i = 1; i <= N - 1; i++){ 
    v = A[i];
    j = i - 1;

    while(j >= 0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
      A[j + 1] = v;
    }
    
    for(k = 0; k < N; k++){
      printf("%d", A[k]);
      if(k != N - 1) printf(" ");
    }
    printf("\n");  
  }
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define vll vector<ll>
#define sz size()
#define pb emplace_back
#define mp make_pair
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL))
const int N = 100005;

int main()
{
	ll n;
	cin>>n;
	ll x[n+1],y[n+1];
	for(ll i=0;i<n;i++)
	cin>>x[i]>>y[i];
	ld ans=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<n;j++)
		{
			if(i!=j)
			{
				ld dis=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
				ans=ans+dis;
			}
		}
	}
	ans=ans/n;
	cout<<fixed<<setprecision(10)<<ans;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc075/tasks/abc075_c?lang=ja


def root(a):
    if parent[a] == -1:
        return a
    parent[a] = root(parent[a])
    return parent[a]


def unite(x, y):
    if same(x, y):
        return False

    x = root(x)
    y = root(y)
    parent[x] = y
    return True


def same(x, y):
    return root(x) == root(y)


n, m = list(map(int, input().split()))
edge = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edge.append((a, b))

result = 0
for i in range(m):
    parent = [-1 for _ in range(n)]
    for j in range(m):
        if j == i:
            continue
        a, b = edge[j]
        unite(a, b)
    a, b = edge[i]
    if not same(a, b):
        result += 1

print(result)


Measured memory_bytes: 75788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[405][405],a[405],pref_cost[405];
const ll inf = 1e18+10;

int main()
{
    int n;
    cin >> n;
    
    for(int i=1;i<=n;++i)
    cin >> a[i];
    
    pref_cost[1]=a[1];
    for(int i=2;i<=n;++i)
    {
        pref_cost[i]+=pref_cost[i-1]+a[i];
    }
    
    for(int i=n;i>=1;--i)
    {
        for(int j=1;j<=n;++j)
        {
            dp[i][j]=inf;
            if(i==j)
            dp[i][j]=0;
            for(int k=i;k<j;++k)
            {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+pref_cost[j]-pref_cost[i-1]);
            }
        }
    }
    
    
    cout << dp[1][n] << '\n';
    
    return 0;
}

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


using namespace std;

#define all(v)              v.begin(),v.end()
#define allr(v)             v.rbegin(),v.rend()
#define sz(v)               (int)sizeof(v)
#define pb(x)               push_back(x)
#define mkpr(x,y)           make_pair(x,y)
#define oo                  INT_MAX
#define noo                 INT_MIN
#define forn(i, n)          for(ll i=0;i<n;i++)
#define fore(i,b,e)         for(ll i=b;i<=e;i++)
#define ford(i,n)           for(ll i=n-1;i>=0;i--)


typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef pair<int, int> ii;

int dx[] = { 1,-1, 0, 0, 1, 1,-1, -1 };
int dy[] = { 0, 0, 1,-1, 1,-1, 1, -1 };

void dance()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void file()
{
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
}

ll gcd(ll a, ll b)
{
    return !b ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

template<typename t>
void printV(vector<t> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i] << ' ';
    }
    cout << endl;
}

bool isPrime(int n)
{

    if (n == 2)
        return true;
    if (n < 2 || n % 2 == 0)
        return false;
    for (int i = 3; i * i <= n; i += 2)
        if (n % i == 0)
            return false;
    return true;
}

/**
 *****code begins here*****
**/

int main()
{
    dance();
    string s;
    cin>>s;
    int b=0;
    ll res=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='W')
            res+=b;
        else
            b++;
    }
    cout<<res<<endl;
    return 0;
}


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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

string s;
ll dp[100001][13];

int main(){

    cin>>s;
    ll n = s.length();
    ll i, j, k;
    ll ans = 0;


    dp[0][0] = 1;

    for(i=0; i<n; i++){
        int c;
        if(s[i] == '?'){
            c = -1;
        }
        else{
            c = s[i] - '0';
        }

        for(j=0; j<10; j++){
            if(c != -1 && c != j){
                continue;
            }
            for(k=0; k<13; k++){
                dp[i+1][(k*10+j)%13] += dp[i][k];
            }
        }
        for(j=0; j<13; j++){
            dp[i+1][j] %= 1000000007;
        }
    }

    ans = dp[n][5];

    cout<<ans<<endl;


    return 0;
    
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
int main() {
  char a,b;
  cin >> a >> b;

  if ((a=='H' && b=='H') || (a=='D' && b=='D')) {
    cout << 'H' << endl;
  } else {
    cout << 'D' << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if((a==b) && (b==c) && (c==a)){
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21972
import java.util.*;
public class Main {

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

	int r=0,dd=d/10;d=d%10;
	if(dd>1){
	for(int i=4;i<=m;i++){
		for(int j=2;j<dd;j++)if(j*2<=i && i%j==0 && i/j<=9)r++;
		if(dd*2<=i && i%dd==0 && i/dd<=d)r++;
	}
	}
	System.out.println(r);
 }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first        
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int a,b,c,d,n;
    cin>>a>>b>>c>>d;
    cin>>n;
    if(n%2==0){
        cout<<min(a*4*n,min(b*2*n,min(c*n,d*(n/2))));
    }
    else{
        cout<<min(a*4*n,min(b*2*n,min(c*n,min(d*(n/2) + a*4,min(d*(n/2) + b*2,d*(n/2) + c)))));
    }
    //cout<<endl;
    //cout<<d * (n/2) + b*2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)

typedef long long ll;

int main()
{
    int N,Y;
    cin >>N>>Y;
    int ans0 = -1, ans1 = -1, ans2 = -1;

    FOR(i,0,N+1){
        FOR(j,0,N+1){
            int k = N-i-j;
            if(i*10000+j*5000+k*1000 == Y && k >= 0){
                ans0 = i;
                ans1 = j;
                ans2 = k;
                goto end;
            }
        }
    }
    end:
    cout << ans0<<" "<<ans1<<" "<<ans2 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((a-c)*(a-c)<=d*d){
    cout << "Yes" << endl;}
  else if((a-b)*(a-b)<=d*d && (b-c)*(b-c)<=d*d){
    cout << "Yes" << endl;}
  else{
    cout << "No" << endl;}
}

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

typedef long long ll;

using namespace std;


ll fun(ll a,ll N){
     
     ll tmp=N/a;

    return  a*(tmp+1)*tmp/2;
}


int main(){

    ll N;
    cin>>N;

    ll ans=0;

    for(ll i=1;i<=N;i++){
        ans+=fun(i,N);
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 3588
import sys
import math
input=sys.stdin.readline


n,k=map(int,input().split())
arr=list(map(int,input().split()))
ans=0
arr.sort(reverse=True)
for i in range(n):
    if(k>0):
        k-=1
    else:
        ans+=arr[i]
print(ans)





Measured memory_bytes: 27276
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h,w;
    std::cin >> h >>w;
    string s;
    int a[53][53]={};
    for (int i = 1; i <= h; i++) {
        std::cin >> s;
        for (int j = 1; j <= w; j++) {
            if(s[j-1]=='#'){
                a[i][j]=100;
                a[i-1][j-1]++;
                a[i-1][j]++;
                a[i-1][j+1]++;
                a[i][j-1]++;
                a[i][j+1]++;
                a[i+1][j-1]++;
                a[i+1][j]++;
                a[i+1][j+1]++;
            }
        }
    }
    
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if(a[i][j]>=100){
                std::cout << "#";    
            }else{
                std::cout << a[i][j];
            }
        }
        std::cout  << std::endl;
    }
    
}


Measured memory_bytes: 256
/*   CREATED BY
       STREAM_CIPHER
       16-02-2020
  */
  #include <bits/stdc++.h>
  using namespace std;
  typedef long long  int ll;

   int main()  
   {
        ios_base::sync_with_stdio(false); 
        cin.tie(NULL); 
        int n;
        cin>>n;
        bool ans=true;
        for(int i=0;i<n;i++)
        {
           int in;
           cin>>in;
           if(in%2==0)
           {
               if(in%3==0||in%5==0)
               {

               }
               else
                    ans=false;
           }
        }
        if(ans)
          cout<<"APPROVED\n";
        else
          cout<<"DENIED\n";
   }    

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

int main() {
	char o1,o2,o3;
	queue<int>q;
	int j=1;
	int d[2]={1,-1};
	int num[4];
	for(int i=0;i<4;i++){
	scanf("%1d",&num[i]);
	}
	int o;
	q.push(num[0]);
	for(int i=1;i<4;i++){
		for(int s=0;s<j;s++){
			o=q.front();
			for(int a=0;a<2;a++){
			q.push(o+num[i]*d[a]);
				if(i==3&&q.back()==7){
					o=a;
					goto X;
					return 0;
				}
			}
		
			q.pop();
		}
		j=j*2;
	}
	X:if(o==0){
		if(num[1]+num[2]+num[0]==7-num[3])cout<<num[0]<<'+'<<num[1]<<'+'<<num[2]<<'+'<<num[3];
		else if(num[1]+num[0]==7-num[3]+num[2])cout<<num[0]<<'+'<<num[1]<<'-'<<num[2]<<'+'<<num[3];
		else if(-num[1]+num[0]==7-num[3]+num[2])cout<<num[0]<<'-'<<num[1]<<'-'<<num[2]<<'+'<<num[3];
		else cout<<num[0]<<'-'<<num[1]<<'+'<<num[2]<<'+'<<num[3];
		
	}
	  else{
		if(num[1]+num[2]+num[0]==7+num[3])cout<<num[0]<<'+'<<num[1]<<'+'<<num[2]<<'-'<<num[3];
		else if(num[1]+num[0]==7+num[3]+num[2])cout<<num[0]<<'+'<<num[1]<<'-'<<num[2]<<'-'<<num[3];
		else if(-num[1]+num[0]==7+num[3]+num[2])cout<<num[0]<<'-'<<num[1]<<'-'<<num[2]<<'-'<<num[3];
		else cout<<num[0]<<'-'<<num[1]<<'+'<<num[2]<<'-'<<num[3];
	  	
	  }
		cout<<"=7";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int a, b, c, d, e;

	scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
	if (a == 0) {
		printf("1\n");
	}
	else if (b == 0) {
		printf("2\n");
	}
	else if (c == 0) {
		printf("3\n");
	}
	else if (d == 0) {
		printf("4\n");
	}
	else if (e == 0) {
		printf("5\n");
	}
	return 0;
}

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

int main(){
	int H;
	cin >> H;
	
	while(H!=0){
		int puzzle[12][5];
		rep(i,H){
			rep(j,5){
				cin >> puzzle[i][j];
			}
		}
		
		bool allign = true;
		
		int ans = 0;
		
		while (allign){
			//まず０のところを落とす。
			for (int i = H-2; i >= 0; --i) {
				rep(j,5){
					int temp = i;
					if(puzzle[i][j] != 0){
						while(puzzle[temp+1][j] == 0){
							puzzle[temp+1][j] = puzzle[temp][j];
							puzzle[temp][j] = 0;
							temp++;
							if(temp == H-1) break;
						}
					}
				}
			}
			
			allign = false;
			
			rep(i,H){
				int count = 1;
				int id = 0;
				rep(j,4){
					if(puzzle[i][j] == 0) {
						if(count < 3){
							count = 1;
							continue;
						}else{
							continue;
						}
					}
					if(puzzle[i][j] == puzzle[i][j+1]){
						count++;
						id = j+1;
					}
					if(puzzle[i][j] != puzzle[i][j+1]){
						if(count < 3){
							count = 1;
						}else{
							break;
						}
					}
				}
				if(count >= 3){
					allign = true;
					for (int j = id - count + 1; j <= id ; ++j) {
						ans += puzzle[i][j];
						puzzle[i][j] = 0;
					}
				}
			}
		}
		
		cout << ans << endl;
		
		cin >> H;
	}
	
    return 0;
}


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

typedef uint32_t u32;

template<u32 N_>
class UnionFindTree {
private:
  u32 par[N_];
  u32 rank[N_];
public:
  UnionFindTree(u32 n) {
    assert(n < N_);
    for(u32 i = 0; i < n; ++i) {
      par[i] = i;
      rank[i] = 0;
    }
    return;
  }
  int find(u32 x) {
    if( par[x] == x ) return x;
    return par[x] = find(par[x]);
  }
  void unite(u32 x, u32 y) {
    x = find(x);
    y = find(y);
    if( x == y ) return;
    if( rank[x] < rank[y] ) {
      par[x] = y;
      return;
    }
    par[y] = x;
    if( rank[x] == rank[y] ) rank[x] += 1;
    return;
  }  
};

template<typename Tw>
class Edge {
private:
  u32 begin_, end_;
  Tw  weight_;
public:
  Edge() {}
  Edge(u32 begin, u32 end, Tw weight) : begin_(begin), end_(end), weight_(weight) {}
  const u32& begin()  const { return begin_;  }
  const u32& end()    const { return end_;    }
  const u32& weight() const { return weight_; }
  static bool comp_be(const Edge<Tw>& left, const Edge<Tw>& right) {
    if( left.begin() != right.begin() ) return left.begin() < right.begin();
    if( left.end()   != right.end()   ) return left.end()   < right.end();
    return false;
  }
  static bool comp_w(const Edge<Tw>& left, const Edge<Tw>& right) {
    return left.weight() < right.weight();
  }
};

int main() {

  u32 V, E;
  Edge<u32> edge[200000];

  std::cin >> V >> E;
  for(u32 i = 0; i < E; ++i) {
    u32 s, t, w;
    std::cin >> s >> t >> w;
    edge[i] = Edge<u32>(s, t, w);
  }

  std::sort(edge, edge + E, Edge<u32>::comp_w);

  u32 res = 0;
  UnionFindTree<20000> uft(V);
  for(u32 i = 0; i < E; ++i) {
    if( uft.find(edge[i].begin()) != uft.find(edge[i].end()) ) {
      uft.unite(edge[i].begin(), edge[i].end());
      res += edge[i].weight();
    }
  }

  std::cout << res << std::endl;
  
  return 0;
}

Measured memory_bytes: 3452
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N = int(input())
p = list(map(int,input().split()))
d = defaultdict(int)
for i in range(N):
    d[p[i]] = i
a,b = [],[]
for i in range(1,N+1):
    a.append(N*i+d[i])
    b.append((N-i+1)*N+d[i])
print(*a,sep=" ")
print(*b,sep=" ")

Measured memory_bytes: 46980
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
h,w,k=gsmi
ans=[]
st_c=[]
first_str=nil
has=false
s=
  h.times.map do |i|
    str=gs
    c=str.count('#')
    st_c<< c
    if !has&&c>0
      idx=str.index('#')
      first_str=[i,idx]
      has=true
    end
    str
  end

cnt=1
first_str[0].upto(h-1) do |i|
  row=s[i]
  ar=[]
  if st_c[i]==0
    if i==0
      ar<<[cnt]*w
    else
      ar<<ans[-1]
    end
    ans<<ar
    next
  end

  r_cnt=0
  w.times do |j|
    r_cnt+=1
    if row[j]=='#'
      cnt+=1 unless i==first_str[0]&&j==first_str[1]
      ar<<[cnt]*r_cnt
      r_cnt=0
    end
  end
  ar<<[cnt]*r_cnt
  ans<<ar.flatten
end

# いちごがない最初の行を補正
ar=ans[0]
c = first_str[0]
c.times{ans.unshift ar}

ans.each{|r|puts r.join(" ")}

Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
typedef pair<int,int> P;
#define INF 1e9
#define rep(i,N) for(int i=0;i<N;i++)

int main(){
    int k,t;
    cin>>k>>t;
    int a[t];
    rep(i,t)cin>>a[i];
    sort(a,a+t,greater<int>());
    int ans = a[0];
    ll cnt = 1;
    for(int i = 1; i < t; i++){
        cnt += a[i];
    }
    ans -= cnt;
    if(ans<0)ans = 0;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{

    class Program
    {
        static void Main(string[] args)
        {
            List<int[,]> resultList = new List<int[,]>();

            string input;
            while ((input = Console.ReadLine()) != "0")
            {
                int n = int.Parse(input);
                int[,] mas = new int[n,n];
                int count = 1;

                int row = n / 2 + 1;
                int col = n / 2;

                while (count <= n * n)
                {
                    if (col > n - 1)
                    {
                        col = 0;
                    }
                    else if (col < 0)
                    {
                        col = n - 1;
                    }
                    else if (row > n - 1)
                    {
                        row = 0;
                    }
                    else if (mas[row, col] != 0)
                    {
                        col--;
                        row++;
                    }
                    else
                    {
                        mas[row, col] = count;
                        row++;
                        col++;
                        count++;
                    }
                }

                resultList.Add(mas);

            }

            foreach (int[,] a in resultList)
            {
                for (int i = 0; i < a.GetLength(0); i++)
                {
                    for (int k = 0; k < a.GetLength(1); k++)
                    {
                        if (a[i, k] / 10 == 0)
                        {
                            Console.Write("   ");
                        }
                        else if (a[i, k] / 100 == 0)
                        {
                            Console.Write("  ");
                        }
                        else
                        {
                            Console.Write(" ");
                        }
                        Console.Write(a[i,k]);
                    }
                    Console.WriteLine();
                }
            }


        }


        
    }
}

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

void insertionsort(vector<int>a,int n)
{
    for(int i=1;i<n;i++)
    {
        int v=a[i];
        int j=i-1;
        while(j>=0&&a[j]>v)
        {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        cout<<a[1];
        for(int j=2;j<n;j++)
            cout<<" "<<a[j];
        cout<<endl;
    }
    }
int main()
{
    int n;
    cin>>n;
    vector<int>a(n+1);
    for(int i=1;i<n+1;i++)
        cin>>a[i];
    insertionsort(a,n+1);
}



Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int n, a, b;
    cin>>n>>a>>b;
    int a2 = MAX2((b - (n-a)), 0);
    int a1 = MIN2(a, b);
    cout<<a1<<" "<<a2;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<complex>
#include<map>
using namespace std;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  int cnt = 0;
  bool flg = true;
  while(flg){
    flg = false;
    for(int i = n-1; i > 0; i--){
      if(a[i-1] > a[i]){
        cnt++;
        swap(a[i-1], a[i]);
        flg = true;
      }
    }
  }
  for(int i = 0; i < n; i++){
    cout << a[i];
    if(i == n-1) cout << endl;
    else cout << " ";
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3088
import sys
input = sys.stdin.readline

n,k = map(int,input().split())
L=list(map(int,input().split()))
town=[]
visit=[False]*(n+1)
next=1
while 1:
    next = L[next-1]
    if not visit[next]:
        visit[next] = True
        town.append(next)
    else:
        town.append(next)
        break
for i in range(n):
    if town[i]==town[-1]:
        mod = i
        loop = len(town)-i-1
        loop_array = town[i:-1]
        break
fin_len = (k-mod)%loop
if k<=mod:
    print(town[k-1])
else:
    print(loop_array[fin_len-1])


Measured memory_bytes: 31452
#include <iostream>

int main() {
  int N;

  std::cin >> N;

  int highest = 0;
  int ans = 0;

  for (int i=0; i<N; i++) {
    int H;
    std::cin >> H;

    if (highest <= H) {
      ans++;
      highest = H;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main (){

  int n,a,b;

  while(1){

    a=0;
    
    cin >>n;
    
    if( n == 0 )break;

    for(int i=1; i <=  sqrt(n) ; i++){
      if( n%i == 0){
	if( i == n/i){
	  a+=i;
	}else{
	  a+=i+n/i;
	}      
      }
    }
    
    
    b=a-n;

    if( n == 1 ){
      b=0;
    }

    if( n == b ){
      cout <<"perfect number"<<endl;
    }else if( n > b ){
      cout <<"deficient number"<<endl;
    }else if( n < b ){
      cout <<"abundant number"<<endl;
    }

  }
    


  
  return 0;
}

Measured memory_bytes: 1156
<?php
list($n, $k) = ints();
$c = 0;
while($n){
    $n = intdiv($n, $k);
    $c++;
}
echo $c;
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}
/**
 * 座圧対象の配列を渡すと以下の値を返す
 * ・圧縮された配列
 * ・復元用のMap
 * ・圧縮用のMap
 **/
function atsu($array){
    $a = array_flip($array);
    $fuku = array_flip($a);
    sort($fuku);
    $atsu = array_flip($fuku);
    foreach($array as $i => $val)$array[$i] = $atsu[$val];
    return [$array, $fuku, $atsu];
}
//配列の最大公約数
function gcdAll($array){
    $gcd = $array[0];
    for($i = 1; $i < count($array); $i++){
        $gcd = gcd($gcd, $array[$i]);
    }
    return $gcd;
}

//最大公約数
function gcd($m, $n){
    if(!$n)return $m;
    return gcd($n, $m % $n);
}

//配列の最小公倍数
function lcmAll($array){
    $lcm = $array[0];
    for($i = 1; $i < count($array); $i++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


Measured memory_bytes: 4728
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		long []x = new long[N];
		for(int i = 0; i < N; i++) {
			long t = scan.nextLong();
			x[i] = t;
		}
		scan.close();
		if(N == 1) {
			System.out.println(Math.abs(x[0]));
			System.exit(0);
		}
		if(K == 1) {
			long min = Math.abs(x[0]);
			for(int i = 0; i < N; i++) {
				if(min < Math.abs(x[i])) {
					min = Math.abs(x[i]);
				}
			}
			System.out.println(min);
			System.exit(0);
		}
		long []y = new long[N - 1];
		for(int i = 0; i < N - 1; i++) {
			y[i] = Math.abs(x[i + 1] - x[i]);
		}
		long []B = new long[N];
		B[0] = 0;
		for(int i = 1; i < N; i++) {
			B[i] = y[i - 1] + B[i - 1];
		}
		long min = Long.MAX_VALUE;
		for(int i = 0; i <= N - K; i++) {
			long t = B[i + K - 1] - B[i] + Math.min(Math.abs(x[i]), Math.abs(x[i + K - 1]));
			if(min > t) {
				min = t;
			}
		}
		System.out.println(min);
//		for(long i : y) {
//			System.out.println(i);
//		}


	}
}

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

#define fi first
#define se second
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;

int main() {
	ios::sync_with_stdio(0);

	int a, b, c, n;
	cin >> a >> b >> c >> n;
	int cnt = 0;
	while (a >= b)
		b *= 2, cnt++;
	while (b >= c)
		c *= 2, cnt++;
	cout << (cnt <= n ? "Yes\n" : "No\n");

	return 0;
}


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

#define f(i, a, b) for (ll i = a; i < (ll)b; i++)
#define af(i, a, b) for (ll i = a; i >= (ll)b; i--)
#define rep(i, a, b, k) for (ll i = a; i < b; i += k)
#define arep(i, a, b, k) for (ll i = a; i >= b; i -= k)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort(a.begin(), a.end())
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define inter                    \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr)
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll MAX = 3e5 + 100;

ll dp[MAX], n, ans[MAX], siz[MAX], fac[MAX], mod = 1e9 + 7;
vi adj[MAX];

ll bp(ll a, ll e)
{
    if (e == 0)
        return 1;
    if (e & 1)
        return (bp(a, e - 1) * a) % mod;
    ll x = bp(a, e >> 1);
    return (x * x) % mod;
}

ll inv(ll a)
{
    return bp(a, mod - 2);
}

void dfs(int u, int f)
{
    dp[u] = 1, siz[u] = 1;
    f(i, 0, adj[u].size())
    {
        ll v = adj[u][i];
        if (v == f)
            continue;
        dfs(v, u);
        siz[u] += siz[v];
        (dp[u] *= dp[v]) %= mod;
        (dp[u] *= inv(fac[siz[v]])) %= mod;
    }
    (dp[u] *= fac[siz[u] - 1]) %= mod;
}

void dfs1(int u, int f)
{
    f(i, 0, adj[u].size())
    {
        ll v = adj[u][i];
        if (v == f)
            continue;
        ans[v] = (ans[u] * ((siz[v] * inv(n - siz[v])) % mod)) % mod;
        dfs1(v, u);
    }
}

int main()
{
    fastio;
    ll u, v;
    fac[0] = 1;
    f(i, 1, MAX)(fac[i] = i * fac[i - 1]) %= mod;
    cin >> n;
    f(i, 1, n)
    {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1, 0);
    ans[1] = dp[1];
    dfs1(1, 0);
    f(i, 1, n + 1) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 26352
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;

int n, a[3], l[8], ans = 100000;

int func3(vector<int>& v2, vector<int>& v4, int id){
  if(id == v4.size()){
    //for(int i = 0; i < v4.size(); i++) cout << v4[i] << " "; cout << endl;
    int sum = 0;
    for(int i = 0; i < v4.size(); i++){
      if(v4[i] == 1) sum++;
    }
    if(sum != 3) return 100000;
    int ret = 0;
    int j = 2, anst = 0;
    for(int i = 0; i < v4.size(); i++){
      if(v4[i] == 1) anst += abs(v2[i] - a[j--]);
    }
    return anst;
  }
  v4[id] = 0;
  int ret1 = func3(v2, v4, id + 1);
  v4[id] = 1;
  int ret2 = func3(v2, v4, id + 1);
  v4[id] = 0;
  return min(ret1, ret2);
}

void func2(vector<int>& v){
  int maxi = 0;
  for(int i = 0; i < v.size(); i++){
    maxi = max(v[i], maxi);
  }
  if(maxi < 2) return;
  vector<int> v2(maxi + 1, 0);
  for(int i = 0; i < v.size(); i++){
    v2[v[i]] += l[i];
  }
  //for(int i = 0; i < v2.size(); i++) cout << v2[i] << " "; cout << endl;
  int anst = (n - (maxi + 1)) * 10;
  sort(v2.begin(), v2.end());
  vector<int> v4(v2.size(), 0);
  anst += func3(v2, v4, 0);
  ans = min(anst, ans);
  return;
}

void func(vector<int>& v){
  if(v.size() == n){
    //for(int i = 0; i < v.size(); i++) cout << v[i]; cout << endl;
    func2(v);
    return;
  }
  int maxv = 0;
  for(int i = 0; i < v.size(); i++){
    maxv = max(v[i], maxv);
  }
  for(int i = 0; i <= maxv + 1; i++){
    v.push_back(i);
    func(v);
    v.pop_back();
  }
  return;
}

void solve(){
  cin >> n >> a[0] >> a[1] >> a[2];
  for(int i = 0; i < n; i++) cin >> l[i];
  vector<int> v;
  v.push_back(0);
  func(v);
  cout << ans << endl;

  return;
}

int main(){
  solve();
  return 0;
}


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


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

h = 10**11+7
b = 10**7+7

H = [1]
for _ in range(N):
    H.append((H[-1]*b)%h)

allSum = 0
for i in range(N):
    allSum = (allSum + H[i]) % h

ok = [True]*N
ans = [0]*N

C = []
D = []
for i in range(N):
    C.append(A[i-1]^A[i])
    D.append(B[i-1]^B[i])


HashA = 0
for i, a in enumerate(C):
    HashA = (HashA + a*H[i]%h) % h

HashB = 0
for i, a in enumerate(D):
    HashB = (HashB + a*H[i]%h) % h

ans = []
for k in range(N):
    if HashA == HashB:
        ans.append(k)
    HashB = (HashB * b) % h
    HashB = (HashB + (1-H[N])*D[-k-1] % h) % h

for k in ans:
    print(k, A[k]^B[0])

Measured memory_bytes: 46388
#include <stdio.h>
#include <stdlib.h>

int cmp(const void* a, const void* b) {
	return *(long int*)b - *(long int*)a;
}

int main() {
	long int n, a[200000];
	long long int ans = 0;
	scanf("%ld", &n);
	for (int i = 0; i < n; i++)scanf("%ld", &a[i]);
	qsort(a, n, sizeof(long int), cmp);
	ans += a[0];
	int t = 1;
	for (int i = 0; i < n - 2; i++){
		if(i%2==0)	ans += a[t];
		else {
			ans += a[t];
			t++;
		}
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 4644
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s[3],a;

	for(int i=0;i<3;i++)
		cin>>s[i];

	a+=s[0][0];
	a+=s[1][1];
	a+=s[2][2];

	cout<<a<<endl;

	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a , b , sum;
  cin >> a >> b ;
  for(int i = a ; i <= b ; i++){
    int n = i;
    int s, t , u , w;
    s = n / 10000;
    t = n / 1000 % 10;
    u = n / 10 % 10;
    w = n % 10;
    if( s == w && t == u){
       sum += 1;
    }
  }
  cout << sum << endl;        
}

Measured memory_bytes: 256