akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

void maxHeapify(int*, int, int);
void buildMaxHeap(int*, int);
void swap(int *, int *);

main(){
  int h, i, *A;

  scanf("%d", &h);
  A = malloc(sizeof(int)*(h+1));
  for(i=1; i<=h; i++){
    scanf("%d", A+i);
  }

  buildMaxHeap(A, h);
  for(i=1; i<=h; i++){
    printf(" %d", *(A+i));
  }
  printf("\n");

  free(A);
  return 0;
}

void maxHeapify(int *A, int h, int i){
  int largest = i;
  int l = i*2;
  int r = i*2 + 1;

  if(l<=h && A[l] > A[i]) largest = l;
  if(r<=h && A[r] > A[largest]) largest = r;

  if(largest != i){
    swap(A+largest, A+i);
    maxHeapify(A, h, largest);
  }
}

void buildMaxHeap(int *A, int h){
  int i;

  for(i=h/2; i >= 1; i--){
    maxHeapify(A, h, i);
  }
}

void swap(int *a, int *b){
  int tmp;

  tmp = *a;
  *a = *b;
  *b = tmp;
}

Measured memory_bytes: 2472
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, z = 1;
    string s;
    cin >> n >> s;
    for (int i = 1; i < n; i++) if (s[i] != s[i - 1]) z++;
    cout << z;
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
	#include <ext/pb_ds/assoc_container.hpp> 
	#include <ext/pb_ds/tree_policy.hpp> 
	#define ll long long
	#define MP make_pair
	#define PB push_back
	#define F first
	#define S second
	#define endl "\n"
	#define pi 3.14159265358979323846264338327950288
	#define MOD 1000000007
	#define INF -100000000000000
	#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
	#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	using namespace std;
	#define lld long double
	using namespace __gnu_pbds;
	int main()
	{
	    fast;
	//    #ifndef ONLINE_JUDGE
	 //   freopen("input.txt", "r", stdin);
	 //   freopen("output.txt", "w", stdout);
	  //  #endif
	    ll int n;cin>>n;ll int a[n];
	    ll int i,x,y,diff,w,z;ll int s=0;map<ll int,ll int> mp;
	    for(i=0;i<n;i++)
	    {
	    	cin>>a[i];
	    	mp[a[i]]++;
	    	s=s+a[i];
	    }
	    ll int q;
	    cin>>q;
	    for(i=0;i<q;i++)
	    {
	    	cin>>x>>y;
	    	w=mp[x];
	    	z=w*y;
	    	diff=z-w*x;
	    	s=s+diff;
	    	mp[x]=0;mp[y]+=w;
	    	cout<<s<<endl;

	    }
	}

