akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int a, b;

  std::cin >> a >> b;

  std::cout << (a + b == 15 ? '+' : a * b == 15 ? '*' : 'x') << std::endl;
  
  return 0;
}


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

struct UnionFind {
    vector<int> parent;
    UnionFind(int N) {
        parent=vector<int>(N,-1);
    }
    int root(int x) {
        if (parent[x] < 0) return x;
        return parent[x] = root(parent[x]);
    }
    int size(int x){
        return -parent[root(x)];
    }
    bool unite(int x, int y) {
        x=root(x);
        y=root(y);
        if (x==y) return false;
        if(size(x)<size(y)) swap(x,y);
        parent[x]+=parent[y];
        parent[y]=x;
        return true;
    }
    bool same(int x, int y) {
        return root(x)==root(y);
    }
};

int main(){

    int n,k,l;
    cin >> n >> k >> l;

    UnionFind ro(n);
    UnionFind li(n);

    rep(i,k){
        int s,t;
        cin >> s >> t;
        s--;
        t--;
        ro.unite(s,t);
    }

    rep(i,l){
        int s,t;
        cin >> s >> t;
        s--;
        t--;
        li.unite(s,t);
    }

    map<pair<int,int>,int> m; 
    rep(i,n){
        m[{ro.root(i),li.root(i)}]++;
    }

    rep(i,n){
        cout << m[{ro.root(i),li.root(i)}] << " ";
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 13568
(require '[clojure.string :as str :only (split join)])

(defn- do-solve
  [p k kk s]
  (if (empty? s)
    (if (== p 0)
      (concat kk (reverse k))
      (recur (- p 1) (cons ")" k) kk s))
    (let [[c & cs] s]
      (case c
        "(" (if (== p 0)
          (recur (+ p 1) '("(") (concat kk (reverse k)) cs)
          (recur (+ p 1) (cons "(" k) kk cs))
        ")" (if (== p 0)
          (recur p (cons ")" k) (cons "(" kk) cs)
          (recur (- p 1) (cons ")" k) kk cs))))))

(defn solve [[_ & s]] (do-solve 0 () () s))

(defn main []
  (read-line)
  (println
    (str/join ""
      (solve (str/split (read-line) #"")))))

(main)

Measured memory_bytes: 66448
#include <cstdio>
#include <algorithm>
 
const int N = 110;
 
int a[N], n, m;
 
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    std::sort(a+1, a+n+1);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (m >= a[i]) {
            m -= a[i];
            ans++;
        } else {
            break;
        }
    }
    if (m != 0 && ans == n) ans--; // 这里我一开始写的是 if (m != 0 && ans > 0) ans--;
    printf("%d\n", ans);
}

Measured memory_bytes: 128
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=3e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

namespace seg{
    int N, d[2 * MAXn];
    void init(int n)
    {
        N = n;
        for(int i = (n<<1);i > 0;i --)d[i] = 0;
    }
    void ins(ll x, ll k)
    {
        for(d[x += N] += k;x > 1;x >>= 1)d[x>>1] = d[x] + d[x^1];
    }
    ll qr(ll l, ll r)
    {
        ll ret = 0;
        for(l += N, r += N;l < r;l >>= 1, r >>= 1){
            if(l & 1)ret += d[l++];
            if(r & 1)ret += d[--r];
        }
        return ret;
    }
};

vector<ll> v[MAXn];
vector<ii> dt[MAXn];
ll ans[MAXn];

int main()
{
    IOS();
    ll n, m;
    cin>>n>>m;
    seg::init(m + 1);
    REP(i,n)
    {
        ll l, r;
        cin>>l>>r;
        dt[l].pb(ii(l-1, 1));
        dt[r+1].pb(ii(l-1, -1));
    }
    REP1(i, m)v[i].pb(i);
    REP1(i, m)
    {
        for(auto p:dt[i])seg::ins(p.X, p.Y);
        for(auto x:v[i])
        {
            ans[x] += seg::qr(i - x, i);
            v[i + x].pb(x);
        }
        v[i].clear();v[i].shrink_to_fit();
    }
    REP1(i,m)cout<<ans[i]<<endl;
}


Measured memory_bytes: 34816
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

int n;
vector<int> G[100010];
bool f = true;

bool dfs(int now, int pre){
    if(pre != -1 && G[now].size() == 1) return false;
    int cnt = 0;
    rep(i, 0, G[now].size()){
        int next = G[now][i];
        if(next == pre) continue;
        if(!dfs(next, now)) cnt++;
    }
    if(cnt > 1) f = false;
    return cnt;
}

signed main(){
    cin >> n;
    rep(i, 0, n - 1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a]. push_back(b);
        G[b]. push_back(a);
    }
    f &= dfs(0, -1);
    cout << (f ? "Second" : "First") << endl;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////

signed main() {
  int n;
  cin>>n;
  map<int,int>m;
  rep(i,n){
    int a;
    cin>>a;
    m[a]++;
  }
  int ans=0;
  for(auto [x,y]:m){
    if(y%2==1)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 9800
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    N = Number(input.split("\n")[0]);
    a = input.split("\n")[1].split(" ").map(Number);
    a.sort(function(a,b){return b-a;});
    Alice = 0; 
    Bob = 0;
    
    for(i = 0; i< N ; i++){
        if(i%2 ==0){
            Alice += a[i];
        }else{
            Bob += a[i];
        }
    }
    answer = Alice - Bob;
    console.log(answer);
}
    


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
H,W=1,1
while True:
    posX,posY=0,0
    H,W=map(int,input().split())
    if (H==W==0)==True:
        break
    tile=[[False for i in range(W)] for j in range(H)]
    tileinfo=[['' for i in range(W)] for j in range(H)]
    for i in range(H):
        tileinfo[i]=input().rstrip()
    while True:
        if tile[posY][posX]==True:
            print('LOOP')
            break
        else:
            tile[posY][posX]=True
        if tileinfo[posY][posX]=='>':
            posX+=1
        elif tileinfo[posY][posX]=='<':
            posX-=1
        elif tileinfo[posY][posX]=='v':
            posY+=1
        elif tileinfo[posY][posX]=='^':
            posY-=1
        elif tileinfo[posY][posX]=='.':
            print('{} {}'.format(posX,posY))
            break

Measured memory_bytes: 6880
#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 vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N, D;
	cin >> N >> D;
	vector<vector<int>> X(N);
	fx(N) {
		fy(D) {
			int a; 
			cin >> a;
			pb(X.at(x),a)
		}
	}
	int ans = 0;
	fx(N) {
		fyg(N,x+1) {
			int a=0;
			fz(D) {
				a += (X.at(x).at(z) - X.at(y).at(z))*(X.at(x).at(z) - X.at(y).at(z));
			}
			for (int z = 0; z <= a;z++) {
				if (z*z==a) {
					ans++;
					break;
				}
			}
		}
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 256
N = gets.to_i
A = gets.chomp.split.map(&:to_i)
sum = 0

counts = [0] * (N+1)
A.each {|a| counts[a] ||= 0; counts[a] += 1}

(1..N).each do |i|
  sum += (counts[i] * (counts[i]-1) / 2)
end

(1..N).each do |j|
  puts sum - (counts[A[j-1]]-1)
end

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

int main()
{
	ll k, a, b;
	cin >> k >> a >> b;
	if(b<=a+2) cout << 1+k << endl;
	else if(k-1<a) cout << 1+k << endl;
	else if((k-(a-1))%2==0) cout << a+((k-(a-1))/2)*(b-a) << endl;
	else cout << a+((k-(a-1))/2)*(b-a)+1 << endl;
	return 0;
}

Measured memory_bytes: 256
def solve():
  import sys
  import math

  sys.setrecursionlimit(10**7)
  readline=sys.stdin.readline

  n,k,q = map(int,input().split())
  point = [0]*n
  for _ in range(q):
    point[int(input())-1] += 1
  for i in range(n):
    print('Yes' if point[i] > q-k else 'No')

    
if __name__ == '__main__':
  solve()

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b){
        if(a == c){
            cout << 1 << endl;
        }
        else{
            cout << 2 << endl;
        }
    }
    else if(b == c){
        cout << 2 << endl;
    }
    else if(a == c){
        cout << 2 << endl;
    }
    else{
        cout << 3 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a < b && b < c)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";	
}

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


Measured memory_bytes: 2036
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){

    int k;
    string s;

    cin >> k >> s;

    if(s.size() > k){
        FOR(i,0,k)cout << s[i];
        cout << "..." << endl;
    }
    else cout << s << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main() {
    string str;
    int i, n, c=0;
    cin>>n;
    cin>>str;
    for(i=0; i<n; i++) {
        if(str[i]=='A') {
            if(str[i+1]=='B') {
                if(str[i+2]=='C') {
                    c++;
                    i++;
                }
            }
        }
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int reslut;
    int Case=1;
    do{
        scanf("%d",&reslut);
        if(reslut==0){
            break;
        }
        printf("Case %d: %d\n",Case,reslut);
        Case++;
    }while(reslut!=0);
    
}


Measured memory_bytes: 2092
# -*- coding: utf-8 -*-
A = int(input())
B = int(input())
C = int(input())
D = int(input())
if(A>=B):
  if(C>=D):
    print(B+D)
  else:
    print(B+C)
else:
  if(C>=D):
    print(A+D)
  else:
    print(A+C)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef vector<long long int> vint;
typedef vector<vint> vvint;
typedef long long int ll;
#define MOD 1000000007

static vint arr;

ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    // Base Case 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; // To store results of recursive call 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    // Update x and y using results of recursive 
    // call 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 

ll modInverse(ll b) 
{ 
    ll x, y; // used in extended GCD algorithm 
    ll g = gcdExtended(b, MOD, &x, &y); 
  
    // Return -1 if b and m are not co-prime 
    if (g != 1) 
        return -1; 
  
    // m is added to handle negative x 
    return (x%MOD + MOD) % MOD; 
} 

void divide(ll& a, ll b){
	a = a % MOD;
	a = (modInverse(b) * a) % MOD; 
}

ll solve(void){
	ll res = 0, n = arr.size(), curr = 0;

	for(int i = 1; i < n; i++){
		curr = (curr + ((arr[0] * arr[i]) % MOD)) % MOD;
	}

	res = curr;

	for(int i = 1; i < n; i++){
		divide(curr, arr[i-1]);
		curr = (curr - arr[i]) % MOD;
		if(curr < 0)
			curr += MOD;

		curr = (curr * arr[i]) % MOD;
		res = (res + curr) % MOD;
	}

	return res;

	// unordered_map<ll, ll> bucket, product;

	// for(ll i:arr)
	// 	bucket[i]++;

	// for(auto itr = bucket.begin(); itr != bucket.end(); itr++){

	// }
}

int main(){
	int n;
	while(cin >> n){
		arr.resize(n);
		for(int i = 0; i < n; i++)
			cin >> arr[i];

		cout << solve() << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 4800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull n,a[100010],ans;

ull dfs(ull deep,ull ent){
	if(ent<a[deep]||ent==0)
		return -1;
	if(deep==n){
		if(ent>=a[n])
			return a[n];
		else
			return ent;
	}
	ll tmp=dfs(deep+1,(ent-a[deep])*2);
	if(tmp==-1)
		return -1;
	if(ent-a[deep]>=tmp){
		ans+=tmp+a[deep];
		return tmp+a[deep];
	}
	else{
		ans+=ent;
		return ent;
	}
		
	
}

int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	ull i,tmp=1;
	
	for(i=0;i<=n;++i)
		cin>>a[i];
	ans=a[n];
	if(dfs(0,1)==-1){
		cout<<"-1";
		return 0;
	}
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 7556
#入力
S = input()
#扱いやすくするためリスト化
ls = list(S)
#反転させたものもリスト化する
lsr = list(reversed(ls))
count = 0
#反転前後リストで不一致の要素数をカウント
for i in range(len(ls)):
  if ls[i] != lsr[i]:
    count += 1
#結果(書いてみればわかるが1つ書き直すべき時は反転させたリストと元のリストは2つ不一致が生まれる)
print(count//2)

Measured memory_bytes: 3060
// AOJ 0172: Doctor's Research Rooms
// 2018.1.24 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { char rm; int light; } Q;
Q q[491520]; int top, end;
Q *used[15][32768];

int rm[15][15], s_rm[15];
int sw[15][15], s_sw[15];

char *msg[7] = {0,
"You can go home in %d steps.\n",
"You can not switch off all lights.",
"Help me!",
"Move to room %d.\n",
"Switch on room %d.\n",
"Switch off room %d.\n" };

typedef struct { char msg, rm; } T;
T res[100]; int sz;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	while (c < '0') c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

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

int main()
{
	int n, m, i, j, s, t, ans;
	int room, light;

	while (n = in()) {
		m = in();
		memset(s_rm, 0, sizeof(s_rm));
		memset(s_sw, 0, sizeof(s_sw));

		for (i = 0; i < m; i++){
			s = in()-1, t = in()-1;
			rm[s][s_rm[s]++] = t;
			rm[t][s_rm[t]++] = s;
		}

		light = 0; for (i = 0; i < n; i++) if (in()) light |= 1 << i;

		for (i = 0; i < n; i++) {
			j = in(); while (j--) sw[i][s_sw[i]++] = in()-1;
			qsort(sw[i], s_sw[i], sizeof(int), cmp);
        }

		memset(used, 0, sizeof(used));
		q[0].rm = 0, q[0].light = light; top = 0, end = 1;
		used[0][light] = q;

		ans = 3;
		while (top < end) {
			s = q[top].rm, t = q[top].light;

			if (s == n-1) {
				if (t == 1<<(n-1)) { ans = 1; break; }
				ans = 2;
			}

			for (i = 0; i < s_sw[s]; i++) if (sw[s][i] != s) {
				light = t ^ (1<<sw[s][i]);
				if (used[s][light] == 0) {
					used[s][light] = q + top;
					q[end].rm = s, q[end++].light = light;
				}
			}

			for (i = 0; i < s_rm[s]; i++) {
				room = rm[s][i];
				if (t & (1<<room)) {
					if (used[room][t] == 0) {
						used[room][t] = q + top;
						q[end].rm = room, q[end++].light = t;
					}
				}
			}

			top++;
		}
 
		if (ans > 1) puts(msg[ans]);
		else {
			Q p = q[top];
			sz = 0;
			while (1) {
				Q nxt = *used[p.rm][p.light];
				if (nxt.rm == p.rm && nxt.light == p.light) break;
				if (p.rm != nxt.rm) res[sz].msg = 4, res[sz++].rm = p.rm;
				else for (i = 0; i < n; i++) if ((p.light & (1<<i)) ^ (nxt.light & (1<<i))) {
					if (p.light & (1<<i)) res[sz].msg = 5; else res[sz].msg = 6;
					res[sz++].rm = i;
					break;
				}
				p = nxt;
			}
			printf(msg[ans], sz);
			while (sz--) printf(msg[res[sz].msg], 1 + res[sz].rm);
		}
    }
    return 0;
}


Measured memory_bytes: 5944
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cstring>
#include <stack>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
#define ll long long
int cnt = 0, temp = 0;
int divisors(int n) {
	for (int i = 1; i < n; i++) {
		if (n % i == 0) {
			cnt++;
			if(max(temp, i) < 9)
				temp = max(temp, i);
		}
	}
	return cnt;
}
int main()
{
	int n, k;
	cin >> n >> k;
	double ans = 0;
	for (int i = 1; i <= n; i++) {
		double p = 1;
		int x = i;
		while (x < k) {
			p *= 0.5;
			x *= 2;
		}
		ans += p / n;

	}
	printf("%.10f \n", ans);

}

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

Measured memory_bytes: 27856
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int p[200010];
set<int> st;
int mx[200010];
int mn[200010];
int cnt[200010];

int main(){
    int n, k;
    cin >> n >> k;
    rep(i, n) cin >> p[i];
    rep(i, k) st.insert(p[i]);
    mn[0] = *st.begin();
    mx[0] = *st.rbegin();
    for(int i = 1; i < n-k+1; i++){
        st.erase(p[i-1]);
        st.insert(p[i+k-1]);
        mn[i] = *st.begin();
        mx[i] = *st.rbegin();
    }

    int ans = n - k + 1;

    rep(i, n-1) cnt[i+1] = cnt[i] + (p[i] > p[i+1]);

    int tmp = 0;
    rep(i, n-k+1){
        if (cnt[i] == cnt[i+k-1]) {
            tmp++;
            continue;
        }
        if (p[i] < mn[i+1] && mx[i] < p[i+k]) ans--;
    }

    cout << ans - max(0, tmp-1)<< endl;

    return 0;
}


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

#define INT long long

INT N;
INT a[110];

int main()
{
	cin>>N;
	INT x; cin>>x;
	for(int i=1;i<=N;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+1+N);
	
//	cout<<"a[]=";
//	for(int i=1;i<=N;i++)
//	{
//		cout<<a[i]<<" ";
//	}
//	cout<<endl;
	
	int sum=0;
	for(int i=1;i<=N;i++)
	{
		sum+=a[i];
		if(sum>x)
		{
			cout<<i-1<<endl;
			return 0;
		}
	}
	if(sum==x) cout<<N<<endl;
	else cout<<N-1<<endl;
	return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    string s; cin >> s;
    int n = s.length();

    int cand1 = 0;
    for(int i = 0; i < n; ++i) {
        if((i%2 && s[i] == '0') || (i%2 == 0 && s[i] == '1')) ++cand1;
    }

    int cand2 = 0;
    for(int i = 0; i < n; ++i) {
        if((i%2 && s[i] == '1') || (i%2 == 0 && s[i] == '0')) ++cand2;
    }

    int ans = min(cand1, cand2);

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


Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <iostream>
#include <bitset>

using ii = std::pair<int, int>;

std::string str;
int table[200001][26];
int next[200001][26];

int solve(int k, int find)
{
	if (k == str.size() - 1)
	{
		if (str[k] != find + 'a')
			return 0;
		else
			return 987654321;
	}

	if (table[k][find] != -1)
		return table[k][find];

	int& res = table[k][find];
	res = 987654321;

	if (find + 'a' == str[k])
	{
		for (int i = 0; i < 26; i++)
		{
			int calc = 1 + solve(k + 1, i);
			if (calc < res)
			{
				res = calc;
				next[k][find] = i;
			}
		}
	}
	else
	{
		res = solve(k + 1, find);
	}

	return res;
}

int main()
{
	std::cin >> str;

	int min = 987654321;
	int first = 0;

	memset(table, -1, sizeof(table));
	memset(next, -1, sizeof(next));

	for (int i = 0; i < 26; i++)
	{
		int k = solve(0, i);
		if (k < min)
		{
			min = k;
			first = i;
		}
	}

	std::string ans;
	ans.push_back(first + 'a');

	for (int i = 0; i < str.size(); i++)
	{
		if (next[i][first] != -1)
		{
			first = next[i][first];
			ans.push_back(first + 'a');
		}
	}

	std::cout << ans;

	return 0;
}

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

using namespace std;

typedef long long ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _lcint;
#define REP(i, n) for (_lcint i = 0; i < n; i++)
#define FOR(i, a, b) for (_lcint i = (_lcint)(a); i < (_lcint)(b); i++)
#define FORREV(i, n) for (_lcint i = (_lcint)(b)-1; i >= (_lcint)(a); i--)
#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)  \
  cout << #v << ": "; \
  REP(i, v.size()) cout << " " << v[i] << endl;

#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = min((a), (b))

int main() {
  int N, M, C;
  cin >> N >> M >> C;

  vi B(M);

  REP(i, M) cin >> B[i];
  int result = 0;

  REP(j, N) {
    int total = 0;
    REP(i, M) {
      int t;
      cin >> t;
      total += t * B[i];
    }
    total += C;
    if (total > 0) {
      result++;
    }
  }

  cout << result;

  return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
    vector<vector<vector<ll>>> Lun(12, vector<vector<ll>>(10, vector<ll>(0)));

    int K;
    cin >> K;

    vector<ll> nums(0);

    for (int i = 0; i < 10; i++)
    {

        Lun[0][i].push_back(i);

        if (i != 0)
        {
            nums.push_back(i);
        }
    }

    for (int i = 1; i < 12; i++)
    {

        for (int j = 0; j < 10; j++)
        {

            if (j > 0)
            {

                for (int k = 0; k < Lun[i - 1][j - 1].size(); k++)
                {

                    ll A = j * pow(10, i) + Lun[i - 1][j - 1][k];

                    Lun[i][j].push_back(A);

                    nums.push_back(A);
                }
            }

            for (int k = 0; k < Lun[i - 1][j].size(); k++)
            {

                ll A = j * pow(10, i) + Lun[i - 1][j][k];

                Lun[i][j].push_back(A);

                if (j != 0)
                {

                    nums.push_back(A);
                }
            }

            if (j < 9)
            {

                for (int k = 0; k < Lun[i - 1][j + 1].size(); k++)
                {

                    ll A = j * pow(10, i) + Lun[i - 1][j + 1][k];

                    Lun[i][j].push_back(A);

                    if (j != 0)
                    {
                        nums.push_back(A);
                    }
                }
            }
        }
    }

    sort(nums.begin(),nums.end());

    cout << nums[K-1] << endl;

    return 0;
}

Measured memory_bytes: 31652
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
using int64 = long long;

void get_ryuka(int &current_idx, int64 &prev, int64 &prev_prev, int N) {
  if (current_idx == N + 1) {
    return;
  }
  int64 tmp = prev;
  prev += prev_prev;
  prev_prev = tmp;
  current_idx += 1;
  get_ryuka(current_idx, prev, prev_prev, N);
}

int main() {
  int N;
  cin >> N;
  int64 prev = 1;
  int64 prev_prev = 2;
  int current_idx = 2;
  get_ryuka(current_idx, prev, prev_prev, N);
  cout << prev << endl;
  return 0;
}

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

int32_t main()
{
	int n;
	cin >> n;
	int arr[n], sum = 0;
	map<int, int> m1;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		sum += arr[i];
		m1[arr[i]] += 1;
	}

	int q;
	cin >> q;
	int b, c;
	while (q--)
	{
		cin >> b >> c;
		// for (auto i : m1)
		// 	cout << i.first << ":" << i.second << " ";
		// cout << "\n";
		if (m1.count(b))
		{
			sum -= b * m1[b];
			sum += c * m1[b];
			m1[c] += m1[b];
			m1.erase(b);
		}
		// for (auto i : m1)
		// 	cout << i.first << ":" << i.second << " ";
		// cout << "\n";
		cout << sum << "\n";
		// cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 8212
#include<bits/stdc++.h>
using namespace std;
string s3="";
void fuck(vector<vector<int> >&dp,int n,int m,string s,string s1)
{
	if(n==0||m==0)
	return ;
	if(s[n-1]==s1[m-1])
	{
			  fuck(dp,n-1,m-1,s,s1);
		s3.push_back(s[n-1]);
           return;
	}
	  else if(dp[n-1][m]>=dp[n][m-1])
	  {
	  	fuck(dp,n-1,m,s,s1);
	  }
	  else
	  {
	  	fuck(dp,n,m-1,s,s1);
	  }
 } 
int main()
{
	int i,j,k,l,n,m;
	string s,s1;
	cin>>s;
	cin>>s1;
	n=s.size();
	 m=s1.size();
	 vector<vector<int> > dp(n+1,vector<int>(m+1,0));
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(s[i-1]==s1[j-1])
			{
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else
			{
				dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
			}
		}
	}
	 fuck(dp,n,m,s,s1);
	 cout<<s3;
	 return 0;	
}

Measured memory_bytes: 65408
#include <bits/stdc++.h>
// #include "/usr/local/include/cxx_pretty_print/cxx_pretty_print.hpp"

using namespace std;
/* type aliases */
using i32 = int32_t; using ui32 = uint32_t; using i64 = int64_t; using ui64 = uint64_t; using i128 = __int128;
using f32 = float;   using f64  = double;   using f80 = long double;
using PII = pair<i32, i32>; using PLL = pair<i64, i64>; using PFF = pair<f32, f32>; using PDD = pair<f64, f64>;
using VB  = vector<bool>;   using VS  = vector<string>;
using VI  = vector<i32>;    using VL  = vector<i64>;    using VF  = vector<f32>;    using VD  = vector<f64>;
using VVI = vector<VI>;     using VVL = vector<VL>;     using VVF = vector<VF>;     using VVD = vector<VD>;
using VPI = vector<PII>;    using VPL = vector<PLL>;    using VPF = vector<PFF>;    using VPD = vector<PDD>;
/* constants */
constexpr i64 mod = 1000000007;                                // 10^9+7
constexpr i64 inf = 9000000000000000000;                       // 9*10^18
/* macros */
#define MAX(c)        *max_element(ALL(c))
#define MIN(c)        *min_element(ALL(c))
#define SIZE(c)       (i64)((c).size())                        // unsined int (size_t) -> int64_t
#define ALL(c)        (c).begin(), (c).end()
#define RALL(c)       (c).rbegin(), (c).rend()
#define REP(i, n)     for (i64 i=0; i<(i64)(n); ++i)           // 0 to n-1
#define FOR(a, b)     for (i64 i=a; i<b; ++i)                  // a to b-1
#define REPD(i, n)    for (i64 i=(i64)(n)-1; i>=0; --i)        // n-1 to 0
/* debug */
#define debug(x)      cerr << #x << ": " << (x) << '\n'
#define debugvec(v)   for (size_t _ = 0; _ < (v).size(); ++_) {cerr << #v << '[' << _ << "]: " << (v)[_] << '\n';}
/* useful output */
auto print = [](auto x) {cout << (x) << '\n';};
template <class T> void printvec(T v, string sep=" ", string end="\n") {REP(i, SIZE(v)-1) cout << v[i] << sep; cout << v[SIZE(v)-1] << end;}
/* useful input */
VS splitstr(string s, char delim=' ') {VS v; string buf; stringstream ss{s}; while (getline(ss, buf, delim)) v.push_back(buf); return v;}




void Main() {
    i32 n;
    cin >> n;
    VI L(n, 0);
    REP(i, n) cin >> L.at(i);
    f32 avg = (f32)accumulate(ALL(L), 0) / n;
    i32 ans{};
    f64 min_diff{inf};
    REP(i, n) {
        f64 diff = abs(L.at(i) - avg);
        if (diff < min_diff) {
            min_diff = diff;
            ans = i;
        }
    }
    print(ans);
}


signed main() {
    cin.tie(nullptr);                                         // cin と cout の tie を切り高速化
    cout << fixed << setprecision(15);                        // 浮動小数点数が 1e-006 のように表示されることを防ぐ
    Main();
}

Measured memory_bytes: 3640
#include<iostream>
#include<set>
using namespace std;
int main() {
	int N;
	int d;
	cin >> N;
	set<int>V;
	for (int i = 0; i < N; ++i) {
		cin >> d;
		V.insert(d);
	}
	cout << V.size();
	return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

double calc(int[] a) {
    a.sort();
    return a.reduce!((a, b) => (a + b) / 2.0);
}

void main() {
    readint;
    auto a = readints;
    writeln(calc(a));
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
const int N=400005;
int n;
long long k;
int a[N];
int pos[N],nxt[N];
int f[N][60];
int vis[N];
int main()
{
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),a[i+n]=a[i];
	for(int i=n*2;i>=1;i--)
		nxt[i]=pos[a[i]],pos[a[i]]=i;
	f[0][0]=1;
	for(int i=n;i>=1;i--)
		if(nxt[i]>n)
		{
			if(nxt[i]==n+n) f[i][0]=0;
			else f[i][0]=nxt[i]-n+1;
		}
		else
		{
			if(nxt[i]==n) f[i][0]=1;
			else f[i][0]=f[nxt[i]+1][0];
		}
	for(int i=1;i<=log2(k);i++)
		for(int u=0;u<=n;u++)
			f[u][i]=f[f[u][i-1]][i-1];
	int p=0;
	for(int i=0;i<=log2(k);i++)
		if(k&(1LL<<i)) p=f[p][i];
	if(p==0) return 0;
	stack<int>s;
	for(int i=p;i<=n;i++)
	{
		if(vis[a[i]])
		{
			while(!s.empty()&&s.top()!=a[i]) vis[s.top()]--,s.pop();
			if(!s.empty()) vis[s.top()]--,s.pop();
		}
		else s.push(a[i]),vis[a[i]]++;
	}
	vector<int>res;
	while(!s.empty()) res.push_back(s.top()),s.pop();
	reverse(res.begin(),res.end());
	for(int u:res)
		printf("%d ",u); 
	return 0;
}

Measured memory_bytes: 56504
import Data.List
f s
 |null s=[]
 |null (init s)=[]
 |otherwise=(s!!1-s!!0):(f (tail s))
main=do
 [n,k]<-map read.words<$>getLine
 s<-map read.words<$>getLine
 print$sum$drop(n-1)(sortBy(flip compare)(f (sort s)))
 

Measured memory_bytes: 32892
#include <bits/stdc++.h>
#define ll         long long int 
#define pb         push_back
#define umap       unordered_map
#define mod        1000000007
#define all(x)     (x).begin(), (x).end()
#define rall(x)    (x).rbegin(), (x).rend()
#define MN(a,b,c)  min(a,min(b,c))
#define MX(a,b,c)  max(a,max(b,c))
#define pr1         pair<ll,ll>
#define F          first
#define S          second
#define mP         make_pair
#define f(i,n)     for(int i=0;i<n;i++)
#define f1(i,x,y)  for(int i=x;i<=y;i++)
#define f2(i,x,y)  for(int i=x;i>=y;i--)
#define yes        cout<<"Yes"<<"\n"
#define no         cout<<"No"<<"\n"
#define modsum(a,b)  ((a%mod)+(b%mod))%mod
#define modpro(a,b)  ((a%mod)*(b%mod))%mod
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes 
//__builtin_ctz(x)      to count the number of trailing zeroes 
//__gcd(a,b)
using namespace std;
ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=((x%M)*(x%M))%M;
        n=n/2;
    }
    return result;
}
ll binaryExponentiation(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}
ll pow1(ll x,ll y)
{
    ll z=1;
    while(y--){z=z*x;}
    return z;
}
ll nCrModpDP(ll n, ll r, ll p) 
{ 
    // The array C is going to store last row of 
    // pascal triangle at the end. And last entry 
    // of last row is nCr 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; // Top row of Pascal Triangle 
  
    // One by constructs remaining rows of Pascal 
    // Triangle from top to bottom 
    for (ll i = 1; i <= n; i++) 
    { 
        // Fill entries of current row using previous 
        // row values 
        for (ll j = min(i, r); j > 0; j--) 
  
            // nCj = (n-1)Cj + (n-1)C(j-1); 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
  
// Lucas Theorem based function that returns nCr % p 
// This function works like decimal to binary conversion 
// recursive function.  First we compute last digits of 
// n and r in base p, then recur for remaining digits 
ll nCrModpLucas(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
   // Compute last digits of n and r in base p 
   ll ni = n%p, ri = r%p; 
  
   // Compute result for last digits computed above, and 
   // for remaining digits.  Multiply the two results and 
   // compute the result of multiplication in modulo p. 
   return (nCrModpLucas(n/p, r/p, p) * // Last digits of n and r 
           nCrModpDP(ni, ri, p)) % p;  // Remaining digits 
} 
  
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 ll S; cin>>S;
    ll ans=0; ll n,r;ll z=1e9+7;
      for(ll i=1;i<=(S/3);i++)
         {
             n=S-(3*i);r=i;
            ll val=nCrModpLucas(n+r-1,r-1,z);
            //cout<<n<<' '<<r<<' '<<' '<<val<<"\n";
            ans=((ans%z)+(val%z))%z;
         }
      cout<<ans;
}


  

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <cstdio>

//2^32/26 = 165191049.846153846153846 = 165191050
#define MAGIC 0x9D89D8A

char shift (char c, int amount)
{
    long n;
    long q ;
    long r;
    
    n = (long) c - 'a' +  amount;
    q = n * MAGIC;
    q >>= 32;
    r = n - q * 26;
    
    return (char) 'a' + r;
}

void shiftString (char* s, int amount)
{
    int i = 0;
    while (s[i]) {
        
        if (s[i] == ' ') {}
        else if (s[i] == '.') {}
        else { s[i] = shift(s[i], amount); }
        i++;
    }
    
}

int main(int argc, const char * argv[]) {

   
    char buffer[256];
    std::string line;
    std::vector<std::string> listString;
    int result = 0;
    std::size_t found;
    
    
    while (std::getline(std::cin, line))
    {
        //sprintf(buffer, "%s", line.c_str());
        listString.push_back(line);
    }
    
    
    std::vector<std::string>::iterator it;
    
    it = listString.begin();
    
    do {
        result = 0;
        sprintf(buffer, "%s", (*it).c_str());
        
        while (!result)
        {
            
            shiftString(buffer, -1);
            line = buffer;
            
            result = 0;
            
            found = line.find("the");
            result += found!=std::string::npos;
            
            found = line.find("this");
            result += found!=std::string::npos;

            found = line.find("that");
            result += found!=std::string::npos;

        }
        
        printf("%s\n", buffer);
        
    } while (++it < listString.end());

    return 0;
}

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

string s;
ll ans=0;
ll a[1000000];


int main() {
  cin >> s;
  int m = s.size();
  int n = m+1;
  for(int i=0; i<n; i++){a[i]=-1;}
  
  if(s[0]=='<'){a[0]=0;}
  if(s[m-1]=='>'){a[n-1]=0;}
  
  for(int i=1; i<n; i++){
    if(s[i-1]=='>' && s[i]=='<'){
      a[i] = 0;
    }    
  }

  for(int i=0; i<m; i++){
    if(a[i] != -1 && s[i]=='<'){
      a[i+1] = a[i]+1;
    }    
  }

  for(int i=m-1; 0<=i; i--){
    if(a[i+1] != -1 && s[i]=='>'){
      a[i] = max(a[i],a[i+1]+1);
    }    
  }

  for(int i=0; i<n; i++){ans+=a[i];}

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

Measured memory_bytes: 5124
#include<iostream>
int gcd(int a, int b) {
	int m = (a > b) ? (a % b) : (b % a);
	if (m == 0)
		return a>b?b:a;
	return gcd(m, ((a > b) ? b : a));
}
int main() {
	using namespace std;
	int a, b, m;
	cin >> a >> b;
	m = gcd(a, b);
	cout << m << endl;
	return 0;
}




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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

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

const int MX = 200005;
int n, k, cn[MX];
ll res = 0;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		if (2 * i % k) continue;
		cn[i % k]++;
	}

	for (int i = 0; i < k; i++)
		res += ll(cn[i]) * cn[i] * cn[i];
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    n, m = LI()
    H = LI()
    ab = []
    good = [True for _ in range(n)]
    for i in range(m):
        a, b = LI_()
        ab.append((a, b))
        if H[a] > H[b]:
            good[b] = False
        if H[a] < H[b]:
            good[a] = False
        if H[a] == H[b]:
            good[b] = False
            good[a] = False
    cnt = 0
    for i in range(n):
        if good[i]:
            cnt += 1
    print(cnt)
main()


Measured memory_bytes: 30052
N = int(input())
L = []
L2 = []
for _ in range(N):
    x = int(input())
    L.append(x)
    L2.append(x)

L2 = sorted(L2)
m1 = L2[-1]
m2 = L2[-2]
for x in L:
    if x == m1:
        print(m2)
    else:
        print(m1)


Measured memory_bytes: 83416
#include <iostream>
#include <string>

using namespace std;

signed main()
{
  int max = 0;
  int start, stop;
  string s;

  cin >> s;

  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'A') {
      start = i;
      break;
    }
  }
  for (int i = s.length() - 1; i >= 0; i--) {
    if (s[i] == 'Z') {
      stop = i;
      break;
    }
  }
  
  cout << stop - start + 1 << endl;

  return (0);
}

Measured memory_bytes: 640
#include <algorithm>
#include <utility> 
#include <iostream>

using namespace std;
int N, M, ans;
pair<int,int> PD[10010];
int main() {
	while (cin >> N >> M && N) {
		ans = 0;
		int d, p, m;
		m = M;
		for (int i=0; i<N; ++i) {
			cin >> d >> p;
			PD[i] = make_pair(p, d);
		}
		sort(PD,PD+N);
		for (int i=0; i<N; ++i){
			if (m <= PD[N-1-i].second || m == 0){
				ans += (PD[N-1-i].second-m)*PD[N-1-i].first;
				m = 0;
			}else{
				m -= PD[N-1-i].second;
			}
			
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3072
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(void)
{

  int v1,v2,i,k,sum,dis1,dis2,flag,tmp;
  int a[10],b[10];
  while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9],&v1,&v2)!=EOF){
    sum=0;
    dis1=dis2=0;
    for(i=0;i<10;i++){
      a[i]*=1000;
      sum+=a[i];
      b[i]=sum;
    }
    i=0;
    k=1;
    while(dis1+dis2<sum){
      dis1+=v1;
      dis2+=v2;
      if(dis1>b[i]){
        i++;
	k++;
      }
    }
    printf("%d\n",k);
  }
  return 0;
}

Measured memory_bytes: 596
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int n;
    cin>>n;
    int a[n+2];
    f(i,1,n)
    {
        cin>>a[i];
    }
    int ses=inf;
    for(int i=-100;i<=100;i++)
    {
        int cost=0;
        f(j,1,n)
        {
            int x=a[j];
            int tmp=(x-i)*(x-i);
            cost+=(tmp);
        }
        ses=min(ses,cost);
    }
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 3648
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N; cin >> N;

    if(N <= 6){
        cout << 1 << endl;
        return 0;
    }

    if(N <= 11){
        cout << 2 << endl;
        return 0;
    }

    ll ans = N / 11 * 2;

    if(N % 11 >= 7){
        ans += 2;
    }else if(N % 11 != 0){
        ans += 1;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int x,y;
		x = sc.nextInt();
		y = sc.nextInt();

		System.out.print((x*y) + " ");
		System.out.println(((2*x)+(2*y)));

		sc.close();

	}

}



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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    string S;
    cin >> S;
    int N = S.size();
    int c = 0;
    for (int i=0; i<N/2; ++i) {
        if (S[i] != S[N-1-i]) c ++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main(){
		int w,n,i,a[31],y,z,j;
		char x;
		std::cin>>w;
		std::cin>>n;
		for(i=1;i<=w;i++){
			a[i]=i;
		}
		for(i=0;i<n;i++){
			std::cin>>y>>x>>z;
			j=a[y];
			a[y]=a[z];
			a[z]=j;
		}
		for(i=1;i<=w;i++){
		std::cout<<a[i]<<std::endl;
		}


	return 0;
}

Measured memory_bytes: 1160
MOD = 10**9+7
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [[0]*(M+1) for i in range(N+1)]
dp[0][0] = 1
for i in range(N+1):
    for j in range(M+1):
        if i-1 >= 0 and j-1>=0 and S[i-1] == T[j-1]:
            dp[i][j] += dp[i-1][j-1]
        if i-1 >= 0:
            dp[i][j] += dp[i-1][j]
        if j-1>= 0:
            dp[i][j] += dp[i][j-1]
        if i-1 >= 0 and j-1>=0:
            dp[i][j] -= dp[i-1][j-1]
        dp[i][j] %= MOD
print(dp[N][M]%MOD)


Measured memory_bytes: 73308
# -*- coding: utf-8 -*-


def main():
    """Function."""
    n = int(input())
    d, x = map(int, input().split())
    a = [int(input()) for _ in range(n)]

    x += n
    for i in range(1, d):
        for j in range(n):
            if i % a[j] == 0:
                x += 1
    print(x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i=0; i<n; i++)
#define println(v) cout << v << "\n";

int main()
{
	int N;
	cin >> N;
	vector<ll> var(256);
	for (char c='A'; c<='C'; c++) cin >> var[c];
	vector<string> s(N);
	REP(i, N) cin >> s[i];

	vector<char> ans(N);
	REP(i, N) {
		char c1 = s[i][0];
		char c2 = s[i][1];
		char cM = (var[c1] >= var[c2] ? c1 : c2);
		char cm = c1 ^ c2 ^ cM;
		if (var[c1] == var[c2] && i+1 < N && (s[i+1][0] == c1 || s[i+1][1] == c1)) {
			swap(cM, cm);
		}
		if (var[cM] == 0) {
			println("No");
			return 0;
		}
		var[cM]--;
		var[cm]++;
		ans[i] = cm;
	}

	println("Yes");
	REP(i, N) {
		println(ans[i]);
	}

	return 0;
}

Measured memory_bytes: 6440