akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		String line2 = sc.nextLine();
		String[] k = line2.split(" ");
		for (int i = 0; i < v; i++) {
			vs[i] = Integer.parseInt(k[i]);
		}
		int i = 0;
		int count = 0;
		while(i<v-1){
			for (int j = v-1; j >-1; j--) {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			}i++;
		}
		
		for (int j = 0; j < v-1 ; j++) {
			System.out.print(vs[j]+" ");

		}
				System.out.println(vs[v-1]);
				System.out.println(count);



	}
}

Measured memory_bytes: 26260
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>

bool neko(std::vector<int> const& g) {
  size_t n = g.size();
  for (size_t i = 1; i < n; ++i)
    if (g[i]-g[i-1] != g[1]-g[0]) return false;
  return true;
}

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  std::vector<int> h(n+1);
  for (auto& hi: h) scanf("%d", &hi);

  for (size_t i = 0; i <= n; ++i) {
    std::vector<int> g;
    for (size_t j = 0; j <= n; ++j)
      if (j != i) g.push_back(h[j]);

    if (neko(g)) return !printf("%d\n", h[i]);
  }
  assert(false);
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2792
#include<stdio.h>


int main(void){
	int h,w;
	char s[53][53];
	//int v[53][53] = {};
	int i,j;
	int x,y;
	int buff;

	scanf("%d %d",&h,&w);
	

	// 下駄履かせながら盤面情報読み込み
	s[0][0] = '.';		s[0][w+1] = '.';
	s[h+1][0] = '.';	s[h+1][w+1] = '.';
	for(i=0;i<w;i++){
		s[0][i+1] = '.';
		s[h+1][i+1] = '.';
	}
	for(i=0;i<h;i++){
		s[i+1][0] = '.';
		scanf("%s",&s[i+1][1]);
		s[i+1][w+1] = '.';
	}

	/*[debag] 読み込んだ盤面表示
	for(i=0;i<h+2;i++){
		for(j=0;j<w+2;j++){
			printf("%c",s[i][j]);		
		}
		printf("\n");		
	}
	*/

	for(i=0;i<h;i++){
		for(j=0;j<w;j++){

			//盤面チェックしつつ結果出力
			if(s[i+1][j+1]=='.'){
				// 空白
				buff = 0;
				for(x=0;x<3;x++){
					for(y=0;y<3;y++){
						if(s[i+y][j+x] == '#'){ buff++; }
					}
				}
				// 個数出力
				printf("%d",buff);
			}else{
				// 爆弾
				printf("#");
			}
		}
		printf("\n");
	}


	return 0;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

constexpr int mod = 1e9 + 7;
constexpr int32_t inf = 1001001001;
constexpr int64_t infll = 1001001001001001001ll;
constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

// clang-format off
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }

template <typename T> void sort(vector<T> &v) { sort(all(v)); }
template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  cout << (in() < 1000 ? "ABC" : "ABD") << endl;
}


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

using namespace std;

typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define forn(n) for(int i = 0; i < n; i++)
#define print(n) cout << n << "\n"
#define fprint(n) fout << n << "\n"

/*
ID: argnowillac
TASK:
LANG: C++
*/

double n;
double v3,v2,v1;
double arr[310];
double dp[310][310][310]={0};

double exp(double nums) {
    return n/nums;
}

double solve(int a1, int a2, int a3) {
    //cout<<a1<<a2<<a3<<endl;
    if(dp[a1][a2][a3]!=0) return dp[a1][a2][a3];
    double nums = a1+a2+a3;
    double ans = 0;
    if(a1>0) ans+=a1*solve(a1-1,a2,a3);
    if(a2>0) ans+=a2*solve(a1+1,a2-1,a3);
    if(a3>0) ans+=a3*solve(a1,a2+1,a3-1);
    ans/=nums;
    ans+=exp(nums);
    dp[a1][a2][a3]=ans;
    //cout<<ans<<endl;
    return ans;
}
int main()
{
    cin>>n;
    forn(n) {
        cin>>arr[i];
        if(arr[i]==3) v3++;
        else if(arr[i]==2) v2++;
        else if(arr[i]==1) v1++;
    }
    dp[0][0][0]=0;
    dp[1][0][0]=n;
    dp[0][1][0]=2*n;
    dp[0][0][1]=3*n;
    printf("%.10f\n",solve(v1,v2,v3));

    return 0;
}


Measured memory_bytes: 225536
// https://atcoder.jp/contests/abc164/tasks/abc164_e

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 0
#if DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " "); cout << endl
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int N_MAX = 50;
const int M_MAX = 100;
const int S_MAX = 1e9;
const int A_I_MAX = 50;
const int B_I_MAX = 1e9;
const int C_I_MAX = 1e9;
const int D_I_MAX = 1e9;
const ll INF = 1e13;
const int COIN_MAX = 2450;

struct edge {
  int to;
  int coin;
  ll time;
  friend ostream& operator<<(ostream& os, const edge& e) {
    os << '(' << e.to << ',' << e.coin << ',' << e.time << ')';
    return os;
  }
};

using P = tuple<ll, int, int>;

int N, M, S;

int cx;
vector<vector<edge>> G;

