akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    a = root(a);
    return -Parent[a];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(a < b) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }

};

int main(){
  ll n,m; cin >> n >> m;
  vi a(m),b(m);
  rep(i,m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  vl ans(m);
  ans[m-1] = n*(n-1)/2;

  UnionFind Uni(n);

  rrep(i,m) {
    if(i == 0) continue;
    ans[i-1] = ans[i];
    if(!Uni.issame(a[i], b[i])){
      ans[i-1] -= (ll)Uni.size(a[i]) * Uni.size(b[i]);
      Uni.merge(a[i], b[i]);
    }
  }
  rep(i,m) cout << ans[i] << endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<utility>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
//#define t ll t;cin>>t;while(t--)
#define nn cout<<endl;
#define ff(a,n) for(ll i=a;i<n;i++)
#define cY cout<<"YES\n"
#define cN cout<<"NO\n"
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
#define sc second
#define fs first
#define c(a) cout<<a<<endl

void solve()
{
	ll n; cin>>n; ll a[n];
	ff(0,n)cin>>a[i];
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			if(a[i]==a[j])continue;
			for(ll k=j+1;k<n;k++)
			{
				if(a[i]==a[k]||a[j]==a[k])continue;
				if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i])ans++;
			} 
		} 
	} 
	cout<<ans<<endl;
}

int main()
{
	solve();
}
/*
10
9 4 6 1 9 6 10 6 6 8



*/


Measured memory_bytes: 3592
import sys
p = [[int(c) for c in r.split()] for r in sys.stdin.read().split('\n') if r != '']
n = p[0][0]
if n == 1:
    print('Yes')
    quit()
h = p[1]
h.reverse()
for i in range(len(h)-1):
    if h[i] + 1 < h[i+1]:
        print('No')
        quit()
    if h[i] < h[i+1]:
        h[i+1] -= 1
if h[i] < h[i+1]:
    print('No')
else:
    print('Yes')

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

int main(){
  ll P = 1000000007, N;
  cin >> N;
  ll u = 1, n8 = 1,n9 = 1;
  for(ll i = 0; i < N; i++){
    u = (u * 10) % P;
    n8 = (n8 * 8) % P;
    n9 = (n9 * 9) % P;
  }
  ll ans = (u + n8 - 2 * n9 + 3*P) % P;
  cout << ans;
}


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

int main() {
  string S;
  int N;
  cin >> N >> S;
  for(int i = 0; i < S.length(); i++){
  	char c = S[i] + N;
    if(c > 90){
    	c = 'A' + (c - 91);
    }
    cout << c;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#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<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
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<<57;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}
 
ll Combination(int n,int k){
	vl a(k);
	for(int i=0;i<k;i++) a[i]=n-i;
	for(int i=1;i<=k;i++){
		int I=i;
		for(int j=0;j<k;j++){
			ll g=gcd(a[j],I);
			a[j]/=g;
			I/=g;
		}
	}
	ll res=1;
	for(int i=0;i<k;i++) res*=a[i];
	return res;
}

int n,s,t;
vl a;

int main(){
	cout<<syosu(9);
	cin>>n>>s>>t;
	a=vl(n);
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a.rbegin(),a.rend());
	bool flag=1;
	double ave=0;
	ll res=0;
	for(int i=0;i<s;i++){
		if(i!=n-1&&a[i]!=a[i+1]) flag=0;
		ave+=a[i];
	}
	ave/=s;
	cout<<ave<<endl;
	for(int i=s-1;i<t;i++){
		if(i!=n-1&&a[i]!=a[i+1]) flag=0;
		int num1=0,num2=0;
		for(int j=0;j<n;j++) if(a[j]==a[i]) num1++;
		for(int j=0;j<=i;j++) if(a[j]==a[i]) num2++;
		res+=Combination(num1,num2);
		if(!flag) break;
	}
	cout<<res<<endl;
}

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

using namespace std;

int N, K;

const long int INF = 1e9 + 7;

long dfs( vector<int> G[], int v, int last )
{
    int nc;
    if ( last == -1 ) {
        nc = K-1;
    } else {
        nc = K-2;
    }
    long int num = 1;
    for ( int i = 0; i < G[v].size(); i ++ ) {
        if ( last == G[v][i] ) continue;
        num *= nc;
//        cout << v << " " << G[v][i] << "  x " << nc << endl;
        nc --;
        num %= INF;
    }
    for ( int i = 0; i < G[v].size(); i ++ ) {
        if ( last == G[v][i] ) continue;
        num *= dfs( G, G[v][i], v );
        num %= INF;
    }
    
    return num;
}

