akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
using ll = long long;
using namespace std;

int main(){
    string s;
    cin >> s;
    int cnt = 0;
    FOR(i, 1, s.length()){
        if(s[i - 1] != s[i]){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;
const ll MOD = 1e9 + 7;

class unionfind {
   public:
    vector<int> a;
    vector<int> h;

    unionfind(int n) : a(n, -1), h(n) {}

    void unite(int v, int u) {
        const int rt_v = find(v);
        const int rt_u = find(u);
        if (rt_v == rt_u) {
            return;
        }

        if (h[rt_v] > h[rt_u]) {
            a[rt_v] = rt_u;
        } else if (h[rt_v] < h[rt_u]) {
            a[rt_u] = rt_v;
        } else {
            a[rt_u] = rt_v;
            h[rt_v]++;
        }
    }

    int find(int v) {
        if (a[v] == -1) {
            return v;
        }
        return a[v] = find(a[v]);
    }

    bool same(int v, int u) { return find(v) == find(u); }
};

class vertex {
   public:
    int id;
    int c0;
    int c1;

    vertex() {}
    vertex(int id, int c0, int c1) : id(id), c0(c0), c1(c1) {}

    bool operator<(const vertex& v) const {
        if (c0 == v.c0) {
            return c1 < v.c1;
        }
        return c0 < v.c0;
    }
};

int main() {
    int n, k, l;
    cin >> n >> k >> l;

    unionfind uf0(n);
    for (int i = 0; i < k; i++) {
        int p, q;
        cin >> p >> q;
        uf0.unite(p - 1, q - 1);
    }

    unionfind uf1(n);
    for (int i = 0; i < l; i++) {
        int r, s;
        cin >> r >> s;
        uf1.unite(r - 1, s - 1);
    }

    vector<vertex> vs(n);
    for (int i = 0; i < n; i++) {
        vs[i] = vertex(i, uf0.find(i), uf1.find(i));
    }

    sort(vs.begin(), vs.end());

    vector<int> ans(n);
    int cnt;
    for (int i = 0; i < n; i += cnt) {
        const int c0 = vs[i].c0;
        const int c1 = vs[i].c1;
        cnt = 0;
        for (int j = i; j < n && c0 == vs[j].c0 && c1 == vs[j].c1; j++) {
            cnt++;
        }

        for (int j = i; j < i + cnt; j++) {
            ans[vs[j].id] = cnt;
        }
    }

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

    return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

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

    int m = min(n, k);
    int ans = 0;
    priority_queue<int, vector<int>, greater<int> > que;

    for (int i=1; i<=m; i++) { //aとbの操作を計何回するか
        rep(j, i+1) { //aを行う回数
            int tmp = 0;
            rep(a, j) {
                tmp += v[a];
                que.push(v[a]);
            }
            rep(b, i-j) {
                tmp += v[n-1-b];
                que.push(v[n-1-b]);
            }

            int cnt = k-i;
            while (cnt > 0 && !que.empty()) {
                int del = que.top(); que.pop();
                if (del >= 0) break;
                tmp -= del;
                cnt--;
            }

            while (!que.empty()) {
                que.pop();
            }
        
            ans = max(ans, tmp);
        }
        
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int m=1e9+7;
map<int,int>a;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<='0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
inline int sum(int x)
{
	if(a[x]!=0)
	   return a[x];
	else 
	   return a[x]=(sum(x/2)+sum((x-1)/2)+sum((x-2)/2))%m;
}
signed main()
{
	a[0]=1;
	a[1]=2;
	int n;
	n=read();
	int s=sum(n);
	cout<<s;
	return 0;
}

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

int main(){
    int t[4][3][10]={0};/*t[棟番号][階層][部屋番号]*/
    int n,b,f,r,v;/*b棟f階のr番目の部屋にv人が追加*/
    cin>>n;
    
    while(n>0){
        cin>>b>>f>>r>>v;
        if(!(t[b-1][f-1][r-1]<0 || t[b-1][f-1][r-1]>9)) t[b-1][f-1][r-1]+=v;
        n--;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                  cout<<" "<<t[i][j][k]<<flush;
            }
            cout<<endl;
        }
        if(i!=3) cout<<"####################"<<endl;
    }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#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(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    cout << a / gcd(a,b) * b << endl;


    
    
}




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

using namespace std;

int dig(int x) {
    int val = 0;
    while (x) {
        val += x % 10;
        x /= 10;
    }
    return val;
}

int main() {
    int n;
    cin >> n;
    int ans = 0x3f3f3f3f;
    for (int i = 1; i < n; i++) {
        ans = min(ans, dig(i) + dig(n - i));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
#define ll long long
ll i;
string s,t;
int main()
{
	cin>>s>>t;
	for (i=0;i<s.size();++i) 
	if (s[i]!=t[i])
	{
		printf("No");
		return 0;
	}
	printf("Yes");
}

Measured memory_bytes: 3768
#include<cstdio>
int n;
int f[100][14];
int p[100][15];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)for (int j = 0; j < 10; j++)scanf("%d", &f[i][j]);
	for (int i = 0; i < n; i++)for (int j = 0; j < 11; j++) scanf("%d", &p[i][j]);
	int res = -(1 << 30);
	for (int b = 1; b < (1 << 10); b++) {
		int cc = 0;
		for (int i = 0; i < n; i++) {
			int c = 0;
			for (int j = 0; j < 10; j++)if ((b >> j & 1) && f[i][j])c++;
			cc += p[i][c];
		}
		if (res < cc)res = cc;
	}
	printf("%d\n", res);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(v) for (auto itr = v.begin(), itr != v.end(); ++itr)
#define LB(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define UB(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    string N;
    cin >> N;
    bool ok = false;
    REP(i, 3) if (N[i] == '7') ok = true;
    if (ok)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 3652
a, b, c = map(int, input().split())
k = int(input())

if max(a, b, c ) == a:
    print(a * 2**k + b + c)
elif max(a, b, c) == b:
    print(a + b * 2**k + c)
elif max(a, b, c) == c:
    print(a + b + c * 2**k)


Measured memory_bytes: 2940
use std::cmp::min;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let mut hs = vec![0i16; 5];
    hs[0] = read(&mut stdin_lock, &mut buf, b'\n');
    hs[1] = read(&mut stdin_lock, &mut buf, b'\n');
    hs[2] = read(&mut stdin_lock, &mut buf, b'\n');
    hs[3] = read(&mut stdin_lock, &mut buf, b'\n');
    hs[4] = read(&mut stdin_lock, &mut buf, b'\n');
    let mut ans = 130 * 5;
    for i in 0..5 {
        let mut a = 0;
        a += hs[i];
        for j in 0..i {
            a += hs[j] / 10 * 10 + if hs[j] % 10 == 0 { 0 } else { 10 };
        }
        for j in (i + 1)..5 {
            a += hs[j] / 10 * 10 + if hs[j] % 10 == 0 { 0 } else { 10 };
        }
        ans = min(ans, a);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
N = int(input())
def calc(N):
    for h in range(1, 3500):
        for n in range(1, 3500):
            if 4 * h * n - N * n - N * h > 0 and (N * h * n) % (4 * h * n - N * n - N * h) == 0:
                w = (N * h * n) / (4 * h * n - N * n - N * h)
                return h, n, int(w)
print('{0[0]} {0[1]} {0[2]}'.format(calc(N)))

Measured memory_bytes: 3064
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    String S[] = new String[H];
    for(int i=1;i<=W+2;i++){
      System.out.print("#");
    }
    System.out.println("");
    for(int i=1;i<=H;i++){
      System.out.print("#");
      System.out.print(sc.next());
      System.out.println("#");
    }
    for(int i=1;i<=W+2;i++){
      System.out.print("#");
    }
    
  }
  

  
}

Measured memory_bytes: 21844
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	Q = int(input())
	D = defaultdict(int)
	S = sum(A)
	for i in range(N):
		D[A[i]] += 1
	for i in range(Q):
		B, C = getlist()
		S += (C - B) * D[B]
		D[C] += D[B]
		D[B] = 0
		print(S)


if __name__ == '__main__':
	main()

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

int main(){

  int a,b,c;

  cin >> a >> b >> c;

  if((a == 1 && b == 1 && c == 0) || (a == 0 && b == 0 && c == 1)) cout << "Open";
  else cout << "Close";

  cout << endl;

}

Measured memory_bytes: 1156
import java.util.Scanner;

/**
 * @author subaru
 */
public class Main {
    // Coloring Colorfully
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        int count0first = 0;
        int count1first = 0;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == '1' && i % 2 == 0) {
                count0first++;
            } else if (S.charAt(i) == '0' && i % 2 == 1) {
                count0first++;
            }
            if (S.charAt(i) == '0' && i % 2 == 0) {
                count1first++;
            } else if (S.charAt(i) == '1' && i % 2 == 1) {
                count1first++;
            }

        }
        System.out.println(Math.min(count0first, count1first));
    }
}