Measured memory_bytes: 10268
def main():
    N, P = (int(i) for i in input().split())

    def enum_divisors(n):
        # 約数列挙
        divs = []
        for i in range(1, n+1):
            if i*i > n:
                break
            if n % i == 0:
                divs.append(i)
                if n//i != i:
                    # i が平方数でない
                    divs.append(n//i)
        return divs

    divs = enum_divisors(P)
    divs.sort()
    ans = 1
    for d in divs[-1:0:-1]:
        v = 1
        for _ in range(N):
            v *= d
            if v > P:
                break
        else:
            if P % v == 0:
                ans = d
                break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63996
// きさま！ 見ているなッ！

#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>
#include<thread>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;

int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

int main()
{
	
	int K; cin >> K; --K;
	cout << a[K] << endl;

	return 0;
}

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

int main(){
    int x,y,z;
    string s1, s2;
    char s;

    cin >> x >> y >> z;

    if ( x+y+z < 22){
        cout << "win" << endl;
    }else{
        cout << "bust" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int  LL;
typedef vector<int> ivec;
typedef vector<string> svec;

int main(){
	LL n;
	cin>>n;
	int amari=n%500;
	cout<<(n/500)*1000+(amari/5)*5<<endl;	
} 


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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;
}
///////////////////////////////////////////////////////////////

struct Edge {
    int to;
    ll cost;
    Edge (int to, ll cost): to(to), cost(cost) {}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; ll P; cin >> N >> M >> P;
    vector<vector<Edge>> G(N);
    rep(i,M) {
        int A,B; ll C; cin >> A >> B >> C;
        A--; B--;
        G[A].emplace_back(Edge(B,P-C));
    }

    vector<ll> dist(N,1e18);
    dist[0] = 0;
    rep(i,3*N) {
        rep(v,N) {
            rep(nv,G[v].size()) {
                Edge e = G[v][nv];
                if (dist[v] != 1e18 && dist[e.to] > dist[v] + e.cost) {
                    dist[e.to] = dist[v] + e.cost;
                    if (i >= N-1) {
                        dist[e.to] = -1e18;
                    }
                }
            }
        }
    }

    if (dist[N-1] == -1e18) cout << -1 << endl;
    else cout << max(-dist[N-1],0LL) << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
using namespace std;

//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for(int i=(int)m; i>=(int)n; --i)
#define rrep(i, m) RREP(i, m, 0)

//簡略化
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> P;

//定義
const int INF = 1e9+7;
const ll LINF = 1e18;
const ll MOD = 1e9+7;

//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//GCD&LCM
ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

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

void dfs(string s);

int N, cnt;
string t;

int main() {

  cin >> N;

  t = to_string(N);

  dfs("");

  cout << cnt << endl;

  return 0;
}

void dfs(string s) {

  if(s.size()>t.size()) {
    return;
  }

  if(s!=""&&stoi(s)>N) {
    return;
  }

  if(s.find("3")!=string::npos&&s.find("5")!=string::npos&&s.find("7")!=string::npos) {
    ++cnt;
  }

  dfs(s+"3");
  dfs(s+"5");
  dfs(s+"7");
}


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

using namespace std;

int k, a, b;
long long ans;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10, mod = 1e9 + 7;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    int k = (a + b) / 2;
    if (abs(a - k) == abs(b - k)) cout << k << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().strip().split())
ab = []
for _ in range(M):
  ab.append(tuple(map(int, input().strip().split())))

c = 0
prevb = 0

for a, b in sorted(ab, key=lambda x: x[1]):
  if a >= prevb:
    c += 1
    prevb = b
print(c)

Measured memory_bytes: 19016
#include <map>
#include <iostream>

using namespace std;
typedef pair<int, int> P;

int main(){
    int n,u,v,m,k;
    cin >> n >> u >> v >> m;
    int usagi_x[n];
    fill(usagi_x,usagi_x+n,0);
    int usagi_y[n];
    fill(usagi_y,usagi_y+n,0);
    int usagi_xy=0,usagi_yx=0;
    int neko_x[n];
    fill(neko_x,neko_x+n,0);
    int neko_y[n];
    fill(neko_y,neko_y+n,0);
    int neko_xy=0,neko_yx=0;
    int usagi_n=0;
    int neko_n=0;

    map<int,P> usagi, neko;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> k;
            usagi[k]=P(i,j);
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> k;
            neko[k]=P(i,j);
        }
    }
    for(int i=0;i<m;i++){
        bool neko_b=false,usagi_b=false;
        cin >> k;
        auto it = usagi.find(k);
        if(it!=usagi.end()){
            int x=it->second.first,y=it->second.second;
            usagi.erase(k);
            if(++usagi_x[x]==n) usagi_n++;
            if(++usagi_y[y]==n) usagi_n++;
            if(x==y){
                if(++usagi_xy==n) usagi_n++;
            }
            if(x+y==n-1){
                if(++usagi_yx==n) usagi_n++;
            }
            if(usagi_n>=u) usagi_b=true;
        }

        it = neko.find(k);
        if(it!=neko.end()){
            int x=it->second.first,y=it->second.second;
            neko.erase(k);
            if(++neko_x[x]==n) neko_n++;
            if(++neko_y[y]==n) neko_n++;
            if(x==y){
                if(++neko_xy==n) neko_n++;
            }
            if(x+y==n-1){
                if(++neko_yx==n) neko_n++;
            }
            if(neko_n>=v) neko_b=true;
        }
        if(n==1){
            if(usagi_n!=0&&1>=u) usagi_b=true;
            else usagi_b=false;
            if(neko_n!=0&&1>=v) neko_b=true;
            else neko_b=false;
        }

        if(neko_b&&usagi_b){
            cout<<"DRAW"<<endl;
            return 0;
        }else if(neko_b){
            cout<<"NEKO"<<endl;
            return 0;
        }else if(usagi_b){
            cout<<"USAGI"<<endl;
            return 0;
        }
    }
    cout<<"DRAW"<<endl;
    return 0;
}

Measured memory_bytes: 20940
n = int(input())
l = input()
a = l.split(' ')

tmp = 0
tmp2 = 0

for i in range(n):
    tmp += int(a[i])

for i in range(n):
    tmp2 += int(a[i])*int(a[i])

print((tmp*tmp-tmp2)//2%1000000007)

Measured memory_bytes: 25040
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int w;
    int latte[]={
        125,140,160,
    };
    while(cin>>w,w!=-1){
        int ans=1150;
        for(int i=0;i<3;i++){
            w-=10;
            if(w>0)ans+=min(10,w)*latte[i];
        }
        w-=10;
        ans+=max(0,w)*latte[2];
        cout<<4280-ans<<endl;

    }
    return 0;
}

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

using namespace std;
using VI = vector<int>;
using VPI = vector<pair<int, int>>;
using LL = long long;

#define FOR(a,n) for(int i=a;i<n;i++)
#define rFOR(a,n) for(int i=n-1;i>=a;i--)
#define IN(n,a) for(int i=0;i<n;i++) cin>>a[i]
#define pIN(n,t) for(int i=0;i<n;i++){int a,b; cin>>a>>b; t.emplace_back(a,b);}
#define SORT(a) sort(a.begin(), a.end())
#define ALL(a) a.begin(), a.end()