int main() {
  cin >> N >> M >> S;
  cx = 0;
  G = vector<vector<edge>>(N);
  REP(i, M) {
    int U, V, A, B;
    cin >> U >> V >> A >> B;
    U--; V--;
    G[U].push_back({V, -A, B});
    G[V].push_back({U, -A, B});
    cx += A;
  }
  REP(v, N) {
    int C, D;
    cin >> C >> D;
    G[v].push_back({v, C, D});
  }

  cx = min(cx, COIN_MAX);
  DUMP2D(G);

  vector<vector<ll>> dp = vector<vector<ll>>(N, vector<ll>(cx + 1, INF));
  priority_queue<P, vector<P>, greater<P>> que;
  int c0 = min(S, cx);
  dp[0][c0] = 0;
  que.push({0, 0, c0});

  while (!que.empty()) {
    auto p = que.top(); que.pop();
    ll time;
    int v;
    int coin;
    tie(time, v, coin) = p;
    if (dp[v][coin] < time) continue;
    for (edge &e : G[v]) {
      int coin2 = min(coin + e.coin, cx);
      if (coin2 < 0) continue;
      ll time2 = time + e.time;
      int v2 = e.to;
      if (dp[v2][coin2] > time2) {
        dp[v2][coin2] = time2;
        que.push({time2, v2, coin2});
      }
    }
  }

  DUMP2D(d);

  FOR(v, 1, N - 1) {
    ll ans = *min_element(dp[v].begin(), dp[v].end());
    cout << ans << endl;
  }
}


Measured memory_bytes: 6052
N=input()
ans = ''
p=''
for i in range(len(N)-1):
    if N[i]=='?':
        if p=='P':
            ans+='D'
        elif N[i+1]=='D':
            ans+='P'
        elif N[i+1]=='P':
            ans+='D'
        else:
            ans+='P'
        
    else:
        ans+=N[i]
    p=ans[-1]

if N[len(N)-1]=='?':
    ans+='D'
else:
    ans+=N[len(N)-1]
print(ans)

Measured memory_bytes: 9584
#include <bits/stdc++.h>
using namespace std;
const int N = 110;

int n;
int d[N][2];
int main()
{
	cin >> n;
	bool flag = false;
	for(int i=1;i<=n;i++)
	{
		cin >> d[i][0] >> d[i][1];
	}
	for(int i=2;i<n;i++)
	{
		if(d[i-1][0] == d[i-1][1] && d[i][0]==d[i][1] && d[i+1][0] == d[i+1][1])
		{
			flag= true;
			break;
		}
	}
		if(flag)	cout << "Yes"<<endl;
		else cout << "No" << endl;
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double dd;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<ll, ll> pll;

#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(), (c).end()
#define MOD 1000000007

int main(){
#ifdef HOME
    freopen("kek.in", "r", stdin);
    freopen("kek.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, a, b;
    cin >> n >> m;
    vi f;
    vi s;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        if(a == 1)
            f.pb(b);
        if(b == n)
            s.pb(a);
    }
    sort(all(f)), sort(all(s));
    vi res;
    set_intersection(all(f), all(s), back_inserter(res));
    if(res.size() >= 1)
        cout << "POSSIBLE";
    else
        cout << "IMPOSSIBLE";
    return 0;
}

Measured memory_bytes: 1276
package main

import (
	"fmt"
)

func main() {
	var n int
	var walk, teleport int64
	fmt.Scan(&n)
	fmt.Scan(&walk)
	fmt.Scan(&teleport)
	x := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i])
	}
	walkLimit := teleport / walk
	var tired int64 = 0
	for i := 1; i < n; i++ {
		distance := x[i] - x[i-1]
		if distance > walkLimit {
			tired += teleport
		} else {
			tired += walk * distance
		}
	}
	fmt.Println(tired)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
int h, w;
#define LL long long
LL solve(int h, int w)
{
    LL ans = 1ll * h * w;
    for (int i = 1; i < h; ++ i)
    {
        LL s1 = 1ll * i * w, s2 = 1ll * (h - i) * (w / 2), s3 = 1ll * (h - i) * (w - w / 2);
        ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));

        s2 = 1ll * ((h - i) / 2) * w, s3 = 1ll * ((h - i) - (h - i) / 2) * w;
        ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
    }
    return ans;
}
int main()
{
    scanf("%d%d", &h, &w);
    cout << min(solve(h, w), solve(w, h));
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define M 1000000
#define L 14

char H[M][L]; /*Hash Table*/

int getChar(char ch){
	if(ch == 'A')return 1;
	else if(ch == 'C')return 2;
	else if(ch == 'G')return 3;
	else if(ch == 'T')return 4;
}

/*convert a string into an integer value*/
long long getkey(char str[]){
	long long sum=0, p=1, i;
	for(i = 0; i < strlen(str); i++){
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key) {return key % M;}
int h2(int key) {return 1 + (key % (M-1));}


int find(char str[]){
	long long key, i, h;
	key = getkey(str);
	for(i = 0; ; i++){
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h], str) == 0)return 1;
		else if(strlen(H[h]) == 0)return 0;
	}
	return 0;
}

