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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int a,b;cin >> a >> b;
    int ans = 0;
    rep(i,100000)
    {
        if(i==0)continue;
        if((int)((double)i*(double)0.08)==a && (int)((double)i*(double)0.1)==b)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector < int > inp(3);
void solve()
{
    sort(inp.begin(),inp.end());
    if (inp[0]==5&&inp[1]==5&&inp[2]==7) cout<<"YES";
    else cout<<"NO";
    cout<<endl;
}
int main()
{
    while(cin>>inp[0]>>inp[1]>>inp[2])
        solve();
}

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

using namespace std;

int n, k;

typedef long long ll;
const ll mod = 1e9+7;
const int MAX_P = 1e+5;

ll pow_mod(ll a, ll x, ll p)
{
    ll ret = 1;
    while (x)
        {
        if (x & 1)  ret = ret * a % p;
        a = a * a % p;
        x >>= 1;
    }
    return ret;
}
ll inv(ll x, ll p)//x关于p的逆元，p为素数
{
    return pow_mod(x, p - 2, p);
}
ll comb(ll n, ll m, ll p)//组合数C(n, m) % p
{
    if(n <m) return 0;
    ll up = 1, down = 1;//分子分母;
    for(int i = n - m + 1; i <= n; i++)up = up * i % p;
    for(int i = 1; i <= m; i++)down = down * i % p;
    return up * inv(down, p) % p;
}
//C(n,m)%p=C(n/p,m/p)*C(n%p,m%p)%p
//p较大时
ll Lucas (ll n , ll m , ll p)
{
    if(m < 0) return 0;
  return m == 0 ? 1 : 1ll*comb (n%p , m%p , p) * Lucas (n/p,m/p,p)%p ;
}
//快速幂运算
int fact[MAX_P]; //预处理n!mod p的表
void init(int p)
{
    fact[0] = fact[1] = 1;
    for(int i = 2; i < p; i++)
    {
        fact[i] = fact[i - 1] * i % p;
    }
}
int extgcd(int a, int b, int &x, int &y)
{
    int d = a;
    if(b != 0)
    {
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }
    else {
        x = 1;
        y = 0;
    }
    return d;
}

ll mod_inverse(int a, ll m)
{
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

//分解 n!=a * p^e
ll mod_fact(int n, ll p, int& e)
{
    e = 0;
    if(n == 0) return 1;

    //计算p的倍数部分;
    ll res = mod_fact(n/p, p, e);
    res += n/p;

    if(n/p%2 != 0) return res * (p - fact[n%p]) % p;
    return res * fact[n%p] %p;
}

ll mod_comb(int n, int k, ll p)
{
    if(n < 0 || k < 0 || n <k) return 0;
    int e1, e2, e3;
    ll a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n - k, p, e3);
    if(e1 > e2 + e3) return 0;
    return a1 * mod_inverse(a2 * a3 % p, p) % p;
}

int main()
{
    while(cin >> n >> k){
    if(n==k)
    {
        cout << "1\n";
        for(int i = 1; i < k;++i)
        {
            cout << "0\n";
        }
    }
    else
    for(int i = 1; i <= k; ++i)
    cout << (Lucas(k-1,i-1,mod)*(Lucas(n-k-1,i-2,mod)+2*Lucas(n-k-1,i-1,mod)%mod+Lucas(n-k-1,i,mod)+mod)%mod+mod)%mod << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<iostream>
#include<set>
#include<map>
#define re register
#define ll long long
using namespace std;
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9'|| ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return sum*f;
}
const double eps=1e-10,Pi=acos(-1.0);
struct node{
	double x,y;
	node operator+(node b){return (node){x+b.x,y+b.y};}
	node operator-(node b){return (node){x-b.x,y-b.y};}
	node operator*(double b){return (node){x*b,y*b};}
	double len(){return sqrt(x*x+y*y);}
};
double cross(node a,node b){return a.x*b.y-a.y*b.x;}
double dot(node a,node b){return a.x*b.x+a.y*b.y;}
node projection(node p1,node p2,node p){node v=p2-p1;return p1+v*(dot(v,p-p1)/dot(v,v));}
node reflection(node p1,node p2,node p){node P=projection(p1,p2,p);P=P*2-p;return P;}
void Counter_Clockwise(node p1,node p2,node p){
	if(cross(p2-p1,p-p1)>eps){puts("COUNTER_CLOCKWISE");return;}
	if(cross(p2-p1,p-p1)<-eps){puts("CLOCKWISE");return;}
	if(dot(p2-p1,p-p1)<-eps){puts("ONLINE_BACK");return;}
	if(dot(p2-p1,p2-p1)>=dot(p-p1,p2-p1)){puts("ON_SEGMENT");return;}
	puts("ONLINE_FRONT");
}
int main(){
	node p1,p2,p;
	p1.x=gi();p1.y=gi();p2.x=gi();p2.y=gi();
	int Q=gi();
	while(Q--){
		p.x=gi();p.y=gi();
		Counter_Clockwise(p1,p2,p);
	}
	return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1; char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=5e5+20;
const int inf=0x3f3f3f3f;

int id[maxn],k,n;

inline void init()
{
	n=read(); k=read();
	REP(i,1,n)id[read()]=i;
}

struct node {
	int mn;
	inline void Merge(node L,node R)
	{
		mn=min(L.mn,R.mn);
	}
};
node c[(1<<20)+20];
#define lc (o<<1)
#define rc (o<<1|1)
#define left lc,l,mid
#define right rc,mid+1,r

void make_tree(int o,int l,int r)
{
	c[o].mn=inf;
	if(l==r)return;
	int mid=l+r>>1;
	make_tree(left);
	make_tree(right);
}

vector<int>ed[maxn];

void update(int x,int d,int o,int l,int r)
{
	if(l==r)return chkmin(c[o].mn,d),void();
	int mid=l+r>>1;
	if(x<=mid)update(x,d,left);
	else update(x,d,right);
	c[o].Merge(c[lc],c[rc]);
}

int query(int ql,int qr,int o,int l,int r)
{
	if(qr<l ||ql>r)return inf;
	if(ql<=l && r<=qr)return c[o].mn;
	int mid=l+r>>1,ans=inf;
	if(ql<=mid)chkmin(ans,query(ql,qr,left));
	if(qr>mid)chkmin(ans,query(ql,qr,right));
	return ans;
}

int rd[maxn];
int p[maxn],ans[maxn];

inline void doing()
{
	make_tree(1,1,n);
	DREP(i,n,1)
	{
		int t;
		t=query(id[i]+1,id[i]+k-1,1,1,n);
		if(t!=inf)ed[id[t]].push_back(id[i]),rd[id[i]]++;
		t=query(id[i]-k+1,id[i]-1,1,1,n);
		if(t!=inf)ed[id[t]].push_back(id[i]),rd[id[i]]++;
		update(id[i],i,1,1,n);
	}
	priority_queue<int>q;
	REP(i,1,n)if(!rd[i])q.push(i);
	int num=n;
	while(!q.empty())
	{
		int u=q.top();q.pop();
		p[num--]=u;
		for(int v:ed[u])
			if(!(--rd[v]))
				q.push(v);
	}
	REP(i,1,n)ans[p[i]]=i;
	REP(i,1,n)printf("%d\n",ans[i]);
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 43392
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define INF (1ll<<60)
#define mod 1000000007
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll N,C;cin>>N>>C;
    Graph D(C,vector<ll>(C)),c(N,vector<ll>(N));
    Graph cnt(3,vector<ll>(C));

    rep(i,C){
        rep(j,C){
            cin>>D[i][j];
        }
    }

    rep(i,N){
        rep(j,N){
            cin>>c[i][j];
            c[i][j]--;
            cnt[(i+j+2)%3][c[i][j]]++;
        }
    }

    ll ans=INF;
    rep(i,C){
        rep(j,C){
            if(i==j) continue;
            rep(k,C){
                if(k==i || k==j) continue;

                ll sum=0;
                rep(l,3){
                    rep(m,C){
                        if(l==0){
                            sum+=D[m][i]*cnt[l][m];
                        }else if(l==1){
                            sum+=D[m][j]*cnt[l][m];
                        }else if(l==2){
                            sum+=D[m][k]*cnt[l][m];
                        }
                    }
                }
                chmin(ans,sum);                
            }
        }
    }

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

Measured memory_bytes: 5560
n,k=map(int,input().split())
p=list(map(int,input().split()))
count=0
ans=[0]*(n-k+2)

for j in range(0,k):
    count+=(p[j]/2+0.5)
ans[0]=count
z=1
#print(ans)
for i in range(k,n):
    #print(p[i],p[z-1])
    ans[z]=ans[z-1]-(p[z-1]/2+0.5)+(p[i]/2+0.5)
    z+=1
#print(ans)
print(max(ans))
"""
n,k=map(int,input().split())
p=list(map(int,input().split()))
count=0
ans=[]
for i in range(n-k+1):
    for j in range(i,k+i):
        count+=(p[j]/2+0.5)

    ans.append(count)
    count=0
print(ans)
print(max(ans))
"""

Measured memory_bytes: 24804
letter=raw_input()
N=input()
ans=0
rings=[]
for i in xrange(N):
    rings.append(raw_input())
for ring in rings:
    if not ring.find(letter) == -1:
        ans+=1
    else:
        failFlag=1
        aring=list(ring)
        for i in xrange(len(ring)):
            l=aring.pop(0)
            aring.append(l)
            ring=''.join(aring)
            if not ring.find(letter) == -1:
                ans+=1
                failFlag=0
                break
            
print ans

Measured memory_bytes: 4248
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#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 revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int A, B; cin >> A >> B;
    cout << max(A*B, max(A-B, A+B)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans,a[10005];
int main()
{
	cin>>n;
	cin>>a[0];
	int cnt=1;
	for(int i=1;i<n;i++)
    {
    cin>>a[i];
    if(a[i]==a[i-1])
    cnt++;
    else
    {
    ans+=cnt/2;
    cnt=1;
	}
	}
	ans+=cnt/2;
    cout<<ans<<endl;
    return 0;
	} 

Measured memory_bytes: 256
#include <list>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);

int main() {
	int N;
	while(cin >> N, N) {
		vvi field(N, vi(N+1));
		REP(i, N) {
			REP(j, N+1) {
				cin >> field[i][j];
			}
		}

		vi dp(1<<N, INT_MAX/10);
		dp[0] = 0;

		REP(i, (1<<N)) {
			REP(j, N) {
				if((i&(1<<j)) == 0) {
					int cost = field[j][0];
					REP(k, N) {
						if(i&(1<<k)) {
							cost = min(cost, field[j][k+1]);
						}
					}
					dp[i|1<<j] = min(dp[i|1<<j], cost+dp[i]);
				}
			}
		}

		cout << dp[(1<<N)-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 1476
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    int x,y;
    cin >> x >> y;
    int d = c*2;
    int ans = INF;
    rep(i,max(x,y)+1){
        if(x>max(x,y)-i && y>max(x,y)-i){
            chmin(ans,(max(x,y)-i)*d+a*(x-max(x,y)+i)+b*(y-max(x,y)+i));
        }
        else if(x>max(x,y)-i){
            chmin(ans,(max(x,y)-i)*d+a*(x-max(x,y)+i));
        }
        else if(y>max(x,y)-i){
            chmin(ans,(max(x,y)-i)*d+b*(y-max(x,y)+i));
        }
        else{
            chmin(ans,max(x,y)*d);
        }
    }
    cout << ans << endl;
}

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

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

    ll d,t,s;
    cin >> d >> t >> s;
    if (d <= t*s){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3604
import java.util.*;

class Main {
	public static void main(String args[]) {
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    String S = sc.next();
	    String F = S.substring(0,N/2);
	    String L = S.substring(N/2);
	    
		if (N%2 == 1 || !F.equals(L)) {
	    	System.out.println("No");
		} else {
	    	System.out.println("Yes");
	    }
	}
}


Measured memory_bytes: 21588
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def dfs(x):
        fx = f[x]
        for y in v[x]:
            if d[y]:
                d[y] = 0
                f[y] += fx
                dfs(y)
    n,q = LI()
    v = [[] for i in range(n)]
    for i in range(n-1):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    f = [0]*n
    for i in range(q):
        p,x = LI()
        p -= 1
        f[p] += x
    d = [1]*n
    d[0] = 0
    q = deque([0])
    while q:
        x = q.popleft()
        fx = f[x]
        for y in v[x]:
            if d[y]:
                d[y] = 0
                f[y] += fx
                q.append(y)
    print(*f,sep=" ")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 56192
#include<stdio.h>
int main (){

// DECLARAÇÕES
int A,B,C,X;
int aux = 0;

// INSTRUÇÕES
scanf ("%d %d %d",&A,&B,&C);
scanf (" %d",&X);

if (A>=C && A>=B){
    for (aux = 0; aux < X; aux++){
        A = 2*A;
    }
    printf ("%d\n",A+B+C);
}

if (B>=C && B>A){
    for (aux = 0; aux < X; aux++){
        B = 2*B;
    }
    printf ("%d\n",A+B+C);
}

if (C>B && C>A){
    for (aux = 0; aux < X; aux++){
        C = 2*C;
    }
    printf ("%d\n",A+B+C);
}

if (A==B && B==C){
    for (aux = 0; aux < X; aux++){
        C = 2*C;
    }
    printf ("%d\n",A+B+C);
}

return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    set<ll> r,g,b;
    
    rep(i,n){
        if(s[i]=='R') r.insert(i);
        else if(s[i]=='G') g.insert(i);
        else b.insert(i);
    }
    ll ans=0;
    for(ll i:r){
        for(ll j:g){
            ll mi=min(i,j);
            ll ma=max(i,j);
            ll cnt=0;
            if(b.count(2*ma-mi)) cnt++;
            if(b.count(2*mi-ma)) cnt++;
            if((mi+ma)%2==0&&b.count((mi+ma)/2)) cnt++;
            ans+=max(0LL,(ll)b.size()-cnt);
        }
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 3808
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class T> inline T re(){
	T N = 0; char c = getchar(); bool neg = 0;
	for (; c < '0' || c > '9'; c = getchar()) neg |= c == '-';
	for (; c >= '0' && c <= '9'; c = getchar())
		N = (N<<3)+(N<<1) + c - '0';
	return neg ? -N : N;
}

int main(){
	string s;
	cin >> s;
	cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << '\n';
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
l = Array.new
n.times do
  l << gets.to_i
end

max = -1000000000
min = l[0]
(1..n-1).each do |i|
  if max < l[i] - min then
    max = l[i] - min
  end
  if min > l[i] then
    min = l[i]
  end
end

puts max



Measured memory_bytes: 8896
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> vec(n);
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
  }

  ll ans = LLONG_MAX;
  for (int i = 0; i + k - 1 < n; i++) {
    ll s = min(abs(0 - vec[i]), abs(0 - vec[i + k - 1]));
    ll l = abs(vec[i + k - 1] - vec[i]);
    ans = min(ans, s + l);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<vector>

using namespace std;
const int INF =1001001001;
#define rep(i,n) for(int i=0;i<n;i++)
int N,M;
	int stonenum[152];
	int C[152][12];
	int G[152][12];
	//[i][j]=i+1行目にある石j個目の C=列(位置)、G=滑りやすさ>
	int dp[152][12][77];
	//[i][j][k]=i行(0,N行は陸)j+1番目にある石にいて、今までにk(<M<=(150+1)/2)回
	//飛ばした時の、対岸までの最短距離


int main(){
	while(1){
	scanf("%d %d",&N,&M);
	if(N==0&&M==0)break;
		rep(i,N){
		int a=0;
		scanf("%d",&a);
		stonenum[i]=a;
		rep(j,a){
			int b,c;
			scanf("%d",&b);
			scanf("%d",&c);
			C[i][j]=b;G[i][j]=c;
		}
	}
	//printf("\nyomikomiOK");
	for(int i=N;i>-1;i--){//i=N…0
		rep(j,stonenum[i]){
			rep(k,M+1){
				if(i==N-1){dp[i][j][k]=0;}
				else if(i==N-2&&k<M){//0距離
					dp[i][j][k]=0;
				}else{
					int ans=INF;
					rep(m,stonenum[i+1]){
						//if(ans==INF)ans=((G[i][k]+G[i+1][m])*abs(C[i][k]-C[i+1][m])+dp[i+1][m][k]);
						ans=min(ans,((G[i][j]+G[i+1][m])*abs(C[i][j]-C[i+1][m])+dp[i+1][m][k]));
					}
					if(k<M){
						rep(m,stonenum[i+2]){
							ans=min(ans,(G[i][j]+G[i+2][m])*abs(C[i][j]-C[i+2][m])+dp[i+2][m][k+1]);
						}
					}
					dp[i][j][k]=ans;
				}
			}
		}
	}
	int ans=INF;
	rep(i,stonenum[0])ans=min(ans,dp[0][i][0]);
	if(M>0)rep(i,stonenum[1])ans=min(ans,dp[1][i][1]);
	printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1588
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main(void){
  int i,j;
  int field[16][16]={0};
  int x,y;
  int size;
  int max=0;
  int none=0;

  while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
    if(size>=1){
      field[x+2][y+2]++;
      field[x+1][y+2]++;
      field[x+3][y+2]++;
      field[x+2][y+1]++;
      field[x+2][y+3]++;
    }
    if(size>=2){
      field[x+1][y+1]++;
      field[x+1][y+3]++;
      field[x+3][y+1]++;
      field[x+3][y+3]++;
    }
    if(size>=3){
      field[x+2][y]++;
      field[x+2][y+4]++;
      field[x][y+2]++;
      field[x+4][y+2]++;
    }
  }

  for(i=2;i<12;i++){
    for(j=2;j<12;j++){
      if(field[i][j]>max){
	max=field[i][j];
      }
      if(field[i][j]==0){
	none++;
      }
    }
  }

  cout<<none<<endl;
  cout<<max<<endl;

  return(0);
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	int ans = 0;
	int val = 0;
	for (auto c: s) {
		(c == 'I') ? val++ : val--;
		ans = max(ans, val);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
s = list(map(int, input()))

if len(s) % 2 == 0:
    a = [1,0] * (len(s) // 2)
    b = [0,1] * (len(s) // 2)
    aa = 0
    bb = 0
    for i in range(len(s)):
        if s[i] != a[i]:
            aa += 1
        if s[i] != b[i]:
            bb += 1
    c = min(aa,bb)
else:
    a = [1,0] * (len(s) // 2) + [1]
    b = [0,1] * (len(s) // 2) + [0]
    aa = 0
    bb = 0
    for i in range(len(s)):
        if s[i] != a[i]:
            aa += 1
        if s[i] != b[i]:
            bb += 1
    c = min(aa, bb)

print(c)

Measured memory_bytes: 6160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n;
    cin>>n;
    vector<string>s(n);
    rep(0,i,n)cin>>s[i];
    sort(s.begin(),s.end());
    ll ans=0;
    string fs="";
    rep(0,i,n){
        if(fs==""||fs!=s[i]){
            fs=s[i];
            ++ans;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 9556
N = int(input())

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

total = 0
minus = 0

l = []
for i in range(N):
  total += abs(A[i])
  l.append(abs(A[i]))
  if A[i] < 0:
    minus += 1

ans = total
if minus % 2 == 1:
  ans = total - 2 * min(l)

print(ans)

Measured memory_bytes: 15996
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())
#define PI 2 * acos(0)

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 




int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,sum=0,i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)
        sum+=i;
    }
    cout<<sum;
}




Measured memory_bytes: 3656
#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;
typedef
tree < int, null_type ,less<int>,
rb_tree_tag,
tree_order_statistics_node_update > ordered_set;

const int N = 1e5+7;
vector<int> a[N], tar[N];

void no() {
    cout<<"No"<<endl;
    exit(0);
}

int v[N];
long long invs[2], flips[2];

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

    int n;
    cin>>n;

    map<vector<int>, int> mp;
    for (int i=1; i<=n; i++) {
        vector<int> v = {3*i-2, 3*i-1, 3*i};
        mp[v] = i;
        reverse(v.begin(), v.end());
        mp[v] = -i;
    }

    for (int i=1; i<=n; i++)    a[i].resize(3);
    for (int i=0; i<3; i++) {
        for (int j=1; j<=n; j++) {
            cin>>a[j][i];
        }
    }

    ordered_set ost[2];
    for (int i=1; i<=n; i++) {
        v[i] = mp[a[i]];
        int x = abs(v[i]);
        if (x%2 != i%2)     no();
        flips[x%2] += v[i] < 0;
    }

    ost[0].clear();
    ost[1].clear();

    for (int i=1; i<=n; i++) {
        int x = abs(v[i]);
        int leftbigger = ost[x%2].size() - ost[x%2].order_of_key(x);
        flips[x%2] += leftbigger;
        invs[x%2] += leftbigger;
        ost[x%2].insert(x);
    }

    ost[0].clear();
    ost[1].clear();

    for (int i=n; i>0; i--) {
        int x = abs(v[i]);
        int rightsmaller = ost[x%2].order_of_key(x);
        flips[x%2] += rightsmaller;
        ost[x%2].insert(x);
    }

    if (ost[0].size() + ost[1].size() != n) no();
    if (flips[0]%2 != invs[1]%2)    no();
    if (flips[1]%2 != invs[0]%2)    no();

    cout<<"Yes\n";

}



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

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int Wdays = sc.nextInt();
		int jp = sc.nextInt();
		int mp = sc.nextInt();
		int mjp = sc.nextInt();
		int mmp = sc.nextInt();
		int dayscnt=0;
		for(int i = 1; i <= Wdays; i++){
			jp -= mjp;
			mp -= mmp;
			dayscnt = i;
			if(jp <= 0 && mp <= 0){
				Wdays -= dayscnt;
				System.out.println(Wdays);
				break;
			}
		}
		
	}
}

Measured memory_bytes: 17164
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	int count;
	int flag;

	scanf("%d", &n);

	int nums[n];

	i = 0;
	while (i < n)
	{
		scanf("%d ", &nums[i]);
		i++;
	}

	flag = 1;
	count = 0;
	while (flag == 1)
	{
		i = 0;
		while (i < n)
		{
			if (nums[i] % 2 != 0)
			{
				flag = 0;
			}
			else
			{
				nums[i] /= 2;
			}
			
			i++;
		}
		if (flag == 1)
		{
			count++;
		}
	}

	printf("%d", count);

	return 0;
}

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

const int N = 2e5 + 5;
char path[N];

int32_t main() {
  int n, a1, b1, a2, b2, b1cpy;
  scanf("%d%d%d%d%d", &n, &a1, &b1, &a2, &b2);
  a1--, b1--, a2--, b2--;
  scanf("%s", path);
  assert(n == strlen(path));

  for (b1cpy = b1; b1 < b2; ) {
    if (path[b1+1] == '.') b1++;
    else if (path[b1+2] == '.' && b1+2 <= b2) b1 += 2;
    else break;
  }

  for (; a1 < a2; ) {
    if (path[a1+1] == '.') a1++;
    else if (path[a1+2] == '.' && a1+2 <= a2) a1 += 2;
    else break;
  }

  if(b1 != b2 || a1 != a2)
    return puts("No"), 0;

  if (a2 > b2) {
    if (path[b1cpy-1] == '.' && path[b1cpy+1] == '.')
        return puts("Yes"), 0;

    if (path[b2-1] == '.' && path[b2+1] == '.')
        return puts("Yes"), 0;

    for (b1 = b1cpy; b1 < b2; ) {
      if (path[b1+1] == '.' && path[b1+2] == '.' && b1+2 <= b2)
        return puts("Yes"), 0;
      else if (path[b1+1] == '.') b1++;
      else if (path[b1+2] == '.' && b1+2 <= b2) b1 += 2;
      else break;
    }
    return puts("No"), 0;
  }

  puts("Yes");
  return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
        String t = sc.next();
        String ans = "Yes";
      
        for(int i=0;i<s.length();i++){if(s.charAt(i)!=t.charAt(i)){ans="No";break;
                                                 }
                            }
       
		System.out.println(ans);
	}
}


Measured memory_bytes: 35672
#include <bits/stdc++.h>
using namespace std;
int main(){
int h,w;
long long M=1000000007;
  cin>>h>>w;
  vector<vector<char>> g(h,vector<char>(w));
   long long dp[h][w];
  for(int i=0;i<h;i++){
  for(int j=0;j<w;j++){
      cin>>g[i][j];
    }
  }
  dp[0][0]=1;
  for(int i=1;i<h;i++){
  if(g[i][0]=='#')
    dp[i][0]=0;
  else
    dp[i][0]=dp[i-1][0];
  }
   for(int i=1;i<w;i++){
  if(g[0][i]=='#')
    dp[0][i]=0;
  else
    dp[0][i]=dp[0][i-1];
  }
  for(int i=1;i<h;i++){
  for(int j=1;j<w;j++){
      if(g[i][j]=='#'){
        dp[i][j]=0;
    }
    else{
    dp[i][j]=((long long)dp[i-1][j]+(long long)dp[i][j-1])%M;
    if(dp[i][j]<0){
        dp[i][j]=dp[i][j]%M;
    }
    }
  }
  }
//   for(int i=0;i<h;i++){
//   for(int j=0;j<w;j++){
//       cout<<dp[i][j]<<" ";
//   }
//   cout<<endl;a
//   }

  cout<<dp[h-1][w-1]%M<<endl;
 
  return 0;
}

Measured memory_bytes: 9088
n, k = map(int, input().split())
a = list(map(int, input().split()))

passed = [-1] * (n+1)
route = []
v = 1
while passed[v] == -1:
    passed[v] = len(route)
    route.append(v)
    v = a[v-1]

c = len(route) - passed[v]
l = passed[v]

if k < l:
    print(route[k])
else:
    k -= l
    k %= c
    print(route[l+k])

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

int n;
string s;

int main()
{
    cin >> n;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        int let = s[i] - 'A';
        let += n;
        let %= 26;
        s[i] = let + 'A';
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
program ABC118B
    implicit none
    integer(8)::h,i,j
    integer(8)::N,M,K
    integer(8)::result=0
    integer(8),allocatable,dimension(:)::S,A

    read(5,*)N,M
    allocate(S(M))
    allocate(A(M))

    do i=1,M
        S(i)=0
    end do

    do h=1,N
        read(5,*)K,(A(i),i=1,K)

        do j=1,K
            S(A(j))=S(A(j))+1
        end do
    end do

    do i=1,M
        if(S(i)==N)then
            result=result+1
        end if
    end do

    print'(i0)',result
    
end program ABC118B

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


bool is_contain(string T, string s) {
    int idx = 0;
    for (int i = 0; i < T.size() && idx < s.size(); i++) {
        if (T[i] == s[idx]) {
            idx++;
        }
    }
    return (idx == s.size());
}

int main() {
    string S, T; cin >> S >> T;
    string s1, s2;
    for (int i = 0; i < S.size(); i += 2) s1 += S[i];
    for (int i = 1; i < S.size(); i += 2) s2 += S[i];
    
    if (is_contain(T, s1) || is_contain(T, s2)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return (0);
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define ces(d) cout<<" "<<endl;

int main() {
 int A,B,C,D;
 cin>>A>>B>>C>>D;
 int T[101]={0,};
 fyg(B,A){
 	T[y]++;
 }
  fyg(D,C){
 	T[y]++;
 }
 int ans=0;
 fx(101){
 	if(T[x]==2){
 		ans++;
 	}
 }

ce(ans);

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
s = "APPROVED"
for i in range(N):
    if (A[i] % 2 == 0):
        if (A[i] % 3 != 0) and (A[i] % 5 != 0):
            s = "DENIED"

print(s)

Measured memory_bytes: 38384
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

import random
n = inp()
a = inpl()
b = inpl()
c = [0] * (n+1)
for i in range(n):
    c[a[i]] += 1
    c[b[i]] += 1
if max(c) > n:
    print('No')
    quit()
q = deque([])
for i in range(n):
    if a[i] == b[i]:
        q.append(i)
while q:
    now = q.popleft()
    nx = random.randint(0,n-1)
    if a[now] != b[nx] and a[nx] != b[now]:
        b[now],b[nx] = b[nx],b[now]
    else: q.append(now)
print('Yes')
print(*b)

Measured memory_bytes: 150580
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var K = one[1];
  if((N - 1) * (N - 2) / 2 < K){
    myout(-1);
    return;
  }
  var output = [];
  for(var i = 2; i <= N; i++){
    output.push("1 " + i);
  }
  var diff = (N - 1) * (N - 2) / 2 - K;
  for(var i = 2; i <= N - 1; i++){
    for(var j = i + 1; j <= N; j++){
      if(diff > 0){
        output.push(i + " " + j);
        diff--;
      }
    }
  }
  myout(output.length);
  myout(myconv(output,9));
}

Measured memory_bytes: 7756
# 多次元リストのsortに使える
from operator import itemgetter

def solve(n,a,b):
    if n % 2 == 0:
        s = n // 2
        t = s - 1
        k1 = [0,0]
        k2 = [0,0]


        ast = sorted(a)
        k1[0] = ast[t]
        k2[0] = ast[s]

        bst = sorted(b)
        k1[1] = bst[t]
        k2[1] = bst[s]

        k = [(k1[0]+k2[0])/2,(k1[1]+k2[1])/2]
        return int(k[1]*2-k[0]*2+1)
    else:
        s = n // 2
        k = [0,0]
        ast = sorted(a)
        k[0] = ast[s]
        bst = sorted(b)
        k[1] = bst[s]

        return int(k[1]-k[0]+1)

if __name__ == '__main__':
    n = int(input())
    a = []
    b = []
    for i in range(n):
        ai,bi = map(int,input().split())
        a.append(ai)
        b.append(bi)
    print(solve(n,a,b))

Measured memory_bytes: 28624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	int co=0;
	int t=0;
	rep(i,100010){
		co++;
		t=in[t]-1;
		if(t==1){
			cout<<co<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
}











Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int x[65536];

int inversions(int p, int n, int q, int r) {
	int x3[15], y[15], z;
	memset(x, 127, sizeof(x));
	x[p] = 0;
	for (int i = 0; i < n * n; i++){
		for (int j = 0; j < (1 << n); j++) {
			if (x[j] < 1000) {
				for (int k = 0; k < n; k++) {
					x3[k] = (j / (1 << k)) % 2;
				}
				for (int k = 0; k < n - 1; k++) {
					z = 0;
					if (x3[k] + x3[k + 1] == 1) {
						for (int l = 0; l < n; l++) {
							y[l] = x3[l];
						}
						y[k] = x3[k + 1];
						y[k + 1] = x3[k];
						for (int l = 0; l < n; l++) {
							z += y[l] * (1 << l);
						}
						x[z] = min(x[z], x[j] + 1);
					}
				}
			}
		}
	}
	return min(x[q], x[r]);
}

int n, m, a, s;
int x1[15], x2[15], cnt, r1, r2;

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a; s += (1 << i) * a;
	}
	for (int i = 0; i < m; i++) {
		cin >> a;
		for (int j = 0; j < a; j++) {
			x1[j + cnt] = i % 2;
			x2[j + cnt] = (i + 1) % 2;
		}
		cnt += a;
	}
	for (int i = 0; i < n; i++) {
		r1 += x1[i] * (1 << i);
		r2 += x2[i] * (1 << i);
	}
	cout << inversions(s, n, r1, r2) << endl;
	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main(void){
	string s;
	cin >> s;
	if(s[0]=='9' or s[1]=='9') 
		puts("Yes");
	else
		puts("No");

	return 0;
}

Measured memory_bytes: 256
package main

import (
  "bufio"
  "fmt"
  "os"
  "strconv"
  "strings"
)

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,10000)}
  s := input.NextLine()
  t := input.NextLine()
  q := input.NextInt()
  sa := make([]int,len(s)+1)
  ta := make([]int,len(t)+1)
  for i:=0;i<len(s);i++ {
    sa[i+1] = sa[i]
    if s[i:i+1] == "A" { sa[i+1]++ }
  }
  for i:=0;i<len(t);i++ {
    ta[i+1] = ta[i]
    if t[i:i+1] == "A" { ta[i+1]++ }
  }
  for k:=0;k<q;k++ {
    a,b,c,d := input.NextInts()
    xa := sa[b]-sa[a-1]
    xb := b-a+1-xa
    x := xa+2*xb
    ya := ta[d]-ta[c-1]
    yb := d-c+1-ya
    y := ya+2*yb
    if x%3 == y%3 {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
  }
}

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInt() int {
  n,_ := strconv.Atoi(i.NextLine())
  return n
}
func(i *Input) NextInts() (int,int,int,int) {
  s := strings.Split(i.NextLine()," ")
  a,_ := strconv.Atoi(s[0])
  b,_ := strconv.Atoi(s[1])
  c,_ := strconv.Atoi(s[2])
  d,_ := strconv.Atoi(s[3])
  return a,b,c,d
}

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

int main(int argc, char const *argv[])
{
  string s;
  cin >> s;
  for(int i = 0; i < s.length(); i++)
  {
    if(s[i] == ',')
      s[i] = ' ';
  }
  cout << s << flush;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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 namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

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

int n, q, a, b, p, x;
vector<vector<int>> G(1e5 * 2 + 10);
vector<ll> V(1e5 * 2 + 10);

void dfs(int p, int q) {
  for (auto next_v : G[p]) {
    if (next_v == q) continue;
    V[next_v] += V[p];
    dfs(next_v, p);
  }
}

int main() {
  cin >> n >> q;
  rep (i, n - 1) {
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  rep (i, q) {
    int pos, pts;
    cin >> pos >> pts;
    V[pos] += pts;
  }

  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    cout << V[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 25068
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climits>
#include <bitset>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#define __float128 long double
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

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

string s;
const int N = 1 << 21;
string v[N];

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

	while (cin >> s, s != "#"){
		string org = s;
		int idx = 0;

		int n = s.size();
		rep(i, 1 << n){
			bool ok = true;
			rep(j, n){
				if (i >> j & 1) s[j] = org[j] + 1;
				else s[j] = org[j];

				if (s[j] > 'z'){
					ok = false;
					break;
				}
			}
			if (!ok) continue;
			int used[26] = {};
			used[0] = 1;
			rep(j, n){
				if (!used[s[j] - 'a']){
					used[s[j] - 'a'] = 1;
					if (s[j]-1 != org[j]){
						ok = false;
						break;
					}
				}
				else{
					if (s[j] != org[j]){
						ok = false;
						break;
					}
				}
			}
			if (!ok) continue;
			v[idx++] = s;
		}

		sort(v, v + idx);
		cout << idx << '\n';

		if (idx <= 10){
			rep(i, idx){
				cout << v[i] << '\n';
			}
		}
		else{
			rep(i, 5){
				cout << v[i] << '\n';
			}
			FOR(i, idx - 5, idx){
				cout << v[i] << '\n';
			}
		}
	}

	return 0;
}

Measured memory_bytes: 18704
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  string s;
  cin >> s;
  REP(i,s.size()/2){
    if(s[i] != s[s.size() - i - 1]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0 && m==0) break;
			
			int[] c = new int[m];
			int[] x = new int[n];
			for(int i=0;i<m;i++) c[i] = sc.nextInt();
			for(int i=0;i<n;i++) x[i] = sc.nextInt();
			
			int[][] dp = new int[n+1][256];
			for(int i=0;i<=n;i++){
				for(int j=0;j<256;j++){
					dp[i][j] = Integer.MAX_VALUE;
				}
			}
			dp[0][128] = 0;
			
			for(int i=1;i<=n;i++){
				for(int j=0;j<256;j++){
					if(dp[i-1][j]==Integer.MAX_VALUE) continue;
					for(int k=0;k<m;k++){
						int num = j + c[k];
						if(num<0) num = 0;
						if(num>255) num = 255;
						int v = dp[i-1][j] + (x[i-1]-num) * (x[i-1]-num);
						dp[i][num] = Math.min(dp[i][num], v);
					}
				}
			}
			
			int min = Integer.MAX_VALUE;
			for(int i=0;i<256;i++){
				min = Math.min(min, dp[n][i]);
			}
			System.out.println(min);
		}
		
	}

}

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

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

#define INFTY 1000000000

int count = 0;

void merge(int A[], int left, int mid, int right)
{
  int n1, n2, k, i, j;
  int *L, *R;
  n1 = mid - left;
  n2 = right - mid;
  L = (int *)malloc(sizeof(int) * (n1 + 1));
  R = (int *)malloc(sizeof(int) * (n2 + 1));
  for(i = 0; i <= n1 - 1; i++)
    {
      L[i] = A[left + i];
    }
  for(i = 0; i <= n2 - 1; i++)
    {
      R[i] = A[mid + i];
    }
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for(k = left; k <= right - 1; k++)
    {
      if(L[i] <= R[j])
	{
	  A[k] = L[i];
	  i = i + 1;
	  count++;
	}
      else
	{
	  A[k] = R[j];
	  j = j + 1;
	  count++;
	}
    }
  free(L);
  free(R);
}

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

int main()
{
  int n, i, S[500000];
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%d", &S[i]);
    }
  mergeSort(S, 0, n);
  for(i = 0; i < n - 1; i++)
    {
      printf("%d ", S[i]);
    }
  printf("%d\n%d\n", S[n-1], count);
  return 0;
}



Measured memory_bytes: 5512