int main()
{
	int n;
	bool ans = false;
	cin >> n;

	if (n > 81)cout << "No";
	else if (n == 1) cout << "Yes";
	else
	{
		FOR(2, 10)
		{
			if (n % i == 0 && n / i < 10)
			{
				ans = true;
				break;
			}
		}
		if (ans)cout << "Yes";
		else cout << "No";
	}
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,m,ans=(1<<18),sum=0;
  cin >> n;
  int64_t a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum+=a[i];
  }
  ans=sum;
  for(int i=0;i<n;i++){
    m+=a[i];
    ans=min(ans,abs(m*2-sum));
  }
  cout << ans << endl;
}


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

int descending_compare(const void *a, const void *b){
    return (int)(*(char*)b - *(char*)a);
}

int ascending_compare(const void *a, const void *b){
    return (int)*(char*)a - *(char*)b;
}


char s[8001];
int x, y;
int dx[8000] = {0};
int dy[8000] = {0};
int xdp[8000][16002] = {0};
int ydp[8000][16002] = {0};

int main(void){
    int i, j;
    int flag = 0;
    scanf("%s", s);
    scanf("%d %d", &x, &y);

    for (i = 0; i < strlen(s); i++){
        if (s[i] == 'T'){
            flag++;
        }else if (flag%2 == 0){
            dx[flag/2]++;
        }else if (flag%2 == 1){
            dy[flag/2]++;
        }
    }

    xdp[0][8000+dx[0]] = 1;
    ydp[0][8000+dy[0]] = 1;
    ydp[0][8000-dy[0]] = 1;

    for (i = 1; i <= flag/2; i++){
        for (j = 0; j < 16002; j++){
            if (xdp[i-1][j] == 1){
                xdp[i][j+dx[i]] = 1;
                xdp[i][j-dx[i]] = 1;
            }
        }
    }

    for (i = 1; i <= flag/2; i++){
        for (j = 0; j < 16002; j++){
            if (ydp[i-1][j] == 1){
                ydp[i][j+dy[i]] = 1;
                ydp[i][j-dy[i]] = 1;
            }
        }
    }

    if (xdp[flag/2][8000+x] == 1 && ydp[flag/2][8000+y] == 1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


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

int N;
int t;

int main() {
    std::map<int, int> m;
    cin >> N;
    rep(i, N) {
        cin >> t;
        m.insert(make_pair(t, (i + 1)));
    }
 
    map<int, int>::iterator ite;
    for (int i = 1; i <= N; i++) {
        ite = m.find(i);
        cout << ite->second << " ";
        
    }

    return 0;
}

Measured memory_bytes: 5504
x = []
y = []
for _ in range(1,10001):
    a, b = map(int,input().split())
    if a == b == 0:
        break
    x.append(a)
    y.append(b)

for x_num, y_num in zip(x,y):
    if x_num > y_num:
        x_num, y_num = y_num, x_num
    print(x_num,y_num)


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

using namespace std;
vector < pair < ll ,ll > > v;
deque < pair < ll , ll > > Q;


int main()
{
    ll n,D,A,x,h;  cin >> n >> D >> A;
    for(int i = 0;i<n;i++)  cin >> x >> h , v.push_back({x , h});
    sort(v.begin() , v.end());
    ll Ans = 0 , sum = 0;
    for(int i = 0;i<v.size();i++){
        while(!Q.empty() && Q.front().first < v[i].first){
            sum-=Q.front().second;
            Q.pop_front();
        }
        ll l = v[i].first + 2 * D;
        ll Need = (v[i].second - sum + A - 1)/A;
        Need = max((ll)0 , Need);
        Ans+=Need;
        Q.push_back({l , Need * A});
        sum+=Q.back().second;
    }
    cout << Ans;
    return 0;
}


Measured memory_bytes: 6636
#include<stdio.h>

int main(void) {
	int N;
	int a[10000];
	int i, j;
	int cnt = 0;

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}

	for (i = 0; i < N; i++) {
		for (j = 2; j*j <= a[i]; j++) {
			if (j != a[i] && a[i] % j == 0) {
				cnt++;
				break;
			}
		}
	}
	
	printf("%d\n", N - cnt);
	return 0;
}


Measured memory_bytes: 2004
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll N, W;
vector<vector<P>> value(4);//value[i][j] : 重さi+w1 のj番目に価値が高いもの
ll sum_value[4][101], sum_weight[4][101];
ll ans = 0;

void depth_first(int n, int b[4]) {
	if (n == 4) {
		ll value_total = 0, weight_total = 0;
		for (int i = 0; i < 4; i++) {
			value_total += (sum_value[i][b[i]] - sum_value[i][0]);
			weight_total += (sum_weight[i][b[i]] - sum_weight[i][0]);
		}
		if (weight_total <= W)ans = max(ans, value_total);
		return;
	}
	int next_b[4];
	next_b[0] = b[0], next_b[1] = b[1], next_b[2] = b[2], next_b[3] = b[3];
	for (int i = 0; i <= value[n].size(); i++) {
		next_b[n] = i;
		depth_first(n + 1 ,next_b);
	}
}

int main() {
	ll base_weight;
	cin >> N >> W;
	for (int i = 0; i < N; i++) {
		ll a, b;
		cin >> a >> b;
		if (i == 0) {
			base_weight = a, value[0].push_back(P(b, a));
		}
		else {
			value[a - base_weight].push_back(P(b, a));
		}
	}
	for (int i = 0; i < 4; i++) {
		sort(value[i].begin(), value[i].end(), greater<P>());
		sum_value[i][0] = 0;
		sum_weight[i][0] = 0;
		for (int j = 1; j <= value[i].size(); j++) {
			sum_value[i][j] = sum_value[i][j - 1] + value[i][j - 1].first;
			sum_weight[i][j] = sum_weight[i][j - 1] + value[i][j - 1].second;
		}
	}

	int tmp[4] = { 0,0,0,0 };
	depth_first(0, tmp);
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  int n;cin>>n;
  set<string> se;
  rep(t,n){
    string s;cin>>s;
    se.insert(s);
  }
  cout<<se.size()<<endl;
  return 0;
}

Measured memory_bytes: 19204
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct edge { int a, b, cost; };
bool operator<(const edge& e1, const edge& e2) { return e1.cost < e2.cost; };
const int inf = 1012345678;
int N, M, K, c[100009], a[100009], b[100009], w[100009], par[200009]; map<pair<int, int>, int> d;
int root(int x) { return par[x] == x ? x : par[x] = root(par[x]); }
void connect(int x, int y) { par[root(x)] = root(y); }
int main() {
	cin >> N >> M >> K;
	for (int i = 0; i < N; i++) cin >> c[i];
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i] >> w[i]; a[i]--, b[i]--;
		if (c[a[i]] > c[b[i]]) swap(a[i], b[i]);
		if (c[a[i]] != 0 && c[b[i]] != 0 && c[a[i]] != c[b[i]]) d[make_pair(c[a[i]], c[b[i]])] = inf;
	}
	vector<edge> v;
	for(int i = 0; i < M; i++) {
		if (c[a[i]] != 0 && c[b[i]] != 0) {
			if (c[a[i]] != c[b[i]]) d[make_pair(c[a[i]], c[b[i]])] = min(d[make_pair(c[a[i]], c[b[i]])], w[i]);
		}
		else if (c[b[i]] != 0) v.push_back(edge{ a[i] + K, c[b[i]] - 1, w[i] });
		else v.push_back(edge{ a[i] + K, b[i] + K, w[i] });
	}
	for (pair<pair<int, int>, int> i : d) {
		v.push_back(edge{ i.first.first - 1, i.first.second - 1, i.second });
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < K + N; i++) par[i] = i;
	int cnt = 0; long long sum = 0;
	for (edge e : v) {
		if (cnt == K - 1) break;
		if (root(e.a) != root(e.b)) sum += e.cost, connect(e.a, e.b), cnt++;
	}
	cout << (cnt != K - 1 ? -1 : sum) << "\n";
	return 0;
}