Measured memory_bytes: 28536
#include <stdio.h>

int main(){
	int a[4], b[4], i, j;
	while(~scanf("%d %d %d %d\n%d %d %d %d\n", &a[0], &a[1], &a[2], &a[3], &b[0], &b[1], &b[2], &b[3])){
		int hit = 0, blow = 0;
		for(i = 0; i < 4; i++){
            for(j = 0; j < 4; j++){
                if(a[i] == b[j])
                    if(i == j){
                        hit++;
                    }else{
                        blow++;
                    }
            }
        }
		printf("%d %d\n", hit, blow);
	}
	return 0;
}

Measured memory_bytes: 600
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);

		//今回のIdxは1から始まる
		int idx = scanner.nextInt();
		scanner.close();

		Deque<Long> lunlunQue = new ArrayDeque<>();

		for(Long i=(long) 1; i < 10; i++) {
			lunlunQue.add(i);
		}

		Long num = (long) 0;

		for(int i=0; i < idx; i++) {
			num = lunlunQue.poll();
//			System.out.println(num);
			if(num%10 != 0) {
				lunlunQue.add(num*10+num%10-1);
			}
			lunlunQue.add(num*10+num%10);
			if(num%10!=9) {
			lunlunQue.add(num*10+num%10+1);
			}
		}

		System.out.println(num);

	}

}


