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

namespace xmaho
{
inline namespace input
{
template<typename T>
T get_value(std::istream& is = std::cin);
template<typename C>
C get_container(std::istream& is = std::cin, typename C::size_type length = std::numeric_limits<typename C::size_type>::max());
}
}
using namespace xmaho;

int main()
{
  const auto N {get_value<unsigned long>(cin)};
  const auto K {get_value<unsigned long>(cin)};
  auto A {get_container<vector<unsigned long>>(cin, N)};

  vector<unsigned long> footprints(N);

  auto pos {0ul};
  for (auto i {0ul}; i < K; ++i) {
    if (footprints[pos] == 0) {
      footprints[pos] = i + 1;
      pos = A[pos] - 1;
    } else {
      const auto loop_length {i + 1 - footprints[pos]};
      if (loop_length > 1) {
        const auto left_count {K - i};
        const auto surplus_left_count {left_count % loop_length};
        const auto it {find(footprints.begin(), footprints.end(), surplus_left_count + footprints[pos])};
        pos = distance(footprints.begin(), it);
        cerr << "i, loop_length: " << i << ' ' << loop_length << '\n';
        cerr << "left_count: " << left_count << '\n';
        cerr << "surplus_left_count: " << surplus_left_count << '\n';
        cerr << "pos: " << pos << '\n';
      }
      break;
    }
  }

  cout << pos + 1 << '\n';

  return 0;
}

class initalization
{
  class custom_numpunct: public std::numpunct<char>
  {
  public:
    using numpunct::numpunct;
  protected:
    std::string do_truename() const override { return "Yes"; }
    std::string do_falsename() const override { return "No"; }
  };

public:
  initalization()
  {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.imbue(std::locale(std::cout.getloc(), new custom_numpunct{}));
    std::cout << std::boolalpha << std::fixed << std::setprecision(15);
  }
} initalize;

template<typename T>
T xmaho::input::get_value(std::istream& is)
{ T v {}; is >> v; return v; }

template<typename C>
C xmaho::input::get_container(std::istream& is, typename C::size_type length)
{
  C v {};
  if (length != std::numeric_limits<typename C::size_type>::max())
    v.reserve(length);
  typename C::value_type e {};
  for (auto i {length}; i != 0 && is >> e; --i)
    v.push_back(std::move_if_noexcept(e));
  return v;
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
int N=100010;
int main()
{
	int a[N]={0};
	int m;
	cin >> m;
	int b[m+10];
	for(int i=0;i<m;i++)
	{
		scanf("%d",&b[i]);
	}
	for(int i=0;i<m;i++)
	{
		a[b[i]+1]++;
		a[b[i]]++;
		a[b[i]-1]++;
	}
	int max=0;
	for(int i=0;i<N;i++)
	{
		if(a[i]>max)max=a[i];
	}
	cout << max << endl;
}

Measured memory_bytes: 1024
const findSet = p => {
	return x => {
		if (x != p[x]) p[x] = findSet(p)(p[x]);
		return p[x];
	}
}
const link = (p,r) => {
	return (x,y) => {
		if (r[x] > r[y]) p[y] = x;
		else {
			p[x] = y;
			if (r[x] === r[y]) r[y]++;
		}
	}
}
const dsFactory = n => {
	this.p = [];
	this.r = [];
	for (let i = 0; i < n; i++) {
		this.p[i] = i;
		this.r[i] = 0;
	}
	this.findSet = findSet(this.p);
	this.link = link(this.p,this.r);
	return {
		same: (x,y) => this.findSet(x) === this.findSet(y),
		unite: (x,y) => this.link(this.findSet(x),this.findSet(y))
	}
}

const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.split("\n");
const [n,q] = lines.shift().split(" ").map(Number);

const ds = dsFactory(n);

lines.forEach(x => {
	const [t,a,b] = x.split(" ").map(Number);
	switch (t) {
		case 0:
			ds.unite(a,b);
			break;
		case 1:
			const ret = ds.same(a,b) ? 1 : 0;
			console.log(ret);
			break;
	}
});


Measured memory_bytes: 64908
n,t = list(map(int,input().split()))
a = list(map(int,input().split()))
max_array = [0]*(n+1)
for i in range(n-1,-1,-1):
    max_array[i] = max(max_array[i+1],a[i])
max_diff = 0
for i in range(n):
    max_diff = max(max_diff,max_array[i] - a[i])
count = 0
for i in range(n):
    count += (max_array[i] - a[i]) == max_diff
print(count)

Measured memory_bytes: 15020
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]


