akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define rrep(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,n) rep(i,0,n)
#define RREP(i,n) rrep(i,n,0)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int main(){
  string s;
  int n,k;
  cin >> n >> k >> s;
  s[k-1] = tolower(s[k-1]);
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int> g[500001];
vector<ll> a;
vector<ll> as;
int cur = 0;


ll dfs(int u, int par){
	ll ans =0;
	for(int v:g[u]){
		if(v!=par){
			ans += dfs(v,u);
		}

	}
	as[u] = a[cur];cur++;
	return as[u]+ans;
}



int main(){
	int n;
	cin>>n;
	a.resize(n);
	as.resize(n+1);
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}

	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(), a.end());
	cout<<dfs(1,0)-as[1]<<endl;
	for(int i=1;i<=n;i++){
		cout<<as[i]<<" ";
	}
	cout<<endl;

}

Measured memory_bytes: 13056
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int N=1e5+100;
int n,ans;
class edge
{
    public:
    int f,t,w;
    edge(int f,int t,int w):f(f),t(t),w(w){}
};
class ufind
{
    vector<int> f,r;
    public:
    ufind(int n)
    {
        f.resize(N);
        r.assign(N,1);
        for(int i=1;i<=n;++i) f[i]=i;
    }
    int find(int x)
    {
        if (x==f[x]) return x;
        else return f[x]=find(f[x]);
    }
    bool unite(int x,int y)
    {
        x=find(x);y=find(y);
        if (x==y) return false;
        if (r[x]<r[y]) swap(x,y);
        f[y]=x;
        if (r[x]==r[y]) r[x]++;
        return true;
    }
};
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    vector<pair<int,int>> x,y;
    for(int i=1;i<=n;++i)
    {
        int xx,yy;
        cin>>xx>>yy;
        x.push_back(make_pair(xx,i));
        y.push_back(make_pair(yy,i));
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    vector<edge> e;
    for(int i=1;i<n;++i) 
    {
        e.push_back(edge(x[i-1].second,x[i].second,x[i].first-x[i-1].first)); 
        e.push_back(edge(y[i-1].second,y[i].second,y[i].first-y[i-1].first)); 
    }
    sort(e.begin(),e.end(),[](const edge &a,const edge &b){return a.w<b.w;});
    ufind s(n);
    for(auto i:e)
        if(s.unite(i.f,i.t)) ans+=i.w;
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<pair<int, int>> lr(q);
	for (int i = 0; i < q; i++) {
		int l_in, r_in;
		cin >> l_in >> r_in;
		lr.at(i) = make_pair(l_in - 1, r_in - 1);
	}

	vector<int> num_ac(n);
	num_ac.at(0) = 0;
	for (int i = 1; i < n; i++) {
		num_ac.at(i) = num_ac.at(i - 1);
		if (s[i - 1] == 'A' && s[i] == 'C') {
			num_ac.at(i)++;
		}
	}

	for (auto lr_ele : lr) {
		int ans = num_ac.at(lr_ele.second) - num_ac.at(lr_ele.first);
		cout << ans << endl;
	}
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++ )

