akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
#include<iterator>
#include<queue>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

class Graph{
    public:
    typedef struct Edge{
        ll from, to, cost;
        Edge(ll f, ll t, ll c): from(f),to(t),cost(c){}
    } Edge;

    bool isDirected;
    ll INF = 1LL << 62;
    ll v; // 頂点数
    std::vector<Edge> edges;  // 辺のリスト
    std::vector<std::vector<std::pair<ll,ll>>> list;  // 隣接リスト
    //std::vector<std::vector<ll>> matrix; // 隣接行列

    Graph(ll n, bool isDirected=false) : isDirected(isDirected) { init(n); }
    void init(ll n){
        v=n;
        edges.clear();
        list.assign(n, std::vector<std::pair<ll,ll>>());
        //matrix.assign(n, std::vector<ll>(n, INF));
    }
    void connect(ll from, ll to){
        con(from, to, 1);
        if(!isDirected) con(to, from, 1);
    }
    void connect(ll from, ll to, ll cost){
        con(from, to, cost);
        if(!isDirected) con(to, from, cost);
    }
    void con(ll from, ll to, ll cost){
        edges.push_back(Edge(from,to,cost));
        list[from].push_back(std::make_pair(to, cost));
        //matrix[from][to] = cost;
    }
};

class StronglyConnectedComponents{  // 強連結成分分解
    public:
    std::vector<std::vector<ll>> list, rlist;
    Graph G;
    std::vector<ll> order; // 帰りがけ順の並び
    std::vector<ll> used;
    std::vector<ll> cmp;   // 属する強連結成分のトポロジカル順序

    StronglyConnectedComponents(Graph G) : G(G){
        list.assign(G.v, std::vector<ll>());
        rlist.assign(G.v, std::vector<ll>());
        order.clear();
        used.assign(G.v, 0);
        cmp.assign(G.v, -1);
    }

    void make_list(){
        for(auto i : G.edges){
            list[i.from].push_back(i.to);
            rlist[i.to].push_back(i.from);
        }
    }
    void dfs(ll idx){
        if(used[idx])return;
        used[idx]=true;
        for(ll to : list[idx]) dfs(to);
        order.push_back(idx);
    }
    void rdfs(ll idx, ll cnt){
        if(cmp[idx] != -1) return;
        cmp[idx] = cnt;
        for(ll to : rlist[idx]) rdfs(to, cnt);
    }
    void build(){
        make_list();
        for(ll i=0; i<list.size(); i++) dfs(i);
        std::reverse(order.begin(), order.end());
        ll ptr=0;
        for(ll i : order)if(cmp[i]==-1) rdfs(i,ptr++);
    }
    ll operator[](ll k){
        return cmp[k];
    }
};

int main(){
    ll v,e,s,t;
    ll q,u,vv;
    cin >> v >> e;
    Graph G(v, true);
    REP(i,e){
        cin >> s >> t;
        G.connect(s,t);
    }
    StronglyConnectedComponents scc(G);
    scc.build();
    //for(auto i : scc.cmp)cout << "###" << i << endl;
    cin >> q;
    REP(i,q){
        cin >> u >> vv;
        if(scc[u]==scc[vv])cout << "1" << endl;
        else cout << "0" << endl;
    }
}


Measured memory_bytes: 7072
using System;
using System.Linq;

namespace abc127
{
    class A
    {
        static void Main(string[] args)
        {
            var input = Input.IntArray();

            int A = input[0];
            int B = input[1];

            int res = 0;
            if (A >= 13) {
                res = B;
            } else if (A >= 6) {
                res = B / 2;
            }
            Console.WriteLine(res);
            
        }

        /** Input Class */
        internal static class Input
        {
            /** input int */
            public static int Int() => int.Parse(Console.ReadLine());

            /** input str */
            public static string Str() => Console.ReadLine();

            /** input array of int */
            public static int[] IntArray() => Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            /** input array of string */
            public static string[] StrArray() => Input.Str().Split(' ');

            /** input array of char */
            public static char[] charArray() => Input.Str().ToCharArray();
        }
    }
}


Measured memory_bytes: 13396
using System;

