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

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define deg(x) cout<<x<<" "

using ld = long double;
using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,k;
	cin >> n >> k;
	ll cnt=0;
	vector <ll> pp;
	f(i,1,n+1){
		if(i<k){
			ll r=ceil(log2(k)-log2(i));
			pp.pb(r);
		}
		else{
			cnt++;
		}
	}
	if(pp.empty()){
		ld ans=((ld)cnt)/((ld)n);
		cout << setprecision(14) << fixed << ans << "\n";
		return 0;
	}
	ll ans=1;
	sort(all(pp),greater<ll>());
	ll g=(1<<pp[0]);
	f(i,1,(ll)pp.size()){
		ll kk=(1<<pp[i]);
		ans+=(g/kk);
	}
	ans=ans+cnt*g;
	ll gg=__gcd(n,ans);
	n=n/gg;
	ans=ans/gg;
	gg=__gcd(ans,g);
	ans=ans/gg;
	g=g/gg;
	g=g*n;
	ld res=((ld)ans)/((ld)g);
	cout << setprecision(14) << fixed << res << "\n";
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;

long long calcArea(const vector<P> &pts){
    long long sum = 0;
    for(int i=0;i<pts.size();i++){
        P a = pts[i];
        P b = pts[(i+1)%pts.size()];
        sum += a.first*b.second - a.second*b.first;
    }
    if(sum<0)sum = -sum;
    return sum / 2;
}


int main(){
    for(int n; cin>>n, n; ){
        long long sum = 0;
        vector<P>C;
        vector<P>W;
        set<int>X;
        set<int>Y;
        int xmin = 40000, xmax = -40000;
        int ymin = 40000, ymax = -40000;
        for(int i = 0; i < n; i++){
            int x, y;
            cin>>x>>y;
            W.push_back(P(x, y));
            X.insert(x);
            Y.insert(y);
        }
        for(int i=0;i<4;i++){
            int x, y;
            cin>>x>>y;
            C.push_back(P(x, y));            
            X.insert(x);
            Y.insert(y);
            xmin = min(xmin, x);
            xmax = max(xmax, x);
            ymin = min(ymin, y);
            ymax = max(ymax, y);
        }
        set<int>::iterator l = X.begin();
        set<int>::iterator r = X.begin();
        r++;
        for(; r != X.end(); l++, r++){
            if(xmin <= (*l) && (*r) <= xmax){
                int d = (*r) - (*l);
                set<int>::iterator b = Y.begin();
                set<int>::iterator u = Y.begin();
                u++;
                for(int on = 0;u!=Y.end();u++, b++){
                    for(int i=0;i<W.size();i++){
                        P p = W[i], q = W[(i+1)%W.size()];
                        if(p.second != q.second)continue;
                        if(p.second != (*b))continue;
                        int mx = max(p.first, q.first);
                        int mn = min(p.first, q.first);
                        if(mn <= (*l) && (*r) <= mx){
                            on = (on+1)%2;
                            break;
                        }
                    }
                    if(on){
                        if(ymin <= (*b) && (*u) <= ymax){
                            sum += d * ((*u) - (*b));
                        }
                    }
                }
            }
        }
        cout<<calcArea(W) - sum<<endl;
        
    }
    
    return 0;
}


Measured memory_bytes: 3100
n,k = gets.chomp.split.map(&:to_i)
h = []
n.times { h << gets.to_i }
h.sort!
min = (h[0]-h[-1+k]).abs
(0..n-k).each do |i|
    min = [min, (h[i]-h[i-1+k]).abs].min
end
puts min

Measured memory_bytes: 4016
/*
Author : Vidish Joshi
*/

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

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define start1 ll t = 1; while(t--)
#define F first
#define S second
#define br "\n"

void solve(){
    int n; cin>>n;
    int a[n];

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

    int dp[n+1] = {INT_MAX};
    dp[n] = -1e4;

    dp[n-1] = 0;
    for(int i=n-2; i>=0; i--){
        dp[i] = min(abs(a[i] - a[i+1]) + dp[i+1], abs(a[i] - a[i+2]) + dp[i+2]);
    }

    cout<<dp[0]<<br;

}

int main(){
    FIO;
    start1{
        solve();
    }
    return 0;
}


Measured memory_bytes: 1024
fun main() {
    val m = readLine()!!.split(' ')[1].toInt()
    val hs = readLine()!!.split(' ').map { it.toInt() to true }.toMutableList()
    repeat(m) {
        val input = readLine()!!.split(' ').map { it.toInt() }
        val l = input[0] - 1
        val r = input[1] - 1
        val lh = hs[l].first
        val rh = hs[r].first
        if (lh == rh) {
            hs[l] = hs[l].copy(second = false)
            hs[r] = hs[r].copy(second = false)
            return@repeat
        }
        val index = if (lh < rh) l else r
        hs[index] = hs[index].copy(second = false)
    }

    println(hs.count { it.second })
}

Measured memory_bytes: 72048
import sys
input = sys.stdin.buffer.readline

n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10**9+7

if n == 1:
    if t[0] != a[0]:
        print(0)
    else:
        print(1)
    exit()

max_list = [10**9+1] * n
min_list = [0] * n

max_list[0] = t[0]
min_list[0] = t[0]
for i in range(1, n):
    if t[i] > t[i-1]:
        max_list[i] = t[i]
        min_list[i] = t[i]
    else:
        max_list[i] = t[i]
        min_list[i] = 1