Measured memory_bytes: 10100
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc139_a.cpp
 * time   : Sat May  2 01:47:47 2020
 * quest  : A - Tenki
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  cout << (s[0] == t[0] ? 1 : 0) + (s[1] == t[1] ? 1 : 0) + (s[2] == t[2] ? 1 : 0) << "\n";
  return 0;
}


Measured memory_bytes: 256
from collections import deque

S = input()
Q = int(input())

t = deque(S)
reverse = False
for _ in range(Q):
    query = input()
    if query[0] == '1':
        reverse = not reverse
    elif query[0] == '2':
        _, F, C = query.split()
        if F == '1':
            if reverse:
                t.append(C)
            else:
                t.appendleft(C)
        elif F == '2':
            if reverse:
                t.appendleft(C)
            else:
                t.append(C)
result = ''.join(t)
if reverse:
    result = result[::-1]
print(result)

Measured memory_bytes: 96532
n=int(input())
a=input()
b=input()
c=input()

co=0
for i in range(n):
    if a[i]==b[i] and b[i]==c[i]:
        co+=0
    elif a[i]==b[i] or b[i]==c[i] or c[i]==a[i] :
        co+=1
    else :
        co+=2

print(co)


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

using namespace std;

typedef long long LL;

LL solve(LL N, LL M) {
  if (N == 1) {
    if (M == 1) return 1;
    return M - 2;
  }
  if (M == 1) {
    return N - 2;
  }

  return (N - 2) * (M - 2);
}
int main() {
  LL N, M;
  cin >> N >> M;
  LL ans = solve(N, M);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
from sys import stdin
import itertools
N,M,Q = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for i in range(Q):
    a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
    data.append((a,b,c,d))
    
ite = []
def f(n,cnt):
    if cnt == N:
        ite.append(n)
        return
    for i in range(1,M+1):
        if n[-1] <= i:
            f(n+[i],cnt+1)
f([1],0)
ans = 0
for i in ite:
    tmp = 0
    for a,b,c,d in data:
        if i[b-1] - i[a-1] == c:
            tmp += d
    ans = max(ans,tmp)
    
print(ans)

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

static const int N = 100;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    int n;
    cin >> n;
    int p[N + 1], m[N + 1][N + 1];
    rep1(i, n) { cin >> p[i - 1] >> p[i]; }
    rep1(i, n) m[i][i] = 0;

    for (int l = 2; l <= n; l++) {
        for (int i = 1; i <= n - l + 1; i++) {
            int j   = i + l - 1;
            m[i][j] = (1 << 21);
            for (int k = i; k <= j - 1; k++) {
                m[i][j] = min(m[i][j],
                              m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }
    cout << m[1][n] << endl;

    return 0;
}



Measured memory_bytes: 3156
/*
 * main.c
 *
 *  Created on: 2020/07/27
 *      Author: 113896
 */
#include <stdio.h>

int main() {

	int r, c;
	scanf("%d%d", &r, &c);

	int table[r+1][c+1];

	for (int i = 0; i < r+1; i++) {
		for (int j = 0; j < c+1; j++) {
			table[i][j] = 0;
		}
	}

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			scanf("%d", &table[i][j]);
		}
	}

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			table[i][c] += table[i][j];
		}
	}

	for (int i = 0; i < c; i++) {
		for (int j = 0; j < r; j++) {
			table[r][i] += table[j][i];
		}
	}

	for (int i = 0; i < r; i++) {
		table[r][c] += table[i][c];
	}

	for (int i = 0; i < r+1; i++) {
		for (int j = 0; j < c+1; j++) {
			printf("%d", table[i][j]);
			if (j == c) printf("\n");
			else printf(" ");
		}
	}

	return 0;
}