if __name__ == "__main__":
    n, m, k = map(int, input().split())

    u = UnionFind(n)
    f_cnts = [0] * n
    b_cnts = [0] * n

    for _ in range(m):
        x, y = map(lambda x: int(x) - 1, input().split())
        u.union(x, y)
        f_cnts[x] += 1
        f_cnts[y] += 1

    for _ in range(k):
        x, y = map(lambda x: int(x) - 1, input().split())
        if u.same(x, y):
            b_cnts[x] += 1
            b_cnts[y] += 1

    cnts = ((u.size(i) - f_cnts[i] - b_cnts[i] - 1) for i in range(n))
    print(' '.join(map(str, cnts)))


Measured memory_bytes: 15548
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n,a,b;
    cin>>n>>a>>b;
    int sum=0;
    for(int i=1;i<=n;i++){
        int num=i,sum_dig=0;
        while(num){
            sum_dig += (num%10);
            num /= 10;
        }
        if(sum_dig>=a && sum_dig<=b){
            sum +=i;
        }
    }
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 384
# include <bits/stdc++.h>
///# include <ext/pb_ds/assoc_container.hpp>
///# include <ext/pb_ds/tree_policy.hpp>

///using namespace __gnu_pbds;
using namespace std;

# define ll long long
# define ld long double
# define pb push_back
# define ppb pop_back

const ll N = 1e5 + 10;
const ll M = 1e7 + 1000;
const ll mod = 998244353;
const ll INF = 1e18;
const ll inf = -1e18;

///typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> void_set;

bool isprime(ll x) {
    if(x == 1) return false;
    ll y = sqrt(x);
    for(int i = 2;i <= y;i++) {
        if(x % i == 0) {
            return false;
        }
    }
    return true;
}

ll bin_pow(ll a, ll b) {
    if(b == 0) return 1;
    if(b == 1) return a;
    if(a == 0) return 0;
    if(a == 1) return a;
    if(b % 2 == 0) {
        ll pw = bin_pow(a, b / 2);
        return pw * pw;
    } else {
        return bin_pow(a, b - 1) * a;
    }
}

const ld pi = acos(-1);

ll n, k, a, ans;

int main() {
    ///ios_base::sync_with_stdio(false);
    ///cin.tie(NULL), cout.tie(NULL);
    ///setlocale(0,"RUS");
    ///ifstream cin("input.txt");
    ///ofstream cout("output.txt");
    cin >> n >> k;
    for(int i = 1;i <= n;i++) {
        cin >> a;
        if(a >= k) ans++;
    }
    cout << ans;
}
/**
**/



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    unordered_map<char, int> nums;
    for (auto c : s) {
        ++nums[c];
    }

    if (nums.size() == 2 && nums.begin()->second == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> si;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
int xa,xb,xc,xd,ya,yb,yc,yd;
int main(){
    cin>>xa>>ya>>xb>>yb;
    xc = xb; yc = yb;
    int x,y;
    x = abs(xb-xa);
    y = abs(yb-ya);
    if(yb>=ya && xb>=xa){xc-=y; yc+=x;}
    else if(yb<=ya && xb>=xa){xc+=y; yc+=x;}
    else if(yb>=ya && xb<=xa){xc-=y; yc-=x;}
    else if(yb<=ya && xb<=xa){xc+=y; yc-=x;}
    yd = yc;
    xd = xc;

    xd += xa-xb;
    yd += ya-yb;

    printf("%d %d %d %d\n",xc,yc,xd,yd);
}


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

using namespace std;

#define M 1000000007

int main() {
	int n;
	cin >> n;
	string a, b;
	cin >> a;
	cin >> b;
	long long int ans = 1;
	bool h = true;
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			if (a[i] == b[i]) {
				ans *= 3;
				h = true;
			}
			else {
				ans *= 6;
				h = false;
				i++;
			}
		}
		else {
			if (h) {
				if (a[i] == b[i]) {
					ans *= 2;
					h = true;
				}
				else {
					ans *= 2;
					h = false;
					i++;
				}
			}
			else {
				if (a[i] == b[i]) {
					ans *= 1;
					h = true;
				}
				else {
					ans *= 3;
					h = false;
					i++;
				}
			}
		}
		ans %= M;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

int n, ans[N];
int main()
{
	int i, t;
	cin >> n;
	for (i = 1; i <= n; i++) {
		scanf("%d", &t);
		ans[t] = i;
	}
	for (i = 1; i <= n; i++) printf("%d ", ans[i]);
    return 0;
}

Measured memory_bytes: 1152
import sys, math
from collections import Counter

def input():
    return sys.stdin.readline()[:-1]

def main():
    N = int(input())
    S = [input() for k in range(N)]
    C = Counter(S)
    t = 0
    for e in C.values():
        t = max(e,t)
    ans = []
    for e in C:
        if C[e] == t:
            ans.append(e)
    print(*sorted(ans),sep="\n")

if __name__ == '__main__':
    main()


Measured memory_bytes: 100312
n = int(input())
robot = list(list(map(int, input().split(' '))) for i in range(n))

for i in range(n):
  robot[i].append(robot[i][0]-robot[i][1])
  robot[i].append(robot[i][0]+robot[i][1])

robot.sort(key=lambda x: x[3])

ans=1
left=robot[0][2]
right=robot[0][3]
for i in range(1,n):
  if robot[i][2]>=right:
    ans+=1
    right=robot[i][3]
    
    
print(ans)  

Measured memory_bytes: 34976
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a = in.nextInt();

            out.println((n % 500) <= a ? "Yes" : "No");
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 21460
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<db> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 
typedef vector<pd> vpd; 

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() 
#define rsz resize
#define ins insert 
#define ft front() 
#define bk back()
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define lb lower_bound 
#define ub upper_bound 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MX  = 2e5+5; 
const int MOD = 1e9+7; // 998244353;
const ll  INF = 1e18; 
const ld  PI  = acos((ld)-1);

const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 

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

constexpr int pct(int x) { return __builtin_popcount(x); } // number of ones 
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) 
template<class T> T cdiv(T a, T b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0 

int fstTrue(function<bool(int)> f, int lo, int hi) {
	hi++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true 
		int mid = (lo+hi)/2; 
		f(mid) ? hi = mid : lo = mid+1; 
	} 
	return lo;
}