int insert(char str[]){
	long long key, i, h;
	key = getkey(str);
	for(i = 0; ; i++){
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h], str) == 0)return 1;
		if(strlen(H[h]) == 0){
			strcpy(H[h], str);
			return 0;
		}
	}
}

int main(void)
{
	int i, n, h;
	char str[L], com[9];
	for(i = 0; i < M; i++)H[i][0] = '\0';
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		scanf("%s %s", com, str);
		
		if(com[0] == 'i'){
			insert(str);
		}
		else {
			if(find(str))printf("yes\n");
			else printf("no\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 15444
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)
 
typedef pair<int, int> pii;
 
int n, a, b, x, y;
pair<pii, int> ps[100000];
 
int s;
vector<int> es[100000];
int deg[100000];
int imos[100001];
 
void conn(int u, int v) {
    es[u].push_back(v);
    es[v].push_back(u);
}
 
void solve() {
    CLEAR(imos);
    sort(ps, ps + n);
    REP(i, n) {
        int x = ps[i].first.first, y = ps[i].first.second, v = ps[i].second;
        pair<pii, int> pl = MP(MP(x + s, y - s + 1), 0), pu = MP(MP(x + s, y + s), n);
        int l = lower_bound(ps, ps + n, pl) - ps;
        int u = upper_bound(ps, ps + n, pu) - ps;
        if (u > l) {
            conn(v, ps[l].second);
            deg[v] += u - l;
            ++deg[ps[l].second];
            ++imos[l]; --imos[u - 1]; 
            // connect from index l, to index u - 1, l-(l+1)-(...)-(u-1)
            // use imos to reduce  loop
        }
    }
    REP(i, n) {
        if (imos[i] > 0) {
            deg[ps[i + 1].second] += imos[i];
            conn(ps[i].second, ps[i + 1].second);
        }
        imos[i + 1] += imos[i];
    }
}
 
bool used[100000];
 
int main(int argc, char **argv) {
    cin >> n >> a >> b;
    --a; --b;
    REP(i, n) {
        cin >> x >> y;
        ps[i].first = MP(x + y, x - y);
        ps[i].second = i;
        deg[i] = 0;
    }
    // after transform from a(x, y) to a'(x+y, x-y), 
    // distance(a, b) = |ax-bx|+|ay-by| = max(|a'x-b'x|,|a'y-b'y|) = distance'(a', b')
    // just image a line y = x
    // the transform is (x+yi) e^{\pi i/4} = (x+yi) (1+i) = (x-y) + (x+y)i 
    s = max(abs(ps[a].first.first - ps[b].first.first), abs(ps[a].first.second - ps[b].first.second));
 
    solve();
    REP(i, n) ps[i].first = MP(ps[i].first.second, -ps[i].first.first); // why `-` ?
    solve();
 
    // a simple bfs of connected component
    ll res = 0;
    queue<int> q;
    q.push(a);
    q.push(b);
    CLEAR(used);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        if (used[v]) continue;
        used[v] = true;
        res += deg[v];
        REP(i, es[v].size()) q.push(es[v][i]);
    }
 
    cout << (res / 2) << endl;
 
    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
using namespace std;
int main()
{
    string s;
    cin >> s;
    bool ok = false;
    if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
        ok = true;
    else if (s[0] == s[2] && s[1] == s[3] && s[2] != s[1])
        ok = true;
    else if (s[0] == s[3] && s[1] == s[2] && s[3] != s[1])
        ok = true;
    
        cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

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

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

long double p[225816];

int main(void){
	int n,k,i;
	long double tmp = 0.0L, ans;
	cin >> n >> k;
	for(i=0; i<n; ++i){
		cin >> p[i];
		p[i]+=1.0L;
		p[i]/=2.0L;
	}
	for(i=0; i<k; ++i){
		tmp += p[i];
	}
	ans = tmp;
	for(i=k; i<n; ++i){
		tmp += p[i];
		tmp -= p[i-k];
		ans = max(ans,tmp);
	}
	cout << fixed << setprecision(50) << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
/*
LINES :
* //WHAT?
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

// #define OJ
#define pb push_back
#define F first
#define S second
#define N '\n'

#define WLL(t) while(t--)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define STF(i, a, b) for(size_t i = a; i < b; i++)
#define RFOR(i, a, b) for(int i = a; i >= b; i--)
#define SRF(i, a, b) for(size_t i = a;i >= b;i--)

#define ALL(v) v.begin(),v.end()
#define FPRECISE(x) cout<<fixed<<setprecision(x)
#define PRECISE(x) cout<<setprecision(x)
#define BOOL cout<<boolalpha
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define MOD 1000000007

#define TO(v, type) static_cast<type>(v)
int main()
{
#ifdef OJ
	READ;
	WRITE;
#endif
	FASTIO;
	int n {};
	cin>>n;
	long long sum {0};
	for(int i= 1 ;i<n ;i++){
		if(n%i == 0){
			sum += (n/i -1);
		}
		else{
			sum += (n/i);
		}
	}
	cout<<sum<<N;
	return 0;
}


Measured memory_bytes: 3636
N, M = map(int, input().split())
abc = [[int(x) for x in input().split()] for _ in range(M)]
Edges = [None]*M
for i in range(M):
    Edges[i] = (abc[i][0]-1, abc[i][1]-1, -abc[i][2])
def bellman_ford(N, edges, s):
    dist = [float("inf")]*(N)
    dist[s] = 0
    for n in range(N):
        for (u,v,c) in edges:
            if dist[u] != float("inf") and dist[v] >  dist[u] + c:
                dist[v] = dist[u] + c
                if n == N-1 and v == N-1:
                    return "inf"
    return -dist[-1]
print(bellman_ford(N, Edges, 0))



Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)

                    
using ll = long long;
using ull = unsigned long long;
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; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main() 
{
    int N;
    cin >> N;
    cout << (N+1)/2 << endl;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    N %= 10;
    switch (N)
    {
    case 3:
        cout << "bon" << endl;
        break;
    case 0:
        cout << "pon" << endl;
        break;
    case 1:
        cout << "pon" << endl;
        break;
    case 6:
        cout << "pon" << endl;
        break;
    case 8:
        cout << "pon" << endl;
        break;
    default:
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3512
/**計算幾何学の問題を解く際に利用するクラス******/
//http://skyblueryu.blog54.fc2.com/blog-entry-27.html
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
#include <cstdio>
#include <iostream>
#define EPS (pow(M_E,(double)-10))
//マクロの書式については 
//http://www7b.biglobe.ne.jp/~robe/cpphtml/html01/cpp01030.html
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;

class Point{
public:
	double x,y;

	//以下の記法に関しては
	//http://ameblo.jp/nana-2007-july/entry-10037680575.html
	Point(double x = 0,double y = 0): x(x), y(y) {};

	/***演算子のオーバーロード***********/
	Point operator + (Point p) { return Point(x + p.x,y + p.y);}
	Point operator - (Point p) { return Point(x - p.x,y - p.y);}
	Point operator * (double a) { return Point(a*x,a*y);}//スカラー倍
	Point operator / (double a) { return Point(x/a,y/a);}//スカラー倍
	/***********************************/

	double norm() { return x*x+y*y;}//ベクトルのノルムを返す
	double abs() { return sqrt(norm());}//ベクトルの長さを返す

	/***演算子のオーバーロード2***********/
	//Pointはクラスオブジェクトなのでサイズが大きく値渡しは適さない
	//Point &pという記法は参照渡しでポインタでない変数
	//に対してアドレスを引数にとりたい場合に使う．
	//参照渡しとポインタ渡しについては以下
	//http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1320144958
	//http://homepage2.nifty.com/well/Reference.html#PASS_BY_REFERENCE
	//
	//Point &pの前のconst修飾子は関数内で引数のオブジェクトの内容を
	//勝手に書き換えないようにするために付けている．(const Point &p)
	//の後のconstはこの関数がconstメンバ関数であることを意味する．
	//constメンバ関数に関して詳しくは以下
	//http://www.s-cradle.com/developer/sophiaframework/tutorial/Cpp/const.html

	bool operator < (const Point &p) const{
		//(条件)?(処理1):(処理2)
		//条件が真なら処理1，偽なら処理2が実行される
		return x != p.x ? x < p.x :y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
	/*************************************/

};

typedef Point Vector;

//ベクトルaとbの内積を計算する関数
//これは参照渡しじゃなくていいんかいという疑問は正直ある
double dot(Vector a,Vector b){
	//double dot(const Vector& a,const Vector& b){
	return a.x*b.x + a.y*b.y;
}

//ベクトルaとbの外積を計算する関数
double cross(Vector a,Vector b){
	//double cross(const Vector& a,const Vector& b){
	return a.x*b.y - a.y*b.x;
}



//線分を表す構造体
struct Segment{
	Point p1, p2;
};
typedef Segment Line;

//円を表すクラス
class Circle {
public:
	Point c;
	double r;
	Circle(Point c = Point(),double r = 0.0):c(c), r(r) {}
};

//多角形の表現(多角形は点の列で表現できる)
typedef vector<Point> Polygon;


int Q;//クエリ数

int main(){
	scanf("%d",&Q);

	Point s1,s2,t1,t2;
	Vector d1,d2;//方向ベクトル

	for(int q = 0;q < Q;q++){
		scanf("%lf %lf",&s1.x,&s1.y);
		scanf("%lf %lf",&s2.x,&s2.y);
		scanf("%lf %lf",&t1.x,&t1.y);
		scanf("%lf %lf",&t2.x,&t2.y);

		//l1の方向ベクトル
		d1.x = (s1.x - s2.x);
		d1.y = (s1.y - s2.y);

		//l2の方向ベクトル
		d2.x = (t1.x - t2.x);
		d2.y = (t1.y - t2.y);

		//l1とl2が直行しているか調べる(内積を計算して0かどうか調べる)
		if(equals(dot(d1,d2),0.0)){
			printf("1\n");
			continue;
		}else if(equals(d1.x*d2.y,d1.y*d2.x)){
			printf("2\n");
			continue;
		}else{
			printf("0\n");
			continue;
		}
	}

	return 0;
}

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

int a[200000];
const int lods = 100;
ld nxt[lods][200000];
int last[200001];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ll n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  fill_n(last, 200001, n);
  for (int i = n-1; i >= 0; i--) {
    last[a[i]] = i+n;
  }
  for (int i = n-1; i >= 0; i--) {
    nxt[0][i] = last[a[i]]-i+1;
    last[a[i]] = i;
  }
  for (int l = 0; l+1 < lods; l++) {
    for (int i = 0; i < n; i++) {
      if (nxt[l][i] > 1e18) {
	nxt[l+1][i] = 1e18;
	continue;
      }
      nxt[l+1][i] = nxt[l][i]+nxt[l][(i+(ll)nxt[l][i])%n];
    }
  }
  ll p = 0;
  for (int l = lods-1; l >= 0; l--) {
    while (p+nxt[l][p%n] < n*k) {
      p += (ll)nxt[l][p%n];
    }
  }
  vector<int> ans;
  set<int> in;
  for (int i = p%n; i < n; i++) {
    if (in.count(a[i])) {
      while (in.count(a[i])) {
	in.erase(ans.back());
	ans.pop_back();
      }
    } else {
      ans.push_back(a[i]);
      in.insert(a[i]);
    }
  }
  for (int i : ans) cout << i << ' ';
  cout << endl;
}


Measured memory_bytes: 325748
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_N 100000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, res;

int solve() {
    int res = 0;
    res += min(9, N);

    if(N >= 100)
        res += min(900, N - 99);
    if(N >= 10000)
        res += min(90000, N - 9999);

    return res;
}

int main(int argc, char **argv) {
    cin >> N;

    
    res = solve();
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <cstdio>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;


int main(){

    int p=1e9,j=1e9;
    REP(i,3){
        int t; cin>>t;
        p=min(p,t);
    }
    
    REP(i,2){
        int t; cin>>t;
        j=min(j,t);
    }
    
    cout<<p+j-50<<endl;
    
    return 0;
}

Measured memory_bytes: 3108
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))

    flag = True
    for i in range(N):
        if A[i] % 2 == 0:
            if A[i] % 3 == 0 or A[i] % 5 == 0:
                pass
            else:
                flag = False

    if flag:
        print("APPROVED")
    else:
        print("DENIED")


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
// -*- coding:utf-8-unix -*-

use proconio::input;
// use proconio::marker::Chars;

fn main() {
    input! {
        s: String,
        q: u64,
    }

    let mut vs: Vec<char> = s.chars().collect();
    let mut is_reversed = false;
    let mut vhead: Vec<char> = vec!();
    let mut vtail: Vec<char> = vec!();
    for _i in 0..q {
        input! {
            c0: char,
        }

        // println!("{:?}", query);
        if c0 == '1' {
            is_reversed = !is_reversed;
        } else {
            input! {
                c1: char,
                c2: char,
            }
            if is_reversed {
                if c1 == '1' {
                    vtail.push(c2);
                } else {
                    vhead.push(c2);
                }
            } else {
                if c1 == '1' {
                    vhead.push(c2);
                } else {
                    vtail.push(c2);
                }
            }
        }
    }

    vhead.reverse();
    vhead.append(&mut vs);
    let mut vs =vhead;
    vs.append(&mut vtail);
    if is_reversed {
        vs.reverse();
    }
    println!("{}", vs.into_iter().collect::<String>());
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n,q;
string op[100010];
vector<int> g[100010];
int mat[8][8];

int calc(int crt,string o,int x,int y){
  if(o[4]=='X'){
    if(o[3]=='&')return crt&x;
    if(o[3]=='|')return crt|x;
    if(o[3]=='^')return crt^x;
  }else{
    if(o[3]=='&')return crt&y;
    if(o[3]=='|')return crt|y;
    if(o[3]=='^')return crt^y;
  }
  return -1;
}

int dfs(int v,int pre,int x,int y,int f,int crt){
  vector<int> vs;
  for(int nv : g[v]){
    if(nv==pre)continue;
    vs.push_back(dfs(nv,v,x,y,1-f,v!=0?calc(crt,op[v],x,y):0));
  }
  if(vs.size()==0){
    return calc(crt,op[v],x,y);
  }
  sort(all(vs));
  return f==0?vs.back():vs.front();
}

int main(){
  cin>>n>>q;
  rep(i,n-1){
    cin>>op[i+1];
  }
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  rep(x,8)rep(y,8){
    mat[x][y]=dfs(0,-1,x,y,0,0);
  }
  rep(i,q){
    int x,y;
    cin>>x>>y;
    bool used[2][2],pat[2][2];
    memset(used,0,sizeof(used));
    memset(pat,0,sizeof(pat));
    int nx=0,ny=0;
    for(int k=20;k>=0;k--){
      if((((x>>k)&1)|((y>>k)&1))&&!used[(x>>k)&1][(y>>k)&1]){
        used[(x>>k)&1][(y>>k)&1]=true;
        nx<<=1; ny<<=1;
        nx|=(x>>k)&1;
        ny|=(y>>k)&1;
      }
    }
    int res=0;
    for(int k=20;k>=0;k--){
      res<<=1;
      if(((x>>k)&1)|((y>>k)&1)){
        rep(nk,3){
          if(((nx>>nk)&1)==((x>>k)&1)&&((ny>>nk)&1)==((y>>k)&1)){
            res|=(mat[nx][ny]>>nk)&1;
          }
        }
      }
    }
    cout<<res<<endl;
  }
  return 0;
}



Measured memory_bytes: 37548
def make_divisors(n):
   divisors = []
   for i in range(1, int(n**0.5)+1):
       if n % i == 0:
           divisors.append(i)
           if i != n // i:
               divisors.append(n//i)
   return divisors

n = int(input())
divisors = make_divisors(n)
steps = min(d + (n // d) for d in divisors)
print(steps - 2)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int n, k, len = 1;
    vector<P> v;
    string s;
    cin >> n >> k >> s;
    s.push_back('2');
    REP(i,s.size()-1){
        if(s[i]!=s[i+1]){
            v.push_back({len,s[i]-'0'});
            len = 1;
        }
        else{
            len++;
        }
    }
    v.push_back({0,0});
    int l=0,r=0,cnt=0,ans=0;
    len = 0;
    while(r<v.size()){
        if(cnt<=k){
            len += v[r].first;
            if(v[r].second==0)cnt++;
            r++;
        }
        if(cnt>k){
            len -= v[l].first;
            if(v[l].second==0)cnt--;
            l++;
        }
        if(cnt<=k){
            ans = max(ans,len);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2548
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

#define rep(i,n) for (int i = 0; i < (n); ++i)

ll dp[100005][2];

int main()
{
  string l;
  cin >> l;
  dp[0][0] = 1;
  rep(i,l.size()) {
    if (l[i] - '0' == 0) {
      /* 上の桁で以下が確定しているとき */
      (dp[i+1][1] += (dp[i][1] * 3) % MOD) %= MOD;
      /* まだ一致しているとき */
      /* (0,0) ならまだ一致 */
      (dp[i+1][0] += dp[i][0]) %= MOD;
      /* (1,0) (0,1) は一致しない */
    } else {
      /* 上の桁で以下が確定しているとき */
      (dp[i+1][1] += (dp[i][1] * 3) % MOD) %= MOD;
      /* まだ一致しているとき */
      /* (0,0) なら以下が確定 */
      (dp[i+1][1] += dp[i][0]) %= MOD;
      /* (1,0) (0,1) はまだ一致 */
      (dp[i+1][0] += (dp[i][0] * 2) % MOD) %= MOD;
    }
  }
  cout << (dp[l.size()][0] + dp[l.size()][1]) % MOD << endl;
}


Measured memory_bytes: 2048
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

const ll max_n=20,max_a=20;
ll x[max_n][max_a],y[max_n][max_a];
ll n;
ll a[max_n];

void solve(){
    ll MAX=0;
    for(int i=0;i<(1<<n);i++){
        bool ok=true;
        ll cnt=0;
        for(int j=0;j<n;j++){
            if(i>>j&1) cnt++;
            for(int k=0;k<a[j];k++){
                if(i>>j&1){
                    if(y[j][k]==1){
                        if(i>>x[j][k]&1) continue;
                        else ok=false;
                    }else{
                        if(i>>x[j][k]&1) ok=false;
                    }
                }
            }
            if(!ok) break;
        }
        if(ok){
            if(MAX<cnt) MAX=cnt;
        }
    }
    cout<<MAX<<endl;
}

int main(){
    cin>>n;
    rep(i,n){
        cin>>a[i];
        rep(j,a[i]){
            cin>>x[i][j]>>y[i][j];
            x[i][j]--;
        }
    }
    solve();
}

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

int main()
{
   int k;
   string str;
   cin>>k>>str;
   
   int len = str.length();
   
   if(len <= k){
       cout<<str;
   }
   else{

        cout<<str.substr(0,k)<<"..."; 
   }
}


Measured memory_bytes: 3624
using System;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        string[] input = ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        string ans = "Yes";
        if( a*b%2==0) { ans = "No"; }

        WriteLine(ans);
        
      }
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int A,B,C;
    cin >> A >> B >> C;

    set<int> ans;
    ans.insert(A);
    ans.insert(B);
    ans.insert(C);
    if( ans.size() == 2 ) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
string s[200005];
map<string,int> m;
int main(){
        int n;
        while(~getI(n)){
                m.clear();
                F(i,0,n) cin>>s[i];
                F(i,0,n) m[s[i]]++;
                int most=0;
                for(auto i:m) most=max(most,i.s);
                for(auto i:m) if(i.s==most) cout<<i.f<<"\n";
                //debug(most);
        }
}

Measured memory_bytes: 26752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

const ll INF = ll(1e18)+1;

int main(){
  int n; ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  ll l = -INF, r = INF;
  while (l+1 < r) {
    ll x = (l+r)/2;
    bool ok = [&]{
      ll tot = 0;
      rep(i, n){
        if (a[i] < 0){
          int l = -1, r = n;
          while (l+1<r) {
            int c = (l+r)/2;
            if (a[i]*a[c] < x) r = c; else l = c;
          }
          tot  += n - r;
        } else {
          int l = -1, r = n;
          while (l+1<r){
            int c = (l+r)/2;
            if (a[i]*a[c] < x) l = c; else r = c;
          }
          tot += r;
        }
        if (a[i]*a[i] < x) tot--;
      }
      tot /= 2;
      return tot < k;
    }();
    if (ok) l = x; else r = x;
  }
  cout << l << endl;
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n,sum=0;
	cin>>n;
	std::vector<ll> a(n);
	std::vector<ll> v;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 1; i < n-1; ++i)
	{
		v.clear();
		v.push_back(a[i-1]);
		v.push_back(a[i]);
		v.push_back(a[i+1]);
		sort(v.begin(),v.end());
		if(v[1]==a[i])
			sum++;
	}
	cout<<sum<<"\n";
}


Measured memory_bytes: 256
import copy
N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))

x=max(A)
count=(A.count(x))
index=[]
if count!=1:
    for i in range(N):
        print(x)
else:
    B=copy.copy(A)
    B.remove(x)
    y=max(B)
    for i in range(N):
        if A[i]==x:
            print(y)
        else:
            print(x)

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

class DSU {
	private:
		int *data;
	public:
		DSU(int n) {
			data = new int[n];
			for(int i = 0; i < n; i++) {
				data[i] = -1;
			}
		}

		~DSU() {delete[] data;}

		// path compression without recursion
		int find(int i) {
			int parent;
			int back_to = -1;
			for(; (parent = data[i]) >= 0; i = parent) {
				data[i] = back_to;
				back_to = i;
			}
			int root = i;
			while(back_to != -1) {
				i = back_to;
				back_to = data[i];
				data[i] = root;
			}
			return root;
		}

		// union by size
		// returns 0 if union not performed
		// note that 'union' is reserved word
		int merge(int i, int j) {
			int ri = find(i), rj = find(j);
			if (ri == rj)
				return 0;
			if (data[ri] > data[rj]) {
				int t = ri;
				ri = rj;
				rj = t;
			}
			data[ri] += data[rj];
			data[rj] = ri;
			return 1;
		}

		int get_size(int i) {
			return -data[find(i)];
		}
};

int main() {
	int n, m;
	cin >> n >> m;
	DSU d(n);
	rep(i, m) {
		int x, y, z;
		cin >> x >> y >> z;
		x--; y--;
		d.merge(x, y);
	}
	vector<int> id(n);
	rep(i, n) id[i] = d.find(i);
	sort(id.begin(), id.end());
	id.erase(unique(id.begin(), id.end()), id.end());
	cout << id.size() << endl;
	
}


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

#define MAX 40


int N, K;
long long L, R;
long long a[MAX];



int main()
{
	cin >> N >> K >> L >> R;
	for( int i = 0; i < N; i++ ) {
		cin >> a[i];
	}

	vector< long long > v[K+1];
	int n1 = N / 2;
	int n2 = N - n1;
	for( int i = 0; i < (1 << n1); i++ ) {
		long long sum = 0;
		int cnt = 0;
		for( int j = 0; j < n1; j++ ) {
			if( i & (1 << j) ) {
				cnt++;
				sum += a[j];
			}
		}
		if( cnt > K ) {
			continue;
		}
		v[cnt].push_back( sum );
	}
	for( int i = 0; i < K + 1; i++ ) {
		sort( v[i].begin(), v[i].end() );
	}
	long long ans = 0;
	for( int i = 0; i < (1 << n2); i++ ) {
		long long sum = 0;
		int cnt = 0;
		for( int j = 0, k = n1; j < n2; j++, k++ ) {
			if( i & (1 << j) ) {
				cnt++;
				sum += a[k];
			}
		}
		if( cnt > K ) {
			continue;
		}
		vector<long long>::iterator r = upper_bound( v[K - cnt].begin(), v[K - cnt].end(), R - sum );
		vector<long long>::iterator l = lower_bound( v[K - cnt].begin(), v[K - cnt].end(), L - sum );
		ans += r - l;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 12352
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define pr pair<int,int> 
using namespace std;
int n;
const int N = 400005;
int a[N], cnt[N];
vector<int> v;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    up(i,1,n) {
    	cin >> a[i];
    	v.push_back(i+a[i]);
    	v.push_back(i-a[i]);
    }
    sort(v.begin(), v.end());
	for(int i=1;i<=n;++i){
		int pos = lower_bound(v.begin(), v.end(),i+a[i]) - v.begin();
		cnt[pos]++;
	}    
	long long ans = 0;
	for(int i=1;i<=n;++i){
		int pos = lower_bound(v.begin(), v.end(),i-a[i]) - v.begin();
		ans += cnt[pos];
	}
	cout << ans << '\n';
}

Measured memory_bytes: 7056
from collections import*;M=lambda:map(int,input().split());n,k,l=M();d=[-1]*n;t=[-1]*n;r=range(n)
def f(l,x):
  if l[x]<0:return x
  else:l[x]=f(l,l[x]);return l[x]
def u(l,x,y):
  if f(l,x)!=f(l,y):l[f(l,y)]=f(l,x)
for _ in[0]*k:a,b=M();u(d,a-1,b-1)
for _ in[0]*l:a,b=M();u(t,a-1,b-1)
p=[(f(d,i),f(t,i))for i in r];c=Counter(p);print(*[c[p[i]]for i in r])

Measured memory_bytes: 44316
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(int argc, const char * argv[]) {
    int a, b;
    
    cin >> a >> b;
    
    cout << a*b << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m;cin>>m;
  int n=m;
  int a[3];
  a[0]=n%10;
  n-=a[0];
  n/=10;
  a[1]=n%10;
  n-=a[1];
  n/=10;
  a[2]=n;
  if(m>a[2]*111) cout<<(a[2]+1)*111<<endl;
  else cout<<a[2]*111<<endl;
}

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

int main(){
	// sengen
	long long n;
	// nyuryoku
	cin >> n;
	// keisan
	long long sum = 0;
	for(int i=1;i < n+1;i++){
		if(i%3 != 0 && i%5 != 0){
			sum += i;
		}
	}
  cout << sum;
}


Measured memory_bytes: 3620
import sys
from collections import deque

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

def bfs(start,end):
    tansaku = deque()
    tansaku.append(start)
    visited = {i:set() for i in range(h)}
    kyori = [[0]*w for _ in range(h)]
    while tansaku:
        pre_y,pre_x = tansaku.popleft()
        if pre_x in visited[pre_y]:
            continue
        for i in range(pre_x-1,pre_x+2,2):
            if 0 <= i <= w-1 and tizu[pre_y][i] == '.':
                tansaku.append([pre_y,i])
                kyori[pre_y][i] = kyori[pre_y][pre_x] + 1
        for j in range(pre_y-1,pre_y+2,2):
            if 0 <= j <= h-1 and tizu[j][pre_x] == '.':
                tansaku.append([j,pre_x])
                kyori[j][pre_x] = kyori[pre_y][pre_x] + 1
        visited[pre_y].add(pre_x)
        if [pre_y,pre_x] == end:
            return kyori[pre_y][pre_x]
    return -1



h,w = nm()
white = 0
tizu = []
for i in range(h):
    temp = list(input())
    white += temp.count('.')
    tizu.append(temp)
res = bfs([0,0],[h-1,w-1])
if res == -1:
    print(res)
else:
    print(white-(res+1))

Measured memory_bytes: 3436
import java.util.*;

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

    int min=Math.min(n*a,b);

    System.out.println(min);
  }
}


Measured memory_bytes: 21712
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#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 A, B;
  cin >> A >> B;
  int ans = 0;
  if (A > B) {
    ans += A;
    --A;
  }
  else {
    ans += B;
    --B;
  }
  if (A > B) {
    ans += A;
    --A;
  }
  else {
    ans += B;
    --B;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

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

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

	vector<int> a(n);
	for (auto& v : a) {
		cin >> v;
	}

	int ans = 0;
	int hp = n;
	while (hp > 0) {
		hp -= k;
		if (hp > 0) {
			hp++;
		}

		ans++;
	}

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


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

vector<string> split(const string &str,char sep){
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while(getline(ss,buffer,sep)){
    v.push_back(buffer);
  }
  return v;
}

bool comp(const pair<int,string>& p1,const pair<int,string>& p2){
  if(p1.first == p2.first){
    return p1.second < p2.second;
  }
  return p1.first > p2.first;
}

int main(){

  while(1){

    int n;

    cin >> n;

    if(n==0){
      break;
    }

    map<char,map<string,int> > mp;

    string s;

    cin.ignore();

    while(n--){
      getline(cin,s);
      vector<string> v = split(s,' ');
      for(int i=0;i<v.size();i++){
        if(mp[v[i][0]].find(v[i]) == mp[v[i][0]].end()){
          mp[v[i][0]][v[i]] = 0;
        }
        mp[v[i][0]][v[i]]++;
      }
    }

    char c;

    cin >> c;

    int count = min(5,static_cast<int>(mp[c].size()) );

    if(count == 0){
      cout << "NA" << endl;
    }
    else{
      vector<pair<int,string> > vec;
      for(map<string,int>::iterator itr=mp[c].begin();itr!=mp[c].end();itr++){
        pair<int,string> p;
        p.first = itr->second;
        p.second = itr->first;
        vec.push_back(p);
      }
      sort(vec.begin(),vec.end(),comp);
      cout << vec[0].second;
      for(int i=1;i<count;i++){
        cout << " " << vec[i].second;
      }
      cout << endl;
    }

  }

  return 0;

}

Measured memory_bytes: 3104
N, M = map(int, input().split())
S = [0 for i in range(M)]
C = [0 for i in range(M)]
for i in range(M):
    S[i], C[i] = list(map(int, input().split()))

if N == 1:
    flg = False
    ans = 0
    for c in C:
        if flg == False:
            if ans != c:
                flg = True
                ans = c
        else:
            if ans != c:
                print(-1)
                break
    else:
        print(ans)
else:
    flg = [False for i in range(N)]
    ans = [1]
    for i in range(N - 1):
        ans.append(0)

    for s, c in zip(S, C):
        if s - 1 == 0 and c == 0:
            print(-1)
            break
        elif flg[s - 1] == False:
            if ans[s - 1] != c:
                flg[s - 1] = True
                ans[s - 1] = c
        else:
            if ans[s - 1] != c:
                print(-1)
                break
    else:
        print(''.join([str(a) for a in ans]))

Measured memory_bytes: 3064