int main()
{

    cin >> N >> K;
    vector<int> E[N];

    for ( int i = 0; i < N-1; i ++ ) {
        int a, b;
        cin >> a >> b;
        a --;
        b --;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    long num = dfs( E, 0,  -1 ) * K;
    num %= INF;
    cout << num << endl;

    return 0;
}

Measured memory_bytes: 11520
#include<stdio.h>
#include <string.h>
int main()
{
    char s[100] , t[100] , temp;
    int a , i , j;

    scanf("%s%s",&s,&t);

    for(a=0;s[a]!='\0';++a);

    for(i=0;i<a;i++)
    {
        if(strcmp(s,t)==0)
        {
            printf("Yes\n");
            goto here;
        }
        temp = s[0];
        for(j = 0; j<a-1; j++)
        {
            s[j] = s[j+1];
        }
        s[a-1] = temp;
    }

    printf("No\n");

    here:
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int n; cin>>n;
    int d[n]; rep(i,n) cin>>d[i];
    int total=0;
    
    rep(i,n-1){
        for(int j=i+1; j<n; j++) total += d[i]*d[j];
    }

    cout << total << ln;
    return 0;
 }


Measured memory_bytes: 256
import itertools
N,M,X = map(int,input().split())
costs = []
books = []
for _ in range(N):
    entry = list(map(int,input().split()))
    costs.append(entry[0])
    books.append(entry[1:])
    
mxcost = sum(costs) + 1
lst = [list(i) for i in itertools.product([0, 1], repeat=N)]
for item in lst:
    cost = sum([item[0]*item[1] for item in zip(costs,item)])
    Xs = [0] * M
    for i in range(N):
        if item[i] == 1:
            for j in range(M):
                Xs[j] += books[i][j]
    if min(Xs) >= X:
        mxcost = min(mxcost,cost)

if mxcost == sum(costs) + 1:
    print(-1)
else:
    print(mxcost)
    

Measured memory_bytes: 9608
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;

void Main() {
  char s[100001];
  cin >> s;
  int n = strlen(s);
  for (int i = 0; i < n; i += 2) {
    printf("%c", s[i]);
  }
}

int main() {
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15);  // 小数を10進数表示
  Main();
}

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

using namespace std;

class UnionFind {
public:
  UnionFind(long long n);
  long long size(long long n);
  bool merge(long long a, long long b);
  long long root(long long a);
  bool isSame(long long a, long long b);

private:
  long long N;
  std::vector<long long> parentArr;
  std::vector<long long> sizeArr;
  std::vector<long long> rankArr;
};

UnionFind::UnionFind(long long n) {
  N = n;
  parentArr.resize(n);
  sizeArr.resize(n);
  rankArr.resize(n);

  for (long long i = 0; i < n; i++) {
    parentArr[i] = i;
    sizeArr[i] = 1;
    rankArr[i] = 0;
  }
}

long long UnionFind::size(long long a) { return sizeArr[root(a)]; }

bool UnionFind::merge(long long a, long long b) {
  long long root_a = root(a);
  long long root_b = root(b);

  if (root_a == root_b) {
    return false;
  }

  if (rankArr[root_a] < rankArr[root_b]) {
    parentArr[root_a] = root_b;
    sizeArr[root_b] += sizeArr[root_a];
  } else {
    parentArr[root_b] = root_a;
    sizeArr[root_a] += sizeArr[root_b];
    if (rankArr[root_a] == rankArr[root_b]) {
      rankArr[root_a]++;
    }
  }
  return true;
}

long long UnionFind::root(long long a) {
  long long tmp = a;
  while (tmp != parentArr[tmp]) {
    tmp = parentArr[tmp];
  }
  return parentArr[a] = tmp;
}

bool UnionFind::isSame(long long a, long long b) { return root(a) == root(b); }