namespace ABC089_D___Practical_Skill_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var HWD = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var maxNumber = HWD[0] * HWD[1];
            var D = HWD[2];
            var positions = new Point[maxNumber + 1];
            for (int j = 0; j < HWD[0]; j++)
            {
                var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                for (int i = 0; i < HWD[1]; i++) positions[read[i]] = new Point(i + 1, j + 1);
            }
            var moveCosts = new int[maxNumber + 1];
            for (int i = D + 1; i <= maxNumber; i++)
            {
                moveCosts[i] = moveCosts[i - D] + Math.Abs(positions[i].x - positions[i - D].x) + Math.Abs(positions[i].y - positions[i - D].y);
            }

            var Q = int.Parse(Console.ReadLine());
            for (int i = 0; i < Q; i++)
            {
                var LR = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                Console.WriteLine(moveCosts[LR[1]] - moveCosts[LR[0]]);
            }
        }
    }
    struct Point
    {
        public int x;
        public int y;
        public Point(int _x, int _y)
        {
            x = _x;
            y = _y;
        }
    }
}


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

int main() {
	string s;
	while (cin >> s, s != "-") {
		int m;
		cin >> m;
		for (int i = 0; i < m; i++) {
			int h;
			cin >> h;
			rotate(s.begin(), s.begin() + h, s.end());
		}
		cout << s << endl;
	}
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
const ll MOD = 1e9 + 7;
int main()
{
    ll n,ans=0;
    cin>>n;
    vector<ll>a(n+5,0),b(n+5,0);
    for(ll i=1,j=n;i<=n;i++,j--)cin>>a[i];
    for(ll i=n;i>=1;i--)b[i]=a[i]+b[i+1],b[i]%=MOD;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans%MOD+(a[i]*b[i+1])%MOD)%MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6404
#include<iostream>
#include<complex>
#include<vector>
#include<iomanip>

using namespace std;

typedef complex<double> P;

#define EPS 1e-9
#define shosu(x) fixed<<setprecision(x)

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L(){;}
};
struct C{
  P c;double r;
  C(const P &c,double r):c(c),r(r){}
};

namespace std{//演算子の定義
  bool operator < (const P& a,const P& b){
    return real(a)!= real(b) ? real(a) < real(b) : imag(a) < imag(b);
    //return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b)
  }
  bool operator == (const P& a,const P& b){
    return a.real()==b.real() && a.imag()==b.imag();
  }
}

double dot(P a,P b){
  return real(conj(a)*b);
}

double cross(P a,P b){
  return imag(conj(a)*b);
}

int ccw(P a, P b, P c) {//3点の関係性
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;                               // a--c--b on line
}

P projection(L l, P p){//pの直線l上の射影の点
  double t=dot(p-l[0],l[0]-l[1])/norm(l[0]-l[1]);
  return l[0]+t*(l[0]-l[1]);
}

P reflection(L l, P p){//点pの直線lに関して対称な点
  return p+2.0*(projection(l,p)-p);
}

bool isOrthogonal(L l, L m){//2直線の直交判定
  return fabs(dot(l[1]-l[0], m[1]-m[0])) < EPS;
}

bool isParallel(L l, L m){//2直線の平行判定
  return fabs(cross(l[1]-l[0],m[1]-m[0])) < EPS;
}

bool intersectLL(L l, L m){//2直線の交差判定
  return !isParallel(l,m);
}

bool intersectSS(const L &s, const L &t) { //2線分の交差判定(完全に交差してないとだめ)
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

P inP(){
  double x,y;
  cin >> x >> y;
  P p(x,y);
  return p;
}

L inL(){
  P p1=inP();
  P p2=inP();
  L l(p1,p2);
  return l;
}

int main(){

  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    L l1,l2;
    l1=inL();
    l2=inL();

    if(intersectSS(l1,l2)){
      cout<<1<<endl;
    }else{
      cout<<0<<endl;
    }
  }

}



Measured memory_bytes: 3276
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int a;
	char b[100],c[100],d[100];
	cin>>a>>b>>c>>d;
	int counter=0;
	for(int i=0;i<a;i++)
	{
		int sep=0;
		if(b[i]!=c[i]) sep++;
		if(b[i]!=d[i]) sep++;
		if(d[i]!=c[i]) sep++;
		switch(sep){
		case	0:break;
		case	1:counter++;break;
		case	2:counter+=1;break;
		case	3:counter+=2;break;
		default:break;
		}
	}
	cout<<counter;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N, T = M()
ans = 100000
for _ in range(N):
    c, t = M()
    if t <= T:
        ans = min(ans, c)
if ans == 100000:
    print('TLE')
else:
    print(ans)

Measured memory_bytes: 74472
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