int main(void){
    int K;
    cin >> K;

    vector<long long> lunlun;   // vectorはqueueとして使用できる 

    // 1桁目は自分で生成する 
    for(int i = 1; i <= 9; i++){
        lunlun.push_back(i);
    }

    /* 入っている数の次の桁のルンルン数を生成し、enqueueしていく */
    while(true){
        // できたかチェック 
        if(K <= lunlun.size()){
            cout << lunlun[K -1] << endl;   // 配列なので-1 
            return 0;
        }else{
            K -= lunlun.size(); // 1順前のルンルンの分を進めて、今回生成した配列から参照しやすくする 
        }

        vector<long long> old;
        swap(lunlun, old);

        // 拡張for文で今あるルンルン数を参照し次の桁のものを作っていく 
        for(long long x : old){
            for(int i = -1; i <= 1; i++){
                int next = x % 10 + i;
                // 桁が移動しちゃうのはNG 
                if((next < 0) || (next > 9)){   // 0, 9「までは」セーフ。9だと次の桁100とかが出ちゃう
                    continue;
                }
                lunlun.push_back((x * 10) + next);
            }
        }
//        rep(i, lunlun.size())   cout << lunlun[i] << " "; // 生成したルンルンを表示する 
//        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <climits>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long ll;

int main(void) {
  int N;
  cin >> N;
  vector<int> V(N, 0);
  vector<int> C(N, 0);
  for (int i = 0; i < N; i++) { cin >> V[i]; }
  for (int i = 0; i < N; i++) { cin >> C[i]; }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (V[i] - C[i] > 0) { ans += (V[i] - C[i]); }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {

	var K, N int
	fmt.Scan(&K, &N)

	A := make([]int, N)
	D := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	for i := 0; i < N-1; i++ {
		D[i] = A[i+1] - A[i]
	}
	D[N-1] = K - A[N-1] + A[0]

	ds := sort.IntSlice(D)
	sort.Sort(ds)

	fmt.Println(K - ds[N-1])
}


Measured memory_bytes: 9216
#include <iostream>
#include <cstdio>
#include <queue>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define pb push_back
using namespace std;

const int N = 1e6+10;
int n, k, ans, a[N], f[N];
vector<int> g[N];

void dfs(int x) { 
	f[x] = 1;
	for (int y:g[x]) dfs(y), f[x] = max(f[x], f[y]+1);
	if (f[x]==k&&a[x]!=1) ++ans,f[x]=0;
}
int main() {
	scanf("%d%d", &n, &k);
	REP(i,1,n) scanf("%d", a+i);
	ans = a[1]!=1;
	a[1] = 1;
	REP(i,2,n) g[a[i]].pb(i);
	dfs(1);
	printf("%d\n", ans);
}





Measured memory_bytes: 34688
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=2000000;
const ll inf=1e16;
const int mod=1e9+7;

int Pow(int a, int b)
{
    int x = 1;
    for(; b; b>>=1)
    {
        if(b&1) x = (ll)x * a % mod;
        a = (ll)a * a % mod;
    }
    return x;
}

//int F[MX+5], IF[MX+5];

//ll nCr(ll n, ll r)
//{
//    return (F[n] * IF[r] % mod * IF[n-r]) % mod;
//}

//void FCT()
//{
//    F[0] = IF[0] = 1;
//    for(ll i=1; i<=MX; i++) F[i] = F[i-1] * i % mod;
//    for(ll i=1; i<=MX; i++) IF[i] = Pow(F[i], mod-2);
//}


int main()
{
    //FasterIO;

    int r1, c1, r2, c2;

    cin>>r1>>c1>>r2>>c2;

    const int N=2e6+5;
    vector<int>F(N), IF(N);
    F[0] = IF[0] = 1;
    for(int i=1; i<N; i++)
    {
        F[i] = (ll)F[i-1] * i % mod;
        IF[i] = Pow(F[i], mod-2);
    }

    auto comb = [&](int n, int k)
	{
		return (ll)F[n] * IF[n-k] % mod * IF[k] % mod;
	};

    int ans=0;
    for(int i=r1; i<=r2; i++)
    {
        ans = (ans + comb(i + c2 + 1, c2)) % mod;
        ans = (ans + mod - comb(i + c1, c1 - 1)) % mod;
    }

    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << ' ' + '=' + ' ' << (x) << endl;
#define MOD 1000000007
#define EPS (1 >> 30)
#define INF (1 << 30)
//#define INFll (1LL << 60)

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n;
    cin>>n;
    vector<int> d(n);
    ll ans=0;
    rep(i, n) cin >> d[i];
    rep(i,n){
        Rep(j,i+1,n){
            
            ans+=d[i]*d[j];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){

	int count[26];
	for(int i = 0;i < 26;i++) {
		count[i] = 0;
	}
	char s[1300];
	while(fgets(s,1300,stdin) != NULL) {
        for(int i = 0;s[i] != '\0';i++) {
            if(s[i] >= 'A' && s[i] <= 'Z') {
                count[s[i] - 'A']++;
            }
            if(s[i] >= 'a' && s[i] <= 'z') {
                count[s[i] - 'a']++;
            }
        }
	}

	for(int i = 0;i < 26;i++) {
		printf("%c : %d\n",'a' + i,count[i]);
	}
	return 0;
}


Measured memory_bytes: 2684
import functools

n,k=map(int,input().split())
d=list(map(int,input().split()))

for i in range(n,n*11):
    count=0
    l = [int(x) for x in list(str(i))]
    for j in l:
        #print(j)
        if j  not in d :
            count+=1
    if count==len(l):
        print( int(functools.reduce(lambda x, y: x + y, [str(x) for x in l])))
        exit()

Measured memory_bytes: 3572
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, W = sc.nextInt()
    val w, v = new Array[Int](N)
    (0 until N) foreach { i =>
      val _w, _v = sc.nextInt()
      w(i) = _w
      v(i) = _v
    }
    val VMAX = Math.pow(10, 5).toInt
    val Inf = 1000000001

    val dp = Array.fill(N+1, VMAX+1)(Inf)
    dp(0)(0) = 0
    var i = 0
    while (i < N) {
      var j = 0
      while (j <= VMAX) {
        if (j >= v(i))
          dp(i+1)(j) = (dp(i)(j - v(i)) + w(i)) min dp(i+1)(j) min dp(i)(j)
        else
          dp(i+1)(j) = dp(i+1)(j) min dp(i)(j)
        j += 1
      }
      i += 1
    }

    println(dp(N).lastIndexWhere(_ <= W))
  }

}


Measured memory_bytes: 84244
#include <bits/stdc++.h>
using namespace std;
  
int main() {
    int N,M;
    cin >> N;
    vector<string> S(N);
    for (int i=0;i<N;i++) {
        cin >> S.at(i);
    }
    cin >> M;
    vector<string> T(M);
    for (int i=0;i<M;i++) {
        cin >> T.at(i);
    }
    
    int count=0;
    int point=0;
    
    for (int i=0;i<N;i++) {
        string word = S.at(i);
        count = 0;
        for (int j=0;j<N;j++) {
            if(word == S.at(j)) {
                count++;
            }
            
        }
        for (int k=0;k<M;k++) {
                if(word == T.at(k)) {
                    count--;
                }
            }
        point = max(point,count);
    }
    cout << point << endl;
    
   }

 

Measured memory_bytes: 3512
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::vector;

int main() {
  int N, C;
  vector<int> s(100000), t(100000), c(100000);
  vector<int> sm(200002);
  vector<int> differential(200002);
  vector<int> accumulation(200002);
  cin >> N >> C;
  for (int pr = 0; pr < N; ++pr)  // Gets input.
    cin >> s[pr] >> t[pr] >> c[pr];
  for (int ch = 1; ch <= C; ++ch) {  // For each channel.
    fill(differential.begin(), differential.end(), 0);
    fill(accumulation.begin(), accumulation.end(), 0);
    for (int pr = 0; pr < N; ++pr) {  // For each program.
      if (c[pr] == ch) {
        ++differential[s[pr] * 2 - 1];
        --differential[t[pr] * 2];
      }
    }
    accumulation[0] = differential[0];
    for (int time = 1; time < 200002; ++time) {
      accumulation[time] = accumulation[time - 1] + differential[time];
    }
    for (int time = 0; time < 200002; ++time) {
      if (accumulation[time] > 0) {
        ++sm[time];
      }
    }
  }
  cout << *max_element(sm.begin(), sm.end()) << endl;
}


Measured memory_bytes: 3712
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち

import numpy as np
from functools import partial
array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)

ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)

'''
DPじゃなくて貪欲に小さい方からくっつけるのじゃだめ？←隣り合うという制約が入れられない

sum a_i から をaiに分解するイメージ
dp[i,j] ... コストの最小. A[i:j]を合体させたとき

更新式
dp[i,j] = min(dp[i,i+1] + dp[i+1,j],
              dp[i,i+2] + dp[i+2,j],...
              ) + sum(A[i,j])

dp[i,i+1]=0かな？
'''


N = a_int()
A = ints()
A_accum = zeros(N + 1)
A_accum[1:] = np.cumsum(A)
dp = full((N + 1, N + 1), -1)
dp[np.arange(N), np.arange(N) + 1] = 0

from numba import njit


@njit('(i8,i8,i8[:,:],i8[:])', cache=True)
def dfs(i, j, dp, A_accum):
    if dp[i, j] != -1:
        return dp[i, j]
    mi = 10**14
    for k in range(i + 1, j):
        mi = min(mi, dfs(i, k, dp, A_accum) + dfs(k, j, dp, A_accum))
    dp[i, j] = mi + A_accum[j] - A_accum[i]
    return dp[i, j]


print(dfs(0, N, dp, A_accum))


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

using ll = long long;

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
    cout << '[';
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len-1) s << ", ";
	}
    cout << ']';
	return s;
}