template<class T> void remDup(vector<T>& v) { 
	sort(all(v)); v.erase(unique(all(v)),end(v)); 
}

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << h; if (sizeof...(t)) cerr << ", ";
	DBG(t...); 
}
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

// FILE I/O
void setIn(str S) { freopen(S.c_str(),"r",stdin); }
void setOut(str S) { freopen(S.c_str(),"w",stdout); }
void setIO(str S = "") {
	ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(S)) { setIn(S+".in"), setOut(S+".out"); } // for USACO
}

int32_t main() { 
	
	setIO();

	int D,T,S; cin >> D >> T >> S;

	if (ld(D)/ld(S) <= ld(T)) {
		cout << "Yes\n";
	} else cout << "No\n";

}

Measured memory_bytes: 3608
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop
import sys
stdin = sys.stdin
mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

a, b = na()

for n in range(10*b, 10*(b+1)):
    if int((n/100)*8) == a:
        print(n)
        quit()
print(-1)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

const int N = 2E5 + 100;
int n, a[N], b[N];

int main() {
    cin >> n;
    FOR (i, 1, n + 1) cin >> a[i];
    FOR (i, 1, n + 1) b[a[i]] = i;
    int now = 1, ans = 0;
    FOR (i, 1, n + 1) {
        if (i > 1 && b[i] > b[i - 1]) now++;
        else now = 1;
        ans = max(ans, now);
    }
    cout << n - ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 100000


int n,k;
long long T[MAX];

int check(long long p){
    int i=0;
    for(int j=0;j<k;j++){
        long long s=0;
        while(s+T[i]<=p){
            s+=T[i];
            i++;
            if(i==n)return n;
        }
    }
return i;}

int solve(){
    long long left=0;
    long long right = 100000*10000;
    long long mid;
    while(right-left>1){
        mid=(left+right)/2;
        int v=check(mid);
        if(v>=n)right=mid;
        else left = mid;
    }
    return right;
}

int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%lld",&T[i]);
    }
    long long ans=solve();
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 4012
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
void setIO(string name) {
	ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
int n,aa;
vector<int> adj[1001];
int dp[1001][2];
int st=1;
void dfs(int no){
	for(auto j:adj[no]){
		dfs(j);
	}

	int su=0;
	int su2=0;
	for(auto j:adj[no]){
		su2+=dp[j][0];
		su2+=dp[j][1];
		su+=min(dp[j][0],dp[j][1]);
	}
	if(su>dp[no][0]){
		st=0;
		return;
	}
	int dp2[5001];
	int dp3[5001];
	for(int i=0;i<5001;i++){
		dp2[i]=0;
	}
	dp2[0]=1;
	for(auto j:adj[no]){
		for(int i=0;i<5001;i++){
			dp3[i]=0;
		}
		dp3[0]=1;
		for(int i=dp[j][0];i<5001;i++){
			dp3[i]=max(dp3[i],dp2[i-dp[j][0]]);
		}
		for(int i=dp[j][1];i<5001;i++){
			dp3[i]=max(dp3[i],dp2[i-dp[j][1]]);
		}
		for(int i=0;i<5001;i++){
			dp2[i]=dp3[i];
		}
	}
	int ind=0;
	for(int i=0;i<=dp[no][0];i++){
		if(dp2[i]){
			ind=max(ind,i);
		}
	}
	dp[no][1]=su2-ind;
	//cout<<no<<","<<dp[no][0]<<","<<dp[no][1]<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;

	for(int i=1;i<n;i++){
		dp[i][0]=0;dp[i][1]=0;
		cin>>aa;
		adj[aa-1].pb(i);
	}
	for(int i=0;i<n;i++){
		cin>>dp[i][0];
	}
	dfs(0);
	if(st==1){
		cout<<"POSSIBLE"<<endl;
	}
	else{
		cout<<"IMPOSSIBLE"<<endl;
	}



	return 0;
}

Measured memory_bytes: 17024
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const int mod = 1e9+7;
const int N = 6e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;

int main() {
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    if(a!=c) cout<<1<<endl;
    else cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    char  word[10] = {}, moji[1001] = {} ;
    int i, r = 0;
    scanf("%s", word);
    for( i = 0; i < strlen( word ); i++ ){
        word[i] = tolower( word[i] );
    }
    for(;;){
        scanf("%s", moji);
        if( strcmp( moji, "END_OF_TEXT" ) == 0 ){
            break;
        }
        for( i = 0; i < strlen( moji ); i++ ){
            moji[i] = tolower( moji[i] );
        }
        if( strcmp( word, moji ) == 0 ){
            r++;
        }
    }
   printf("%d\n", r);
    return 0;
}

Measured memory_bytes: 552
#include<stdio.h>
#include <string.h>
 
int main()
{
    char card[2];
    int i, j, taro, mark, number, str[4][13] = { 0 };
    scanf("%d", &taro);
    for (i = 0; i<taro ; i++){
        scanf("%s %d", card, &number);
        if (strcmp(card,  "S") == 0){ mark = 0; }
        else if (strcmp(card, "H") == 0){ mark = 1; }
        else if (strcmp(card, "C") == 0){ mark = 2; }
        else if (strcmp(card, "D") == 0){ mark = 3; }
        str[mark][number - 1] = 1;
    }
 
    for (i = 0; i<4; i++){
        for (j = 0; j<13; j++){
            if (str[i][j] == 0){
                if (i == 0){ mark = 'S'; }
                else if (i == 1){ mark = 'H'; }
                else if (i == 2){ mark = 'C'; }
                else if (i == 3){ mark = 'D'; }
                printf("%c %d\n", mark, j + 1);
            }
        }
    }
    return 0;
}

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

int main(){
    int n,p;
    while(cin>>n>>p,n|p){
        int a[51]={};
        int P=p,i=0;
        while(1){
            if(p){
                p--;
                a[i]++;
            }else{
                p=a[i];
                a[i]=0;
            }
            if(a[i]==P)break;
            if(++i==n)i=0;
        }
        cout<<i<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,m,k;
  cin>>n>>m>>k;
  vll a(n);
  vll b(m);
  rep(i,n) cin>>a[i];
  rep(i,m) cin>>b[i];
  vll bb(m);
  bb[0]=b[0];
  rep(i,m){
    if(i==0) continue;
    bb[i]+=bb[i-1]+b[i];
  }
  ll ccu=0;
  ll ans=0;
  rep(i,m){
    ccu+=b[i];
    if(ccu<=k){
      ans++;
    }
    else break;
  }
  ll cu=0;
  rep(i,n){
    cu+=a[i];
    ll no=k-cu;
    if(no>0){
      auto Iter1 = upper_bound(all(bb),no);
      ll bk=Iter1 - bb.begin();
      ans=max(i+1+bk,ans);
    }
    else if(no==0){
      ans=max(ans,i+1);
    }
    else break;
  }
  COUT(ans);
}


Measured memory_bytes: 7996
//18
#include<iostream>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int ans=0;
    for(int i=0;i*4<n;i++){
      int i;
      cin>>i;
      ans+=i;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import math
while True:
    n = int(input())
    if n==0:
        break
    else:
        l = input().split()
        m = 0.0000
        s = 0.0000
        for i in range(n):
            m = m + float(l[i])
        m = m/n
        for i in range(n):
            s = s + (float(l[i])-m)**2
        print(math.sqrt(s/n))


Measured memory_bytes: 5784
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
long long a,b;
int main()
{
	scanf("%I64d %I64d",&a,&b);
	if(a%b==0)
	{
		printf("-1\n");
		return 0;
	}
	for(long long i=2;i*a<=1000000000000000000ll;i++)
	{
		if(a*i%b!=0)
		{
			printf("%I64d\n",a*i);
			return 0;
		}
	}
	printf("-1\n");;
}

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

int arr[102];
int main()
{

    int n,k,x,a,cnt=0;
    scanf("%d%d",&n,&k);
    while(k--)
    {
        scanf("%d",&x);
        {
            for(int i=1; i<=x; i++)
            {
                scanf("%d",&a);
                arr[a] = 1;
            }
        }
    }

    for(int i=1; i<=n; i++)
    {
        if(!arr[i])
            cnt++;
    }

    printf("%d\n",cnt);
    return 0;
}



Measured memory_bytes: 3780
ans = []
while true
  count, value = gets.split(" ").map(&:to_i)
  break if count.zero? && value.zero?
  sum = 0
  memo = []
  (1..count).each do |val1|
    (1..count).each do |val2|
      next if val2 < val1 || val2 == val1
      (1..count).each do |val3|
        next if val3 < val2 || val2 == val3
        sum += 1 if val1 + val2 + val3 == value
      end
    end
  end
  ans << sum
end

puts ans

Measured memory_bytes: 6108
from collections import deque
N,M = map(int,input().split())
g = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
ans = 0
que = deque([[0]])
while len(que) != 0:
    p = que.popleft()
    if len(p) == N:
        ans += 1
    else:
        for i in range(len(g[p[-1]])):
            if not g[p[-1]][i] in p:
                que.append(p + [g[p[-1]][i]])
print(ans)


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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

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

  vector<int> v(n);
  rep(i, n) { cin >> v[i]; }

  sort(all(v), greater<int>());
  int sum = 0;
  rep(i, k) {
    sum += v[i];
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	sort(a.rbegin(),a.rend());
	ll b=0,c=0;
	bool flg=false;
	rep(i,n-1){
		if(a.at(i)==a.at(i+1)){
			if(flg){
				c=a.at(i);
				break;
			}
			else{
				b=a.at(i);
				i++;
				flg=true;
			}
		}
	}
	cout << b*c << endl;
}

Measured memory_bytes: 640
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = INT()

@lru_cache(maxsize=None)
def rec(x):
    if x == 0: return 1

    ret = 0
    for i in range(x-2):
        ret += rec(i)
        ret %= mod
    return ret

print(rec(S))


Measured memory_bytes: 10348
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define INF 2e9

#define REP(i,n) for(int i = 0; i < n;++i)
#define REPA(i,a,n) for(int i = a; i < n; ++i)
#define ALL(a) a.begin, a.end()

using namespace std;

int main(void) {

	int N;

	cin >> N;

	vector<int> H(N);

	REP(i, N) cin >> H[i];

	int max = H[0] - 1;

	REP(i, N) {
		if (max < H[i]) {
			max = H[i] - 1;
		}
		if (max > H[i]) {
			cout << "No\n";
			return 0;
		}
	}

	cout << "Yes\n";

	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  map<int, int> a_dis;
  for (int i = 0; i < N; ++i) {
    ll tmp;
    cin >> tmp;
    if (tmp % 2 != 0)
      tmp = 1;
    else if (tmp % 4 == 0)
      tmp = 4;
    else
      tmp = 2;
    auto itr = a_dis.find(tmp);
    if (itr != a_dis.end()) {
      a_dis[tmp] += 1;
    } else {
      a_dis[tmp] = 1;
    }
  }

  if (a_dis[2] == 0) {
    if (a_dis[1] <= a_dis[4] + 1)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  } else {
    if (a_dis[1] <= a_dis[4])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int t, cnt, sum=0, i, j, start=0, dif;
    string ss;
    vector<string>vc;
    scanf("%lld", &t);
    for(i=0; i<t; i++)
    {
        cin>>ss;
        vc.push_back(ss);
        sort(vc[i].begin(), vc[i].end());
    }
    sort(vc.begin(), vc.end());
    for(i=1; i<t; i++)
    {
        if(vc[start]!=vc[i])
        {
            dif=i-start;
            sum=sum+(dif*(dif-1))/2;
            start=i;
        }
    }
    dif=t-start;
    sum=sum+(dif*(dif-1))/2;
    printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 5748
#include<stdio.h>
#define NC 0
#define C -1
#define N 1000
#define W 0
#define G 1
#define B 2
int HAKO[N][N];
int color[N];
int Stack[N];
int d[N];
int f[N];
int h[N];
int num=0;
int time=0;
int n;

void push(int u){
  Stack[num]=u;
  num++;
  }
void pop(void){
  Stack[num]=-1;
  num--;
}
int next(int u){
  int i;
  for(i=1;i<=n;i++){
    if(HAKO[u][i]==C && color[i]==W) return i; 
      }
  return NC;
  }

void visit(int r){
  int u,v;
  push(r);
  color[r]=G;
  d[r]=++time;
    while(num!=0){
    u=Stack[num-1];
    v=next(u);
    // printf
    if(v!=NC){
      if(color[v]==W){
	push(v);
	color[v]=G;
	d[v]=++time;
      }
    }
    else{
      pop();
      color[u]=B;
      f[u]=++time;
      }
    

    }
  //  printf("%d",num);

}


void dfs(int u){
  int i;
  for(i=1;i<=u;i++) {
    if(color[i]==W) visit(i);
  }
};
int main(){
  int i,j,u,k,v;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=0;j<n;j++){
      HAKO[i][j]=NC;
    }
  }
  for(i=1;i<=n;i++){
    scanf("%d %d",&u,&k);
    h[i]=0;
    color[i]=W;
    for(j=0;j<k;j++){
      if(k==0) break;
      scanf("%d",&v);
      HAKO[u][v]=C;
    }
  }
 
  dfs(n);
    for(i=1;i<=n;i++){
      printf("%d %d %d\n",i,d[i],f[i]);}  
  return 0;
}



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

int main(void){
    int n;
    cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    int cnt=0;
    rep(i,n-1){
        if(p[i] == i+1){
            swap(p[i],p[i+1]);
            cnt++;
        }
    }
    if(p[n-1] == n){
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 640
//#include<bist_stdc++.h>
#include <iostream>
#include <vector>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;

int main() {
    int r, c;
    cin >> r >> c;
    vector<vector<int> > sheet(r, vector<int>(c));
    rep(i, r) rep(j, c) cin >> sheet[i][j];
    vector<int> rsum(r, 0);
    vector<int> csum(c + 1, 0);
    rep(i, r) rep(j, c) rsum[i] += sheet[i][j];
    rep(i, c) rep(j, r) csum[i] += sheet[j][i];
    rep(i, r) csum[c] += rsum[i];
    rep(i, r) {
        rep(j, c) cout << sheet[i][j] << " ";
        cout << rsum[i] << endl;
    }
    rep(i, c) cout << csum[i] << " ";
    cout << csum[c] << endl;
}



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 1e18+18;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a, b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n, m, arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n, arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n, arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>
istream &operator>>(istream &i, vector<T> &v) {
    rep(j, v.size())i>>v[j];
    return i;
}

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

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len = vv.size();
    for(int i = 0; i < len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n, c;
    cin>>n>>c;
    //ll MAX = 13;
    ll MAX = 1e5;
    VV tm(MAX);
    rep(i, n) {
        ll s, t, ch;
        cin>>s>>t>>ch;
        tm[s].pb(ch);
        tm[t].pb(ch*-1);
    }
    ll ans = 1;

    set<ll> se;
   // dbg(tm);
    REP(i,1, MAX) {
        Vec del;
        set<ll> dup;
        Each(x, tm[i]) {
            if(x > 0) {
                if(se.find(x)!=se.end()){
                    dup.insert(x);
                }else{
                    se.insert(x);
                }
            } else if(x<0){
                del.pb(-1*x);
            }
        }
        chmax(ans,(ll)se.size());
        //dbg(se.size());
        Each(x,del){
            if(dup.find(x)==dup.end()){
                se.erase(x);
            }
        }
    }

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


Measured memory_bytes: 6144
// URL: https://atcoder.jp/contests/abc134/tasks/abc134_c

import std.algorithm, std.container, std.math, std.range, std.typecons, std.string;

version(unittest) {} else
void main()
{
  int n; io.getV(n);
  int[] a; io.getC(n, a);

  auto b = a.dup.sort!"a>b";
  foreach (ai; a)
    io.putB(ai == b[0], b[1], b[0]);
}

auto io = IO();

struct IO
{
  import std.algorithm, std.conv, std.format, std.meta, std.range, std.stdio, std.traits;

  dchar[] buf;
  auto sp = (new dchar[](0)).splitter;
  int precision = 10;
  string delimiter = " ";

  void nextLine()
  {
    stdin.readln(buf);
    sp = buf.splitter;
  }

  auto get(T)(ref T v)
  {
    if (sp.empty) nextLine();
    v = sp.front.to!T;
    sp.popFront();
  }

  auto getV(T...)(ref T v)
  {
    foreach (ref w; v) get(w);
  }

  auto getA(T)(size_t n, ref T v)
  if (hasAssignableElements!T)
  {
    v = new T(n);
    foreach (ref w; v) get(w);
  }

  auto getC(T...)(size_t n, ref T v)
  if (allSatisfy!(hasAssignableElements, T))
  {
    foreach (ref w; v)
      w = new typeof(w)(n);
    foreach (i; 0..n)
      foreach (ref w; v) get(w[i]);
  }

  auto getM(T)(size_t r, size_t c, ref T v)
  if (hasAssignableElements!T && hasAssignableElements!(ElementType!T))
  {
    v = new T(r);
    foreach (ref w; v) getA(c, w);
  }

  auto putA(T)(T v)
  {
    static if (isInputRange!T && hasLength!T && !isSomeString!T) {
      foreach (i, w; v) {
	putA(w);
	if (i < v.length - 1) write(delimiter);
      }
    } else if (isFloatingPoint!T) {
      writef(format("%%.%df", precision), v);
    } else {
      write(v);
    }
  }

  auto put(T...)(T v)
  {
    foreach (i, w; v) {
      putA(w);
      if (i < v.length - 1) write(delimiter);
    }
    writeln;
  }

  auto putB(S, T)(bool c, S t, T f)
  {
    if (c)
      put(t);
    else
      put(f);
  }

  auto dbg(T...)(T v)
  {
    stderr.writeln(v);
  }
}


Measured memory_bytes: 6012
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define INF 1000000007
using P = pair<int, int>;
using ll = long long;
int main(){
    int n;
    cin>>n;
    int a[214514];
    for(int i=0;i<n;i++)cin>>a[i];
    if(n%2==1){
        for(int i=n/2*2;i>=0;i-=2)cout<<a[i]<<" ";
        for(int i=1;i<n;i+=2)cout<<a[i]<<" ";
        cout<<endl;
    }else{
        for(int i=n-1;i>=0;i-=2)cout<<a[i]<<" ";
        for(int i=0;i<n;i+=2)cout<<a[i]<<" ";
        cout<<endl;
    }
    return 0;
}



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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
    int n;
    while (cin >> n) {
        map<string,int> cnt;
        FOR(i,0,n) {
            string s; cin >> s; sort(ALL(s)); cnt[s]++;                
        }
        LL ans = 0;
        FOR_ALL(s,cnt) {
            const LL x = s->second;
            ans += x*(x-1)/2;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int k;
  cin >> k;
  vector<P> p;
  rep(i, k) {
    int r, c;
    cin >> r >> c;
    p.push_back(P(r, c));
  }
  vi v = {0, 1, 2, 3, 4, 5, 6, 7};
  do {
    bool ok = true;
    rep(i, k) {
      int x = p[i].first;
      int y = p[i].second;
      if(v[x] != y) ok = false;
    }
    rep(i, 7) {
      int x = i, y = v[i];
      rep2(j, i + 1, 8) {
        int nx = j, ny = v[j];
        if(abs(x - nx) == abs(y - ny)) ok = false;
      }
    }
    if(ok) break;
  } while(next_permutation(all(v)));
  rep(i, 8) {
    rep(j, 8) cout << (v[i] == j ? 'Q' : '.');
    cout << endl;
  }
}


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

int main() {
 int N,K;
 cin >> N >> K;
 vector<int>P(N);
 
  for(int i=0;i<N;i++){
    cin >> P.at(i);
  }
  sort(P.begin(),P.end());
  
  int sum = 0;
  
  for(int i=0;i<K;i++){
    sum += P.at(i);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3604
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] X = new int[M];
        for(int i = 0; i < M; i++){
            X[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(X);
        int[] dis = new int[M-1];
        for(int i = 0; i < M-1; i++){
            dis[i] = X[i+1] - X[i];
        }
        Arrays.sort(dis);
        int ans = X[M-1] - X[0];
   
        if(N>=M)
            System.out.println(0);
        else{
            for(int i = 0; i < N-1; i++){
                ans -= dis[M-2-i];
            }
            System.out.println(ans);
        }
    }
}


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

int main(){
  int n;
  int id[5],t[5];
  int m,s;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<4;i++){
      cin >> id[i];
      t[i] = 0;
      for(int j=0;j<4;j++){
	cin >> m >> s;
	t[i] += m*60 + s;
      }
    }

    for(int i=0;i<3;i++){
      for(int j=i+1;j<4;j++){
	if(t[i]>t[j]){
	  swap(t[i],t[j]);
	  swap(id[i],id[j]);
	}
      }
    }

    for(int i=4;i<n;i++){
      cin >> id[4];
      t[4] = 0;
      for(int j=0;j<4;j++){
	cin >> m >> s;
	t[4] += m*60 + s;
      }
      if(t[4] < t[0]){
	swap(t[0],t[1]);
	swap(id[0],id[1]);
	swap(t[0],t[4]);
	swap(id[0],id[4]);
      }else if(t[4] < t[1]){
	swap(t[1],t[4]);
	swap(id[1],id[4]);
      }

      if(t[4] > t[3]){
	swap(t[2],t[3]);
	swap(id[2],id[3]);
	swap(t[3],t[4]);
	swap(id[3],id[4]);
      }else if(t[4] > t[2]){
	swap(t[2],t[4]);
	swap(id[2],id[4]);
      }
    }

    cout << id[0] << endl << id[1] << endl << id[2] << endl;
  }
}

Measured memory_bytes: 864
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val S = in.next
  val nR = S.count(_ == 'R')
  val nG = S.count(_ == 'G')
  val nB = N - nR - nG

  @inline 
  def c(i: Int) = S.charAt(i)

  val un = (for {
    i <- 0 to N - 3
    j <- i + 1 to N - 2 if 2 * j - i < N
  } yield if (c(i) != c(j) && c(i) != c(2 * j - i) && c(j) != c(2 * j - i)) 1 else 0).sum

  println(nR.toLong * nG * nB - un)
}

Measured memory_bytes: 76312
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};
#[fastout]
fn main() {
    input!(n: usize);

    let mut count = 0;
    for i in 1..n {
        count += (n - 1) / i;
    }
    println!("{}", count);
}


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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	int d; cin >> d;

	if(d == 5 or d == 3 or d == 7){
		cout << "YES" << endl;
		return 0;
	}

	cout << "NO" << endl;

	
	return 0;
}

Measured memory_bytes: 256
/*
  AUTHOR:SOURABH
  CREATED:27:12:19
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll n,a,b;
    cin>>n>>a>>b;
    if((b-a)%2==0)
    cout<<(b-a)/2;
    else
    cout<<min(a+(b-a)/2,n-b+1+(b-a)/2);
    return 0;
}








Measured memory_bytes: 256
n = int(input())
a = sorted(list(map(int, input().split())))
if n % 2 == 0:
  if a == sorted(2*[2*x+1 for x in range(int(n/2))]):
    print((2**int(n/2))%1000000007)
  else:
    print(0)
else:
  if a == sorted(list(2*[2*x for x in range(n//2+1)])[1:]):
    print((2**(n//2))%1000000007)
  else:
    print(0)

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

int main(void){
    int n, a[100];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    // bubble sort
    int end_flag = 0, swap_num = 0, temp;
    while(!end_flag){
        end_flag = 1;
        for(int i=n-1; i >= 1; i--){
            if(a[i] < a[i - 1]){
                end_flag = 0;
                temp = a[i];
                a[i] = a[i - 1];
                a[i - 1] = temp;
                swap_num++;
            }
        }
    }
    // display array
    for (int i = 0; i < n; i++){
        if(i) cout << " ";
        cout << a[i];
    }
    cout << endl;
    cout << swap_num << endl;
    return 0;
}


Measured memory_bytes: 3088