int main(){
	
	string s;
	cin >> s;
	int ans = 0;
	for(auto c : s) if(c == '2') ans++;
	cout << ans << endl;
	
	
	
	
	
	
    return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long N, std::vector<std::string> S, std::vector<long long> P){
  vi idx(N);
  iota(ALL(idx),0);
  sort(ALL(idx),[&](int l,int r){
    if(S[l]!=S[r]) return S[l]<S[r];
    return P[l]>P[r];
  });
  rep(i,N) cout << idx[i]+1 << endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<std::string> S(N);
  std::vector<long long> P(N);
  for(int i = 0 ; i < N ; i++){
    std::cin >> S[i];
    scanf("%lld",&P[i]);
  }
  solve(N, std::move(S), std::move(P));
  return 0;
}


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

  bool isac[100005];
  int  pen[100005];
 int main(){
  int n,m,ac=0,pe=0;
  cin>>n>>m;
  for(int i =0;i<n;i++){
    isac[i]=false;
    pen[i]=0;
  }
  for(int i=0;i<m;i++){
    int p;
    string s;
    cin>>p;
    cin>>s;
    if(isac[p]) continue;
    if(s=="WA") pen[p]++;
    else{
      ac++;
      pe+=pen[p];
      isac[p]=true;
    }
  }
  cout<<ac<<" "<<pe<<endl;
  return 0;
}

Measured memory_bytes: 768
line = input()

num_query = int(input())

for loop in range(num_query):

    input_str = list(input().split())

    if input_str[0] == 'replace':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + input_str[3] + line[right:]

    elif input_str[0] == 'reverse':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + line[left:right][::-1] + line[right:]

    else: # print
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        for i in range(left, right):
            print(line[i], end="")
        print()



Measured memory_bytes: 5716
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  int n;  cin >> n;
  rep(i, 1, 10) rep(j, 1, 10) {
    if(n==i*j){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b){
		if(b<c){
			printf("%d %d %d\n",a,b,c);
		}
		else if(a<c){
			printf("%d %d %d\n",a,c,b);
		}
		else{
			printf("%d %d %d\n",c,a,b);
		}
	}
	else{
		if(c<b){
			printf("%d %d %d\n",c,b,a);
		}
		else if(a<c){
			printf("%d %d %d\n",b,a,c);
		}
		else{
			printf("%d %d %d\n",b,c,a);
		}
	}
	return 0;
}


Measured memory_bytes: 2092
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
  string s;
  cin>>s;
  string yaki = "YAKI";
  bool ok = true;;
  for(int i = 0;i<4;i++){
    if(s[i] != yaki[i])
      ok = false;
  }
  if(ok)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[2005];

void calc(int n, string& s0, string& s1, vector<int>& v)
{
    int n0 = strlen(s0.c_str());
    int n1 = strlen(s1.c_str());
    int i,j;
    for (i = 0; i <n; i++) {
        int bad = 0;
        for (j = i; j < n0; j++) {
            int k = j - i;
            if (k >= 0 && k < n1) {
                if (s0[j] != '?' && s1[k] != '?' && s0[j] != s1[k]) {
                    bad = 1;
                    break;
                }
            }
        }
        v[i] = (bad ? 0 : 1);
    }

    return;
}

int solve3(int n, string& s0, string& s1, string& s2)
{
    int ans = INF;

    vector<int> v01(n), v12(n), v02(n);
    calc(n, s0, s1, v01);
    calc(n, s1, s2, v12);
    calc(n, s0, s2, v02);

    int len0 = strlen(s0.c_str());
    int len1 = strlen(s1.c_str());
    int i, j;
    for (i = 0; i <= len0+len1; i++) {
        if (v01[i] == 0) continue;
        for (j = 0; j <= len0+len1-i; j++) {
            if (v12[j] == 0) continue;
            if (v02[i + j]) {
                int len0= i + j+strlen(s2.c_str());
                int len1 = i + strlen(s1.c_str());
                int len2 = strlen(s0.c_str());
                int ans0 = MAX(MAX(len0, len1), len2);
                ans=MIN(ans,ans0);
            }
        }
    }
    return ans;
}