Measured memory_bytes: 31316
//Kannondou
#include <cstdio>
#include <vector>
using namespace std;
int main(){
	int n;
	vector<long long int> step;	step.push_back(1);
	refrain:
	scanf("%d",&n);
	if(n==0)	return 0;
	for(int i=step.size();i<=n;i++){
		step.push_back(0);
		for(int j=1;j<=i&&j<=3;j++)	step[i]+=step[i-j];
	}
	long long int ans=(step[n]+9)/10;
	ans=(ans+364)/365;
	printf("%lld\n",ans);
	goto refrain;
}

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

#define int int64_t

using namespace std;

#define MAX 105
#define MAX_K 100005

int n, k, a[MAX], dp[MAX_K];

int f(int r)
{
    // printf("%lld %lld\n", i, r);
    if (dp[r] != -1)
        return dp[r];
    for (int j = 0; j < n; j++)
        if (r - a[j] == 0)
            return dp[r] = 0;
        else if (r - a[j] > 0)
            if (f(r - a[j]) == 1)
                return dp[r] = 0;
    return dp[r] = 1;
}

signed main()
{
    scanf("%lld %lld", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%lld", a + i);
    for (int j = 0; j <= k; j++)
        dp[j] = -1;
    // for (int i = 0; i < n; i++)
    //     a[i] *= -1;
    // sort(a, a + n);
    // for (int i = 0; i < n; i++)
    //     a[i] *= -1;
    printf("%s\n", !f(k) ? "First" : "Second");
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << endl; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;

V c;
ll s = 0;
Vll ans, dp;

using Graph = vector<vector<int>>;
Graph G;

void dfs(int u, int p=-1) {
  ll tmp = dp[c[u]] + s;
  for (auto v : G[u]) {
    if (v == p) continue;
    ll tmp2 = dp[c[u]] + s;
    dfs(v, u);
    ll x = dp[c[u]] + s - tmp2;
    ans[c[u]] -= x*(x+1)/2;
  }
  ++s;
  dp[c[u]] = tmp - s;
}

int main() {
  ll n; cin >> n;

  c.assign(n, 0);
  dp.assign(n, 0);
  ans.assign(n, n*(n+1)/2);

  rep(i, n) {
    cin >> c[i];
    --c[i];
  }

  G.assign(n, V());
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(0);
  rep(i, n) {
    ll x = dp[i] + s;
    ans[i] -= x*(x+1)/2;
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 33744
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <numeric>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mod = 1000000007;

#define bs(n) (1ll<<(ll)(n))
#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define rrep(i, n) for(ll (i) = 1;(i) <= (n);(i)++)

int n, a[200001];
int dist[200001], dist2[200001];

pair<int, int> dfs(int cur) {
    if (dist[a[cur]] == 0) {
        dist[a[cur]] = dist[cur] + 1;
        return dfs(a[cur]);
    } else {
        return make_pair(a[cur], dist[cur] - dist[a[cur]] + 1);
    }
}

int main() {
    ull k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    dist[1] = 1;
    auto t = dfs(1);
    int cur = 1;
    if(dist[t.first] - 1 <= k) {
        k -= dist[t.first] - 1;
        cur = t.first;
        k %= t.second;
    }
    for(int i = 0;i < k;i++) {
        cur = a[cur];
    }
    cout << cur << endl;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  bool ans  = false;

  sort(a.begin(),a.end());
  rep(i,n-1){
    if(a[i] == a[i+1]) ans = true;
  }

  if(ans) cout << "NO";
  else cout << "YES";

}


Measured memory_bytes: 3976
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int N=2010;
int n,a[N],go[N][N],deg[N];
int gcd(int x,int y){return y?gcd(y,x%y):x;}
bool used[N];
int vis[N],C,root;
vector<int> ans,q[N];
void merge(vector<int> &a,vector<int> &b){
	static int q[N];
	int i=0,j=0,p=0;
	while (i<a.size()&&j<b.size()) q[p++]=(a[i]>b[j]?a[i++]:b[j++]);
	for (;i<a.size();q[p++]=a[i++]);
	for (;j<b.size();q[p++]=b[j++]);
	a.clear();
	for (int i=0;i<p;i++) a.push_back(q[i]);
}
void dfs(int x){
	used[x]=1;
	q[x].push_back(1e9);
	for (int i=1;i<=deg[x];i++){
		int v=go[x][i];
		if (used[v]) continue;
		dfs(v);
		merge(q[x],q[v]);
	}
	q[x][0]=a[x];
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++)
		if (gcd(a[i],a[j])!=1) go[i][++deg[i]]=j;
	for (int i=1;i<=n;i++)
		if (!used[i]) dfs(i),merge(ans,q[i]);
	for (int i=0;i<n;i++) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 26752
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            Console.Write(180 * (N -2));
        }

    }

    //var N = int.Parse(Console.ReadLine());
    //var S = Console.ReadLine();
    //var K = Console.ReadLine().Split(' ');
    //var N = int.Parse((K[0]));
    //var M = int.Parse((K[1]));
}


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

typedef long long ll;
ll arr[2000005], arr2[100000] ;
ll MOD = 1e9 + 7;

int main()
{
  ll n, first, last, dist = 1e15, val;
  cin>>n;

  for(ll i = 1; i <= sqrt(n); i++){
    if(n % i == 0){
      val = abs((n/i) - i);
      if(val < dist){
        first = i;
        last = n/i;
        dist = val;
      }
    }
  }
  cout<<((first - 1) + (last - 1))<<endl;
}



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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

int N, K;
bool okDigit[10] = {};

int main()
{
    cin >> N >> K;
    REP(i, 10) { okDigit[i] = true; }
    REP(i, K) {
        int k;
        cin >> k;
        okDigit[k] = false;
    }
    for(int i = N; i <= 100000; ++i) {
        // i に嫌いな数字が入っていないか
        ll num = i;
        bool isOk = true;
        while(num > 0) {
            if(!okDigit[num % 10]) {
                isOk = false;
                break;
            }
            num /= 10;
        }
        if(isOk) {
            printf("%d\n", i);
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

using namespace std;

struct U {
  int a[111111];
  U() { memset(a, -1, sizeof(a)); }
  int root(int p) { return a[p] < 0 ? p : (a[p] = root(a[p])); }
  bool find(int p, int q) { return root(p) == root(q); }
  bool merge(int p, int q) {
    if (find(p, q)) return false;
    a[root(p)] += a[root(q)];
    a[root(q)] = root(p);
    return true;
  }
  int sz(int p) { return -a[root(p)]; }
};

U u;
long long res[111111];
int a[111111], b[111111];

int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", a+i, b+i);
  }

  long long c = (long long)n * (n - 1) / 2;
  for (int i = m-1; i >= 0; i--) {
    res[i] = c;
    if (!u.find(a[i], b[i])) {
      c -= (long long)u.sz(a[i]) * u.sz(b[i]);
      u.merge(a[i], b[i]);
    }
  }
  for (int i = 0; i < m; i++) printf("%lld\n", res[i]);
  return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int m;cin>>m;
    string s;cin>>s;
    string tmp="I";
    rep(i,n)tmp+="OI";
    int co=0;
    rep(i,s.size()-2*n)if(s.substr(i,2*n+1)==tmp)co++;
    cout<<co<<endl;
  }
}

Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

signed main() {

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

    map<int, int> L;
    map<int, int> R;
    rep(i, n){
        int l = i - a[i];
        int r = i + a[i];
        L[l]++;
        R[r]++;
    }
    
    int ans = 0;
    for(auto m : L){
        ans += m.second * R[m.first];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 39048
taro_score = 0
hanako_socore = 0
game_times = int(input())
for _ in range(game_times):
    cards = input().split()
    if cards[0] > cards[1]:
        taro_score += 3
    elif cards[0] == cards[1]:
        taro_score += 1
        hanako_socore += 1
    else:
        hanako_socore += 3
print(taro_score, hanako_socore)



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

long long n, l = 0, r = 0, m = 1;
string s;
bool f = 0;

const long long T = 1000000007;

int main()
{	
	cin >> n >> s;

	for (long long i = 0; i < n * 2; i++) {
		if (((l - r) % 2 == 0 && s[i] == 'B') || ((l - r) % 2 == 1 && s[i] == 'W')) {
			l++;
			m = m * (l - r) % T;
		}
		else
			r++;

		if (r > l || l > n || r > n) {
			f = 1;
			break;
		}
	}

	if(f)
		cout << 0 << endl;
	else {
		for (long long i = 2; i <= n; i++)
			m = m * i % T;

		cout << m << endl;
	}

	return 0;
}

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


int main()
{
	int n;
	int t;
	int s;
	int tim[3001];
	int fun[3001];
	cin >> n >> t >> s;
	int nmax = n + 10;
	int tmax = t + 10;
	int ** dp1; int ** dp2;
	dp1 = new int*[nmax]; for (int i = 0; i < nmax; i++)dp1[i] = new int[tmax];
	
	dp2 = new int*[nmax]; for (int i = 0; i < nmax; i++)dp2[i] = new int[tmax];

	for (int i = 0; i < n; i++)cin >> fun[i] >> tim[i];
	for (int i = tim[0]; i <= s; i++)dp1[0][i] = fun[0];
	for (int i = tim[n - 1] + s; i <= t; i++)dp2[n - 1][i] = fun[n - 1];
	for (int k = 1; k < n; k++)
	{
		for (int i = 0; i <= s; i++)
		{
			if (i - tim[k] < 0){
				dp1[k][i] = dp1[max(k - 1, 0)][i];
				continue;
			}
			
			dp1[k][i] = max(dp1[max(k - 1, 0)][i], dp1[max(k - 1, 0)][i - tim[k]] + fun[k]);

		}
	}
	for (int k = n - 2; k >= 0;k--)
	{
		for (int i = s; i <= t; i++)
		{
			if (i - tim[k] < s){
				dp2[k][i] = dp2[min(k + 1, n - 1)][i];
				continue;
			}
			dp2[k][i] = max(dp2[min(k + 1, n - 1)][i],dp2[min(k+1,n-1)][max(i-tim[k],0)]+fun[k]);
		}
	}
	int ans = 0;
	int x = 0; int y = 0;
	for (int i = 0; i < n - 1; i++){
		x = 0; y = 0;
		for (int k = 0; k <= s; k++)x = max(x, dp1[i][k]);
		for (int k = s; k <= t; k++)y = max(y, dp2[i+1][k]);
		ans = max(ans, x + y);
	}
	cout << ans << endl;
	for (int i = 0; i < nmax; i++)
	{
		delete[] dp1[i];
		delete[] dp2[i];
	}
	delete[] dp1;
	delete[] dp2;

}

Measured memory_bytes: 60408
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    ll a;
    cin >> a;
    fin(a+a*a+a*a*a);
    return 0;
}

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

int main(){
    int n, l, i, j, a1, a2 = 0, flag = 0;
    cin >> n >> l;
    for(i=0; i<n; i++){
        cin >> a1;
        if(a1 + a2 >= l){
            flag = 1;
            break;
        }
        a2 = a1;
    }
    if(flag == 0){
        cout << "Impossible";
    }else{
        cout << "Possible" << '\n';
        for(j=1; j<i; j++){
            cout << j << '\n';
        }
        for(j=n-1; j>=i && j>0; j--){
            cout << j << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{string s;cin>>s;int flag=1;
for(int i=0;i<s.size();i++){
	if(s[i]==s[s.size()-i-1])  flag=1;
	else {flag=-1;break;
	}
}
if(flag==1){
	for(int i=0;i<(s.size()-1)/2;i++){
		if(s[i]==s[(s.size()-1)/2-i-1]) flag=1;
		else{flag=-1;break;
		}
	}}
	if(flag==1){
		for(int i=(s.size()+3)/2;i<s.size();i++){
		if(s[i]==s[s.size()-i-1])flag=1;
		else{flag=-1;break;
		}
	}
}
if(flag==-1)cout<<"No"<<"\n";
else cout<<"Yes"<<"\n";
}

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

using namespace std;

long long gcd(long long a, long long b)
{
	return (b == 0 ? a : gcd(b, a % b));
}

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

int main()
{
	int n;
	cin >> n;
	long long ans = 1;
	for (int i = 0; i < n; i++)
	{
		long long t;
		cin >> t;
		ans = lcm(ans, t);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#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>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;


int main(){
	int m;
	while(cin>>m,m){
		double a = 0;
		int sm = 0;
		FOR(i,m-1){ int x; cin>>x;  sm += x; a += sin(x/180.0*M_PI); }
		a += sin((360-sm)/180.0*M_PI);
		cin>>m;
		sm = 0;
		FOR(i,m-1){ int x; cin>>x;  sm += x; a -= sin(x/180.0*M_PI); }
		a -= sin((360-sm)/180.0*M_PI);
		if(abs(a) < 1e-8) puts("0");
		else puts(a > 0 ? "1" : "2");
	}

	return 0;
}

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

int main() {
	int N,M,num;
	priority_queue<int> que;
	ll sum = 0;
	cin >> N >> M;
	rep(i, N){
		cin >> num;
		que.push(num);
	}
	rep(i, M){
		int temp = que.top(); que.pop();
		que.push(temp/2);
	}
	rep(i, N){
		int temp = que.top(); que.pop();
		sum += temp;
	}
	cout << sum;
}

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

int main() {
    vector<long> numbs;
    long numb;
    cin >> numb;
    numbs.push_back(numb);
    int counter = 0;

    long i = 0;
    while(pow(2, i) <= numb) {
        i++;
    }

    cout << fixed << long(pow(2, i)-1) << endl;
}

Measured memory_bytes: 256
n, d = map(int, input().split())
x = list(list(map(int, input().split())) for _ in range(n))

cnt = 0
for i in range(n - 1):
  
  for j in range(i + 1, n):
    sq_dis = 0
    
    for k in range(d):
      sq_dis += (x[i][k] - x[j][k])**2
      
    dis = sq_dis ** 0.5

    if dis.is_integer() == True:
      cnt += 1
        
print(cnt)

Measured memory_bytes: 9340
n = int(input())
nums = list(map(int, input().split()))

def mid(threeints):
	a, b, c = threeints[0], threeints[1], threeints[2]
	
	if ((a < b) and (b < c)) or ((a > b) and (b > c)):
		return True
	else:
		return False
		
def solve():
	count = 0
	for i in range(n - 2):
		threeints = nums[i:i+3]
		count += mid(threeints)
	return count
	
print(solve())

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    int n ;
    cin >> n ;

    int c = 1 ;
    int ok = 0 ;

    for ( int i=0 ; i < n ; i ++ )
    {
        int temp ; cin >> temp ;

        if ( temp == c )
        {
            c ++ ;
            ok ++ ;
        }
    }

    if ( ok == 0 ) { cout << -1 ; line ; R ; }

    cout << n - ok ;
    line
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 384
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;

int f[maxn];
int pd(int x){
  if(x!=f[x])f[x] = pd(f[x]);
  return f[x];
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++)f[i] = i;
  int ret = n;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    int px = pd(x);
    int py = pd(y);
    if(px!=py){
      f[px] = py;
      ret--;
    }
  }
  cout<<ret-1<<endl;
  return 0;
}

Measured memory_bytes: 3968
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();
		for(int i=2;i<s.length();i+=2){
			int n = s.length() - i;
			String str1 = s.substring(0, n/2);
			String str2 = s.substring(n/2,n);
			if(str1.equals(str2)){
				System.out.println(n);
				return;
			}
		}
	}

}


Measured memory_bytes: 20948
import java.util.Scanner;

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

		int x = sc.nextInt();
		int y = sc.nextInt();

		for (int i = 0; i <= x; i++) {
			if (((i * 2) + (x - i) * 4) == y) {
				System.out.println("Yes");
				return;
			}
			sc.close();
		}
		System.out.println("No");

	}
}

Measured memory_bytes: 27092
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (A, B): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let ans = if A <= 9 && B <= 9 { A * B } else { -1 };

    println!("{}", ans);
}