ll dp[100001][4];


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
	cin >> s;

	int n = s.size();

	dp[n][3] = 1;
	for(int i = 0; i < 3; ++i){
		dp[n][i] = 0;
	}

	for(int i = n-1; i >= 0; --i){
		int m = (s[i] == '?') ? 3 : 1;
		dp[i][3] = m * dp[i+1][3] % MOD;
	}

	for(int i = n-1; i >= 0; --i){
		for(int j = 2; j >= 0; --j){
			int m = (s[i] == '?') ? 3 : 1;
			int k = (s[i] == '?') or (s[i] == "ABC"[j]);
			dp[i][j] = (m * dp[i+1][j] % MOD + k * dp[i+1][j+1] % MOD) % MOD;
		}
	}


	ppp(dp[0][0]);

    return 0;
}


Measured memory_bytes: 3664
import os


N = int(input())

sts = []
for i in range(N):
    s, t = input().split()
    sts.append( (i, s, int(t)))

s_ = input()

ist = [ i for i, s, t in sts if s == s_]

i = ist[0]

ans = 0
for k in range(i+1, len(sts)):
    ans += sts[k][2]

print(ans)

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

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

int lcm(int a, int b) {
  int gc = gcd(a, b);
  return ((a / gc) * (b / gc)) * gc;
}