void solve()
{
    int i,j;
    string s[3];
    for (i = 0; i < 3; i++) {
        scanf("%s", str);
        s[i]=string(str);
    }
    int n0 = strlen(s[0].c_str());
    int n1 = strlen(s[1].c_str());
    int n2 = strlen(s[2].c_str());
    int n = n0 + n1 + n2+5;

    int ans = INF;
    for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
            if (i == j) continue;
            int k = 3 - i - j;

            int ans0 = solve3(n, s[i], s[j], s[k]);
#ifdef _DEBUG
            printf("%s %s %s %d\n", s[i].c_str(), s[j].c_str(), s[k].c_str(), ans0);
#endif
            ans = MIN(ans, ans0);
        }
    }
    printf("%d\n", ans);
    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


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

#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define FORD(i, b, e) for (int i = (b); i >= (int)(e); i--)
#define ll long long
#define st f
#define nd s
#define pb PB
#define eb emplace_back
#define mp make_pair
#define siz(c) SIZ(c)
const int inf = 1e9 + 7;
const LL INF = 1e18L + 7;

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type
{int o = 0; p << "{"; for (auto c : y) {if (o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if (p > y) p = y;}
sim, class s> void maxi(n &p, s y) {if (p < y) p = y;}

#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "

const int N = 2e5+7;

int n, a, b, c, d;

string s;

int dp[N];

bool ok(int l, int r)
{
	memset(dp, 0, sizeof dp);
	dp[l] = 1;

	for(int i = l+1; i <= r; ++i)
	{
		if(s[i]=='.' && (dp[i-1] || dp[i-2]))
			dp[i] = 1;
	}

	return dp[r];
}

bool przeskocz(int l, int r)
{
	for(int i = l; i <= r; ++i)
	{
		if(s[i-1]!='#' && s[i]!='#' && s[i+1]!='#')
			return 1;
	}

	return 0;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n >> a >> b >> c >> d >> s;
	s = '#' + s;

	if(c<d)
	{
		if(ok(a, c) && ok(b, d))
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	else
	{
		if(ok(a, c) && ok(b, d) && przeskocz(b, d))
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
}

Measured memory_bytes: 1304
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int main(){
  long long N, K;
  scanf("%lld", &N);
  scanf("%lld", &K);
  if (N<K){
    printf("%lld\n", std::min(N, K-N));
  } else {
    printf("%lld\n", std::min(std::min((N-K)%K, (N-K)%K), K-(N-K)%K));
  }
  return 0;
}


Measured memory_bytes: 888
#include <cstdio>

using namespace std;

int a, b;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

int main() {
	while(scanf("%d%d", &a, &b) != EOF) {
		int gcd = GCD(a, b);
		printf("%d %d\n", gcd, a / gcd * b);
	}
	return 0;
}

Measured memory_bytes: 2588
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 1000000000000000000

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> c(H+2,vector<char>(W+2,'#'));
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin>>c.at(i).at(j);
    }
  }
  vector<vector<int>> row(H+2,vector<int>(W+2,0)),line(H+2,vector<int>(W+2,0));
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(c.at(i).at(j)=='.'){
        row.at(i).at(j)++;
        row.at(i).at(j)+=row.at(i).at(j-1);
      }
    }
    for(int j=W;j>0;j--){
      if(c.at(i).at(j)=='.'){
        row.at(i).at(j)=max(row.at(i).at(j),row.at(i).at(j+1));
      }
    }
  }
  for(int j=1;j<=W;j++){
    for(int i=1;i<=H;i++){
      if(c.at(i).at(j)=='.'){
        line.at(i).at(j)++;
        line.at(i).at(j)+=line.at(i-1).at(j);
      }
    }
    for(int i=H;i>0;i--){
      if(c.at(i).at(j)=='.'){
        line.at(i).at(j)=max(line.at(i).at(j),line.at(i+1).at(j));
      }
    }
  }
  int ans=0;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      ans=max(ans,row.at(i).at(j)+line.at(i).at(j)-1);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