Measured memory_bytes: 4352
import time



n,a,b = map(int,input().split())
start = time.time() # 時間計測開始

M = 10**9+7

# 2**n
twon = pow(2,n,M)

# nCr+1 = nCr * (n-r)/(r+1)
# nCr = A(r)とおくと ※nは固定
# A(r+1) = A(r) * (n-r)/(r+1)
# ここでmod M では、フェルマーの小定理より
# 1/(r+1) === (r+1)**(M-2) ※===は合同記号の意味
# よって　A(r+1) = A(r) * (n-r) * (r+1)**(M-2)
# L = [0] * (2*(10**5) + 1)
# L[0] = 1
# for i in range(len(L)-1):
#     L[i+1] = ( L[i] * (n-i) * pow(i+1,M-2,M) ) % M

def comb_mod(n,r,mod):
    x = 1
    y = 1
    for i in range(r):
        x = (x*(n-i)) % mod
        y = (y*(i+1)) % mod
    return (x * pow(y,mod-2,mod))



# nCa
# nCa = L[a]
nCa = comb_mod(n,a,M)
# nCb
# nCb = L[b]
nCb = comb_mod(n,b,M)

ans = twon - 1 - nCa - nCb

elapsed_time = time.time() - start # 時間計測終了
# print(elapsed_time)
print(ans % M)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
using namespace std;
int abs(int,int);
int main(){
int N,i,x;
scanf("%d",&N);
vector<int>a(N+2),c(N+2);
  c[0]=0;a[0]=0;a[N+1]=0;
for(i=1;i<=N;i++){
scanf("%d",&a[i]);
c[i]=c[i-1]+abs(a[i-1],a[i]);
}
  c[N+1]=c[N]+abs(0,a[N]);
for(i=1;i<=N;i++){
x=c[i-1]+c[N+1]-c[i+1]+abs(a[i-1],a[i+1]);
printf("%d\n",x);
}
return 0;
} 
int abs(int a,int b){
int c;
if(b-a>=0)c=b-a;
else c=a-b;
return c;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> hito(n);
    vector< pair<int,int> > a(n);
    for(int i = 0;i < n;i++)
    {
        cin >> hito.at(i);
        int x = hito.at(i) ;
        int y = i ;
         a[i] =  make_pair(x,y) ;
    }
    sort(a.begin(),a.end()) ;
    for(int i= 0; i < n ;i++)
    {
        cout << a.at(i).second + 1 << " " << endl;
    }

return 0;
}