Measured memory_bytes: 2060
n = int(input())
A = [int(i) for i in input().split()]

x1 = sum(A)
for i in range(n):
    if i % 2 != 0:
        x1 -= 2 * A[i]
ans = [x1]
for i in range(n-1):
    tmp = 2 * A[i] - ans[i]
    ans.append(tmp)

print(" ".join([str(int(n)) for n in ans]))

Measured memory_bytes: 19144
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
	
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


string e;
vector<int> sets[256];
vector<int> calculate(char ope, const vector<int>& left, const vector<int>& right)
{
	vector<int> res(left.size() + right.size());
	vector<int>::iterator end;
	if (ope == 'u')
		end = set_union(all(left), all(right), res.begin());
	else if (ope == 'i')
		end = set_intersection(all(left), all(right), res.begin());
	else if (ope == 'd')
		end = set_difference(all(left), all(right), res.begin());
	else if (ope == 's')
		end = set_symmetric_difference(all(left), all(right), res.begin());

	res.erase(end, res.end());
	return res;
}
vector<int> parse(int a, int b)
{
	int p = b;
	for (int par = 0; p >= a; --p)
	{
		if (e[p] == '(')
			++par;
		else if (e[p] == ')')
			--par;
		else if (par == 0 && strchr("uids", e[p]))
			break;
	}
	if (p < a)
	{
		if (e[a] == 'c')
			return calculate('s', sets['U'], parse(a + 1, b));
		else if (e[a] == '(')
			return parse(a + 1, b - 1);
		else
			return sets[e[a]];
	}

	return calculate(e[p], parse(a, p - 1), parse(p + 1, b));
}
int main()
{
	while (true)
	{
		rep (i, 256)
			sets[i].clear();

		vector<int> universe;
		while (true)
		{
			char a;
			int n;
			if (!(cin >> a >> n))
				return 0;

			if (a == 'R')
				break;

			sets[a] = vector<int>();
			while (n--)
			{
				int t;
				cin >> t;
				sets[a].push_back(t);
				universe.push_back(t);
			}
			sort(all(sets[a]));
		}
		sort(all(universe));
		universe.erase(unique(all(universe)), universe.end());
		sets['U'] = universe;

		cin >> e;
		vector<int> res = parse(0, e.size() - 1);
		if (res.empty())
			cout << "NULL" << endl;
		else
		{
			for (int i = 0; i < res.size(); ++i)
			{
				cout << res[i];
				if (i + 1 < res.size())
					cout << ' ';
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ss = Console.ReadLine().Split();
            var N = int.Parse(ss[0]);
            var K = int.Parse(ss[1]);

            var sum = 0;
            for (int i = N - 2; i > 0; i--)
            {
                sum += i;
            }

            if (sum < K)
            {
                Console.WriteLine(-1);
                return;
            }

            var edgeList = new List<string>();
            var edgeNum = 0;

            edgeList.Add("1 2");
            edgeNum++;

            for (int i = 3; i <= N; i++)
            {
                edgeList.Add("2 " + i);
                edgeNum++;
            }

            if (sum == K)
            {
                ShowAns(edgeNum, edgeList);
                return;
            }

            var diff = sum - K;
            for (int i = 3; i <= N; i++)
            {
                edgeList.Add("1 " + i);
                edgeNum++;

                diff--;
                if (diff == 0)
                {
                    ShowAns(edgeNum, edgeList);
                    return;
                }
            }

            for (int i = 3; i < N; i++)
            {
                for (int j = i + 1; j <= N; j++)
                {
                    edgeList.Add(i + " " + j);
                    edgeNum++;

                    diff--;
                    if (diff == 0)
                    {
                        ShowAns(edgeNum, edgeList);
                        return;
                    }
                }
            }
        }

        static void ShowAns(int edgeNum, List<string> edge)
        {
            Console.WriteLine(edgeNum);
            foreach (var item in edge)
            {
                Console.WriteLine(item);
            }
        }
    }
}

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

int power(int x,int n){
  if(x==0) return 0;
  if(n==0) return 1;
  if(n==1) return x;
  int res = power(x,n/2);
  res = (res*res)%mod;
  if(n%2) return (res*x)%mod;
  return res;
}

int nCr(int n, int r)
{ 
    if (r == 0) 
        return 1; 
    vector <int> f(n + 1); 
    f[0] = 1; 
    for (int i = 1; i <= n; i++) 
        f[i] = (f[i-1]*i)%mod; 
  
    return ((f[n]*power(f[r],mod-2))%mod * power(f[n-r],mod-2))%mod; 
} 
  

int32_t main(){
     string s; cin>>s;
     int n = s.length();
     if(s[n-1]=='s') cout<<s+"es";
     else cout<<s+"s";
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

def main():
    N, A, B = map(int, input().split())
    tmp = B - A
    if tmp&1:
        ans = min(A - 1, N - B)
        ans += (tmp + 1) // 2
    else:
        ans = tmp // 2
    
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll Mod = 998244353;
int main() {
  string S;
  cin >> S;
  if (S[0] == S[1] && S[1] == S[2]) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //String str = sc.next();
        double N = sc.nextDouble();
        double rate = 1.08;
        
        double a = N/rate;
        double a1 = Math.ceil(a);
        double a2 = Math.floor(a);
        //System.out.println(a+":"+a1+":"+a2);
        //System.out.println((int)N+":"+(int)Math.floor(a1*rate)+":"+a2);
        
        if((int)(a1*rate)==(int)N){
            System.out.println((int)a1);
        }else if((int)(a2*rate)==(int)N){
            System.out.println((int)a2);
        }else{
            System.out.println(":(");
        }
    }
}

Measured memory_bytes: 37200
#include<iostream>
#include<algorithm>

using namespace std;

void trace(int a[], int N) {
	int i;
	for (i = 0;i < N;i++) {
		if (i != 0)cout << " ";
		cout << a[i];
	}
	cout << endl;
}

void insertionSort(int a[], int N) {
	int i, j, v;
	for (i = 1;i < N;i++) {
		v = a[i];
		for (j = i - 1;j >= 0 && a[j] > v;j--) {
			a[j + 1] = a[j];
		}
		a[j + 1] = v;
		trace(a, N);
	}
}

int main() {
	int N;
	cin >> N;
	int a[114514];
	int i, j;
	for (i = 0;i < N;i++) {
		cin >> a[i];
	}
	trace(a, N);
	insertionSort(a, N);
	return 0;
}


Measured memory_bytes: 3100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(bf.readLine());
        while(st.hasMoreTokens()){
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            System.out.println(a*b+" "+2*(a+b));
        }
    }
}