const int N=55;
int n,m,a[N],b[N],fa[N],d[N],s[N];
long long ans;
vector<int>e[N];
void dfs(int u,int f)
{
	fa[u]=f,d[u]=d[f]+1;
	for(auto v:e[u])
		if(v!=f)
			dfs(v,u);
}
void cal(int x,int y)
{
	if(d[x]<d[y])
		swap(x,y);
	while(d[x]>d[y])
	{
		s[x]=0;
		x=fa[x];
	}
	while(x!=y)
	{
		s[x]=s[y]=0;
		x=fa[x],y=fa[y];
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1,0);
	scanf("%d",&m);
	for(int i=0;i<m;i++)
		scanf("%d%d",&a[i],&b[i]);
	for(int i=0;i<(1<<m);i++)
	{
		for(int j=2;j<=n;j++)
			s[j]=1;
		for(int j=0;j<m;j++)
			if(i&(1<<j))
				cal(a[j],b[j]);
		int t=0;
		for(int j=2;j<=n;j++)
			t+=s[j];
		ans+=(1ll<<t)*(__builtin_popcount(i)&1?-1:1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define mod (1e9 + 7)
#define PI 3.1415926535897932
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for (int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second

typedef long long ll;

ll comb(ll n) {
   return n*(n-1)/2;
}

void solve1()
{
   int n; cin >> n;
   set<int> s;
   vector<int> a(n); 
   rep(i, n) {
      cin >> a[i];
      s.insert(a[i]);
   }

   vector<int> as(a);
   map<int, int> m;
   sort(all(as));

   ll sum = 0;
   for(set<int>::iterator itr = s.begin(); itr != s.end(); itr++) {
      int num = upper_bound(all(as), *itr) - lower_bound(all(as), *itr);
      m.insert(make_pair(*itr, num));
      sum += comb(m[*itr]);
   }

   rep(i, n) {
      cout << sum - comb(m[a[i]]) + comb(m[a[i]]-1) << endl;
   }

}

int main()
{
   solve1();
}


Measured memory_bytes: 16728
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int N = NextInt();
        List<int> A = LineInt().ToList();
        List<int> B = LineInt().ToList();
        List<int> C = LineInt().ToList();
        //int N = 100000;
        //List<int> A = Enumerable.Repeat(1, N).ToList();
        //List<int> B = Enumerable.Repeat(2, N).ToList();
        //List<int> C = Enumerable.Repeat(3, N).ToList();
        A.Sort();
        C.Sort();
        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            long a = MoreSearch(A, B[i]);
            long b = N - (LessSearch(C, B[i]) + 1);
            //Console.WriteLine(i + " : " + a + "個 " + b + "個");
            a *= b;
            if (a < 0) continue;
            ans += a;
        }
        Console.WriteLine(ans);
    }
    private static int MoreSearch(List<int> list, int n)
    {
        int a = 0, b = list.Count();
        if (list[a] >= n) return a;
        else if (list[b - 1] < n) return b;
        while (b - a != 1)
        {
            int x = (a + b) / 2;
            if (list[x] >= n) b = x;
            else a = x;
        }
        return b;
    }
    private static int LessSearch(List<int> list, int n)
    {
        int a = 0, b = list.Count();
        if (list[b - 1] <= n) return b - 1;
        else if (list[a] > n) return -1;
        while (b - a != 1)
        {
            int x = (a + b) / 2;
            if (list[x] <= n) a = x;
            else b = x;
        }
        return a;
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); }
    public static string NextString() { Confirm(); return queue.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


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

int nlist[110];
int dp[110][110];

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> nlist[i] >> nlist[i+1];
  }
  for(int i = 1; i < n; i++){
    for(int j = 0; j < n - i; j++){
      dp[j][j+i] = 1 << 30;
      for(int k = 0; k < i; k++){
	    dp[j][j+i] = min(dp[j][j+i], dp[j][j+k] + dp[j+k+1][j+i] + nlist[j] * nlist[j+k+1] * nlist[j+i+1]);
      }
    }
  }
  cout << dp[0][n-1] << endl;
  return 0;
}


Measured memory_bytes: 3120
import java.util.*;

public class Main {
  public static int w;
  public static int h;
  public static int[][] c = new int[50][50];

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (true) {
      w = sc.nextInt();
      h = sc.nextInt();
      if (w == 0 && h == 0) {
        return;
      }
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          c[i][j] = sc.nextInt();
        }
      }
      int count = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (c[i][j] == 1) {
            dfs(i, j);
            count++;
          }
        }
      }
      System.out.println(count);
    }
  }

  public static void dfs(int y, int x) {
    if (y >= 0 && y < h && x >= 0 && x < w && c[y][x] == 1) {
      c[y][x] = 0;
      for (int dy = -1; dy <= 1; dy++) {
        for (int dx = -1; dx <= 1; dx++) {
          dfs(dy + y, dx + x);
        }
      }
    }
  }
}