Measured memory_bytes: 2048
n,m = map(int,raw_input().split())
arr = [1]*n
x = [False]*n
x[0] = True
counter = 0
for i in xrange(m) :
    a,b = map(int,raw_input().split())
    if x[a-1] :
        x[b-1] = True
    arr[a-1] -= 1
    arr[b-1] += 1
    if arr[a-1] == 0 :
        x[a-1] = False
for j in x :
    if j  :
        counter += 1
print counter


Measured memory_bytes: 4228
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
const int N=300000+10;
struct apple
{
	ll v;
	int col;
}p[N];
int x,y,a,b,c,cnt;
bool cmp(const apple& a,const apple& b)
{
	return a.v>b.v;
}
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>x>>y>>a>>b>>c;
    for(int i=1;i<=a;i++){
    	cin>>p[i].v;
    	p[i].col=1;
    }
    for(int i=a+1;i<=a+b;i++){
    	cin>>p[i].v;
    	p[i].col=2;
    }
    for(int i=a+b+1;i<=a+b+c;i++){
    	cin>>p[i].v;
    	p[i].col=3;
    }
    sort(p+1,p+1+a+b+c,cmp);
    ll ans=0,sum=0;
    for(int i=1;i<=a+b+c;i++){
    	if(x+y-cnt==0)break;
    	if(p[i].col==1&&x){
    		sum+=p[i].v;
    		x--;
    	}
    	if(p[i].col==2&&y){
    		sum+=p[i].v;
    		y--;
    	}
    	if(p[i].col==3){
    		sum+=p[i].v;
    		cnt++;
    	}
    }
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N;
    cin >> N;
    map<string, int> A;
    for (int i = 0; i < N; i++){
        string S;
        cin >> S;
        A[S]++;
    }
    int ma = 0;

    for (pair<string, int> p: A) {
        string key = p.first;
        int value = p.second;
        ma = max(ma, value);
    }
    for (pair<string, int> p : A) {
        string key = p.first;
        int value = p.second;
        if (value == ma){
            cout << key << endl;
        }
    }

}


Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll test;
    cin >> test;

    ll current_amt = 0;

    while(current_amt <test) {
        current_amt += 1000;
    }

    cout << current_amt - test << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 500005;

