akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a, b) printf(a, b);
#define c(s) cout << (s) << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define cyn(c) cout << (c ? "Yes" : "No") << endl;
#define cYN(c) cout << (c ? "YES" : "NO") << endl;
#define pyn(c) printf("%s\n", c ? "Yes" : "No");
#define pYN(c) printf("%s\n", c ? "YES" : "NO");
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> P;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}
ULL mod = 1e9 + 7;

int main() {
    int n,m; cin>>n>>m;
    long long a[55]={},b[55]={},c[55]={},d[55]={};
    rep(i,n)cin>>a[i]>>b[i];
    rep(i,m)cin>>c[i]>>d[i];

    rep(i,n){
        long long vmin = abs(a[i]-c[0])+abs(b[i]-d[0]);
        int checkpoint = 1;
        repp(j,1,m){
            long long value = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(vmin > value){
                vmin = value;
                checkpoint = j+1;
            }
        }
        cout<<checkpoint<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>

using namespace std;

const int N = 100000 + 1;

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

	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	int ans = 0;

	vector<int> a(N,0);

	while (n--) {
		int x;
		cin >> x;
		if (x >= N) {
			ans++;
			continue;
		}
		a[x]++;
	}
	for (int i = 1; i < N; i++) {
		if (a[i] < i)
			ans += a[i];
		else
			ans += a[i] - i;
	}
	cout << ans << endl;

	return 0;
}

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

int main(){

  int N, A, B, ans=0;
  int a, b, c, d, e;
  cin >> N >> A >> B;

  for(int i=1; i<=N; i++){
    e = (i / 10000) % 10;
    a = (i / 1000) % 10;
    b = (i / 100) % 10;
    c = (i / 10) % 10;
    d = i % 10;

    ans += (a+b+c+d+e) >= A && (a+b+c+d+e) <= B ? i : 0 ;
  }

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


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

void dep(int now,vector<pair<int,int>> &ch){
    cout<<' '<<now;
    if(ch[now].first!=-1) dep(ch[now].first,ch);
    if(ch[now].second!=-1) dep(ch[now].second,ch);
    return;
}

void ino(int now,vector<pair<int,int>> &ch){
    if(ch[now].first!=-1) ino(ch[now].first,ch);
    cout<<' '<<now;
    if(ch[now].second!=-1) ino(ch[now].second,ch);
    return;
}

void post(int now,vector<pair<int,int>> &ch){
    if(ch[now].first!=-1) post(ch[now].first,ch);
    if(ch[now].second!=-1) post(ch[now].second,ch);
    cout<<' '<<now;
    return;
}

int main(){
    int u;
    cin>>u;
    vector<pair<int,int>> ch(u);
    vector<int> pr(u,-1);
    vector<int> dp(u);
    for(int i=0;i<u;i++){
        int a,k,l;
        cin>>a>>k>>l;
        ch[a]=make_pair(k,l);
        if(k!=-1) pr[k]=a;
        if(l!=-1) pr[l]=a;
    }
    int rt=find(pr.begin(),pr.end(),-1)-pr.begin();
    cout<<"Preorder"<<endl;
    dep(rt,ch);
    cout<<endl<<"Inorder"<<endl;
    ino(rt,ch);
    cout<<endl<<"Postorder"<<endl;
    post(rt,ch);
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll> 
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  set<string> st;
  string s;
  rep(i,n) {cin>>s;st.insert(s);}
  print(st.size());
  return 0;
}

Measured memory_bytes: 19232
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String a = sc.next();
      String b = sc.next();
int count=0;
      for(int i= 0;i<a.length();i++){
      	if(!a.substring(i,i+1).equals(b.substring(i,i+1))){
          count++;
      	}
      }

      System.out.println(count);
      
	}
}

Measured memory_bytes: 45800
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

#define EPS (1e-7)
#define IINF ((int)1e9)


MY_NAMESPACE(testbed)
int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int k;
	cin >> k;
	vector<int> modres(k);
	int res = -1;
	for (int i = 0; i < k; i++)
	{
		if (i == 0)
			modres[i] = 7 % k;
		else
			modres[i] = (10 * modres[i - 1] + 7) % k;

		if (modres[i] == 0)
		{
			res = i + 1;
			break;
		}
	}
	cout << res << "\n";
	return 0;
}
MY_NAMESPACE_

Measured memory_bytes: 7064
def pres(data, N):
    for i in range(N):
        if i < N-1:
            print('%d '%data[i], end='')
        else:
            print(data[i])
        