Measured memory_bytes: 46516
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int a[110][110];
int b[110][110];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    rep(i, 110) rep(j, 110) a[i][j] = b[i][j] = INF;
    rep(i, M) {
        int s, t, d; cin >> s >> t >> d;
        s--; t--;
        a[s][t] = b[s][t] = d;
        a[t][s] = b[s][t] = d;
    }
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
            }
        }
    }
    int ans = 0;
    rep(i, 110) {
        rep(j, 110) {
            if (b[i][j] == INF) continue;
            if (a[i][j] != b[i][j]) ans++;
        }
    }
    cout << ans << endl;


    return 0;
}


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

int main(){
	// sengen
	long long a,sum;
	double b;
	long long bb;
	// nyuryoku
	cin >> a >> b;
	bb = (long long)(b*100 + 0.001);
	sum = (long long)a*bb/100;
	// keisan
	cout << sum;
	// syutsuryoku
}

Measured memory_bytes: 3704
def main():
    H, W, K = [int(c) for c in input().split()]
    cake = [list(input()) for _ in range(H)]
    ichigo = [0]*H
    result = [[] for _ in range(H)]
    last_one = -1
    for i in range(H):
        for j in range(W):
            if cake[i][j] == "#":
                ichigo[i]+=1
    ichigo_no = 0
    for i in range(H):
        if ichigo[i] == 0:
            continue
        ichigo_no+=1
        for j in range(W):
            if cake[i][j] == ".":
                result[i].append(ichigo_no)
            else:
                result[i].append(ichigo_no)
                ichigo[i] -= 1
                if ichigo[i] != 0:
                    ichigo_no += 1

    for i in range(1,H):
        if len(result[i]) == 0 and len(result[i-1]) != 0:
            result[i] = result[i-1]
    for i in reversed(range(H-1)):
        if len(result[i]) == 0 and len(result[i+1]) != 0:
            result[i] = result[i+1]
    for i in range(H):
        for j in range(W-1):
            print(result[i][j], end=" ")
        print(result[i][-1])

main()


Measured memory_bytes: 8272
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;
int n,ans=0;
vector<int>node[100009];
int d[100009];

void dfs(int now,int last,int cnt){
  d[now]=cnt;
  rep(i,node[now].size()){
    int next=node[now][i];
    if(next==last)continue;
    dfs(next,now,cnt+1);
  }
}

int dfs2(int now,int last,int cnt){
  if(cnt>=d[now]){
    ans=max(ans,d[now]);
    return 0;
  }
  else if(node[now].size()==1){
    ans=max(ans,d[now]-1);
  }
  rep(i,node[now].size()){
    int next=node[now][i];
    if(next==last)continue;
    dfs2(next,now,cnt+1);
  }
  return 0;
}

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

  dfs(v,-1,0);
  dfs2(u,-1,0);

  cout<<ans<<endl;

  return(0);
}


Measured memory_bytes: 11264
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  int n;
  cin>>n;
  if(n%2!=0){
    cout<<2*n<<endl;
    return 0;
  }
  cout<<n<<endl;
  return 0;

}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define DSORT(c, type) sort(ALL(c), greater<type>())

using namespace std;


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

  int n, k; 
  cin >> n >> k;
  vector<int> p(n);

  for(int i=0; i<n; ++i)
    cin >> p[i];
  SORT(p);

  int diff = pow(10, 9);
  for(int i=0; i<=n-k; ++i){
    if(diff > p[i+k-1]-p[i])
      diff = p[i+k-1]-p[i];
  }

  cout << diff << "\n";

  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		char[] list = s.toCharArray();
		int count = 0;

		for (int i = 0; i < s.length() / 2; i++) {
			if (list[i] != list[s.length() - i-1]) {
				count++;
			}

		}

		System.out.println(count);

		sc.close();
	}
}