int main(int argc, char const *argv[]) {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> edge(M + 1);
  for (int i = 1; i < M + 1; i++) {
    cin >> edge[i].first >> edge[i].second;
  }

  int ans = 0;
  for (int i = 1; i < M + 1; i++) {
    UnionFind uf(N + 1);
    for (int j = 1; j < M + 1; j++) {
      if (j != i) {
        uf.merge(edge[j].first, edge[j].second);
      }
    }
    if (uf.size(1) != N) {
      ans++;
    }
  }
  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
from collections import deque

K = int(input())

queue = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

x = 1
count = 0
while K != count:
    x = queue.popleft()
    if (x % 10) != 0:
        queue.append(10 * x + (x % 10) - 1)
    queue.append(10 * x + (x % 10))
    if (x % 10) != 9:
        queue.append(10 * x + (x % 10) + 1)
    count += 1
print(x)


Measured memory_bytes: 40944
import copy

N = int(input())
num = list(map(int,input().split()))
memo = copy.deepcopy(num)
num.sort()

ans1 = num[0]
ans2 = num[N-1]
min = abs(ans2/2-num[0])
for i in range(1,N-1):
  if abs(ans2/2-num[i]) < min:
    ans1 = num[i]
    min = abs(ans2/2-num[i])
print(ans2,ans1)

Measured memory_bytes: 14812
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::pair<ll, ll> pll;

using namespace std;

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

    set<ll> ans;

    irep(i, n) {
        ll tmp;
        cin >> tmp;
        if(ans.find(tmp) != ans.end()) {
            ans.erase(tmp);
        } else {
            ans.insert(tmp);
        }
    }

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

    return 0;
}


Measured memory_bytes: 4864
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/
#include<bits/stdc++.h>
#define mod 1000000007
#define modc 998244353
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define deb(x) cout << #x << " " << x << endl;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using namespace std;
void solve()
{
	int n;
	cin >> n;
	string a = to_string(n);
	if(a[0] == '7' || a[1] == '7' || a[2] == '7')
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	while(t--)
		solve();
}


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

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

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

using real = double;
real EPS = 1e-10;
struct Point {
    real x, y;
    Point& operator+=(const Point a) { x += a.x; y += a.y;  return *this; }
    Point& operator-=(const Point a) { x -= a.x; y -= a.y;  return *this; }
    Point& operator*=(const real k) { x *= k; y *= k;  return *this; }
    Point& operator/=(const real k) { x /= k; y /= k;  return *this; }
    Point operator+(const Point a) const {return Point(*this) += a; }
    Point operator-(const Point a) const {return Point(*this) -= a; }
    Point operator*(const real k) const {return Point(*this) *= k; }
    Point operator/(const real k) const {return Point(*this) /= k; }
    bool operator<(const Point &a) const { return (x != a.x ? x < a.x : y < a.y); }
    explicit Point(real a = 0, real b = 0) : x(a), y(b) {};
};

istream& operator>> (istream& s, Point& P){
    s >> P.x >> P.y;
    return s;
}

inline real dot(Point a, Point b){ return a.x*b.x + a.y*b.y; }
inline real cross(Point a, Point b){ return a.x*b.y - a.y*b.x; }
inline real abs(Point a){ return sqrt(dot(a, a)); }

static constexpr int COUNTER_CLOCKWISE = 1;
static constexpr int CLOCKWISE = -1;
static constexpr int ONLINE_BACK = 2;
static constexpr int ONLINE_FRONT = -2;
static constexpr int ON_SEGMENT = 0;

int ccw(Point a, Point b, Point c){
    b -= a; c -= a;
    if(cross(b, c) > EPS) return COUNTER_CLOCKWISE;
    if(cross(b, c) < -EPS) return CLOCKWISE;
    if(dot(b, c) < 0) return ONLINE_BACK;
    if(abs(b) < abs(c)) return ONLINE_FRONT;
    return ON_SEGMENT;
}
struct Segment {
    Point a, b;
    Segment(Point x, Point y) : a(x), b(y) {};
};

double distance(Segment l, Point c){
    if(dot(l.b-l.a, c-l.a) < EPS) return abs(c-l.a);
    if(dot(l.a-l.b, c-l.b) < EPS) return abs(c-l.b);
    return abs(cross(l.b-l.a, c-l.a)) / abs(l.a-l.b);
}

bool intersect(Segment l1, Segment l2){
    return (ccw(l1.a, l1.b, l2.a)*ccw(l1.a, l1.b, l2.b) <= 0 &&
            ccw(l2.a, l2.b, l1.a)*ccw(l2.a, l2.b, l1.b) <= 0);
}

Point crossPoint(Segment l1, Segment l2){
    real d1 = abs(cross(l1.b-l1.a, l2.b-l2.a));
    real d2 = abs(cross(l1.b-l1.a, l1.b-l2.a));
    if(d1 < EPS && d2 < EPS) return l2.a;
    return l2.a+(l2.b-l2.a)*d2/d1;
}