def ins_sort(data, N):
    for i in range(1, N):
        flag = data[i]
        j = i-1
        while j>=0 and data[j]>flag:
            data[j+1] = data[j]
            j-=1
        data[j+1] = flag
        pres(data, N)
    
    
N = int(input())
data  = list(map(int, input().split()))

pres(data, N)
ins_sort(data, N)



Measured memory_bytes: 5984
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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 &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    string s, t;
    cin >> s >> t;
    int ans = INF;
    for (int i = 0; i + t.size() <= s.size(); ++i) {
        int tmp = 0;
        for (int j = 0; j < t.size(); ++j) {
            if (s[i + j] != t[j]) tmp++;
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
  int n, t, a, ans;
  double md = INF + 0.1;
  cin>>n>>t>>a;

  REP (i,n) {
    int h;
    cin>>h;
    if (abs(t - h * 0.006 - a) < md) {
      md = abs(t - h * 0.006 - a);
      ans = i+1;
    }
    //cout<<i+1<<" "<<md<<endl;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
def solve():
  n = int(input())
  treenode = [[] for _ in range(n)]
  treecolor = [-2]*n
  for i in range(n-1):
    u,v,w = (int(i) for i in input().split())
    u -= 1
    v -= 1
    treenode[u].append((v,w%2))
    treenode[v].append((u,w%2))
  query = deque([(0,0,0)])
  while query:
    a,b,c = query.popleft()
    if b%2 == 0:
      treecolor[a] = c
      nextc = c
    else:
      treecolor[a] = 1^c
      nextc = 1^c
    for nextnode,weight in treenode[a]:
      if treecolor[nextnode] != -2:
        continue
      else:
        query.append((nextnode,weight,nextc))  
        treecolor[nextnode] = -1
  for i in treecolor:
    print(i)
solve()

Measured memory_bytes: 36016
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (lint i = 0; i < lint(n); ++i)
#define Rep(i, n) for (lint i = lint(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
using DI = pair<double, int>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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;
}

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

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

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }


int main() {
	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if (m2 - m1 == 1) {
		cout << 1 << endl;
	}
	else if (m1 == 12 && m2 == 1) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
from Queue import Queue
while True:
    s=raw_input()
    if s=="0":break
    s=s.replace("r","0")
    s=s.replace("b","1")
    s=s.replace("g","2")
    Q=Queue()
    visited=set()
    visited.add(s)
    Q.put((s,0))
    while not Q.empty():
        ptn,tim=Q.get()
        if len(set(ptn))==1:
            print tim
            break
        for i in range(len(ptn)-1):
            if ptn[i]==ptn[i+1]:
                continue
            col1,col2=int(ptn[i]),int(ptn[i+1])
            s=list(ptn)
            if col1+col2==1:
                s[i]=s[i+1]="2"
            elif col1+col2==2:
                s[i]=s[i+1]="1"
            elif col1+col2==3:
                s[i]=s[i+1]="0"
            s="".join(s)
            if s not in visited:
                Q.put((s,tim+1))
                visited.add(s)
    else:
        print "NA"

Measured memory_bytes: 6196
def main():
    import sys
    input = sys.stdin.readline
    from collections import deque
    A = deque(list(input()))
    B = deque(list(input()))
    C = deque(list(input()))
    x = A.popleft()
    while True:
        if x == "a":
            x = A.popleft()
            if not A:
                print("A")
                break
        if x == "b":
            x = B.popleft()
            if not B:
                print("B")
                break
        if x == "c":
            x = C.popleft()
            if not C:
                print("C")
                break

if __name__ == '__main__':
    main()

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

using namespace std;

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

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

ll mod_pow(ll x, ll n, ll mod) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	
	return res;
}

vector<ll> fact, inv;
void fact_inv(int n, ll mod) {
	fact.resize(n + 1);
	inv.resize(n + 1);
	
	fact[0] = 1;
	FOR(i, 1, n + 1) fact[i] = fact[i - 1] * i % mod;
	inv[n] = mod_pow(fact[n], mod - 2, mod);
	for (int i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

ll ncr(ll n, ll r, ll mod) {
	if (n < r || r < 0 || n < 0) return 0;
	return fact[n] * inv[r] % mod * inv[n - r] % mod;
}

int n;
int a[112345];
bool done[112345];

int main() {
	cin >> n;
	REP(i, n + 1) scanf("%d", a + i);
	
	int num = -1;
	REP(i, n + 1) {
		if (done[a[i]]) num = a[i];
		done[a[i]] = true;
	}
	
	int l = -1, r = -1;
	REP(i, n + 1) if (a[i] == num) {
		if (l == -1) l = i;
		else r = i;
	}
	
	fact_inv(112345, MOD);
	
	FOR(k, 1, n + 2) {
		ll ans = ncr(n + 1, k, MOD);
		
		ll c = r - l - 1;
		if (n - 1 - c >= k - 1) ans -= ncr(n - 1 - c, k - 1, MOD);
		
		ans = (ans + MOD) % MOD;
		printf("%lld\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;
 
int main() {
  ll n, p, even=0;
  cin >> n >> p;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a.at(i);
    if(a.at(i) % 2 == 0) even++;
  }
  if(even == n && p == 1) cout << 0;
  else if (even==n) {
    ll ans = pow(2, n);
    cout << ans;
  }
  else {
    ll ans = pow(2, n-1);
    cout << ans;
  }
}

Measured memory_bytes: 384
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author https://github.com/rishabhdeepsingh/competitive
 */

// Created by White Knife on 15/04/20.
// doot diddly donger cuckerino Hahahahahah

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC target("popcnt")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

// @formatter:off
#define F               first
#define S               second
#define all(x)          (x).begin(), (x).end()
#define sz(x)           int((x).size())
#define sim             template<typename T
#define ris             return *this
#define dor             > debug & operator <<
#define eni(x)          sim > typename enable_if<sizeof dud<T>(0) x 1, debug&>::type operator<<(T i)
sim> struct rge { T b, e; };
sim> rge<T> rang(T i, T j) { return rge<T>{i, j}; }
sim> auto dud(T *x) -> decltype(cerr << *x, 0);
sim> char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) { cerr << boolalpha << i; ris; }
  eni(==) { ris << rang(all(i)); }
  sim, typename U dor(pair<U, T> d) { ris << "(" << d.first << ", " << d.second << ")"; }
  sim dor(rge<T> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
  sim dor(const T&) { ris; }
#endif
};
#define pr(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ull = unsigned long long;
using ld = long double;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vb = vector<bool>;

using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
template <typename T> using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

const ld PI = acos(-1);

template<typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template<typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
template<typename T> int sgn(T val) { return (T(0) < val) - (val < T(0));}
template<typename T> T rand(T x, T y) { return rand() % (y - x + 1) + x; }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T> T gcd(T x, T y) { return (y == T(0)) ? x : gcd(y, x % y); }
// @formatter:on


class ALphabet {
public:
  
  void solveOne(istream& cin, ostream& cout) {
  
  }
  
  void solve(std::istream& cin, std::ostream& cout) {
    char c;
    cin >> c;
    if (c <= 'Z' and c >= 'A') {
      cout << "A\n";
    } else {
      cout << "a\n";
    }
  }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
	ALphabet solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
typedef tuple<int,int,int> TP;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  int res = 0;
  rep(i,n) {
    int a;
    cin >> a;
    mp[a]++;
  }
  for (auto e : mp) {
    if (e.first < e.second) res += abs(e.first - e.second);
    if (e.first > e.second) res += e.second;
  }
  cout << res << endl;
  return 0;
} 

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

int main() {
    int n;
    cin >> n;
    long long a, b, c, d;
    cin >> a >> b;
    for (int i = 0; i < n - 1; ++i) {
        cin >> c >> d;
        while (a % c != 0) ++a;
        while (b % d != 0) ++b;
        if (a / c * d >= b) b = a / c * d; else a = b / d * c;
    }
    cout << a + b << endl;
    return 0;
}


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

int main(){

    int m, f, r;
    queue<string> grade;

    while(1){
        cin >> m >> f >> r;
        if((m == -1) && (f ==-1) && (r == -1)){
            break;
        }
        else if((m == -1) || (f == -1) || (m+f < 30)){
            grade.push("F");
        }
        else if(m+f >= 80 ){
            grade.push("A");
        }
        else if((m+f >= 65) && (m+f < 80) ){
            grade.push("B");
        }
        else if((m+f >= 50) && (m+f < 65)){
            grade.push("C");
        }
        else if((m+f >= 30) && (m+f < 50)){

            if(r >= 50){
                grade.push("C");
            }else{
                grade.push("D");
            }
        }

    }
    int length = grade.size();
    for(int i=0; i<length; i++){
        cout << grade.front() << endl;
        grade.pop();
    }    


    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  string s;
  cin >> s;

  regex re(R"(^A?KIHA?BA?RA?$)");
  smatch m;

  string ans = "NO";
  if (regex_match(s, m, re)) {
    ans = "YES";
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val s = sc.next()

  var max = 0
  for (i in 1 until n) {
    val sub1 = s.substring(0, i)
    val sub2 = s.substring(i, n)

    var tmp = 0
    for (c in 'a'..'z') {
      if (sub1.contains(c) && sub2.contains(c)) {
        tmp++
      }
    }
    max = Math.max(tmp, max)
  }
  println(max)
}


Measured memory_bytes: 37656
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,x,m=map(int,input().split())


cnt=1
now=x
ans=x
jisyo=defaultdict(list)
jisyo[now]=[ans,cnt]
while cnt<n:
    nex=now**2%m
    cnt+=1
    ans+=nex
    now=nex
    if nex in jisyo:
        tmp=jisyo[nex]
        # print(tmp)
        ans+=(ans-tmp[0])*((n-cnt)//(cnt-tmp[1]))
        cnt=n-(n-cnt)%(cnt-tmp[1])
        break
    else:
        jisyo[now]=[ans,cnt]
    # print(ans,cnt,now)
for i in range(n-cnt):
    now=now**2%m
    ans+=now
print(ans)

Measured memory_bytes: 75592
def inp():
    ls=list(map(int,input().split()))
    return ls
x,n=map(int,input().split())
ls=inp()
ans=0
d=float('inf')
for i in range(102):
    if i in ls:
        continue
    tmp = abs(x - i)
    if tmp < d:
        d = tmp
        ans = i
print(ans)

Measured memory_bytes: 9192
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]


def dfs(i, a, b, c):
    if n == i:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(A - a) + abs(B - b) + abs(C - c)

    res = dfs(i + 1, a, b, c)
    res = min([res, dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0)])
    res = min([res, dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0)])
    res = min([res, dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])
    return res


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<vector<int>> bai(n + 1);
    int onum = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] == 1)
            onum++;
    }
    if (onum == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    int num = 0;
    vector<int> ans(n + 1, 0);
    for (int i = n; i > 0; i--)
    {
        int j = 1;
        int tmp = 0;
        while (j * i <= n)
        {
            if (ans[j * i] == 1)
                tmp++;
            j++;
        }
        if (tmp % 2 != a[i])
        {
            ans[i] = 1;
            num++;
        }
    }
    cout << num << endl;
    for (int i = 0; i < n + 1; i++)
    {
        if (ans[i] == 1)
            cout << i << "\n";
    }
}