signed main() {
  int n, t[101];
  cin >> n;
  rep(i, 0, n) cin >> t[i];
  rep(i, 1, n) {
    t[i] = lcm(t[i], t[i - 1]);
  }
  cout << t[n - 1] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
double pi = 3.141592653589793;
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
//ここから始めよう
int cost[200][200];int n,m,r;
int rcost[10][10];
int dfs(int bit,int k){
    int res=mod;
    if(bit==(1<<r)-1)return 0;
    rep(i,0,r){
        if(!(bit&1<<i))res=min(res,dfs(bit|1<<i,i)+rcost[k][i]);
    }
    return res;
}
signed main(){
    cin>>n>>m>>r;
    int R[10];rep(i,0,r)cin>>R[i];
    Fill(cost,mod);
    rep(i,0,m){
        int a,b,c;cin>>a>>b>>c;
        a--;b--;
        cost[a][b]=c;
        cost[b][a]=c;
    }
    rep(k,0,n){
        rep(i,0,n){
            rep(j,0,n){
                cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
            }
        }
    }
    rep(i,0,r){
        rep(j,0,r){
            rcost[i][j]=cost[R[i]-1][R[j]-1];
        }
    }
    rep(i,0,r){
        //rep(j,0,r)cout<<rcost[i][j]<<" ";cout<<endl;
    }
    int ans=mod;
    rep(i,0,r){
        ans=min(ans,dfs(1<<i,i));
    }
    cout<<ans<<endl;return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll N; cin >> N;
	ll sum = 0;
	
	ll fl;
	for (fl = 1; fl*fl < N; fl++) {
		ll r, l;
		r = N/fl;
		l = N/(fl+1)+1;
		//cout << l << " " << r << endl;
		//[l, r]
		//ma = N-fl a = (N-fl)/l
		for (ll a = max((N-fl)/r - 1, 1ll); a <= (N-fl)/l + 1; a++) {
			if ((N-fl)%a == 0) {
				ll m = (N-fl)/a;
				if (l <= m && m <= r) {
					sum += m;
				}
			}
		}
	}
	cout << sum << endl;
}

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


Measured memory_bytes: 3652
#include<iostream>
#include<queue>
using namespace std;
struct State { char x[12][6]; };
pair<State, bool>solve(State U) {
	bool used[12][6], r[12][6]; for (int i = 0; i < 72; i++) { used[i / 6][i % 6] = false; r[i / 6][i % 6] = false; }
	int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
	for (int i = 0; i < 12; i++) {
		for (int j = 0; j < 6; j++) {
			if (used[i][j] == true || U.x[i][j] == 'O' || U.x[i][j] == '.')continue;
			queue<pair<int, int>>Q; Q.push(make_pair(i, j)); int c = 0;
			vector<pair<int, int>>v; used[i][j] = true;
			while (!Q.empty()) {
				int a1 = Q.front().first, a2 = Q.front().second; c++; Q.pop();
				v.push_back(make_pair(a1, a2));
				for (int k = 0; k < 4; k++) {
					int ex = a1 + dx[k], ey = a2 + dy[k];
					if (ex < 0 || ey < 0 || ex >= 12 || ey >= 6 || U.x[i][j] != U.x[ex][ey])continue;
					if (used[ex][ey] == false) { Q.push(make_pair(ex, ey)); used[ex][ey] = true; }
				}
			}
			if (c >= 4) {
				for (int k = 0; k < v.size(); k++) {
					r[v[k].first][v[k].second] = true;
					for (int l = 0; l < 4; l++) {
						int ex = v[k].first + dx[l], ey = v[k].second + dy[l];
						if (ex < 0 || ey < 0 || ex >= 12 || ey >= 6)continue;
						if (U.x[ex][ey] == 'O') { r[ex][ey] = true; }
					}
				}
			}
		}
	}
	bool update = false;
	for (int i = 0; i < 72; i++) { if (r[i / 6][i % 6] == true) { U.x[i / 6][i % 6] = '.'; update = true; } }
	for (int i = 0; i < 24; i++) {
		for (int j = 0; j < 11; j++) {
			for (int k = 0; k < 6; k++) {
				if (U.x[j][k] != '.' && U.x[j + 1][k] == '.')swap(U.x[j][k], U.x[j + 1][k]);
			}
		}
	}
	return make_pair(U, update);
}
int main() {
	int t; cin >> t;
	for (int i = 0; i < t; i++) {
		State V;
		for (int j = 0; j < 12; j++) { for (int k = 0; k < 6; k++)cin >> V.x[j][k]; }
		int cnt = 0;
		while (true) {
			pair<State, bool>D = solve(V);
			if (D.second == false)break;
			V = D.first; cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3048
#include<iostream>

using namespace std;
int main(){
  int A,B;
  int count=0;
  cin >> A >> B;
  
  
  if(A>B){
    count+=A;
    A--;
  }else{
    count+=B;
    B--;
  }
  
  if(A>B){
    count+=A;
    A--;
  }else{
    count+=B;
    B--;
  }
  
  cout << count << endl;
  
  return 0;
}

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

vector<long long> enum_divisors(long long N){
    vector<long long> res;
    for(long long i=1;i*i<=N;i++){
        if(N%i==0){
            res.push_back(i);
            if(N/i!=i) res.push_back(N/i);
        }
    }
    sort(res.begin(),res.end());
    return res;
}

int main(){
    ll n,m;
    cin >> n >> m;
    auto em=enum_divisors(m);
    ll ans=1;
    for(ll i=0;i<em.size();i++){
        if(em[i]>=n){
            ans=m/em[i];
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
using namespace std;
int main(){
  char s[10];
  cin >> s;
  string ans;
  int i=0;
  while(s[i]!='\0'){
    if((s[i]=='0')||(s[i]=='1')){
      ans+=s[i];
    }else{
      if(ans.size()!=0){
        ans.pop_back();
      }
    }
    i++;
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

const ll mod = 1e9+7;
const ll hlf = 5e8+4;

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

	int n, q;
	cin >> n >> q;

	vi as(n);
	trav(x, as) cin >> x;

	vector<vector<ll>> mat(n, vector<ll>(n));
	rep(i,0,n) rep(j,0,n) mat[i][j] = (as[i]>as[j]) - (as[j]>as[i]);

	rep(_,0,q){
		int x, y;
		cin >> x >> y;
		--x, --y;
		rep(k,0,n){
			ll res = mat[x][k] + mat[y][k];
			res *= hlf;
			res %= mod;
			mat[x][k] = mat[y][k] = res;
		}
		rep(k,0,n){
			ll res = mat[k][x] + mat[k][y];
			res *= hlf;
			res %= mod;
			mat[k][y] = mat[k][x] = res;
			
		}
	}

	ll ans = 0;

	rep(i,0,n) rep(j,0,i) ans += mat[j][i];
	rep(i,0,n) rep(j,0,i) ans += (as[i]!=as[j]);
	rep(i,0,q) ans = ans * 2 % mod;
	ans = ans * hlf % mod;
	if(ans < 0) ans += mod;

	cout << ans << endl;
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vec a = ivec(n);
    vec b(n);
    b[0] = a[0];
    For(i, 1, n - 1) b[i] = max(b[i - 1], a[i]);
    int ans = 0;
    rep (i, n)
        ans += b[i] - a[i];
    print(ans);

    return 0;
}


Measured memory_bytes: 6348
#include <algorithm>
#include <cstdio>
#include <vector>


using i64 = long long;

int main() {
  i64 n;
  scanf("%lld", &n);
  n += 2;
  std::vector<i64> a(n);
  a[0] = a[n - 1] = n;
  for (i64 i = 1; i != n - 1; ++i) {
    scanf("%lld", &a[i]);
  }

  std::vector<i64> pp(n), p(n), s(n), ss(n), st0, st1, temp;
  st0.reserve(n);
  st1.reserve(n);
  temp.reserve(n);
  {
    st0.push_back(0);
    st1.push_back(0);
    for (i64 l = 1; l <= n; ++l) {
      const i64 i = std::min(l, n - 1);
      while (a[st1.back()] < a[i]) {
        ss[st1.back()] = i;
        st1.pop_back();
      }
      while (a[st0.back()] < a[i]) {
        s[st0.back()] = i;
        temp.push_back(st0.back());
        st0.pop_back();
      }
      st0.push_back(i);
      while (!temp.empty()) {
        st1.push_back(temp.back());
        temp.pop_back();
      }
    }
    st0.clear();
    st1.clear();
  }
  {
    st0.push_back(n - 1);
    st1.push_back(n - 1);
    for (i64 l = n - 2; l >= -1; --l) {
      const i64 i = std::max(l, i64(0));
      while (a[st1.back()] < a[i]) {
        pp[st1.back()] = i;
        st1.pop_back();
      }
      while (a[st0.back()] < a[i]) {
        p[st0.back()] = i;
        temp.push_back(st0.back());
        st0.pop_back();
      }
      st0.push_back(i);
      while (!temp.empty()) {
        st1.push_back(temp.back());
        temp.pop_back();
      }
    }
    st0.clear();
    st1.clear();
  }

  i64 ans = 0;
  for (i64 i = 1; i != n; ++i) {
    ans += a[i] * ((p[i] - pp[i]) * (s[i] - i) + (i - p[i]) * (ss[i] - s[i]));
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 6400
from collections import defaultdict
import itertools

n, m = map(int, input().split())
connected_dict = defaultdict(lambda: [])

for i in range(m):
    a, b = map(int, input().split())
    connected_dict[a].append(b)
    connected_dict[b].append(a)

count = 0
for permutation in list(itertools.permutations(range(2, n + 1))):
    flag = True
    pre_num = 1
    for num in permutation:
        if num not in connected_dict[pre_num]:
            flag = False
            break
        pre_num = num
    if flag:
        count += 1
print(count)


Measured memory_bytes: 40048
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;

#define ran 111111

int n;
vector<int> e[ran];
char c[ran];
int sz[ran];
bool del[ran], is_leaf[ran];
int q[ran], l, r;

int get_par(int cur) {
	for(int i=0;i<e[cur].size();i++) {
		int nxt = e[cur][i];
		if(!del[nxt]) return nxt;
	}
	return -1;
}
int get_leaf(int cur) {
	int res = 0;
	for(int i=0;i<e[cur].size();i++) {
		int nxt = e[cur][i];
		if (!del[nxt] && is_leaf[nxt]) res++;
	}
	return res;
}

int main() {
	scanf("%d", &n);
	for(int i=1;i<n;i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	memset(del, false, sizeof del);
	memset(is_leaf, false, sizeof is_leaf);
	l=r=0;
	for(int i=1;i<=n;i++) {
		sz[i] = e[i].size();
		if(sz[i]==1) {
			is_leaf[i] = true;
			q[r++] = i;
		}
	}
	while(l<r) {
		int cur = q[l++];
		if(sz[cur]==0) {
			bool chk = true;
			for(int i=0;i<e[cur].size() && chk;i++) {
				int nxt = e[cur][i];
				if(c[nxt]=='B') chk = false;
			}
			if(chk) {
				puts("First");
				return 0;
			}
			continue;
		}
		int par = get_par(cur);
		if (get_leaf(par) > 1) {
			puts("First");
			return 0;
		}
		del[cur] = true;
		del[par] = true;
		c[cur] = 'B';
		c[par] = 'W';
		for(int i=0;i<e[par].size();i++) {
			int nxt = e[par][i];
			sz[nxt] --;
			if(sz[nxt]==1) q[r++] = nxt;
		}
	}
	puts("Second");
	
	return 0;
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<set>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;

int main(){
    int n;
    cin>>n;
    int p=n%10;
    if(p==2||p==4||p==5||p==7||p==9) cout<<"hon"<<endl;
    else if (p==0||p==1||p==6||p==8) cout<<"pon"<<endl;
    else cout<<"bon"<<endl;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
int main(void)
{
	char b;
	char a[100];
	scanf("%s",a);
	if(strcmp(a,"ani")==0){
		printf("square1001");
	}
	else if(strcmp(a,"otouto")==0){
		printf("e869120");
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 2108
#include <iostream>

int main()
{
    std::string s;
    int n, i, cnt, ans, right, left;

    std::cin >> n >> s;

    ans = 0; cnt = 0; right = 0; left = 0;
    for(i = 1;i < n - 1;i++) {
        for (char c = 'a';c <= 'z';c++) {
            for (int l = 0;l < i;l++) {
                if(s[l] == c) {
                    right++;
                }
            }
            for (int l = i;l < n;l++) {
                if(s[l] == c) {
                    left++;
                }
            }

            if (left != 0 && right != 0) {
                cnt++;
            }
            right = 0; left = 0;
        }
        if(ans < cnt) {
            ans = cnt;
        }
        cnt = 0;
    }

    std::cout << ans <<"\n";
    
    return 0;
}

Measured memory_bytes: 384
// Problem : C - Interpretation
// Contest : AtCoder - CODE FESTIVAL 2016 Final
// URL : https://atcoder.jp/contests/cf16-final/tasks/codefestival_2016_final_c
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int n,m,deg[maxn],vis[maxn];
map<int,int> mp;
vector<int> adj[maxn];
void dfs(int curr)
{
	vis[curr]++;
	for(auto x:adj[curr])
	{
		if(vis[x]==0)
		dfs(x);
	}
}
void solve()
{
	cin >> n >> m;
	rep(i,0,n)
	{
		int k,prev,curr;
		cin >> k;
		rep(i,0,k)
		{
			if(i == 0)
				cin >> curr;
			else 
			{
				cin >> curr;
				adj[curr].pb(prev);
				adj[prev].pb(curr);
				deg[curr]++;
				deg[prev]++;
				prev = curr;
			}
			mp[curr]++;
			prev=curr;
		}
	}
	for(int i=1;i<=m;i++)
	{
		if(deg[i] > 0)
		{
			dfs(i);
			break;
		}
	}
	for(int i=1;i<=m;i++)
	{
		if(deg[i] > 0 and vis[i] == 0)
		{
			cout << "NO" <<"\n";
			return;
		}
	}
	for(int i=1;i<=m;i++)
	{
		if(mp.count(i) and vis[i]==0 and mp.size()>1)
		{
			cout <<"NO"<<"\n";
			return;
		}
	}
	cout << "YES" <<"\n";
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 17368
a = [i for i in input()]
target1 = []
target2 = []
for i, n in enumerate(a):
    if i % 2 == 0:
        target1.append('1')
        target2.append('0')
    else:
        target1.append('0')
        target2.append('1')

result1 = 0
result2 = 0
for i, el in enumerate(a):
    if target1[i] != el:
        result1 += 1
    if target2[i] != el:
        result2 += 1

print(min(result1, result2))

Measured memory_bytes: 5528
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  cin >> n;
  n %= 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
    cout << "hon" << endl;
  if (n == 0 || n == 1 || n == 6 || n == 8)
    cout << "pon" << endl;
  if (n == 3)
    cout << "bon" << endl;

  return 0;
}


Measured memory_bytes: 3632
// Working program with FastReader
import java.io.BufferedReader; 

import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer;
import java.lang.*;
public class Main
{ 
	static class FastReader 
	{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

		int nextInt() 
		{ 
			return Integer.parseInt(next()); 
		} 

		long nextLong() 
		{ 
			return Long.parseLong(next()); 
		} 

		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	} 

	long gcd(long a, long b) {
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
	public static void main(String[] args) {
		FastReader ob = new FastReader();
		int n = ob.nextInt();
		String s =ob.next();
		int count=0;
		for (int i = 0; i < n-2; ) {
			if(s.charAt(i)=='A' && s.charAt(i+1)=='B' && s.charAt(i+2)=='C' ) {
				count++;
				i+=3;
				//System.out.println(i);
			}
			else {
				i++;
			}
			
		}
		System.out.println(count);
	}

} 


Measured memory_bytes: 22484
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>

int n, m, k;
using namespace std;

int main() {
	cin >> n >> m >> k;
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= m; j++){
			if(i * m + j * n - i * j * 2 == k){
				cout << "Yes" << endl;
				return 0;
			} 
		}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(void){
	int h, w;
    while(true){
        scanf("%d %d", &h, &w);
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if ((i % 2 == 1 && j % 2 == 0) ||
                    (i % 2 == 0 && j % 2 == 1)) {
                    printf(".");
                } else {
                    printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
}



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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++)
	{
		string c;
		cin >> c;
		cout << c << "\n"
				 << c << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector <int> a(m);
  REP(i, m) {
	cin >> a[i];
  }
  int ans = n;
  REP(i, m) {
	ans -= a[i];
  }
  cout << max(-1, ans) << endl;
  return 0;
}


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

int main(){
  string c1, c2;
  cin >> c1 >> c2;
  
  if(c1[0]==c2[2] && c1[1]==c2[1] && c1[2]==c2[0]){
    cout << "YES" << endl;
  }
  else{cout << "NO" << endl;}
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int K = Integer.parseInt(scan.next());
		int[] x = new int[N];
		for (int i = 0; i < N; i++) {
			x[i] = Integer.parseInt(scan.next());
		}
		int time;
		int minTime;
		minTime = Math.min(Math.abs(x[0]) + Math.abs(x[K - 1] - x[0]), Math.abs(x[K - 1]) + Math.abs(x[K - 1] - x[0]));
		for (int i = 1; i < N - K + 1; i++) {
			time = Math.min(Math.abs(x[i]) + Math.abs(x[K + i - 1] - x[i]),
					Math.abs(x[K + i - 1]) + Math.abs(x[K + i - 1] - x[i]));
			minTime = Math.min(minTime, time);
		}
		System.out.println(minTime);
	}
}


Measured memory_bytes: 48732
#include<stdio.h>

int main(void){
int h,w;
int i,j;
while(1){
scanf("%d %d",&h,&w);
if(h == 0 && w == 0)break;

for(i=0;i<h;i++){
for(j=0;j<w;j++){
  printf("#");
}
  printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin >> a >> b;
	if(a<b){
		int t=a;
		a=b;
		b=t;
	}
	for(int i=0;i<a;i++){
		cout << b;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

N = int(input())
A = [int(x) for x in input().split()]

f = 1
x1 = 0
for a in A:
    x1 += (a * f)
    f *= -1

x1 /= 2

X = []
X.append(x1)

for i in range(N - 1):
    x = A[i] - X[i]
    X.append(x)

X = [str(int(2 * x)) for x in X]
# print(X)

print(" ".join(X))


Measured memory_bytes: 18876
from typing import List


def main():
    n = int(input())
    nums = input().split(' ')
    r = don(n, nums)
    if r:
        print('YES')
    else:
        print('NO')


def don(n: int, nums: List[str]) -> bool:
    s = set()
    result = True

    for i in range(n):
        num = nums[i]
        if num in s:
            result = False
            break
        s.add(num)

    return result


if __name__ == '__main__':
    main()


Measured memory_bytes: 38380
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
using ll = long long;

int main(){
    string s;
    ll k;
    cin >> s >> k;
    for(int i = 0;i < s.length();i++){
        if(s[i]!='1'){
            if(i >= k){cout << 1;return 0;}
            else {cout << s[i];return 0;}
        }
    }
    cout << 1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    int ans=0;
    cin >> n;
    map<string,int> cnt;
    rep(i,n){
        string a;
        cin >> a;
        cnt[a]++;
    }
    for(auto c:cnt){
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 19252
event = []
inning = int(input())


NONE   = 0b000
FIRST  = 0b001
SECOND = 0b010
THIRD  = 0b100

runner = NONE
currentInning = 0
score = 0
outCount = 0
inningScore = []

while currentInning < inning:
    data = input()
    if data == "HIT":
        if (runner & THIRD) == THIRD:
            score += 1
            runner &= ~THIRD
        runner = runner << 1
        runner |= FIRST
    elif data == "OUT":
        outCount += 1

    elif data == "HOMERUN":
        if (runner & THIRD) == THIRD:
            score += 1
        if (runner & SECOND) == SECOND:
            score += 1
        if (runner & FIRST) == FIRST:
            score += 1
        score += 1
        runner = NONE
    
    if outCount == 3:
        inningScore.append(score)
        currentInning += 1
        outCount = 0
        score = 0
        runner = NONE

for i in range(inning):
    print(inningScore[i])



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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    bool ans = true;
    rep(i, n)
    {
        if (a[i] % 2 == 0)
        {
            if (a[i] % 3 != 0 && a[i] % 5 != 0)
            {
                ans = false;
                break;
            }
        }
    }
    if (ans)
    {
        cout << "APPROVED" << endl;
    }
    else
    {
        cout << "DENIED" << endl;
    }
    return 0;
}

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

int main(){
    lint n;
    cin >> n;
    lint cntr = 0;
    for(lint i=sqrt(n); i>0; i--){
        if(n%i == 0){
            cntr+= n/i + i;
            break;
        }
    }
    cout << cntr -2;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+9;
const int mod=1e9+7;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    ll n=0;
    cin>>s;
    for(int i=0;i<s.size();i++){
    	n+=s[i]-'0';
    }
    cout<<(n%9==0?"Yes":"No");
    
    

}


    


Measured memory_bytes: 3708
while 1:
	n = input().split()
	a = int(n[0])
	op = n[1]
	b = int(n[2])
	if op == "?":
		break
	if op == "+":
		print(a+b)
	elif op == "-":
		print(a-b)
	elif op == "*":
		print(a*b)
	elif op == "/":
		print(int(a/b))

Measured memory_bytes: 7644
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int makeframe(int h, int w){
    for ( int i = 0; i < h; i++ ){
        if (i == 0 || i == h-1 ){
            for ( int j = 0; j < w; j++ ){
                cout << "#";
            }
        }
        else {
            for ( int j = 0; j < w; j++ ){
                if (j == 0 || j == w-1){
                cout << "#";
                }
                else {
                    cout << ".";
                }
            }
        }
        cout << endl;
        
    }
    return 0;
}

int main(){
    int a, c, d;
    a = 0, c = 1, d = 1;
    while ( c > 0 || d > 0 ){
        cin >> c >> d;
        if ( c > 0 || d > 0 ){
            makeframe(c,d);
            cout << endl;
        }
       
    }
    
    
    
    return 0;
    
}



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

int main(){

    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;

    rep(i,n){
        cout << s[i] << t[i] ;
    }cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    string s;
    cin>>s;
    int a=(s[0]-'0')*10+(s[1]-'0');
    int b=(s[2]-'0')*10+(s[3]-'0');
    bool mma=(1<=a&&a<=12);
    bool mmb=(1<=b&&b<=12);
    if(mma&&mmb){
        cout<<"AMBIGUOUS"<<endl;
    }else if(mma){
        cout<<"MMYY"<<endl;
    }else if(mmb){
        cout<<"YYMM"<<endl;
    }else{
        cout<<"NA"<<endl;
    }
}


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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  d=d*d;
  
  int ac,ab,bc;
  ac=(a-c)*(a-c);
  ab=(a-b)*(a-b);
  bc=(b-c)*(b-c);
  
  if(ac<=d){
    cout<<"Yes"<<endl;
	}
  else if(ab<=d && bc<=d){
    cout<<"Yes"<<endl;
	}
  else{
    cout<<"No"<<endl;
	}

  }

Measured memory_bytes: 256
while True:
  try:
    n = int(input())
    count = 0
    for a in range(10):
      for b in range(10):
        for c in range(10):
          for d in range(10):
            if a + b + c + d == n:
              count += 1
    print(count)
  except EOFError:
    break


Measured memory_bytes: 5596
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;

void main(){
	auto S = readln.chomp;
	auto F = S[0..2].to!int;
	auto R = S[2..$].to!int;

	if((1<=F&&F<=12) && (1<=R&&R<=12)) writeln("AMBIGUOUS");
	else if(1<=F&&F<=12) writeln("MMYY");
	else if(1<=R&&R<=12) writeln("YYMM");
	else writeln("NA");
}

Measured memory_bytes: 256
#include<stdio.h>

void m_multiple(int a[100][100], int b[], int c[], int n, int m){
    int i, j;
    for (i = 0; i < n;i++){
        for (j = 0; j < m;j++){
            c[i] += a[i][j] * b[j];
        }
    }
}

int main(void){
    int n, m;
    int i, j;
    int a[100][100];
    int b[100];
    int c[100];
    for (i = 0; i < 100;i++){
        c[i] = 0;
    }
        scanf("%d %d", &n, &m);
    for (i = 0; i < n;i++){
        for (j = 0; j < m;j++){
            scanf("%d", &a[i][j]);
        }
    }
    for (i = 0; i < m;i++){
        scanf("%d", &b[i]);
    }
    m_multiple(a, b, c, n, m);
    for (i = 0; i < n;i++){
        printf("%d\n", c[i]);
    }
    return 0;
}


Measured memory_bytes: 2088
W, H, N = map(int, input().split())

right = W
left = 0
top = H
bottom = 0

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and left <= x:
        left = x
    elif a == 2 and right >= x:
        right = x
    elif a == 3 and bottom <= y:
        bottom = y
    elif a == 4 and top >= y:
        top = y

if (top-bottom)*(right-left) > 0 and (top-bottom)>0 and (right-left)>0:
    print((top-bottom)*(right-left))
else:
    print(0)


Measured memory_bytes: 3064