Point project(Segment s, Point p){
    Point Q = s.b-s.a;
    return s.a + Q*(dot(p-s.a, Q) / dot(Q, Q));
}

Point refrect(Segment s, Point p){
    Point Q = project(s, p);
    return Q*2-p;
}


int main(){
    Point a, b;
    cin >> a >> b;
    Segment s(a, b);
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        Point P;
        cin >> P;
        Point ans = refrect(s, P);
        printf("%.10lf %.10lf\n", ans.x, ans.y);
    }
    return 0;
}


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

signed main(){
    ll N;
    cin >> N;
    for(int h = 1; h <= 3500; h++){
        for(int n = 1; n <= 3500; n++){
            if((4 * h * n - (h + n) * N) != 0 && (h * n * N) % (4 * h * n - (h + n) * N) == 0 && (h * n * N) / (4 * h * n - (h + n) * N) > 0){
                cout << h << " " << n << " " << (h * n * N) / (4 * h * n - (h + n) * N) << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

int n;
int A[20];

bool solve(int i, int m) {
  if (m == 0) return true;
  if (i >= n) return false;
  bool res = (solve(i+1, m-A[i]) || solve(i+1, m));
  return res;
}

int main() {
  int q;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int val;
    cin >> val;
    if (solve(0, val)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

struct edge {
  ll to, cap, cost, rev;
};
ll V = 3500;
vector<edge> G[3500];
ll h[3500];  // potential
ll dist[3500];
ll prevv[3500], preve[3500];

void add_edge(ll from, ll to, ll cap, ll cost) {
  G[from].push_back((edge){to, cap, cost, G[to].size()});
  G[to].push_back((edge){from, 0, -cost, G[from].size() - 1});
}

// if impossible return -1
ll mincostflow(ll s, ll t, ll f) {
  ll res = 0;
  fill(h, h + V, 0);
  while (f > 0) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(dist, dist + V, INF);
    dist[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      ll v = p.second;
      if (dist[v] < p.first) continue;
      for (ll i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
          dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
          prevv[e.to] = v;
          preve[e.to] = i;
          que.push(P(dist[e.to], e.to));
        }
      }
    }
    if (dist[t] == INF) return -1;
    for (int v = 0; v < V; v++) h[v] += dist[v];
    ll d = f;
    for (ll v = t; v != s; v = prevv[v]) {
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * h[t];
    for (ll v = t; v != s; v = prevv[v]) {
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}
string s[55];
int n, m;

bool val(int i, int j) {
  if (i < n && j < m && s[i][j] != '#') return 1;
  return 0;
}

VVI d;
void dfs2(int s, int t) {
  if (val(s + 1, t) && d[s + 1][t] == -1) {
    d[s + 1][t] = d[s][t] + 1;
    dfs2(s + 1, t);
  }
  if (val(s, t + 1) && d[s][t + 1] == -1) {
    d[s][t + 1] = d[s][t] + 1;
    dfs2(s, t + 1);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int i, j;
  cin >> n >> m;
  VP v;
  for (i = 0; i < n; i++) cin >> s[i];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == 'o') v.pb(P(i, j));
    }
  }
  int st = 3488;
  for (i = 0; i < v.size(); i++) {
    d = VVI(n, VI(m, -1));
    d[v[i].fi][v[i].se] = 0;
    dfs2(v[i].fi, v[i].se);

    add_edge(st, n * m + i, 1, 0);

    for (j = 0; j < n; j++) {
      for (int k = 0; k < m; k++) {
        if (d[j][k] >= 0) add_edge(n * m + i, j * m + k, 1, -d[j][k]);
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      add_edge(i * m + j, st + 1, 1, 0);
    }
  }
  cout << -mincostflow(st, st + 1, v.size()) << endl;
}

Measured memory_bytes: 9788
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
int n;
int w[101];
int kijyun;
int min=999999;
int s1=0,s2=0;
scanf("%d",&n);

for(int i=0;i<n;i++){
    scanf("%d",&w[i]);
}


    for(int i=0;i<n;i++){
        s1=0;s2=0;
        kijyun=i;
        for(int j=0;j<n;j++){
                if(i<=j){
                    s1=s1+w[j];
                }
                else{s2=s2+w[j];}
            
        }
        int minh=abs(s1-s2);
        //printf("%d %d\n",s1,s2);
        if(min>=minh){min=minh;}
    }
    printf("%d",min);

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define err(A) cout << #A << " = " << (A) << endl
using namespace std;
const int N=2e5+100;
int32_t main(){
    string s;
    cin >> s;
    if (s.size()%2==1) {
        cout << "No" << endl;
        return 0;
    }
    for (int i=0;i<s.size();i+=2){
        if (s[i]!='h' || s[i+1]!='i') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;

int main() {
	string O, E;
	cin >> O >> E;

	int n = (int)E.size();
	for (int i = 0; i < n; i++) {
		cout << O[i] << E[i];
	}
	if ((int)O.size() > n) cout << O.back() << endl;
	else cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int X[3], A, B, C;
    cin >> X[0] >> X[1] >> A >> B >> C;
    priority_queue<Pll> que;
    ll x;
    for(int i=0;i<A;++i) {
        cin >> x;
        que.emplace(x, 0);
    }
    for(int i=0;i<B;++i) {
        cin >> x;
        que.emplace(x, 1);
    }
    for(int i=0;i<C;++i) {
        cin >> x;
        que.emplace(x, 2);
    }

    int n[3] = {0, 0, 0};
    vector<ll> sum_xy(200001, 0), sum_z(100001, 0);
    while(!que.empty()) {
        Pll p = que.top(); que.pop();
        if(p.second == 2) {
            ++n[2];
            sum_z[n[2]] = sum_z[n[2]-1] + p.first;
        } else {
            if(n[p.second] == X[p.second]) continue;
            ++n[p.second];
            sum_xy[n[0]+n[1]] = sum_xy[n[0]+n[1]-1] + p.first;
        }
    }

    ll ans = 0;
    for(int i=0;i<=C;++i) {
        if(X[0]+X[1]-i >= 0) ans = max(ans, sum_xy[X[0]+X[1]-i]+sum_z[i]);
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 10476
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iterator>
#include <map>
#include <unordered_map>
#define ll long long int
#define vi vector<long long int>
#define vvi vector<vll>
#define vs vector<string>
#define vsf v.begin(),v.end()
#define pb push_back
#define mp make_pair
using namespace std;
int main(){
	ll i,n,s,j,k;
	cin>>n>>k;
	vi v(n),dp(n);
	for(i=0;i<n;i++) cin>>v[i];
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	for(i=2;i<n;i++){
		s=pow(10,9);
		for(j=i-1;j>=max(i-i,i-k);j--) s=min(s,dp[j]+abs(v[i]-v[j]));
		dp[i]=s;
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#define ll unsigned long long int
using namespace std;
int main(){
	ll h,v;
	cin>>h>>v;
	ll ans = 0;
	if(h > 1 && v > 1)ans = ((h+1)/2) * ((v+1)/2) + ((h-(h+1)/2)) * (v - ((v+1)/2));
	else ans = 1;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
IDX_TABLE=\
{1:[4,2,3,5],
 2:[1,4,6,3],
 3:[1,2,6,5],
 4:[1,5,6,2],
 5:[4,1,3,6],
 6:[3,2,4,5]}

nums = ["dummy"] + [int(x) for x in raw_input().split(" ")]
n = int(raw_input())

for i in range(n):
    up, front = tuple([int(x) for x in raw_input().split(" ")])
    up_idx = nums.index(up)
    front_idx = nums.index(front)
    ring_list = IDX_TABLE[up_idx]
    ring_idx = ring_list.index(front_idx)

    print nums[ring_list[(ring_idx+1) % 4]]

Measured memory_bytes: 4240
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string str;
    cin >> str;
    int N = str.length();
    char last = str[0];
    int changeCount = 0;
    for(int i = 1;i < N;i++){
        char checkC = str[i];
        if(checkC == last){
            changeCount++;
            last = checkC == '1' ? '0' : '1'; 
        }else{
            last = checkC;
        }
    }
    cout << changeCount << endl;
    return 0;
}


Measured memory_bytes: 512
using System;

class MyClass
{
    static void Main(string[] args)
    {
        string str;
        while ((str = Console.ReadLine()) != "0 0")
        {
            int h = int.Parse(str.Split(' ')[0]);
            int w = int.Parse(str.Split(' ')[1]);
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    Console.Write((i + j) % 2 == 0 ? "#" : ".");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 5300
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n, m;
	scanf("%d%d", &n, &m);
	int k, p;
	vector<int> a(m);
	rep(i, n) {
		scanf("%d", &k);
		rep(j, k) {
			scanf("%d", &p);
			++a[--p];
		}
	}
	int ans = 0;
	rep(i, m) {
		if (a[i] == n)++ans;
	}
	printf("%d\n", ans);

	Please AC;
}


Measured memory_bytes: 256
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        ++$this->pointer;

        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int) $this->next();
    }

    public function nextDouble()
    {
        return (float) $this->next();
    }
}

$sc = new Scanner();
$n = $sc->nextInt();
$s = $sc->next();
$array = str_split($s);
$answer = '';
$count = 0;

$chr = $array[0];

foreach ($array as $key => $value) {
    if ($value !== $chr) {
        ++$count;
        $chr = $value;
    }
}

if ($n > 0) {
    ++$count;
} else {
    $count = 0;
}

echo $count.PHP_EOL;


Measured memory_bytes: 22216
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
constexpr int A_MAX = 200000;

int main() {
    int n, m, a, b;
    cin >> n >> m;
    vector<bool> c1(n, false), cn(n, false);
    for(int i=0;i<m;++i) {
        cin >> a >> b;
        --a; --b;
        if(a > b) swap(a, b);
        if(a == 0) {
            c1[b] = true;
        }
        if(b == n-1) {
            cn[a] = true;
        }
    }

    for(int i=0;i<n;++i) {
        if(c1[i] && cn[i]) {
            cout << "POSSIBLE\n";
            return 0;
        }
    }
    cout << "IMPOSSIBLE\n";
    return 0;
}


Measured memory_bytes: 3680
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    int n,m,x,y,z,cnt=0;
    cin>>n>>m;
    vector <int> v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    sort(v.begin(),v.end());
    for(int i=0;i<m;i++)cnt+=v[i];
    cout<<cnt<<endl;
    return 0;
}

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

using namespace std;

int main()
{
	string S;
	int i,counter;
	cin>>S;
	counter=0;
	for(i=1 ; i<3 ; i++)
	{
		if(S[i]!=S[0])
		{
			counter=1;
			break;
		}
	}
	if(counter==0)
	{
		cout<<"No";
	}
	else 
	{
		cout<<"Yes";
	}
	return 0;
}


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

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

A.sort()

Col = [0]*(3*10**5+1)
ind = 0
for i, a in enumerate(A):
    while ind <= a:
        Col[ind] = i
        ind += 1

while ind <= 3*10**5:
    Col[ind] = N
    ind += 1

l = 0
r = 2*10**5+1
while r-l > 1:
    m = (l+r)//2
    count = 0
    for i, a in enumerate(A):
        rem = m - a
        if rem < 0:
            count += N
        else:
            count += N - Col[rem]
    if count >= M:
        l = m
    else:
        r = m

b = 0
B = [0]
for a in A:
    b += a
    B.append(b)


# C以上になるのがMこある最小のC
C = l
ans = 0
Count = 0
for i, a in enumerate(A):
    rem = C-a
    if rem < 0:
        Count += N
        ans += B[N] + a*N
    else:
        c = Col[rem]
        pittari = Col[rem+1] - c
        Count += N-c
        ans += B[-1] - B[-(N-c)-1] + a*(N-c)

ans += (M-Count)*C
print(ans)

Measured memory_bytes: 61840
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  double a, b, c, d;
  cin >> a >> b >> c;
  double unko = c/(a*a*b);
  double tmp;
  double aki;
  aki = 1.000000-unko;
  if(unko>=(0.5)) tmp = (aki*2*b)/a;
  else tmp = (unko*2*a)/b;
  double ans = (double)atan(tmp)*180.0/PI;
   if(unko>=(0.5)) printf("%.12lf\n", ans);
  else printf("%.12lf\n", 90.00000000-ans);
}

Measured memory_bytes: 256
n,k = map(int,input().split())
s = list(input())
if s[0] == "1":
    cnt_list = []
else:
    cnt_list = [0]
cnt = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        cnt_list.append(cnt)
        cnt = 1
cnt_list.append(cnt)
if s[-1] == '0':
    cnt_list.append(0)
#print(cnt_list)
sum_list = [0]
for i in range(len(cnt_list)):
    sum_list.append(sum_list[i] + cnt_list[i])
ans = 0
for i in range(0,len(sum_list),2):
    right = min(i+2*k+1,len(sum_list)-1)
    ans = max(ans,sum_list[right]-sum_list[i])
print(ans)


Measured memory_bytes: 8620
#include <bits/stdc++.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
using namespace std;

int main(){
    int n, i, sum=0;
    vector<int> w;
    cin >> n;
    for(i = 0; i < n; i++){
        int t;
        cin >> t;
        w.push_back(t);
        sum += t;
    }
    int mid = sum / 2;
    int t = 0;
    for(i = 0; i < n; i++){
        t += w[i];
        if(t > mid){
            int a = abs(t - w[i] - (sum - t + w[i]));
            int b = abs(t - (sum - t));
            cout << MIN(a, b) << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n; cin>>n;
    vector<long> v(100,0);
    for(int i=2;i<=n;i++){
        long t=i;
        for(int j=2;j<=t;j++){
            while(t%j==0){
                v[j]++;
                t/=j;
            }
        }
    }
    int count=0;
    for(int i=2;i<=n;i++){
        if(v[i]>=74)
            count++;
        for(int j=i+1;j<=n;j++){
            if(v[i]>=2&&v[j]>=24)
                count++;
            if(v[i]>=24&&v[j]>=2)
                count++;
            if(v[i]>=4&&v[j]>=14)
                count++;
            if(v[i]>=14&&v[j]>=4)
                count++;
            for(int k=j+1;k<=n;k++){
                if(v[i]>=2&&v[j]>=4&&v[k]>=4)
                    count++;
                if(v[i]>=4&&v[j]>=2&&v[k]>=4)
                    count++;
                if(v[i]>=4&&v[j]>=4&&v[k]>=2)
                    count++;
            }
        }
    }
    cout<<count;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,m;
	int money[1001];
	int list[1001] = {};
	cin >> n >> m;
	for(int i = 0; i < n; i++) {
		cin >> money[i];
	}
	int mx = -1;
	for (int i = 0; i < m; i++) {
		int b;
		cin >> b;
		for(int j = 0; j < n; j++) {
			if(money[j] <= b) {
				list[j]++;
				mx = max(mx, list[j]);
				break;
			}
		}
	}

	for(int i = 0; i < n; i++) {
		if(list[i] == mx) {
			printf("%d\n", i + 1);
			break;
		}
	}
	

	return 0;
}

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

int main(){
    int a, b, order, i;
    while (cin >> a >> b) {
        order = 0;
        for (i = 7; i > 0; i--) {
            if ((a + b) / pow(10, i-1) < 10) {
                order = i;
            }
        } 
        cout << order << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
if __name__ == '__main__':
  V = input()
  
  #print(V)
  
  flg = 0
  max_v = 0
  for i in V:
    #print(i)
    if i == 'A' or i=='T' or i=='G' or i=='C':
      flg += 1
      max_v = max(max_v, flg)
    else:
      flg = 0
      
  print(max_v)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;
#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

int main()
{
    IOS
    ll n;
    cin>>n;
    vll v(n,0);
    for(ll i=0;i<n;i++)
    {
        cin>>v[i];
    }
    sort(v.begin(),v.end(),greater<int>());
    ll res=0;
    res+=v[0];
    ll i=1;
    ll x=0;
    while(x<n-2)
    {
        res=res+v[i]+v[i];
        i++;
        x+=2;
    }
    if(n%2)
    {
        res-=v[i-1];
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
#include<utility>
#include<algorithm>

#define pan(i,n) for(int i=0;i<n;i++)
#define pans(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
#define inf 200007
#define P pair<ll,ll>

using namespace std;

int main(){
    int n,k,pc,nc;
    cin>>n>>k;
    ll x[n],ans=INF;
    pan(i,n) cin>>x[i];
    for(int i=0;i<n-k+1;i++){
        ll time=min(abs(x[i])+abs(x[i]-x[i+k-1]),abs(x[i+k-1])+abs(x[i]-x[i+k-1]));
        ans=min(ans,time);
    }
    cout<<ans;
}   

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n;
  cin >> n;
  int ans = 0;
  int num = 1;
  while(num+=2, num <= n)
  {
    int cnt = 0;
    for(int i = 1; i * i < num; ++i)
    {
      cnt += (num % i == 0);
    }
    ans += (cnt == 4);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    vector<int> vec;
    cin >> N;
    vec.resize(N);

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

    int current = vec[0] - 1;
    int count = 1;
    if (vec[0] == 2) {
        cout << count << endl;
        return 0;
    } else {
        for (int i = 0; i < N; ++i) {
            if (vec[current] == 2) {
                ++count;
                cout << count << endl;
                return 0;
         }  else {
                ++count;
                current = vec[current] - 1;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int A, B;

int main() {
	cin >> A >> B;
	set<int>st;
	st.insert(A);
	st.insert(B);
	for (int i = 1;; i++) {
		if (st.insert(i).second) {
			cout << i << endl;
			return 0;
		}
	}
}


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

   void dfs(int s,vector<bool>&vis,vector<int>&topo){
   	vis[s]=true;
   	list<int>::iterator it = adj[s].begin();
   	for(; it!=adj[s].end();it++){
   		if(!vis[*it])
   		  dfs(*it,vis,topo);
   	}
   	 topo.push_back(s);    
   }
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int node,edge;
	cin>>node>>edge;
	
	adj = new list<int>[node+1];
	
	int u,v;
	
	for(int i = 0;i<edge;i++){
		cin>>u>>v;
		adj[u].push_back(v);
	}
    vector<int>topo;
    vector<bool>vis(node+1,false);
    for(int idx = 1;idx<=node;idx++){
    	if(!vis[idx])
    	dfs(idx,vis,topo);
    }
	vector<int>dist(node+1,-1);

	for(int idx = node-1;idx>=0;idx--){
		int s = topo[idx];
         if(dist[s]==-1)
           dist[s]=0;
		list<int>::iterator it = adj[s].begin();
		for(;it!=adj[s].end();it++){
			dist[*it]=max(dist[*it],dist[s]+1);
		}
	}
	cout<<*(max_element(dist.begin(),dist.end()));
	return 0;
}

Measured memory_bytes: 8568
/*	ex5_3
	suzuto	*/

#include <stdio.h>
#define LIMIT 100

int main(void) {
  int height, width, i, j, det; /*変数の宣言*/
  char board[LIMIT + 1][LIMIT + 1];

  scanf("%d %d\n", &height, &width); /*縦幅、横幅を入力*/
  for(i = 0; i < height; i++){
    for(j = 0; j < width; j++){
      scanf(" %c", &board[i][j]); /*(i + 1,j + 1)のマスの色を配列の[i][j]に収納*/
    }
  }

  for(i = 0; i < height; i++){
    det = 1; /*detを初期化*/
    for(j = 0; j < width; j++){
      if (board[i][j] == '#'){
        det = 0; /*一列すべて白でないことを記憶*/
        break;
      }
    }
    if (det == 1){ /*一列白の時blankに*/
      for(j = 0; j < width; j++){
        board[i][j] = 'b'; /*マスを白からblankに*/
      }
    }
  }

  for(j = 0; j < width; j++){
    det = 1; /*detを初期化*/
    for(i = 0; i < height; i++){
      if (board[i][j] == '#'){
        det = 0; /*一列すべて白またはblankでないことを記憶*/
        break;
      }
    }
    if (det == 1){ /*一列白とblankの時blankに*/
      for(i = 0; i < height; i++){
        board[i][j] = 'b'; /*マスを白からblankに*/
      }
    }
  }

  for(i = 0; i < height; i++){
    det = 0; /*detを初期化*/
    for(j = 0; j < width; j++){
      if(board[i][j] != 'b'){ /*blankでなければ出力*/
        printf("%c", board[i][j]);
        det = 1; /*空行でないことを記憶*/
      }
    }
    if(det == 1){ /*出力していれば改行*/
      printf("\n");
    }
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;

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

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  int cnt = 0;
  map<int, int> memo;
  for (int i = 0; i < n; ++i) {
    int m = 0;
    fscanf(stdin, "%d", &m);
    if (memo.count(m)) {
      cnt += memo[m];
    }
    else if (is_prime(m)) {
      ++cnt;
      memo[m] = 1;
    }
    else { memo[m] = 0; }
  }
  fprintf(stdout, "%d\n", cnt);
  return 0;
}

Measured memory_bytes: 1660
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>

using namespace std;

int main()
{
string a,b;

cin >> a>> b;

if(a == b){

cout << "="<<endl;

}else if(a > b){

cout <<">"<<endl;

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

 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VL a(n), b(n); cin >> a >> b;

    int ans = 0;
    VL u;
    ll d = 0;
    FOR(i, 0, n) {
        if (a[i] > b[i])u.push_back(a[i] - b[i]);
        else if (a[i] < b[i]) {
            d += b[i] - a[i];
            ++ans;
        }
    }
    rSORT(u, greater<ll>());

    eFOR(i, 0, u.size()) {
        if (d <= 0) {
            cout << ans + i << "\n";
            return 0;
        }
        if (i == u.size())cout << "-1\n";
        else d -= u[i];
    }
}

Measured memory_bytes: 2428