ll modexp(ll x, ll n)
{
    if(n==0)
        return 1LL;
    if(n%2==0)
    {
        ll y = modexp(x,n/2)%mod;
        return (y*y)%mod;
    }
    return (x*modexp(x,n-1)%mod)%mod;
}

ll powr(ll x, ll n)
{
    ll ans = 1;
    for(int i=1;i<=n;i++)
        ans=ans*x;
    return ans;
}

int a[MAX];
ll sz[MAX];

int root(int x)
{
    while(a[x]!=x)
    {
        a[x] = a[a[x]];
        x = a[x];
    }
    return x;
}

int join(int x, int y)
{
    int px = root(x);
    int py = root(y);
    if(px==py)
        return 0;
    ll ret = (sz[px]*sz[py]);
    if(sz[px]>sz[py])
    {
        a[py] = px;
        sz[px] += sz[py];
    }
    else
    {
        a[px] = py;
        sz[py] += sz[px];
    }
    return ret;
}

vector<pair<int,int> > v;
vector<ll> fans;


int main()
{
    for(int i=0;i<MAX;i++)
    {
        a[i] = i;
        sz[i] = 1;
    }
    ll n,m;
    sl(n),sl(m);
    for(int i=0;i<m;i++)
    {
        int x,y;
        si(x),si(y);
        v.pb(mp(x,y));
    }
    ll ans = n*(n-1)/2;
    reverse(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        fans.pb(ans);
        ans = ans - join(v[i].first,v[i].second);
    }
    for(int i=fans.size()-1;i>=0;i--)
    {
        pfl(fans[i]);
    }
    return 0;
}