Measured memory_bytes: 7168
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String a = sc.next();
		String b = sc.next();
		boolean flg = true;

		if ("D".equals(a))
			flg = false;

		if (flg) {
			System.out.println(b);
		} else {
			if ("H".equals(b))
				System.out.println("D");
			else
				System.out.println("H");
		}
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}

/* main */

signed main(){
    ll N;
    cin >> N;
    vl A(N),B(N);
    FOR(i,0,N)cin >> A[i];
    FOR(i,0,N)cin >> B[i];
    ll sum_A = 0,sum_B = 0;
    FOR(i,0,N)sum_A += A[i];
    FOR(i,0,N)sum_B += B[i];
    if(sum_A < sum_B){
        cout << -1 << endl;
        return 0;
    }
    vl C(N);
    FOR(i,0,N)C[i] = A[i] - B[i];
    sort(ALL(C));
    vl v;
    FOR(i,0,N)if(A[i] < B[i])v.pb(B[i]-A[i]);
    ll sum_v = 0;
    for(auto x:v)sum_v += x;
    ll yay = 0;
    REP(i,0,N){
        if(yay >= sum_v){
            cout << (N-1-i) + v.size() << endl;
            return 0;
        }
        yay += C[i];
    }
}

Measured memory_bytes: 3196
{-# LANGUAGE BangPatterns #-}
import Control.Arrow (second)
import Control.Monad
import Control.Monad.Fix
import Data.Foldable (foldl')
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread i v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite i a v = accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

uswap :: VUM.Unbox a => Int -> Int -> VUM.IOVector a -> VUM.IOVector a
uswap i j v = accursedUnutterablePerformIO $ VUM.unsafeSwap v i j >> return v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw v = accursedUnutterablePerformIO $ VU.unsafeThaw v

newtype UnionFind = UnionFind (VUM.IOVector Int, VUM.IOVector Int)

findUF :: UnionFind -> Int -> Int
findUF (UnionFind (elems, _)) k = fix
  ( \f (elems, k, path) -> case uread k elems of
    n | n == k -> foldl' (\acc p -> uwrite p n acc) elems path `seq` n
    n          -> f (elems, n, n : path)
  )
  (elems, k, [k])

sizeUF :: UnionFind -> Int -> Int
sizeUF uf@(UnionFind (_, sizes)) i = uread (findUF uf i) sizes

unionUF :: UnionFind -> Int -> Int -> UnionFind
unionUF uf@(UnionFind (elem, sizes)) i j =
  let pi = findUF uf i
      pj = findUF uf j
      si = uread pi sizes
      sj = uread pj sizes
  in  if pi == pj
        then uf
        else
          let (t1, t2) = if si < sj then (pi, pj) else (pj, pi)
          in  UnionFind (uwrite t1 t2 elem, uwrite t2 (si + sj) sizes)

solve :: Int -> Int -> VU.Vector (Int, Int) -> VU.Vector Int
solve n m abs = VU.init $ ufreeze $ (\(_, _, _, acc) -> acc) $ VU.foldr'
  go
  ( group
  , m - 1
  , nC2
  , uwrite m nC2 $ accursedUnutterablePerformIO $ VUM.unsafeNew (m + 1)
  )
  abs
 where
  go (a, b) (uf, k, prev, acc) =
    let ga  = findUF uf a
        gb  = findUF uf b
        n1  = sizeUF uf a
        n2  = sizeUF uf b
        res = prev - n1 * n2
    in  ( unionUF uf a b
        , k - 1
        , if ga == gb then prev else res
        , uwrite k prev acc
        )

  nC2 = n * (n - 1) `div` 2

  group :: UnionFind
  group = UnionFind
    (uthaw $ VU.enumFromN 0 n, accursedUnutterablePerformIO $ VUM.replicate n 1)

main = do
  let readInt = fmap (second B.tail) . B.readInt

  (n, m) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  abs <- VU.replicateM
    m
    (   (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
    )

  VU.mapM_ print $ solve n m abs


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

	int main() {
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cout.tie(NULL);
		long long n;
		cin >> n;
		long long happiness = 0;
		happiness  = 1000*(n/500);
		n = n%500;
		happiness += 5*(n/5);
		cout << happiness << "\n";
		return 0;
	}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define printjudge(cond) {if(cond) printf("Yes\n"); else printf("No\n");}
#define printans(ans) {printf("%d\n",(ans));}
#define Ntimes(N) for(int i=0; i<N; i++)
typedef int* intarray;
typedef char* string;

int main(){
    char S[11], X[4];
    scanf("%s", S);
    int len = strlen(S);
    X[3] = '\0';
    int temp, min = 1000;
    Ntimes(len-2){
        for(int j=0; j<=2; j++) X[j] = S[i+j];
        temp = std::abs(atoi(X)-753);
        min = (temp<min) ? temp : min;
        if(min==0) break;
    }
    printans(min);
    return 0;
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<string> akiba = {
        "AKIHABARA",
        "AKIHABAR",
        "AKIHABRA",
        "AKIHABR",
        "AKIHBARA",
        "AKIHBAR",
        "AKIHBRA",
        "AKIHBR",
        "KIHABARA",
        "KIHABAR",
        "KIHABRA",
        "KIHABR",
        "KIHBARA",
        "KIHBAR",
        "KIHBRA",
        "KIHBR"
    };
    string s;
    cin >> s;
    for(string t:akiba){
        if(s==t){
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;

    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		int a = scanner.nextInt();
		int b = scanner.nextInt();

		int ans = x - a;
		while (ans >= b) {
			ans -= b;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
H,W=map(int,input().split())
S=[0]*H
for i in range(H):
  S[i]=list(str(input()))

DX=[-1,0,1]
DY=[-1,0,1]

for i in range(H):
  for j in range(W):
    if S[i][j]=='#':
      for dy in DY:
        for dx in DX:
          if dx==0 and dy==0:
            continue
          x = j+dx
          y = i+dy
          if 0<=x<W and 0<=y<H:
            if S[y][x]=='.':
              S[y][x]=1
            elif S[y][x]!='#':
              S[y][x]+=1

for i in range(H):
  for j in range(W):
    if S[i][j]=='.':
      S[i][j]=0
    S[i][j]=str(S[i][j])
for i in S:
  print(''.join(i))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  int count=0;
  cin>>a;
  
  for(int i=0;i<3;i++){
    if(a[i]=='1'){
      count = count + 1;
    }
  }
  cout<<count<<endl;
    

}

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

m = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    com = list(map(int, input().split()))
    for j in range(com[1]):
        m[i][com[j+2]-1] = 1

color = ["white" for i in range(n)]

from collections import deque
queue = deque()

d = [-1 for i in range(n)]

def bfs():
    color[0] = "gray"
    d[0] = 0
    queue.append(0)
    while len(queue) != 0:
        u = queue.popleft()
        for i in range(n):
            if m[u][i] and color[i] == "white":
                color[i] = "gray"
                d[i] = d[u] + 1
                queue.append(i)
        color[u] = "black"

bfs()
for i in range(n):
    print(i+1, d[i])


Measured memory_bytes: 6124
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <map>
#include <time.h>

using namespace std;

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n, k;
  cin >> n >> k;
  if(n % 2) n++;
  if(n / 2 >= k) {
    cout << "YES" << endl;
  }else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 764
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
#include <time.h>


/// Bismillahir Rahmanir Rahim


short int nCk(short int n);

int main(void)
{
    int short n, m, ans = 0;

    scanf("%hd %hd", &n, &m);

    ans = nCk(n);
    ans = ans + nCk(m);

    printf("%hd\n", ans);



    return 0;
}

short int nCk(short int n)
{
    if (n < 2) return 0;

    short int nck_val = 1;

    for(int i = n; i > n-2; --i) nck_val *= i;
    nck_val /= 2;

    return nck_val;
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll a,b,c,d; cin >> a >> b >> c >> d;
    if(c!=-1 && d!=-1){
        if(c>d) puts("Alice");
        else if(c==d) puts("Draw");
        else puts("Bob");
    }else{
        if(a>b) puts("Bob");
        else if(a==b) puts("Draw");
        else puts("Alice");
    }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector< vector<int> > A(n,vector<int>(m));
  vector<int> b(m);
  for (int i = 0; i < n; i++){
    for (int j = 0; j < m; j++){
      cin >> A[i][j];
    }
  }
  for (int i = 0; i < m; i++){
    cin >> b[i];
  }
  vector<int> c(n,0);
  for (int i = 0; i < n; i++){
    for (int j = 0; j < m; j++){
      c[i] += A[i][j] * b[j];
    }
    cout << c[i] << endl;
  }
}


Measured memory_bytes: 3176
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

const int N = 100000;

int m, a, b, aw, ah/*, aw2, ah2*/;
vector<int> prime;
bool is_prime[N+1];

void sieve(){
  fill(is_prime, is_prime+N+1, true);
  is_prime[0] = is_prime[1] = false;
  for(int i=2;i<=N;i++){
    if(is_prime[i]){
      prime.push_back(i);
      for(int j=2*i;j<=N;j+=i) is_prime[j] = false;
    }
  }
}

void solve(){
  for(int i=m;i>=0;i--){
    for(int j=0;prime[j]*prime[j]<=i;j++){
      if(i % prime[j] == 0){
        int w = prime[j];
        if(is_prime[i/w]){
          int h = i/w;
          if(a*h <= w*b){
            aw = w;
            ah = h;
            return;
          }
        }
      }
    }
  }
}

main(){
  sieve();
  while(cin >> m >> a >> b && (m|a|b)){
    solve();
    cout << aw << ' ' << ah << endl;
  }
}

Measured memory_bytes: 1108
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  
  pair<int, int> c01 = make_pair(0,0);
  for(int i = 0; i < n; i++){
    if(s[i] == '0')
      c01.first++;
    else
      c01.second++;
  }
  cout << min(c01.first, c01.second) * 2 << endl;  
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Aug  2 21:38:01 JST 2020
 **/

using namespace std;
struct Mo {
    // using ADD = function<void(int)>;
    // using DEL = function<void(int)>;
    // using REM = function<void(int)>;

    int width;
    vector<int> left, right, order;
    vector<bool> v;

    Mo(int N, int Q) : width((int)sqrt(N)), order(Q), v(N) { iota(begin(order), end(order), 0); }

    void add(int l, int r) { /* [l, r) */
        left.emplace_back(l);
        right.emplace_back(r);
    }

    template <class ADD, class DEL, class REM> void run(const ADD &add, const DEL &del, const REM &rem) {
        assert(left.size() == order.size());
        sort(begin(order), end(order), [&](int a, int b) {
            int ablock = left[a] / width, bblock = left[b] / width;
            if (ablock != bblock) return ablock < bblock;
            if (ablock & 1) return right[a] < right[b];
            return right[a] > right[b];
        });
        int nl = 0, nr = 0;
        auto push = [&](int idx) {
            v[idx].flip();
            if (v[idx])
                add(idx);
            else
                del(idx);
        };
        for (auto idx : order) {
            while (nl > left[idx]) push(--nl);
            while (nr < right[idx]) push(nr++);
            while (nl < left[idx]) push(nl++);
            while (nr > right[idx]) push(--nr);
            rem(idx);
        }
    }
};

constexpr Int K = (Int)5e5 + 1;
Int a[K], ans[K], cnt[K];
signed main() {
    Int n, Q;
    std::cin >> n >> Q;
    REP(i, n) std::cin >> a[i];
    Mo mo(n, Q);
    REP(q, Q) {
        Int l, r;
        std::cin >> l >> r, l--;
        mo.add(l, r);
    }
    Int cur = 0;
    auto add = [&](Int i) {
        if (cnt[a[i]]++ == 0) cur++;
    };
    auto del = [&](Int i) {
        if (--cnt[a[i]] == 0) cur--;
    };
    auto rem = [&](Int i) { ans[i] = cur; };
    mo.run(add, del, rem);
    REP(q, Q) std::cout << ans[q] << "\n";
}


Measured memory_bytes: 21484
import java.util.Scanner;

public class Main {
	static long cnt=0;
	public static void Merge(int a[],int start,int end){
		if (start>=end) return;
		int center=(start+end)/2;
		Merge(a,start,center);
		Merge(a,center+1,end);
		int n1=center-start+1;
		int n2=end-center;
		int[] L=new int[n1];
		int[] R=new int[n2];
		for (int i=0;i<n1;i++){L[i]=a[start+i];}
		for (int i=0;i<n2;i++){R[i]=a[center+1+i];}
		int i=0; int j=0;
		for (int k=start;k<=end;k++){
			if (i==n1) a[k]=R[j++];
			else if (j==n2) a[k]=L[i++];
			else if (L[i]<=R[j]) a[k]=L[i++];
			else {a[k]=R[j++]; cnt+=n1-i;}
		}
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
	    int n = in.nextInt();
	    int[] A = new int[n];
	    for (int i = 0; i<n; i++) {
	      A[i] = in.nextInt();
	    }
		Merge(A,0,n-1);
		System.out.println(cnt);
	}
}

Measured memory_bytes: 101364
#include<stdio.h>
#include<string.h>
int main() {
	int i, j, count=0;
	char s[30];
	scanf("%s", s);
	
	for (i = 0;i < strlen(s);i++) {
		for (j = i + 1;j < strlen(s);j++) {
			if (s[i] == s[j]) {
				printf("no\n");
				return 0;
			}
		}
	}
	printf("yes\n");
	return 0;
}



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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Combination {
    Combination(ll n) {
        mNumTbl.resize(n + 1);
        mInverseNumTbl.resize(n + 1);
        mNumTbl[0] = 1;
        mInverseNumTbl[0] = 1;
        FOR(i, n + 1, 1) {
            mNumTbl[i] = (mNumTbl[i - 1] * i) % MOD;
        }
        FOR(i, n + 1, 1) {
            mInverseNumTbl[i] = modpow(mNumTbl[i]);
        }
    }

    ll get(ll n, ll r) {
        if (n < r || n < 0)
            return 0;
        return (((mNumTbl[n] * mInverseNumTbl[r]) % MOD) * mInverseNumTbl[n - r]) % MOD;
    }

    ll modpow(ll n) {
        ll s = 1, p = n;
        for (ll i = 0; (1LL << i) <= MOD - 2; ++i, p = (p * p) % MOD) {
            if (((MOD - 2) & (1 << i)) == 0)
                continue;
            s *= p;
            s %= MOD;
        }
        return s;
    }

    vector<ll> mInverseNumTbl;
    vector<ll> mNumTbl;
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    Combination cmb(N + 5);
    ll space = N - K + 1;
    REP(i, K) {
        ll p = cmb.get(space, i + 1);
        ll q = cmb.get(K - 1, i);
        cout << (p * q) % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define rollcall cout<<"I'm Sucu."<<endl
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll


signed main(void){
    int N,M;
    int x[1010],y[1010],z[1010];
    int a[8]={1,1,1,1,-1,-1,-1,-1};
    int b[8]={1,1,-1,-1,1,1,-1,-1};
    int c[8]={1,-1,1,-1,1,-1,1,-1};
    
    int v[1020]={};
    int Ans=0;
    
    cin >> N >> M;
    REP(i,N){
        cin >> x[i] >> y[i]  >> z[i];
    }
    REP(k,8){
        REP(i,N){
            v[i]=(a[k]*x[i])+(b[k]*y[i])+(c[k]*z[i]);
        }
        sort(v,v+N,greater<>());
        int sum=0;
        REP(i,M){
            sum+=v[i];
        }
        Ans=max(Ans,sum);
    }
    cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),flagp=0,flagq=0;
		String p="",q="";
		for(int i=0;i<n;i++)p+=String.valueOf(sc.nextInt());
		for(int i=0;i<n;i++)q+=String.valueOf(sc.nextInt());

		String s="";
		for(int i=1;i<=n;i++) {
			s+=String.valueOf(i);
		}
		List<String> res=new ArrayList<String>();
		permutation(s,"",res);
		for(int i=0;i<res.size();i++) {
			if(p.equals(res.get(i)))flagp=i;
			if(q.equals(res.get(i)))flagq=i;
		}
		System.out.println(Math.abs(flagp-flagq));
	}
	public static List<String> permutation(String q, String ans, List<String> res){
        // Base Case
        if(q.length() <= 1) {
            res.add(ans+q);
        }
        // General Case
        else {
            for (int i = 0; i < q.length(); i++) {
                permutation(q.substring(0, i) + q.substring(i + 1),
                        ans + q.charAt(i), res);
            }
        }
		return res;
    }
}



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

using namespace std;

int a[100005];

int main(){

	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(a[i]%2!=0){
			cout << "first" << endl;
			return 0;
		}
	}
	cout << "second";

}

Measured memory_bytes: 640
#方針: 中心点は 101×101パターンしかないので全探索できる。
n = gets.to_i
ary = Array.new(n){gets.split.map(&:to_i)}.sort_by{|a| a[2]}.reverse

#p ary

def calc(x,y,cx,cy,h)
  return (x-cx).abs + (y-cy).abs + h
end

(0..100).each do |i|
  (0..100).each do |j|
    tmp1 = [] #h>0が矛盾しないか判定用
    tmp2 =[] #h=0が矛盾しないか判定用
    ary.each do |a|
      if a[2]>0
        
        tmp1 << calc(a[0],a[1],i,j,a[2])
      else
        tmp2 << a
      end
    end
    if tmp1.uniq.length == 1
      flag = true
      tmp2.each do |t|
        if tmp1[0] - (t[0]-i).abs - (t[1]-j).abs > 0
          flag = false
        end
      end
      puts "%d %d %d" % [i,j,tmp1[0]] if flag
    end
  end
end

Measured memory_bytes: 5348
'use strict';
const main = input => {
  const n = parseInt(input[0], 10);
  let a = input[1].split(' ').map(val => parseInt(val, 10));
  // console.log(a);
  a = a.map(val => 1/val);
  // console.log(a);
  let sum = a.reduce((sum, data) => sum + data);
  // console.log(sum);
  let ans = 1/sum;
  console.log(ans);
  
};
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 21192
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
    int h, w;
	cin >> h >> w;
	int d[10][10];
	rep(i,10) rep(j,10) cin >> d[i][j];
	rep(k,10) rep(i,10) rep(j, 10) chmin(d[i][j], d[i][k]+d[k][j]);
	
	int ans = 0;
	rep(i,h) rep(j,w) {
			int x;
			cin >> x;
			if (x!=-1) ans += d[x][1];
		}
	
	cout << ans << "\n";
}

Measured memory_bytes: 256
def main():
  M=10**9+7
  r1,c1,r2,c2=map(int,input().split())
  n=r2+c2+2
  fac=[1]
  val=1
  append=fac.append
  for i in range(1,n+1):
    val=val*i%M
    append(val)
  f=lambda r,c:fac[r+c+2]*pow(fac[c+1],M-2,M)*pow(fac[r+1],M-2,M)-c-r-2
  print((f(r2,c2)-f(r2,c1-1)-f(r1-1,c2)+f(r1-1,c1-1))%M)
main()

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

typedef pair<int,int> P;
int n,d,a,now,ans;
priority_queue<P,vector<P>,greater<P>> que;

signed main(){
  cin>>n>>d>>a;
  while(n--){
    int x,h;cin>>x>>h;
    que.push(P(x,h));
  }
  while(que.size()){
    P p=que.top();que.pop();
    int x=p.first,h=p.second;
    if(h<0)now+=h;
    if(h-now>0){
      int A=(h-now-1)/a+1;
      ans+=A;now+=A*a;
      que.push(P(x+d*2+1,-A*a));
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 6384