Measured memory_bytes: 35484
/**
 *   author: Shubham Srivastava
 *   created: 01 September 2019  17:55:46
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n;cin>>n;
    ll ans = (n*(n-1))/2;
    cout<<ans;
return 0;
}

Measured memory_bytes: 256
n = int(input())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))

res = 0
for i in range(n):
    a = list_a[i]
    b = list_b[i]
    if b >= a:
        res += a
        b -= a
    else:
        res += b
        b = 0
    c = list_a[i + 1]
    if b >= c:
        list_a[i + 1] = 0
        res += c
    else:
        list_a[i + 1] -= b
        res += b
print(res)


Measured memory_bytes: 82020
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <stdlib.h>

using namespace std;
typedef long long ll;
#define MOD 1000000007

int main()
{
  // ios_base::sync_with_stdio(false);
  // cin.tie(nullptr);

  ll n, m;
  cin >> n >> m;

  vector<int> wa_nums(100001, 0);
  vector<bool> is_accepted(100001, false);

  ll p;
  string res_type;
  for (auto i = 0; i < m; i++)
  {
    cin >> p >> res_type;

    if (is_accepted[p])
    {
      continue;
    }
    else if (res_type == "AC")
    {
      is_accepted[p] = true;
      continue;
    }
    else if (res_type == "WA")
    {
      wa_nums[p]++;
    }
    else
    {
      throw logic_error("invalid condition");
    }
  }

  ll ac = 0;
  ll wa = 0;
  for (auto i = 0; i < 100001; i++)
  {
    if (is_accepted[i])
    {
      ac++;
      wa += wa_nums[i];
    }
  }

  cout << ac << " " << wa << endl;
  return 0;
}


Measured memory_bytes: 1272
#include <stdio.h>
int main(void){
    long long int N,A,B;
    scanf("%lld %lld %lld",&N,&A,&B);
    if(A>B)
    {
        printf("0\n");
    }
    else if (N==1&&A!=B)
    {
        printf("0\n");
    }
    else if (N==1&&A==B)
    {
        printf("1\n");
    }
    else if (N>=2&&A<=B)
    {
        printf("%lld\n",(N-2)*(B-A)+1);
    }
    return 0;
    
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
using namespace std;

int main() {
    string s;
    cin >> s;
    if(s == "Sunny") 
    {
        cout << "Cloudy"; 
        return 0;
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy"; 
        return 0;
    }
    else if (s == "Rainy")
    {
        cout << "Sunny"; 
        return 0;
    }
}


Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<vector>
#include <math.h>

#define LL long long
#define MOD 1000000007
#define rep(i,n) for(int i = 0;i < (n);i++)

using namespace std;

int main(){

    int N,K;

    cin >> N >> K;

    vector<LL> Lsum(N+1);
    vector<LL> Rsum(N+1);

    Lsum[0] = 0;
    Rsum[0] = N;
    for(int i = 1; i <= N; i ++){
        Lsum[i] = Lsum[i-1] + i; 
        Rsum[i] = Rsum[i-1] + (N-i);
    }
    
    LL ans = 0;
    for(int i = K; i <= N+1;i++){
        ans += (Rsum[i-1] - Lsum[i-1] + 1) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 6280
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,m;
	int ans=0;
	cin >>n>>m;
	cout<<n*m<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
ll INF = 1LL<<40;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N, K;
    cin >> N >> K;
    vector<vector<ll>> s(N);
    REP(i, N){
        ll t, d;
        cin >> t >> d;
        t--;
        s[t].push_back(d);
    }
    
    for(auto &v : s){
        sort(v.begin(), v.end(), greater<ll>());
        if(v.empty()) v.push_back(-INF);
    }
    
    sort(s.begin(), s.end(), [&](vector<ll> a, vector<ll> b){return a[0] > b[0];});
    
    ll cur = 0;
    priority_queue<ll> q;
    REP(i, K){
        cur += s[i][0];
        for(int j = 1; j < s[i].size(); j++){
            q.push(s[i][j]);
        }
    }
    for(int i = K; i < N; i++){
        for(int j = 0; j < s[i].size(); j++){
            q.push(s[i][j]);
        }
    }
    
    ll res = cur + K*K;
    for(ll x = K-1; x >= 1; x--){
        ll v = s[x][0];
        ll w = q.top();
        if(v < w){
            q.pop(); cur += w;
            q.push(v); cur -= v;
        }
        res = max(res, cur + x*x);
    }
    cout << res <<endl;
    return 0;
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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


#define mkf(n,mod)  int *fact=(int *)malloc((n+1)*sizeof(int)); mfac((n),fact,(mod)) //enables to let x!=fact[x]
#define mkfiv(n,mod)  int *finv=(int *)malloc((n+1)*sizeof(int)); mfiv((n),finv,fact[n],(mod)) // 1/x! = finv[x]

int mmul(int p,int q,int m){ //O(1)?
    ll lp=p,lq=q; return ((lp%m)*(lq%m))%m;}

int mpow(int x,int n,int m){ //O(logN)
    ll res=x,ans=1;
    while(n!=0){
        if(n%2==0){ res = mmul(res,res,m);n>>=1;
        }else{      ans = mmul(ans,res,m);--n;}}return ans;}

int mdiv(int p,int q,int m){ //O(logMOD)
    return mmul(p,mpow(q,m-2,m),m);}

void mfac(int x,int *f,int m){//O(n)
    *f=1; for(int i=1;i<=x;++i)f[i]=mmul(f[i-1],i,m);}

void mfiv(int x,int *f,int fx,int m){//O(n)
    f[x] = mdiv(1,fx,m); 
    for(int i=x;i>0;--i)f[i-1]=mmul(f[i],i,m);}

int mncr(int n,int r,int m,int* fac,int* fiv){//O(1)
    return mmul(fac[n],mmul(fiv[r],fiv[n-r],m),m);}



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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    mkf(200010,MOD);
    mkfiv(200010,MOD);

    int n,a,b;
    cin >>n>>a>>b;

    ans = mpow(2,n,MOD);

    ans--;
    if(ans < 0)ans += MOD;

    int nCa=1,nCb=1;

    rep1(i,1,a+1){
        nCa = mmul(nCa,n-i+1,MOD);
        nCa = mdiv(nCa,i,MOD);
    }

    rep1(i,1,b+1){
        nCb = mmul(nCb,n-i+1,MOD);
        nCb = mdiv(nCb,i,MOD);
    }

    //db3(ans,nCa,nCb);ln;

    ans -= nCa;
    if(ans < 0)ans += MOD;

    ans -= nCb;
    if(ans < 0)ans += MOD;



    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

int main() {
  uint32_t N = 0, K = 0;
  std::cin >> N >> K;

  std::vector<uint32_t> count(N + 1, 0);
  for (size_t i = 0; i < N; i++) {
    uint32_t a = 0;
    std::cin >> a;
    count[a]++;
  }

  std::sort(count.begin(), count.end(), std::greater<uint32_t>());

  uint32_t sum = 0;
  for (size_t i = K; i < count.size() && count[i] != 0; i++) sum += count[i];

  std::cout << sum << std::endl;

  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    while(true){
        int n;
        scanf("%d",&n);
        if(!n) break;
        
        int k[n],m = 0;
        for(int i = 0; i < n; i++){
            scanf("%d",&k[i]);
            m += k[i];
        }
        
        double sum = 0.0, ave = (double)m/n;
        for(int i = 0; i < n; i++){
            sum += (k[i]-ave) * (k[i]- ave); 
        }
        double hensa = sqrt((double)sum/n);
        printf("%.10f\n",hensa);
    }
    return 0;
}


Measured memory_bytes: 3200
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  A = [int(input())-1 for _ in range(N)]

  next_ = A[0]
  cnt = 1
  lighten = set([0])
  while True:
    if next_ == 1:
      print(cnt)
      return
    if next_ in lighten:
      break
    lighten.add(next_)
    next_ = A[next_]
    cnt += 1

  print(-1)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 84344
#include <stdio.h>
int main(void){
    int a[256];
    int i,sum,count,max;
    sum = count = max = 0;
    scanf("%d %d %d %d %d",&a[1],&a[2],&a[3],&a[4],&a[5]);
    for (i = 1; i < 6; i++){
        while(1){
            if (a[i] % 10 != 0){
                a[i] = a[i] + 1;
                count++;
            }
            if (a[i] % 10 == 0){
                sum = sum + a[i];
                 if (max < count){
                     max = count;
                 }
                 count = 0;
                break;
            }
        }
    }
    sum = sum - max;
    printf("%d",sum);
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    long long int n,s=0,i=1;
    scanf("%lld",&n);
    while(i<=n)
    {
        if(i%3!=0&&i%5!=0&&i%15!=0)
        {
            s=s+i;
        }
        i++;
    }
    printf("%lld\n",s);
    return 0;
}


Measured memory_bytes: 1712
n = int(input())

x = [list(map(int, input().split())) for i in range(n)]

for i in range(n-2):
        if(x[i][0] == x[i][1] and x[i+1][0] == x[i+1][1] and x[i+2][0] == x[i+2][1]):
            p = "Yes"
            break
        else:
            p = "No"


print(p)

Measured memory_bytes: 9124
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  cin>>s;
  int n=s.size();
  string ans="";
  rep(i,n)
    if(s[i]!='B'){
      ans+=s[i];
    }else if(ans.size()>0){
      ans.erase(ans.size()-1);
    }
  cout<<ans<<endl;
}


Measured memory_bytes: 256