max_list[n-1] = a[n-1]
min_list[n-1] = a[n-1]
for i in range(n-2, -1, -1):
    if a[i] > a[i+1]:
        if min_list[i] <= a[i] <= max_list[i]:
            max_list[i] = a[i]
            min_list[i] = a[i]
        else:
            print(0)
            exit()
    else:
        if max_list[i] == min_list[i]:
            if max_list[i] > a[i]:
                print(0)
                exit()
        else:
            max_list[i] = min(max_list[i], a[i])

ans = 1
for i in range(n):
    ans = (ans * (max_list[i] - min_list[i] + 1)) % mod
print(ans)


Measured memory_bytes: 62828
#include <bits/stdc++.h>
#define ll long long

const int mxw = 1e5+1, mxn = 100;
ll dp[mxw][mxn+1];
ll val[mxn], w[mxn];

int n, wt;
using namespace std;



int main(){
    
    cin>>n>>wt;
    for(int i=0; i<n; ++i){
        ll weight, v;
        cin>>weight>>v;
        val[i] = v;
        w[i] = weight;
    }
    for(int i=0; i <= n; ++i){
        for(int j=0; j <= wt; ++j){
            if(i == 0 || j == 0)
                dp[j][i] = 0;
            else if(w[i-1] <= j)
                dp[j][i] = max(val[i-1]+dp[j-w[i-1]][i-1], dp[j][i-1]);
            else{
                dp[j][i] = dp[j][i-1];
            }
        }
    }
    cout<<dp[wt][n]<<endl;
    return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

struct DOOR{
	string id;
};

int find_door(string id, vector<DOOR> doors) {
	for (int i = 0; i < doors.size(); i++) {
		if (id == doors[i].id)
			return i;
	}
	return -1;
}

int main(void) {
	int N;
	cin >> N;
	cin.ignore();
	vector<DOOR> door(N);
	for (int i = 0; i < N; i++) {
		getline(cin, door[i].id);
	}
	
	bool isOpen = false;
	int M;
	cin >> M;
	cin.ignore();
	for (int i = 0; i < M; i++) {
		string id;
		getline(cin, id);
		int index = find_door(id, door);
		if (index != -1) {
			if (isOpen) {
				cout << "Closed by " << id << endl;
				isOpen = false;
			}else {
				cout << "Opened by " << id << endl;
				isOpen = true;
			}
		}else {
			cout << "Unknown " << id << endl;
		}
	}

	return 0;
}

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

using namespace std;

int main() {
  string str;
  int i = 0;
  int data[3][3];
  while(getline(cin, str)) {
    for(int i = 0; i < str.length(); i++) {
      switch(str[i]) {
      case 'o': data[i/3][i%3] = 1;  break;
      case 'x': data[i/3][i%3] = -1; break;
      case 's': data[i/3][i%3] = 0; break;
      }
    }
    int flag = 0;
    for(int i = 0; i < 3; i++) {
      int kind;
      for(int j = 0; j < 3; j++) {
	if(data[i][j] == 0) break;
	if(j == 0) kind = data[i][j];
	else {
	  if(data[i][j] != kind) break;
	  else if(j == 2) flag = kind;
	}
      }
    }
    if(flag == 0) {
      for(int i = 0; i < 3; i++) {
	int kind;
	for(int j = 0; j < 3; j++) {
	  if(data[j][i] == 0) break;
	  if(j == 0) kind = data[j][i];
	  else {
	    if(data[j][i] != kind) break;
	    else if(j == 2) flag = kind;
	  }
	}
      }
      if(flag == 0) {
	if(data[0][0] == data[1][1] && data[0][0] == data[2][2]
	   && data[0][0] != 0) {
	  flag = data[0][0];
	} else if(data[2][0] == data[1][1] && data[2][0] == data[0][2]
		  && data[2][0] != 0) {
	  flag = data[2][0];
	}
      }
    }
    switch(flag) {
    case 0: cout << 'd' << endl; break;
    case 1: cout << 'o' << endl; break;
    case -1: cout << 'x' << endl; break;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

//container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,n,0)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";

map<int, int> m;
int main() {
	int n;
	cin >> n;
	REP(i, n){
		int x;
		cin >> x;
		if(!EXIST(m, x))m[x] = 0;
		m[x]++;
	}
	int fs = 0, sec = 0;
	EACH(it, m){
		int i=(*it).first;
		int t=(*it).second;
		REP(j,2){
			if(t>=2){
				if(fs<=i){
					sec=fs;
					fs=i;
				}else if(sec<i){
					sec = i;
				}
			}
			t-=2;
		}
	}
	cout << (ll)fs * sec << endl;
}


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

int main() {
    long long l, r;
    long long minv = 1e9;
    cin >> l >> r;
    
    for (long long i = l; i <= r; i++)
    {
        for (long long j = i + 1; j <= r; j++)
        {
            minv = min(minv, i * j % 2019);
            
            if (minv == 0)
            {
                cout << minv << endl;
                return 0;
            }
            
        }
    }
    
    cout << minv << endl;
}

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

int main()
{
  int N, ans = 0;
  cin >> N;
  vector<int> a(N, 0);
  for (int i = 0; i < N; i++)
  {
    cin >> a[i];
  }

  while (1)
  {
    bool e = true;
    for (int i = 0; i < N; i++)
    {
      if (a[i] % 2 == 0)
      {
        a[i] /= 2;
        ans++;
        e = false;
        break;
      }
    }
    if (e)
    {
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3608
N, M = map(int, input().split())
L, R = [], []

for i in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)

max_L = max(L)
min_R = min(R)

if max_L > min_R:
  print(0)
else:
  print(min_R - max_L + 1)

Measured memory_bytes: 10996
import java.util.Scanner;

/**
 * B - I miss you...
 * 文字列 S が与えられます。
 * S のすべての文字を x で置き換えて出力してください。
 */
public class Main {

    public static void main( String[] args ) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        String s = sc.next();   // 英小文字のみからなる文字列

        StringBuilder reseult = new StringBuilder();
        for( int i = 0; i < s.length(); i++ ) {
            reseult.append( "x" );
        }

        System.out.println( reseult );

        sc.close();
    }
}

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

using namespace std;

typedef long long ll;

int n;
ll need = (int)1e6;

int main() {
	while (1) {
		cin >> n; if (n == 0) break;
		
		map<ll, ll> sum;
		vector<ll> ids;
		for (int i = 0; i < n; i++) {
			ll id, p, q; cin >> id >> p >> q;
			bool add = true;
			for (int j = 0; j < (int)ids.size(); j++) {
				if (ids[j] == id) add = false;
			}
			if (add) ids.push_back(id);
			sum[id] += (p * q);
		}
		
		bool na = true;
		for (int i = 0; i < (int)ids.size(); i++) {
			if (sum[ids[i]] >= need) {
				cout << ids[i] << endl;
				na = false;
			}
		}
		
		if (na) cout << "NA" << endl;
	}
	
	return 0;
}

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

struct BipartiteGraph {
	struct Edge {
		const int from;
		const int to;
		Edge(const int from, const int to) :
			from(from),
			to(to)
			{}
	};
	const int V;
	vector<vector<Edge>> G;
	vector<int> color;
	BipartiteGraph(const int V) :
		V(V),
		G(vector<vector<Edge>>(V, vector<Edge>())),
		color(vector<int>(V, -1))
		{}
	void addEdge(const int from, const int to) {
		G[from].emplace_back(from, to);
		G[to].emplace_back(to, from);
	}
	bool dfs(const int from, const int col) {
		color[from] = col;
		bool ret = true;
		for(Edge e : G[from]) {
			if(color[e.to] == -1) {
				ret &= dfs(e.to, col ^ 1);
			}
			if(color[e.to] == col) {
				return false;
			}
		}
		return ret;
	}
	int bipart() {
		if(not dfs(0, 0)) throw "NOT Bipartite Graph";
		int ret = 0;
		for(int i : color) ret += i;
		return ret;
	}
};

int main() {
	int n; cin >> n;
	bool s[n][n] = {};
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			char c; cin >> c;
			if(c == '1') {
				s[i][j] = true;
			}
		}
	}
	BipartiteGraph bg(n);
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			if(s[i][j]) bg.addEdge(i, j);
		}
	}
	try {
		bg.bipart();
		int ans = 0;
		for(int from = 0; from < n; ++from) {
			int dp[n];
			for(int i = 0; i < n; ++i) {
				dp[i] = -1;
			}
			dp[from] = 0;
			queue<int> que;
			que.push(from);
			while(que.size()) {
				int cur = que.front();
				que.pop();
				for(int nxt = 0; nxt < n; ++nxt) {
					if(s[cur][nxt]) {
						if(dp[nxt] == -1) {
							dp[nxt] = dp[cur] + 1;
							que.push(nxt);
							ans = max(ans, dp[nxt]);
						}
					}
				}
			}
		}
		cout << ans + 1 << '\n';
	}
	catch(...) {
		cout << -1 << '\n';
	}
	return 0;
}

Measured memory_bytes: 640
def main():
    N,K = map(int,input().split())
    A = [int(x) for x in input().split()]
    A_cumsum = [0]
    for i in range(0,N):
        A_cumsum.append(A_cumsum[-1]+A[i])
    
    digit = len(bin(sum(A)))-2

    ls = []
    for i in range(N+1):
        for j in range(i+1,N+1):
            now = bin(A_cumsum[j]-A_cumsum[i])[2:]
            now = "0"*(digit-len(now))+now
            ls.append(now)
    
    ans = [0 for _ in range(digit)]

    for i in range(digit):
        
        now = []
        for j in range(len(ls)):
            if ls[j][i]=="1":
                now.append(ls[j])
        if K<=len(now):
            ls = now
            ans[i]=1
    out = ""
    for i in ans:
        out += str(i)
    print(int(out,2))

    
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 143892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;
V v;

int main(){
	while (getline(cin, s)){
		if (s == "END OF INPUT")break;
		int co = 0;
		REP(i, s.size()){
			if (s[i] == ' '){
				v.push_back(co);
				co = 0;
			}
			else{
				co++;
			}
		}
		if (co > 0)v.push_back(co);
		REP(i, v.size())cout << v[i];
		cout << endl;
		v.clear();
	}
}

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

int main(int argc, char *argv[])
{
  char buf[100 + 3];
  char *s;
  char p[100];

  scanf("%s", buf);
  s = (char *)malloc(sizeof(char) * (2 * strlen(buf) + 1));
  strcpy(s, buf);
  strcpy(&s[strlen(buf)], buf);

  scanf("%s", p);
  if (strstr(s, p) != NULL) printf("Yes\n");
  else printf("No\n");

  return 0;
}

Measured memory_bytes: 564
N = int(input())
a = []
for i in range(N):
    a.append(list(map(int, input().split())))

dp = [[0, 0, 0] for i in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1][k] = max(dp[i+1][k], dp[i][j]+a[i][k])

print(max(dp[-1]))


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

using namespace std;
#define int long long
#define N 666666
int sum[N];
char str[N];
signed main(){
	
	cin>>(str+1);
	int add=0;
	int ans=0;
	int len=strlen(str+1);
	for(int i=1;i<=len;i++){
		if(str[i]=='A'){
			sum[i]=sum[i-1]+1;	
		}else if(str[i]=='C'){
			add=0;
	//		sum[i]=sum[i-1];
		}else{
			if(i-1>=1&&i+1<=len){
				if(str[i-1]=='A'&&str[i]=='B'&&str[i+1]=='C'){
					//cout<<sum[i-1]<<" ";
					ans+=sum[i-1];
					sum[i+1]+=sum[i-1];
					str[i+1]='A';
					i=i+1;
				}
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    ll n;
    cin >> n;
    int count = 0;
    for (long long i = 2; (i * i) <= n; ++i) {
        if (n % i == 0) {
            int y = 0, c = 0;
            while (n % i == 0) {
                n /= i;
                ++y;
                if (c < y) {
                    count++;
                    c++;
                    y = 0;
                }
            }
        }
    }
    if (n > 1) {
        ++count;
    }
    cout << count << '\n';
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll mod = 1e9 + 7;

ll solve(void)
{
	ll n;
	cin >> n;

	vll A(n);
	sort(A.begin(), A.end());
	for (auto &a: A) {cin >> a;}

	map<ll, ll> m;
	for (auto a: A) {m[a] ++;}

	vector<bool> B(10e6+10, true);
	for (auto v : m)
	{
		auto a = v.first;
		if (!B[a]) {continue;}
		for (ll i = 2; i * a < B.size(); i++)
			B[i * a] = false;
	}

	ll ans = 0;
	for (auto a: A)
		ans += (m[a] == 1 && B[a] == true);

	cout << ans << endl;

	return 0;
}

int main(void)
{
	while(solve()){}

	return 0;
}

Measured memory_bytes: 18464
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
  int a, b, c1, c2, c3;

  while(cin >> a >> b){
    if(a == 0 && b ==0){
      break;
    }
    c1 = c2 = c3 = 0;

    b -= a;
    while(b-1000 >= 0){
      c1++;
      b-=1000;
    }
    while(b-500 >= 0){
      c2++;
      b-=500;
    }
    while(b-100 >= 0){
      c3++;
      b-=100;
    }
    cout << c3 << " " << c2 << " " << c1 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

struct bellmanford {
	ll N;//頂点数(1-index)
	vector<vector<edge>> g;//有向グラフ
	ll s;


	vector<edge> e;
	vector<ll> ans;//頂点sからiまでの距離(負閉路がない場合)
	ll minuscycle;//sから到達可能な負閉路があるか

	bellmanford(ll N0, ll s0, vector<vector<edge>> g0) {
		N = N0;
		s = s0;
		g = g0;

		ans.assign(N + 1, INF);
		ans[s] = 0;

		repn(i, N) {
			for (edge ed : g[i]) {
				e.push_back(ed);
			}
		}

		minuscycle = 0;

		repn(i, N) {
			for (edge ed : e) {
				if (ans[ed.fr] != INF && ans[ed.fr] + ed.d < ans[ed.to]) {
					ans[ed.to] = ans[ed.fr] + ed.d;
					if (i == N) { minuscycle = 1; }
				}
			}
		}

		}
};

//負の辺のある頂点数Nの有向グラフの頂点sからtまでの距離
ll bell_distance(ll N, ll s, ll t, vector<vector<edge>> g) {

	vector<vector<edge>> rev(N+1);
	repn(v, N) {
		for (edge e : g[v]) {
			rev[e.to].push_back({ e.ind,e.to,e.fr,e.d });
		}
	}

	vector<bool> con(N + 1, 0);
	queue<ll> q;
	con[t] = 1;
	q.push(t);

	while (!q.empty()) {
		ll v = q.front();
		q.pop();

		for (edge e : rev[v]) {
			if (con[e.to] == 1) { continue; }
			con[e.to] = 1;
			q.push(e.to);
		}

	}

	vector<vector<edge>> subg(N + 1);

	repn(v, N) {
		for (edge e : g[v]) {
			if (con[e.fr] == 1 && con[e.to] == 1) { subg[v].push_back(e); }
		}
	}

	bellmanford bf(N, s,subg);

	if (bf.minuscycle == 0) { return bf.ans[t]; }
	else { return -INF; }
}

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

	vector<vector<edge>> g(N+1);

	repn(i, M) {
		ll a, b, c;
		cin >> a >> b >> c;
		g[a].push_back({ i,a,b,-c });
	}

	ll ans = -bell_distance(N, 1, N, g);

	if (ans == INF) { cout << "inf"; }
	else { cout << ans; }
	system("PAUSE");
}






Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
int main()
{
    ll n, ans=0, temp;
    cin >> n;
    for(ll i=1; i<=n; i++){
        temp = n/i;
        ans += i*((temp*(temp+1))/2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int i, g = 0, n, j;
	while (1)
	{
		cin >> j;
		if (j == 0)
			break;
		g = j;
		for (i = 0; i < 9; i++)
		{
			cin >> n;
			g -= n;
		}
		cout << g << endl;
	}
	return 0;
}

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


int main() {
    int x,y;
    while(1){
        cin >> x >> y;

        if(x == 0 && y == 0){
            break;
        }else{
            if(x > y){
                cout << y << " " << x << endl;
            } else {
                cout << x << " " << y << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    string s, t;
    cin >> s >> t;
    lli cnt = 0;

    rep(i, 3) if(s[i] == t[i]) cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

map<string, int> m;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	m["SUN"] = 0;
	m["MON"] = 1;
	m["TUE"] = 2;
	m["WED"] = 3;
	m["THU"] = 4;
	m["FRI"] = 5;
	m["SAT"] = 6;
	string s;
	cin >> s;
	cout << 7 - m[s];
}

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

int main() {
  int N, i, temp, count, current, result = 1000000000;
  vector<int> A;
  cin >> N;

  for (i = 0; i < N; i++) {
    cin >> temp;
    A.push_back(temp);
  }

  for (i = 0; i < N; i++) {
    count = 0;
    current = A[i];

    while (true) {
      if (current % 2 != 0) {
        break;
      }

      count++;
      current = current / 2;
    }

    if (count < result) {
      result = count;
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX=81;
const int MAXF=100000;
int H; int W;
int anum[MAX][MAX];
int bnum[MAX][MAX];
bool ans[MAX][MAX][MAXF];

  
int main(){
  cin>>H>>W;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>anum[i][j];
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>bnum[i][j];
    }
  }
  ans[0][0][abs(anum[0][0]-bnum[0][0])]=true;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      for(int k=0;k<=80*160;k++){
        if(ans[i][j][k]){
          ans[i+1][j][k+abs(anum[i+1][j]-bnum[i+1][j])]=true;
          ans[i+1][j][abs(k-abs(anum[i+1][j]-bnum[i+1][j]))]=true;
          ans[i][j+1][k+abs(anum[i][j+1]-bnum[i][j+1])]=true;
          ans[i][j+1][abs(k-abs(anum[i][j+1]-bnum[i][j+1]))]=true;
        }
      }
    }
  }
  for(int i=0;i<=80*160;i++){
    if(ans[H-1][W-1][i]){
      cout<<i<<endl;
      return 0;
    }
  }
} 

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

int main(){
int n,m,x;
long long cost = 0;
cin >> n >> m >> x;
vector<long long> ans((1<<n),10000000000);
vector<vector<int>> v(n,vector<int>(m+1));
    for(int i=0;i<n;i++){
        for(int j=0;j<m+1;j++)cin >> v[i][j];
    }
    for(int a=0;a<(1<<n);a++){
        bitset<14> b(a);
        vector<long long> v2(m,0);
        for(int i=0;i<n;i++){
            if(b[i] == 1){
                for(int j=0;j<m;j++){
                  v2[j] += v[i][j+1];
                }
                cost += v[i][0];
            }
        }
        sort(v2.begin(),v2.end());
        if(v2[0] >= x){
            ans[a] = cost;
        }
        cost = 0;
    }
    sort(ans.begin(),ans.end());
    if(ans[0] == 10000000000) cout << -1 << endl;
    else cout << ans[0] << endl;
}

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

int main() {
  int N;
  cin >> N;
  int X = N;
  int t = 0;
  while (X > 0) {
    t += X % 10;
    X /= 10;
  }
  if (N % t) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int d[LIMIT2]={0};
  int a[LIMIT1]={0};
  int b[LIMIT1]={0};
  char s[LIMIT1];
  int h[LIMIT1]={0};
  int res[LIMIT1]={0};
  
  scanf("%lld %lld",&n,&m);
  rep(i,n) scanf("%d",&h[i]);
  rep(i,m){
    scanf("%d %d",&a[i],&b[i]);
  }
  rep(i,m){
    j = h[a[i]-1];
    k = h[b[i]-1];
    if(j==k){
      res[a[i]-1]=-1;
      res[b[i]-1]=-1;
    }else if(j<k){
      res[a[i]-1] = -1;
      if(res[b[i]-1]==0) res[b[i]-1]=1;
    }else{
      res[b[i]-1] = -1;
      if(res[a[i]-1]==0) res[a[i]-1]=1;
    }
  }
  rep(i,n){
    //printf("%d ",res[i]);
    if(res[i]!=-1) result++;
  }
  printf("%lld",result);
  return 0;
}



Measured memory_bytes: 4856
from collections import Counter
N = int(input())
A = map(int, input().split())
A=Counter(A)
t = []
for k, v in A.items():
    if v > 1:
        t.append(k)
        if v > 3:
            t.append(k)
A = sorted(t,reverse=True)
if len(A) < 2:
    print(0)
else:
    print(A[0] * A[1])

Measured memory_bytes: 24224
#include<cstdio>
using namespace std;

const int N=100000+5;

int n, m;
int d[N], v[N], c[N];

int cnt, first[N], to[2*N], next[2*N];
void add(int u, int v) {
	to[++cnt]=v; next[cnt]=first[u]; first[u]=cnt;
	to[++cnt]=u; next[cnt]=first[v]; first[v]=cnt;
}

int col[N], mark[N];
void work(int now, int len, int color) {
	if(len<0||(col[now]>0&&mark[now]>=len)) return;
	if(col[now]==0) col[now]=color;
	mark[now]=len;
	for(int p=first[now]; p; p=next[p])  work(to[p], len-1, color);
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i=1, a, b; i<=m; i++) {
		scanf("%d%d", &a, &b);
		add(a, b);
	}
	int Q;
	scanf("%d", &Q);
	for(int i=1; i<=Q; i++) scanf("%d%d%d", &v[i], &d[i], &c[i]);
	for(int i=Q; i>=1; i--) work(v[i], d[i], c[i]);
	for(int i=1; i<=n; i++) printf("%d\n", col[i]);
	return 0;
}

Measured memory_bytes: 4480
import sys
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N = int(input())

total = int(N//100)
print(1 if total*5 >= N%100 else 0)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
using namespace std;

int n, m;
int c[15];
string dp[10005];
signed main() {
	cin >> n >> m;
	rep(i, m) {
		int a; cin >> a;
		if (a == 1)c[2] = 1;
		if (a == 2 || a == 3 || a == 5)c[5] = max(c[5], a);
		if (a == 4)c[4] = a;
		if (a == 6 || a == 9)c[6] = max(c[6], a);
		if (a == 7)c[3] = 7;
		if (a == 8)c[7] = 8;
	}
	rep(i, n + 1)dp[i] = "-1";
	rep(i, 9) {
		if (c[i])dp[i] = (char)('0' + c[i]);
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 2; j <= 7; j++) {
			if (i >= j && dp[i - j] != "-1"&&c[j]) {
				if (dp[i] == "-1")dp[i] = dp[i - j] + (char)('0' + c[j]);
				else if (dp[i - j].size() >= dp[i].size()) {
					dp[i] = dp[i - j] + (char)('0' + c[j]);
				}
				else if (dp[i - j].size() == dp[i].size() - 1) {
					dp[i] = max(dp[i], dp[i - j] + (char)('0' + c[j]));
				}
			}
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 39552
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<ll>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf_char=vector<vector<char>>;
using Graf_int=vector<vector<int>>;
#define MAX 100000

int main()
{
    int n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n+1),b(m+1);
    rep(i,n)cin >> a[i+1];
    rep(i,m)cin >> b[i+1];

    rep(i,n){
        a[i+1]+=a[i];
    }
    rep(i,m){
        b[i+1]+=b[i];
    }
    int ans=0;int lim_b=0;int p,q;p=0;q=0;
    ll tmp=0;
    int i=0;
    while(a[i]<=k&&i<=n){
        ++i;
    }
    ans=i-1;tmp=a[ans];
    i=0;
    while(b[i]<=k&&i<=m){
        ++i;
    }
    lim_b=i-1;
    p=ans;
    rep(i,lim_b+1){
        if(a[p]+b[i]>k){
            ans=max(p+i-1,ans);
            while(a[p]+b[i]>k){
                p--;
                if(p==0){
                    break;
                }
            }    
        }
        if(p==0&&a[p]+b[i]>k){
            break;
        }
        if(i==lim_b&&a[p]+b[i]<=k){
            ans=max(p+i,ans);
        }
    }
    cout << ans << endl;


    
}

Measured memory_bytes: 6428
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[10][8];
int r[8][3]={
{0,1,2},
{0,2,4},
{0,4,3},
{0,3,1},
{5,2,1},
{5,4,2},
{5,3,4},
{5,1,3}
};
int used[10];
int now[8];
int r1[8];
int r2[8];
int solve(int a){
	if(a==8)return 1;
	for(int i=0;i<8;i++){
		if(used[i])continue;
		used[i]=1;
		now[a]=i;
		for(int j=0;j<8;j++)for(int k=0;k<3;k++){
			r1[a]=j;r2[a]=k;
			int cn=__builtin_popcount(a)%2;
			if((a&1)&&(str[i][r[j][(k+1+!cn)%3]]^32)!=str[now[a-1]][r[r1[a-1]][(r2[a-1]+1+cn)%3]])continue;
			if((a&2)&&(str[i][r[j][(k+1+cn)%3]]^32)!=str[now[a-2]][r[r1[a-2]][(r2[a-2]+1+!cn)%3]])continue;
			if((a&4)&&(str[i][r[j][k%3]]^32)!=str[now[a-4]][r[r1[a-4]][(r2[a-4])%3]])continue;
			int val=solve(a+1);
			if(val)return 1;
		}
		used[i]=0;
	}
	return 0;
}
int main(){
	while(1){
		scanf("%s",str[0]);
		if(str[0][0]=='0')break;
		for(int i=1;i<8;i++)scanf("%s",str[i]);
		for(int i=0;i<8;i++)used[i]=0;
		int res=solve(0);
		if(res)printf("YES\n");
		else printf("NO\n");
	}
}

Measured memory_bytes: 948
def main():
    N = int(input())
    T = [int(input()) for i in range(N)]
    ans = 1

    def gcd(x, y):
        if y == 0:
            return x
        while y != 0:
            x, y = y, x % y
        return x

    def lcm(x, y):
        return x*y//gcd(x, y)

    for t in T:
        ans = lcm(ans, t)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int givenNumber = scanner.nextInt();
        int[] array = new int[givenNumber];
        for(int i=0; i<givenNumber; i++) {
            array[i] = scanner.nextInt();
        }
        Arrays.sort(array);
        int aliceCards = 0;
        int bobCards = 0;
        for(int i=0; i<array.length; i++) {
            if(i % 2 == 0) {
                bobCards += array[i];
            } else {
                aliceCards += array[i];
            }
        }
        System.out.println(Math.abs(aliceCards - bobCards));
    }
}


Measured memory_bytes: 22100
Public Class Program
  Shared Sub Main()
    Dim nm As Integer() = Cin.IntArr()
    Dim n As Integer = nm(0)
    Dim m As Integer = nm(1)
    Dim s(0 To m - 1)() As Integer
    Dim ans As Integer = 0
    For i As Integer = 0 To m - 1
      Dim ks As Integer() = Cin.IntArr()
      Dim k As Integer = ks(0)
      s(i) = New Integer(0 To k - 1) {}
      For j As Integer = 0 To k - 1
        s(i)(j) = ks(j + 1)
      Next
    Next
    Dim p As Integer() = Cin.IntArr()

    For i As Integer = 0 To Math.Pow(2, n) - 1
      Dim switchesStatus(0 To n - 1) As Boolean
      For j As Integer = 0 To n - 1
        switchesStatus(j) = (((i >> j) And 1) = 1)
      Next

      Dim ok As Boolean = True
      For j As Integer = 0 To m - 1
        Dim count As Integer = 0
        For k As Integer = 0 To s(j).Length() - 1
          If switchesStatus(s(j)(k) - 1) Then count += 1
        Next
        If Not p(j) = (count Mod 2) Then ok = False
      Next
      If ok Then ans += 1
    Next
    Console.WriteLine(ans.ToString())
  End Sub
End Class

Public Class Cin
  Public Shared Function Str() As String
    Return Console.ReadLine().Trim()
  End Function
  Public Shared Function Int() As Integer
    Return Integer.Parse(Str())
  End Function
  Public Shared Function Lng() As Long
    Return Long.Parse(Str())
  End Function
  Public Shared Function Dbl() As Double
    Return Double.Parse(Str())
  End Function
  Public Shared Function StrArr(Optional separator As String = " ") As String()
    Return Str().Split(separator)
  End Function
  Public Shared Function IntArr(Optional separator As String = " ") As Integer()
    Return Array.ConvertAll(Of String, Integer)(StrArr(separator), AddressOf Integer.Parse)
  End Function
  Public Shared Function LngArr(Optional separator As String = " ") As Long()
    Return Array.ConvertAll(Of String, Long)(StrArr(separator), AddressOf Long.Parse)
  End Function
  Public Shared Function DblArr(Optional separator As String = " ") As Double()
    Return Array.ConvertAll(Of String, Double)(StrArr(separator), AddressOf Double.Parse)
  End Function
End Class

Measured memory_bytes: 11220
#include<bits/stdc++.h>
#define maxn 200100
#define inf 1000000007
using namespace std;
typedef pair<int,int> par;
struct data{
	int lc,rc,atg;
	par p;
}s[maxn*60];
int n,a[maxn],ptr,rt;
par qry(int& o,int l,int r,int ql,int qr){
	if(!o)s[o=++ptr].p=par(l,l);
	if(ql<=l&&r<=qr)
		return s[o].p;
	int mid=l+r>>1;
	par ans(inf,inf);
	if(ql<=mid)ans=min(ans,qry(s[o].lc,l,mid,ql,qr));
	if(qr>mid)ans=min(ans,qry(s[o].rc,mid+1,r,ql,qr));
	return par(ans.first+s[o].atg,ans.second);
}
void mdy(int &o,int l,int r,int ql,int qr){
	if(ql>qr)return ;
	if(!o)s[o=++ptr].p=par(l,l);
	if(ql<=l&&r<=qr){
		s[o].atg++;
		s[o].p.first++;
		return ;
	}
	int mid=l+r>>1;
	if(ql<=mid)mdy(s[o].lc,l,mid,ql,qr);
	if(qr>mid)mdy(s[o].rc,mid+1,r,ql,qr);
	s[o].p=min(s[o].lc?s[s[o].lc].p:par(inf,inf),s[o].rc?s[s[o].rc].p:par(inf,inf));
	s[o].p=par(s[o].p.first+s[o].atg,s[o].p.second);
}
int main(){
	scanf("%d",&n);
	long long ans=0;
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		par x=qry(rt,1,inf,a[i],inf);
		ans+=x.first-a[i],mdy(rt,1,inf,1,x.second-1);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 235648
using System;
using System.Collections;
using System.Collections.Generic;

class Program {

    static void Main (string[] args) {
        long N = long.Parse (Console.ReadLine ());
        var str = Console.ReadLine ().Split (' ');
        var A = new long[N];
        var add = new long[N - 1];
        var sub = new long[N - 1];
        for (int i = 0; i < N; i++) {
            A[i] = int.Parse (str[i]);
            if (i + A[i] < N - 1) {
                add[i + A[i]]++;
            }
            if (i - A[i] >= 0) {
                sub[i - A[i]]++;
            }
        }
        long ans = 0;
        for (int i = 0; i < N - 1; i++) {
            if (add[i] > 0 && sub[i] > 0) {
                ans += (add[i] * sub[i]);
            }
        }
        Console.WriteLine (ans);
    }
}

Measured memory_bytes: 46716
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define endl "\n"
#define all(x) (x).begin(),(x).end()
const int MOD = 1e9+7;
const int mxN = 2e5+3;

void solve(){
	int n;
	cin >> n;
	n--;
	if(n == 0){
		cout << 'a' << endl;
		return;
	}
	string s = "";
	while(n >= 0){
		int x = n % 26;
		char c = char(97 + x);
		s = c + s;
		n /= 26;
		n--;
	}
	cout << s << endl;
}

int32_t main(){
	IO;
	
	int nT = 1;
	//cin >> nT;
	for(int i = 1; i <= nT; ++i)
		solve();
	return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>

int main()
{
	int x,y,d;
	while(scanf("%d %d",&x,&y))
	{
		if(x==0)
		{
			return 0;
		}
		else if(x==1||x==2)
		{
			d=(2003+2003/4-2003/100+2003/400+(13*(x+12)+8)/5+y)%7;
		}
		else if(x>=13)
		{
			d=7;
		}
		else
		{
			d=(2004+2004/4-2004/100+2004/400+(13*x+8)/5+y)%7;
		}

		if(d==0)
		{
			printf("Sunday\n");
		}
		else if(d==1)
		{
			printf("Monday\n");
		}
		else if(d==2)
		{
			printf("Tuesday\n");
		}
		else if(d==3)
		{
			printf("Wednesday\n");
		}
		else if(d==4)
		{
			printf("Thursday\n");
		}
		else if(d==5)
		{
			printf("Friday\n");
		}
		else if(d==6)
		{
			printf("Saturday\n");
		}
		else if(d==7)
		{
		}
	}
}

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

void shuffle( vector <int>& cards, int p, int c )
{
    vector <int> replaced( cards.begin() + p - 1, cards.begin() + p + c - 1 );
    replaced.insert( replaced.end(), cards.begin(), cards.begin() + p - 1 );
    for ( int i = 0; i < p+c-1; i++ ) cards[i] = replaced[i];
}

int main( void )
{
    int n, r, p, c;

    while ( cin >> n >> r && n > 0 && r > 0 )
    {
        vector <int> cards( n );
        for ( int i = 0; i < n; i++ ) cards[i] = n - i;
        for ( int i = 0; i < r; i++ )
        {
            cin >> p >> c;
            shuffle( cards, p, c );
        }
        int answer = cards[0];
        cout << answer << endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<queue>
#define int long long
using namespace std;
int usi[221001]; string test[210012], cou[213456], ans[213456];
signed main() {
	int n, a; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a;
		if (a % 2 == 0) {
			if (a % 3 != 0 && a % 5 != 0) {
				cout << "DENIED" << endl; return 0;
			}
		}
	}
	cout << "APPROVED" << endl;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
ll r[300005],c[300005];
vector<ll>v[300005];
multiset<ll>s;
multiset<ll>:: iterator si;
main()
{
     ll h,w,i,j,m,x,y,ans=0,z;
     cin>>h>>w>>m;
     for(i=1;i<=m;i++)
     {
         cin>>x>>y;
         v[x].push_back(y);
         r[x]++;c[y]++;
     }
     for(i=1;i<=w;i++)
     {
         //cout<<c[i]<<endl;
         s.insert(c[i]);
     }
     for(i=1;i<=h;i++)
     {
         for(j=0;j<v[i].size();j++)
         {
             z=v[i][j];
             ans=max(ans,r[i]+c[z]-1);
         }
         //cout<<i<<endl;
         for(j=0;j<v[i].size();j++)
         {
             z=v[i][j];
             //cout<<c[z]<<" "<<z<<endl;
             si=s.lower_bound(c[z]);
             s.erase(si);
             //cout<<s.size()<<endl;
         }
         //cout<<i<<endl;
         if(!s.empty())
         {
             si=s.end();
             si--;
             //cout<<i<<" "<<r[i]<<" "<<(*si)<<endl;
             ans=max(ans,(*si)+r[i]);
         }
         for(j=0;j<v[i].size();j++)
         {
             z=v[i][j];
             s.insert(c[z]);
         }
     }
     cout<<ans<<endl;
}


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

int main(){
    ll h,w; cin >>h >>w;
    vector<string> s(h);
    rep(i,h){
        cin >>s[i];
        /*
         rep(j,w){
         if((i+j)%2)continue;
         if(s[i][j]=='.')s[i][j]='#';
         else s[i][j] = '.';
         }
         */
        //cout << s[i] << endl;
    }
    
    vv check(h, vi (w,0));
    
    vector<P> ans;
    
    queue<P> q;
    vi di = {-1,1,0,0};
    vi dj = {0,0,-1,1};
    
    rep(i,h)rep(j,w){
        if(check[i][j])continue;
        check[i][j] = 1;
        ans.emplace_back(0,0);
        if((i+j)%2)
            ans.back().first++;
        else
            ans.back().second++;
        
        q.emplace(i,j);
        
        while(!q.empty()){
            int ni = q.front().first;
            int nj = q.front().second;
            
            rep(k,4){
                int xi = ni + di[k];
                int xj = nj + dj[k];
                if(xi<0 || xi>=h || xj<0 || xj>=w)continue;
                if(s[ni][nj]==s[xi][xj])continue;
                if(check[xi][xj])continue;
                
                if((xi+xj)%2)
                    ans.back().first++;
                else
                    ans.back().second++;
                
                check[xi][xj] = 1;
                q.emplace(xi,xj);
            }
            q.pop();
        }
    }
    ll rtn = 0;
    rep(i,ans.size()){
        //cout << ans[i].first <<" "<< ans[i].second << endl;
        rtn += ans[i].first * ans[i].second;
    }
    
    cout << rtn << endl;
    
    return 0;
}



Measured memory_bytes: 5488
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    h, w, k = LI()
    c = SR(h)
    ans = 0
    for mask in range(1 << h):
        for mask2 in range(1 << w):
            tmp = 0
            for hi in range(h):
                for wi in range(w):
                    if mask & 1 << hi or mask2 & 1 << wi: continue
                    if c[hi][wi] == "#":
                        tmp += 1
            if tmp == k: ans += 1
            
    print(ans)


    return


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


Measured memory_bytes: 77948
#include <bits/stdc++.h>
#define MP make_pair
using namespace std;
typedef long long ll;
template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
int n,i;
ll a[5];
char s[20];
int main(){
    read(n);
    for (i=1;i<=n;i++){
        scanf("%s",s);
        if (s[0]=='M') a[0]++;
        if (s[0]=='A') a[1]++;
        if (s[0]=='R') a[2]++;
        if (s[0]=='C') a[3]++;
        if (s[0]=='H') a[4]++;
    }
    ll res=a[0]*a[1]*a[2]+a[0]*a[1]*a[3]+a[0]*a[1]*a[4]
            +a[0]*a[2]*a[3]+a[0]*a[2]*a[4]+a[0]*a[3]*a[4]
            +a[1]*a[2]*a[3]+a[1]*a[2]*a[4]+a[1]*a[3]*a[4]
            +a[2]*a[3]*a[4];
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256