Measured memory_bytes: 23820
n=gets.to_i
a=[0,1]
f,q=a.map{(1..n).map{gets.split.map &:to_i}}
p a.repeated_permutation(10).map{|e|(0...n).map{|i|q[i][(0..9).count{|j|e[j]*f[i][j]==1}]}.inject :+}[1..-1].max

Measured memory_bytes: 1916
from math import sqrt
from sys import stdin
input = stdin.buffer.readline

def main():
    xs, ys, xt, yt = map(int, input().split())
    n = int(input())

    xyr = [(0, 0, 0)] * (n+2)
    xyr[0] = (xs, ys, 0)
    xyr[1] = (xt, yt, 0)
    for i in range(2, n+2):
        x, y, r = map(int, input().split())
        xyr[i] = (x, y, r)

    # dijkstra
    inf = float('inf')
    dic = {i: inf for i in range(n+2)}
    dic[0] = 0.0
    while True:
        ind, cost = min(dic.items(), key=lambda x: x[1])
        dic.pop(ind)

        if ind == 1:
            print(cost)
            break

        x, y, r = xyr[ind]
        for i, old_cost in dic.items():
            xi, yi, ri = xyr[i]
            new_cost = max(sqrt((x-xi)*(x-xi)+(y-yi)*(y-yi))-(r+ri), 0.0) + cost
            if new_cost < old_cost:
                dic[i] = new_cost