Measured memory_bytes: 8820
N, M = map(int, input().split())

l = []
r = []

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

ans = N-max(l)-max(r)

if ans > 0:
	print(ans)
else:
	print(0)

Measured memory_bytes: 11020
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, sumA, sumB int
	fmt.Scan(&n)
	var a []int
	for i := 1; i <= n; i++ {
		var ai int
		fmt.Scan(&ai)
		a = append(a, ai)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	for j := 0; j <= n-1; j++ {
		if j%2 == 0 {
			sumA += a[j]
		} else {
			sumB += a[j]
		}
	}
	fmt.Println(sumA - sumB)
}

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

int main(void) {
    string s;
    getline(cin, s);
    for (int i = 0; i < s.size(); i++) {
        if (s[i] >= 'A' && s[i] <= 'Z') {
            s[i] += 'a' - 'A';
        }else if (s[i] >= 'a' && s[i] <= 'z') {
            s[i] -= 'a' - 'A';
        }
    }
    cout << s << endl;
}


Measured memory_bytes: 3224
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;cin>>n;
  int i,j,k;
  vector<int> v;
  for(i=0;i<n;i++){
    cin >> k;
    v.push_back(k);
  }
  for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
  for(i=1;i<n;i++){
    for(j=0;j<i;j++){
      if(v[j]>v[i]){
	k=v[i];
	v.erase(v.begin()+i);
	v.insert(v.begin()+j,k);
	break;
      }
    }
    for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
  }
  return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n-1);
    for(int i=0;i<n-1;i++){
        cin>>a[i];
    }
    vector<int> ans(n,0);
    for(int i=0;i<n-1;i++){
        ans[a[i]-1]++;
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 4788
#include<stdio.h>


int main() {
	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if (a > b) {
		int	temp = a;
		a = b;
		b = temp;
	}

	 if (b > c) {
		int temp = b;
		b = c;
		c = temp;
	}

	 if (a > b) {
		int temp = a;
		a = b;
		b = temp;
	}
	
	printf("%d %d %d\n", a, b, c);

	return 0;
}

Measured memory_bytes: 1796
def resolve():
    # 隣り合う要素の差を大きくするには、大きい数と小さい数が交互に現れればよい。
    # 数列をsortして両端から交互に要素を取り、並べていく
    # 並べ方のパターン 小大小大小大を例に
    # |a1 -a2| + |a2 - a3| + |a3-an-1| + |an-1 - an|
    # 式を見ると両端は1回、その他は2回計算される

    def f(arr):
        res = 0
        for i in range(N - 1):
            res += abs(arr[i + 1] - arr[i])
        return res

    N = int(input())
    A = sorted([int(input()) for _ in range(N)])

    # Nが偶数なら、大小…大小
    # Nが奇数なら、大小…大小大 or 小大…小大小の二択の良い方

    mid = N // 2
    ans = 0
    if N % 2 == 0:
        low, high = A[:mid], A[mid:]
        B = []
        for i in range(mid):
            B.append(high[i])
            B.append(low[i])
        ans = f(B)

    else:
        res1 = 0
        low, high = A[:mid], A[mid + 1:]
        B = []
        for i in range(mid):
            B.append(high[i])
            B.append(low[i])
        # 後方に追加
        B.append(A[mid])
        res1 = f(B)

        # 先頭に追加
        B = [A[mid]] + B[:-1]

        ans = max(res1, f(B))

    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 15872
fn main() {
    // loop{ //For test
        solve();
    // }
}

#[allow(dead_code)]
fn solve(){
    let mut tmp: Vec<i32> = read_vec();
    let mut H: i32 = tmp[0];
    let mut A: i32 = tmp[1];
    let mut cnt = 0;
    while H > 0 {
        cnt += 1;
        H = H - A;
    }
    println!("{}", cnt );
}

fn is_even(arr: &Vec<i32>) -> bool {
    return arr.iter().all(|x| x%2==0);
}

/// 標準入力から一行を読み取り、指定の型に変換する関数
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    let _ = std::io::stdin().read_line(&mut s);
    s.trim().parse().ok().unwrap()
}

/// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

/// 標準入力からn行を読み取り、各行を空白文字で分割し、各要素を指定の型に変換する関数
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

Measured memory_bytes: 4352
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    int c = h % a;
    int d = w % b;
    
    cout << h * d + w * c - c * d << endl;
    return 0;
}



Measured memory_bytes: 3072
#include <iostream>

int main(void)
{
    int n, f = 0;
    std::cin >> n;
    {
        int m = n;
        while (0 < m)
        {
            f += m % 10;
            m /= 10;
        }
    }
    bool flag = (n % f) == 0;
    std::cout << (flag ? "Yes" : "No") << std::endl;
    return 0;
}


Measured memory_bytes: 256