main()


Measured memory_bytes: 9372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int main()
{
    string str;
    cin >> str;
    int n = str.size() + 1;
    vector<int> cnt(n); // a[i] について、cnt[i] = max(左に連続する < の個数, 右に連続する > の個数)

    // 左から < をカウントする
    for (int i = 0; i < n - 1; ++i)
    {
        if (str[i] == '<')
        {
            cnt[i + 1] = (std::max)(cnt[i + 1], cnt[i] + 1);
        }
    }

    // 右から > をカウントする
    for (int i = n - 2 ; i >= 0; --i)
    {
        if (str[i] == '>')
        {
            cnt[i] = (std::max)(cnt[i], cnt[i+1] + 1);
        }
    }

    long long ans = 0;
    for (int i = 0; i < n; ++i)
    {
        ans += cnt[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2820
N = int(input())
A = list(map(int, input().split()))

maximum = max(A)
count = [0]*(maximum + 2)

for i in range(N):
    if A[i] == 0:
        count[0] += 1
        count[1] += 1
        
    elif A[i] == maximum:
        count[A[i]] += 1
        count[A[i] - 1] += 1
    
    else:
        count[A[i] + 1] += 1
        count[A[i]] += 1
        count[A[i] - 1] += 1

print(max(count))

Measured memory_bytes: 13964
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

#define all(v) (v).begin(), (v).end()
using namespace std;

const int MAX_N = 1e4 + 5, MAX_DIGITS = 10, oo = 1e6;
int max_length_with_last_digit[MAX_N][MAX_DIGITS];
int digit_cost[MAX_DIGITS] = {0,2,5,5,4,5,6,3,7,6};

int main()
{
    int cost, no_of_digits;
    cin >> cost >> no_of_digits;

    vector <int> is_present(MAX_DIGITS, false);
    for(int i = 1; i <= no_of_digits; i++)
    {
        int digit;
        cin >> digit;
        is_present[digit] = true;
    }

    memset(max_length_with_last_digit, 0, sizeof(max_length_with_last_digit));

    vector <int> max_length(cost + 1, -oo);
    max_length[0] = 0;

    for(int i = 1; i <= cost; i++)
    {
        for(int last_digit = 1; last_digit <= 9; last_digit++)
        {
            if(!is_present[last_digit] || digit_cost[last_digit] > i)
                continue;

            max_length_with_last_digit[i][last_digit] = 1 + max_length[i - digit_cost[last_digit]];
            //cout << "f(" << i << ", " << last_digit << " ) = " << max_length_with_last_digit[i][last_digit] << endl;

            max_length[i] = max(max_length[i], max_length_with_last_digit[i][last_digit]);
        } //cout << "f(" << i << ") = " << max_length[i] << endl;
    }

    vector <int> answer;

    for(int i = cost; i > 0; )
    {
        for(int last_digit = 9; last_digit >= 1; last_digit--)
        {
            if(!is_present[last_digit])
                continue;

            if(max_length_with_last_digit[i][last_digit] == max_length[i])
            {   //cout << "Digit pushes i " << last_digit << " and cost is now " << i - digit_cost[last_digit] << endl;
                answer.push_back(last_digit);

                i -= digit_cost[last_digit];

                break;
            }
        }
    }

    for(int i = 0; i < answer.size(); i++)
        cout << answer[i];
    return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, N, D[100001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(D[i]));
	
	int count[100001] = {}, flag = 1;
	for (i = 1; i <= N; i++) count[D[i]]++;
	for (i = 1; count[i] > 0; i++);
	for (; i <= N && count[i] == 0; i++);
	if (D[1] != 0 || count[0] > 1 || i <= N) {
		printf("0\n");
		fflush(stdout);
		return 0;
	}

	int j;
	long long ans = 1;
	for (i = 2; count[i] > 0; i++) {
		for (j = 0; j < count[i]; j++) ans = (ans * count[i-1]) % 998244353;
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>

int main(void){

  int n;
  scanf("%d\n", &n);
  char s[n+1];
  char t[n+1];
  for (int i = 0; i < n; i++) {
    scanf("%c", &s[i]);
  }
  scanf("%s", t);

  for (int i = 0; i < n; i++) {
    printf("%c%c", s[i], t[i]);
  }
  printf("\n");

  return 0;
}

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


int main() {
    int N;
    cin >> N;
    int ans = 0;
    while (N > 0) {
        if (N % 10 == 2) ++ans;
        N /= 10;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3528
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        int H = sc.nextInt();
        int W = sc.nextInt();
        sc.nextLine();
        for (int i = 0; i <= H + 1; ++i) {
            if (i > 0 && i <= H) {
                _out.print("#");
                _out.print(sc.nextLine());
                _out.print("#");
            } else {
                for (int j = 0; j <= W + 1; ++j) {
                    _out.print("#");
                }
            }
            _out.println();
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 22228
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

ll N;
string ans = "";

signed main(){
    cin >> N;
    while(N > 0){
        N--;
        ans += (char)(N%26+'a');
        N /= 26;
    }
    reverse(all(ans));
    cout << ans << endl;
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto& e : a) scanf("%d", &e);
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[a[i]-1] == i+1) ans++;
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string, int>;
int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ab = 0;
    int pos = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        if(abs(a[i]) > ab)
        {
            pos = i;
            ab = abs(a[i]);
        }
    }
    if(a[pos] == 0)
    {
        cout << 0 << endl;
    }
    else if(a[pos] > 0)
    {
        cout << 2*n - 1 << endl;
        for(int i = 1; i <= n; i++)
        {
            cout << pos+1 << " " << i << endl;
        }
        for(int i = 1; i < n; i++)
        {
            cout << i << " " << i+1 << endl;
        }
    }
    else
    {
        cout << 2*n - 1 << endl;
        for(int i = 1; i <= n; i++)
        {
            cout << pos+1 << " " << i << endl;
        }
        for(int i = n; i > 1; i--)
        {
            cout << i << " " << i-1 << endl;
        }
    }
}


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

int main(void){
    int K;
    double A,B;
    cin >> K;
    cin >> A >> B;
    int CEA,tmp;
    CEA = ceil(A/K) * K;
    if(CEA >= A && CEA <= B) cout << "OK" << endl;
    else cout << "NG" << endl;

    return 0;
}

Measured memory_bytes: 3704
// from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn main() {
    input! {
      n: i32,
      d: i32
    };
    let n: i32 = n;
    let d: i32 = d;
    let r = n / (d * 2 + 1);
    let x = if n % (d * 2 + 1) == 0 { r } else { r + 1 };
    println!("{}", x)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i, n) for( int i=0 ; i<n ; i++ )
#define f(i, a, b) for( int i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll fact(ll n)
{
    ll ans = 1e14;
    for(ll i = 1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            ll sol = (i - 1) + (n/i - 1);
            ans = min(ans,sol);
        }
    }
    return ans;
}
int visited[200000] = {0};
vector<vector<int> > v(200000);
int dfs(int x)
{
    int ans = 0;
    if(visited[x]==0)
    {
        visited[x] = 1;
        ans++;
        int a = v[x].size();
        for(int j = 0;j<a;j++)
        {
            int data = v[x][j];
            ans = ans + dfs(data);
        }
    }
    return ans;
}
int main()
{
    ll n,m;
    cin>>n>>m;
    fi(i,m)
    {
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int ans = 0;
    fi(i,n)
    {
        if(visited[i]==0)
        {
            ans = max(ans,dfs(i));
        }
    }
    cout<<ans<<endl;
}


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

// clang-format off
#define forn(i, x, y) for(int i = x; i < y; i++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)
#define printVector(a) for(auto it = a.begin() ; it != a.end(); it++) { cout << *it << " "; } cout << endl;
// clang-format on

const long long MOD = 1000000007;

using LL = long long;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVLL = vector<VLL>;

template <typename T>
void add(T &a, T b)
{
  a += b;
  if (a >= MOD)
    a -= MOD;
}

int main()
{
  IOS;

  int N;
  cin >> N;
  string s;
  cin >> s;

  VLL dp0(N, 1);

  forn(i, 1, N)
  {
    VLL dp1(N);
    if (s[i - 1] == '<')
    {
      for (int j = 0; j < N - i; j++)
      {
        dp1[j] = dp0[j];
        if (j > 0)
          add(dp1[j], dp1[j - 1]);
      }
    }
    else
    {
      for (int j = N - i - 1; j >= 0; j--)
      {
        dp1[j] = dp1[j + 1];
        add(dp1[j], dp0[j + 1]);
      }
    }
    dp0 = dp1;
  }

  cout << dp0[0] << endl;

  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k,q,a[100005],cnt[100005];
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k>>q;
    for(int i=1;i<=q;i++){
        cin>>a[i];
        cnt[a[i]]++;
    }
    for(int i=1;i<=n;i++){
        if(k-(q-cnt[i])<=0){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,i,j,k,l,m,n,ans,tmp,hoge,fuga,piyo;
ll x[200100],y[200100],z[200100];
string s,str;
int main(){
  ll a[2019];
  for(int i=0;i<2019;i++){
    a[i]=0;
  }
  cin>>s;
  n=s.length();
  for(int i=0;i<n;i++){
    x[i]=s[i]-'0';
  }
  y[0]=x[n-1];
  z[0]=1;
  for(int i=1;i<n;i++){
    z[i]=10*z[i-1]%2019;
  }
  for(int i=1;i<n;i++){
    y[i]=(z[i]*x[n-i-1]+y[i-1])%2019;
  }
  for(int i=0;i<n;i++){
    a[y[i]]++;
  }
  a[0]++;
  for(int i=0;i<2019;i++){
    ans+=a[i]*(a[i]-1)/2;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 8412