akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
long X,K,D;
main()
{
	cin>>X>>K>>D;
	if(X<0)X=-X;
	if(X/D>=K)
	{
		X-=K*D;
		cout<<X<<endl;
		return 0;
	}
	long t=X/D;
	K-=t;
	X-=t*D;
	if(K%2==0)cout<<X<<endl;
	else cout<<D-X<<endl;
}


Measured memory_bytes: 3632
//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#define MOD 1000000007
#define MAX 0x3f3f3f3f
#define MAX2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int n, m;
char in[10];

int main()
{
	int i, j, k, l;
	cin>>n>>m;
	for(i=0;i<n;i++) for(j=0;j<m;j++)
	{
		string x;
		cin>>x;
		if(x == "snuke") printf("%c%d", 'A'+j, i+1);
	}
	cout<<endl;
	return 0;
}
//*/

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i, h) cin >> s[i];

    ll dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
    auto func = [&](ll sx, ll sy, ll gx, ll gy) {
        if(s[sy][sx] == '#') return 0LL;
        if(s[gy][gx] == '#') return 0LL;

        vector<vector<ll>> dist(h, vector<ll>(w, INF));
        dist[sy][sx] = 0;
        queue<PII> que;
        que.push({sx, sy});
        while(que.size()) {
            PII p = que.front(); que.pop();
            REP(i, 4) {
                ll nx = p.first + dx[i], ny = p.second + dy[i];
                if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
                if(s[ny][nx] == '#') continue;
                if(dist[ny][nx] == INF) {
                    dist[ny][nx] = dist[p.second][p.first] + 1;
                    que.push({nx, ny});
                }
            }
        }
        // REP(i, h) dump(dist[i]);
        return dist[gy][gx];
    };

    ll ret = 0;
    REP(i, h) REP(j, w) REP(k, h) REP(l, w) {
        ll tmp = func(j, i, l, k);
        // dump(i, j, k, l, tmp);
        chmax(ret, tmp);
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include <utility>
#include <algorithm>
#include <iostream>

using namespace std;
int T;
long long int N;
int K;
int A[1000000+10];
int B[1000000+10];
int maxl = 0;


int main() {
  cin >> T;
  for (int i=0;i<T;++i){
    cin >> N;
    cin >> K;
    for (int j=0;j<N;++j)cin >> A[j];
    if(N == 1)B[0] = 0;//output???????????????
    maxl = 0;
    for (int j=0;j+1<N;++j){
      B[j] = A[j+1] - A[j];
    }
    sort(B,B+N-1);
    for(int j=0;j<N-K;++j){
      maxl += B[j];
    }
    cout << maxl << endl;


  }
}
  
  

Measured memory_bytes: 3900
import java.util.*;

public class Main {

	private void doit(){
		Scanner sc = new Scanner(System.in);
		long mod = 1000000007;
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int l = sc.nextInt();
			
			System.out.println((n + m) * l / 2);
			
			
		}

	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 9936
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
typedef long long ll;
using namespace std;

int main(){
  vector<ll> jijo(1001);
  rep(i,1001) jijo[i]=i*i;
  int N,D;
  cin >> N >> D;
  int xy[10][10];
  rep(i,10)rep(j,10) xy[j][i]=0;
  rep(y,N)rep(x,D) cin >> xy[y][x];
  int ans = 0;
  rep(i,N){
    for(int j=i+1;j<N;j++){
      int d=0;
      rep(k,D){
        d += (xy[i][k]-xy[j][k])*(xy[i][k]-xy[j][k]);
      }
      //cout << d << endl;
      rep(k,1001){
        if(d==jijo[k]){ans++;break;}
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {

	void solve() {
		
		int h = inint(), w = inint();

		char[][] map = new char[h][w];
		for (int i=0; i<h; i++) {
			String temp = instr();
			for (int j=0; j<w; j++) {
				map[i][j] = temp.charAt(j);
			}
		}
		
		
		int maxNum = 0;
		
		for (int i=0; i<h; i++) {
			for (int j=0; j<w; j++) {
				if (map[i][j] == '.') { //幅優先探索開始
					
					int[][] memo = new int[h][w];
					Point s = new Point(j, i);
					
					memo[i][j] = 1;
					
					ArrayDeque<Point> dq = new ArrayDeque<>();
					dq.add(s);
					
					int num = 0;
					
					while (dq.size() > 0) {
						Point p = dq.removeFirst();
						for (int k=0; k<4; k++) {
							int x = p.x + dx[k];
							int y = p.y + dy[k];
							if (x >= 0 && x < w && y >= 0 && y < h) {
								if (map[y][x] == '.' && memo[y][x] == 0) {
									dq.addLast(new Point(x, y));
									memo[y][x] = memo[p.y][p.x] + 1;
									num = memo[p.y][p.x] + 1;
								}
							}
						}
					}
					
					maxNum = Math.max(maxNum, num);
					
					//out.println(num);
					//print(memo);
					
				}
			}
		}
		
		out.println(maxNum - 1);
		
	}
	
	public void print(int[][] a) {
		for (int i=0; i<a.length; i++) {
			for (int j=0; j<a[0].length; j++) {
				out.print(a[i][j]);
			}
			out.println();
			out.println();
		}
	}
	
	int[] dx = {0, 1, 0, -1};
	int[] dy = {-1, 0, 1, 0};
	
	public double calc(int[] a, int b) {
		double d = 0;
		for (int i=0; i<a.length; i++) d += a[i];
		d += b;
		return d / (double)(a.length + 1);
	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}

	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

class Point {
	public Point(int x, int y) {
		this.x = x;
		this.y = y;
	}
	int x;
	int y;
}

Measured memory_bytes: 24788
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s1 = scanner.next();
        String s2[] = s1.split("");
        int count = 0;
        for(String s: s2){
            if(s.equals("1")) count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 35640
#include<iostream>
#include<array>
#include<utility>

using namespace std;

//ABC72 D
int main()
{
	array<int, 100000> p;
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> p[i];
	}

	int swapCount = 0;
	for (int i = 0; i < N; ++i)
	{
		if (p[i] == i + 1)
		{
			if (i < N - 1)
			{
				swap(p[i], p[i + 1]);
			}
			else
			{
				swap(p[i], p[i - 1]);
			}
			swapCount++;
		}
	}

	cout << swapCount << endl;

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
	int a[100][100];
	int b[100];
	int c[100]={0};
	int n,m;
	int i,j;
	
	  //??????A???????´??????\???
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	 //??????B???????´??????\???
	for(j=0;j<m;j++){
		scanf("%d",&b[j]);
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			c[i]+=(a[i][j]*b[j]);
		}
		printf("%d\n",c[i]);
	}
	
	return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

bool solve(){
  int n;
  cin>>n;
  vector<int> t(n),x(n),y(n);
  rep(i,n){
    cin>>t[i]>>x[i]>>y[i];
  }
  int pt=0,px=0,py=0;
  rep(i,n){
    int dt = t[i]-pt;
    int dd = abs(x[i]-px) + abs(y[i]-py);
    if(dt < dd || dt%2 != dd%2) return false;

    pt = t[i];
    px = x[i];
    py = y[i];
  }
  return true;
}

int main(){
  cout << (solve() ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll MOD = 1000000007;
const double PI = 3.141592653589793238463;
const ll N=2e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    cout<<700+(s[0]=='o')*100+(s[1]=='o')*100+(s[2]=='o')*100;
    return 0;
}


Measured memory_bytes: 256
def insertion_sort(A,n,g):
    cnt = 0
    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        
        A[j + g] = v
    
    return cnt

def shell_sort(A,n):
    cnt = 0
    
    G = []
    val = 1
    while True:
        G.append(val)
        val = (3 * val) + 1
        if val > (n // 3) + 1:
            break
    
    G.reverse()
    m = len(G)

    for g in G:
        cnt += insertion_sort(A,n,g)

    #output
    print(m)
    print(*G)
    print(cnt)
    for a in A:
        print(a)

n = int(input())
#print(f"#dbg n:{n}")
A = []
for i in range(n):
    A.append(int(input()))

#print("#dbg A:",*A)

shell_sort(A,n)



    
    





Measured memory_bytes: 45504
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
const int MOD = 1e9 + 7;
const int INF = 9e18;

signed main() {
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(N));
    vector<unordered_map<int, int>> coordinate(N, unordered_map<int, int>());
    for (int i = 0; i < N; i++) for (int j = 0; j < N - 1; j++) {
        cin >> A[i][j];
        A[i][j]--;
        coordinate[i][A[i][j]] = j;
    }
    vector<vector<int>> match(N, vector<int>(N, -1));
    int count = 0;
    for (int j = 0; j < N - 1; j++) for (int i = 0; i < N; i++) {
        if (match[i][j] == -1) {
            match[i][j] = count;
            match[A[i][j]][coordinate[A[i][j]][i]] = count;
            ++count;
        }
    }
    vector<vector<int>> G(count, vector<int>());
    vector<int> check(count, 0);
    for (int i = 0; i < N; i++) {
        for (int j = 1; j < N - 1; j++) {
            G[match[i][j - 1]].push_back(match[i][j]);
            check[match[i][j]]++;
        }
    }
    queue<int> next;
    vector<int> ans(count, -1);
    for(int i = 0; i < count; i++) {
        if (check[i] == 0) {
            ans[i] = 1;
            next.push(i);
        }
    }
    while (!next.empty()) {
        int now = next.front();
        next.pop();
        for (int temp : G[now]) {
            ans[temp] = max(ans[temp], ans[now] + 1);
            check[temp]--;
            if (check[temp] == 0) {
                next.push(temp);
            } else if (check[temp] < 0) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    int date = 0;
    for (auto i : ans) {
        if (i == -1) {
            cout << -1 << endl;
            return 0;
        }
        date = max(date, i);
    }
    cout << date << endl;
}

Measured memory_bytes: 96000
N, M = map(int, input().split())
# 始点を0にするため1を引く
# kを除くために[1:]
connected_switches = [[int(i) - 1 for i in input().split()[1:]]
                      for _ in range(M)]
ps = list(map(int, input().split()))

# https://atcoder.jp/contests/abc128/submissions/9251177 がとてもわかりやすいので参考にする

ans = 0
# どのスイッチがONになっているかの全パターン
for bit in range(2 ** N):
    ok = True
    # 各電球について回す、これは電球個（M個）あるpsが全て条件を満たしているかを確認するため
    for i in range(M):
        # i番目の電球に繋がっている、状態onのスイッチ個数
        connected_on_num = 0
        for s in connected_switches[i]:
            """
            今確認しているパターン（bit）で
            i番目の電球に繋がっているスイッチsがonとなる場合
            例: Nが4、bitが3は
            0番目: ON
            1番目: ON
            2番目: OFF
            3番目: OFF
            を想定している
            このケースで、forで回しているs（i番目の電球に繋がっているスイッチ）が
            0番目もしくは1番目のとき、connected_numが加算され2となる
            """
            if bit & (1 << s):
                """
                1 を左にsだけシフトする（10進数では2 ** s を掛けることと同じ）
                1 << 0 は 2進数で0001、10進数で1
                1 << 1 は 2進数で0010、10進数で2
                1 << 2 は 2進数で0100、10進数で4...
                bitが3のとき（2進数で0010のとき）
                bit & (1 << s) は
                0011 & (1 << s) という演算が行われる
                これがTrueとなるのは
                sが0: (1 << s) → (1 << 0) → 0001
                sが1: (1 << s) → (1 << 1) → 0010
                のときだけ
                """
                connected_on_num += 1
        if connected_on_num % 2 != ps[i]:
            ok = False
            break
    # 今確認しているパターン（bit）で
    # すべての電球が点灯している場合（connected_on_num % 2 != ps[i] が全てFalseだった場合）
    if ok:
        ans += 1

print(ans)


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

int main()
{
    int n;
    cin >> n;
    map<int , int> s;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        s[a]++;
    }
    int t;
    cin >> t;
    int ok = 1;
    for(int i = 0; i < t; i++)
    {
        int a;
        cin >> a;
        s[a]--;
        if(s[a] < 0)ok = 0;
    }
    if(ok == 1)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 9600
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define msg(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define pri(a) cout << a << endl;

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

  ll n,a,b,ans=0;
  cin >> n >> a >> b;

  if(n%(a+b)<=a){
      pri(n/(a+b)*a+n%(a+b));
  }
  else{
    pri(n/(a+b)*a+a);
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
//ll const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

ll N,K;
ll A[2000];

int main(){
    cin>>N>>K;
    rep(i,N) cin>>A[i];

    ll ans=0;
    rep(i,N){
        ll bef=0,aft=0;
        rep(j,N){
            if(A[i]>A[j]){
                if(j<i) bef++;
                if(i<j) aft++;
            }
        }
        //cout<<bef<<' '<<aft<<endl;
        ans+=K*aft+(bef+aft)*((K*(K-1)/2)%MOD)%MOD;
        ans%=MOD;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3632
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, N = map(int, readline().split())
m = map(int,read().split())
AB = list(zip(m,m))
#print(AB)
def chmin(l, i, v):
  if l[i] > v:
    l[i] = v
    return True
  return False

def chmax(l, i, v):
  if l[i] < v:
    l[i] = v
    return True
  return False

# コスト無限大で初期化
INF = float("inf")
dp = [ INF ] * (H + 1)
dp[0] = 0

for h in range(1, H+1):
  # 体力hでの最小魔力コストは、
  # dp[h-Ai] + Bi
  # の中で最小となるもの
  for A, B in AB:
    chmin(dp, h, B if h <= A else dp[h - A] + B)

#print(dp)
print(dp[H])


Measured memory_bytes: 42476
import numpy as np
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
z = [(a&1<<i).sum() for i in range(40)]
o = [max((n<<i)-z[i], z[i])  for i in range(40)]
c = np.cumsum(o)
r = s = 0
for i in reversed(range(40)):
    if k&1<<i:
        if i > 0:
            r = max(r, s + z[i] + c[i-1])
        s += o[i]
    else:
        s += z[i]
print(max(r, s))

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

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

  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    a.at(i)--;
  }

  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
  }

  for (int i = 0; i < n - 1; i++) {
    cin >> c.at(i);
  }

  /* main */

  int count = 0;

  for (int i = 0; i < n; i++) {
    count += b.at(i);
  }

  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) + 1 == a.at(i + 1)) {
      count += c.at(a.at(i));
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  string s;
  int K;
  cin>>s>>K;
  int n = SZ(s);
  REP (i, n) {
    int to_a = 'z' - s[i] + 1;
    if (s[i] == 'a') {
      to_a = 0;
    }
    if (K >= to_a) {
      s[i] = 'a';
      K -= to_a;
    }
  }
  K %= 26;
  s.back() = s.back() + K;
  if (s.back() > 'z') {
    s.back() -= 26;
  }
  cout<<s<<endl;
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 592
x = int(input())

def is_prim(n):
    if n == 1: return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0: return False
    return True

for i in range(x, 20**5+1):
    if is_prim(i):
        print(i)
        exit()

Measured memory_bytes: 9324
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int pa[220000];
int find(int n) {
	if (pa[n] < 0) return n;
	else return pa[n] = find(pa[n]);
}
void merge(int a, int b) {
	a = find(a);
	b = find(b);
	if (a == b) return;
	pa[b] += pa[a];
	pa[a] = b;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, M; cin >> N >> M;
	memset(pa, -1, sizeof(pa));
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b;
		merge(a, b);
	}
	int ans = 0;
	for (int i = 1; i <= N; i++) ans = max(ans, -pa[i]);
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4464
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

int N;
int A,B;
int P[100];

int main()
{
	FAST;

	cin >> N >> A >> B;
	vector<int> first;
	vector<int> second;
	vector<int> third;

	rep(i,N) {
		int p;
		cin >> p;
		if (p<=A) first.push_back(p);
		else if(A+1<=p&&p<=B) second.push_back(p);
		else if(B+1<=p) third.push_back(p);
	}

	int ans = min(min(first.size(), second.size()), third.size());

	cout << ans << LF;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, m, i, j, k;
int main(){
    scanf("%d", &n);
    m=n%10;
    if(m==2||m==4||m==5||m==7||m==9){
    	printf("hon");
	}
	else if(m==0||m==1||m==6||m==8){
		printf("pon");
	}
	else if(m==3){
		printf("bon");
	}
	return 0;
}

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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (a > b) {
        cout << 0 << endl;
        return 0;
    }
    if (n == 1) {
        cout << (a == b ? 1 : 0) << endl;
        return 0;
    }

    cout << (b - a) * (n - 2) + 1ll << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

S = input()
L = len(S)-1
flags = []
for i in range(2**L):
	t = format(i,'010b')
	flags.append(list(t[10-L:]))


ans = 0

for flag in flags:
	tmp_li = [0]
	for i,fl in enumerate(flag):
		if fl == '1':
			tmp_li.append(i+1)
	tmp_li.append(L+1)

	for i in range(len(tmp_li)-1):
		l = tmp_li[i]
		r = tmp_li[i+1]
		ans += int(S[l:r])

print(ans)

Measured memory_bytes: 4328
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;
int main(){
  int n;
  cin >> n;
  vector<pair<string, int>> mp, sub;
  for(int i = 0; i < n; i++) {
    string s;
    int p;
    cin >> s >> p;
    mp.push_back(make_pair(s, -p));
    sub.push_back(make_pair(s, p));
  }
  
  sort(mp.begin(), mp.end());

  for(auto const&[k, v] : mp) {
    pair<string, int> tmp = make_pair(k, -v);
    auto itr = find(sub.begin(), sub.end(), tmp);
    cout << distance(sub.begin(), itr)+1  << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <sstream>
#include <random>
#include <functional>
#include<algorithm>
using namespace std;

int main() {
	string str;
	cin >> str;
	bool b = false;
	for (size_t i = 0; i + 1< str.size(); i++)
	{
		if (str[i] == 'A') {
			i++;
			if (str[i] == 'C')b = true;
		}
	}
	cout << ((b) ? ("Yes") : ("No"));
	return 0;
}

Measured memory_bytes: 256
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
N = inp.shift() * 1
A = inp.shift().split(' ')
B = inp.shift().split(' ')
sumA = 0
sumB = 0
s = 0
t = []
cnt = 0
for (i=0; i<N; i++) {
  a = A[i] * 1
  b = B[i] * 1
  d = a - b
  if (d < 0) {
      cnt++
      s += d 
  } else {
      t.push(d)
  }
  sumA += a
  sumB += b
}

if (sumA >= sumB) {
  t.sort((a, b) => b - a)
  j = 0
  while (s < 0) {
      s += t[j]
      j++
  }
  console.log(cnt+j)
} else {
  console.log(-1)
}


Measured memory_bytes: 36624
#include<bits/stdc++.h>
#define inf 2000000000
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define fastread ios::sync_with_stdio(false);cin.tie(NULL)
#define rng_23 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef set<int> si;
typedef multiset<int> msi;
typedef map<int,int> mii;
int main()
{
    int n,m;
    int sum=0;
    int ara[10000];
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>ara[i];
        sum+=ara[i];
    }
    if(sum>n)
        cout<<"-1";
    else
        cout<<n-sum;
}


Measured memory_bytes: 3616
import Control.Applicative
import Control.Monad
import Data.List(sort, group, nub)

data Dice = Dice [Int] deriving (Show, Ord, Eq)

roll :: Dice -> Char -> Dice
roll (Dice [top, front, right, left, back, bottom]) 'S' = Dice [back, top, right, left, bottom, front]
roll (Dice [top, front, right, left, back, bottom]) 'E' = Dice [left, front, top, bottom, back, right]

toS = flip roll 'S'
toE = flip roll 'E'
rev = toS . toS

turn1 :: Dice -> Dice
turn1 (Dice [top, front, right, left, back, bottom]) = Dice [top, right, back, front, left, bottom]
turn2 = turn1 . turn1
turn3 = turn2 . turn1

turnAll :: Dice -> [Dice]
turnAll dice =  nub $ sort $ [id, turn1, turn2, turn3] <*> dices dice
    where dices :: Dice -> [Dice]
          dices dice = [dice
                       , rev dice
                       , toS dice
                       , toE dice
                       , rev (toS dice)
                       , rev (toE dice)
                       ]

allUnique :: Ord a => [a] -> Bool
allUnique = all ((==1) . (length)) . group . sort

solve :: Dice -> [Dice] -> String
solve dice dices | dice `elem` dices = "Yes"
                 | otherwise         = "No"

main :: IO ()
main = do
    n <- readLn
    xs <- map (Dice . map ri . words) <$> replicateM n getLine
    let wl = sort $ concatMap turnAll xs
     in case allUnique wl of
          True -> putStrLn "Yes"
          _    -> putStrLn "No"
    where ri :: String -> Int
          ri = read


Measured memory_bytes: 5188
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
typedef pair<int,int> pii;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

    
void solve()
{
	int n;cin>>n;
    int a[n];REP(i,n)cin>>a[i];
    vector<int>dp(3,0);
    ll ans=1;
    REP(i,n){
        int tmp=0,id=-1;
        REP(j,3)if(a[i]==dp[j]){tmp++;id=j;}
        if(id==-1){cout<<0<<endl;return;}
        dp[id]++;
        ans*=tmp;
        ans%=mod;
    }
    cout<<ans<<endl;

}

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


Measured memory_bytes: 640
if __name__ == "__main__":
    INF = 40 ** 18 + 1
    N, K = map(int, input().split())
    Point = list()
    for i in range(N):
        Point.append(list(map(int, input().split())))

    # 四角形の頂点を２点選んでその中にK点含まれてて、面積が小さければ更新
    ans = INF
    # iは1点目のx, jは1点目のy、kは2点目のx, lは2点目のy
    for i in range(N):
        for j in range(N):
            for k in range(N):
                for l in range(N):
                    x0 = Point[i][0]
                    y0 = Point[j][1]
                    x1 = Point[k][0]
                    y1 = Point[l][1]
                    # 四角形作れない座標の組み合わせと、1点目 < 2点目の座標関係で無いならスルー
                    if x0 >= x1 or y0 >= y1:
                        continue
                    count = 0
                    for m in range(N):
                        x, y = Point[m][0], Point[m][1]
                        if x0 <= x <= x1 and y0 <= y <= y1:
                            count += 1
                        if count >= K:
                            area = (x1 - x0) * (y1 - y0)
                            if area < ans:
                                ans = area
                            break

    print(ans)


Measured memory_bytes: 55492
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static int MAX = 2000000;
    public static int tree[] = new int[MAX];
    public static void update(int qs,int qe,int cs,int ce,int ci){
        if(cs>ce||cs>qe||qs>ce){
            return;
        }
        if(cs>=qs&&ce<=qe){
            //System.out.println(ci);
            tree[ci]++;
            return;
        }
        int mid = (cs+ce)/2;
        update(qs,qe,cs,mid,2*ci+1);
        update(qs,qe,mid+1,ce,2*ci+2);
    }
    public static void lazyPropagation(){
        for(int i=0;i<=MAX/2;i++){
            int v1 = 2*i+1;
            int v2 = 2*i+2;
            if(v1<MAX){
                tree[v1] += tree[i];
            }
            if(v2<MAX){
                tree[v2] += tree[i];
            }
        }
    }
    public static int get(int qs,int qe,int cs,int ce,int ci,int limit){
        if(cs>ce||cs>qe||qs>ce){
            return 0;
        }
        if(cs>=qs&&ce<=qe){
            if(tree[ci]==limit){
                return ce-cs+1;
            }else if(cs==ce){
                return 0;
            }
        }
        int mid = (cs+ce)/2;
        int left = get(qs,qe,cs,mid,2*ci+1,limit);
        int right = get(qs,qe,mid+1,ce,2*ci+2,limit);
        return left+right;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());
        //int num[] = new int[100001];
        for(int i=0;i<M;i++){
            st = new StringTokenizer(br.readLine());
            int L = Integer.parseInt(st.nextToken());
            int R = Integer.parseInt(st.nextToken());
            //for(int j=L;j<=R;j++){
            //    num[j]++;
            //}
            update(L,R,1,100000,0);
        }
        lazyPropagation();
        int ans = get(1,100000,1,100000,0,M );
        System.out.println(ans);
    }
}


Measured memory_bytes: 46608
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
 
int main() {
	long long int N = 0, n, maxi = -1, ans = 0;
	cin >> N;
	n = sqrt(N);
	for (long long int i = 1; i<=n; i++)
	{
		if (N%i == 0)maxi = N / i;
	}
	n = 1;
	for (long long int i = 1; maxi>=n; i++)
	{
		n *= 10;
		ans = i;
	}
	cout << ans;
	return 0;
}

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


int findMin(int h[], int n, int k) {
	int cost[n];
	cost[0] = 0;
	cost[1] = abs(h[0] - h[1]);

	for(int i=2; i<n; i++) {
		int minCost = INT_MAX;
		for(int j=1; j<=k; j++) {
			int tp = INT_MAX;
			if(i >= j) {
				tp = cost[i-j] + abs(h[i] - h[i-j]);
				//cout<<tp<<" ";
			}
			minCost = min(minCost, tp);
		}
		cost[i] = minCost;
		//cout<<"----"<<i<<" :"<<cost[i]<<endl;
	}

	return cost[n-1];
}

int main() {
	int n,k;
	int h[100000];
	cin>>n>>k;
	for(int i=0;i <n; i++)
		cin>>h[i];


	cout<<findMin(h, n, k)<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
#define enld endl
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int N; cin >> N;
    string s; cin >> s;
    int cntred = 0;
    for(int i=0;i<N;i++){
        if(s[i] == 'R') cntred++;
    }
    int ans = 0;
    for(int i=cntred;i<N;i++){
        if(s[i] == 'R') ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3740
#include <stdio.h>
#include <algorithm>
#define il inline
#define int long long
#define N 8001
using namespace std;
const int gi=3,mod=998244353;

int n,m,inv,ans;
int base=1,l,rev[4*N];
int fac[N+2],iac[N+2];
int f[N][N/40+1],F[4*N],G[4*N];

il int ksm(int a,int b)
{
	int res=1;
	for ( ; b; b>>=1,a=a*a%mod) if (b&1) res=res*a%mod;
	return res;
}

il void NTT(int *Z,int opt)
{
	int i,j,k;
	for (i=1; i<base; i++) if (i<rev[i]) swap(Z[i],Z[rev[i]]);
	for (i=1; i<base; i<<=1)
	{
		int Wn=ksm(gi,(mod-1)/(i<<1));
		for (j=0; j<base; j+=(i<<1))
		{
			int W=1;
			for (k=0; k<i; W=W*Wn%mod,k++)
			{
				int X=Z[j+k],Y=W*Z[j+i+k]%mod;
				Z[j+k]=(X+Y)%mod,Z[j+i+k]=(X-Y+mod)%mod;
			}
		}
	}
	if (opt==1) return;
	reverse(Z+1,Z+base);
	for (i=0; i<base; i++) Z[i]=Z[i]*inv%mod;
}

signed main()
{
	scanf("%lld%lld",&n,&m);
	int i,j;
	for (i=fac[0]=1; i<=n+2; i++) fac[i]=fac[i-1]*i%mod;
	for (i=n+2,iac[i]=ksm(fac[i],mod-2); i>=1; i--) iac[i-1]=iac[i]*i%mod;
	while (base<=n+n+2) base<<=1,l++;
	for (i=1,inv=ksm(base,mod-2); i<base; i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(l-1));
	
	for (i=1; i<=n; i++) G[i]=iac[i+2];
	f[0][0]=1,NTT(G,1);
  	for (j=1; j<=m; j++)
	{
    	for (i=0; i<=n; i++) F[i]=f[i][j-1]*iac[i];
    	for (i=n+1; i<base; i++) F[i]=0;
    	NTT(F,1);
    	for (i=0; i<base; i++) F[i]=F[i]*G[i]%mod;
    	NTT(F,-1);
    	for (i=0; i<=n; i++) f[i][j]=(F[i]*fac[i+2]%mod+f[i][j-1]*(1ll+i*(i+1)/2)%mod)%mod;
  	}
  	for (i=0; i<=n; i++) ans=(ans+f[i][m]*fac[n]%mod*iac[i]%mod*iac[n-i]%mod)%mod;
  	printf("%lld",ans);
	
	return 0;
}

Measured memory_bytes: 13184
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func solve(sc *scanner, wr *bufio.Writer) int {
	K := sc.i()
	S := sc.s()

	if len(S) <= K {
		fmt.Println(S)
	} else {
		fmt.Printf("%s...\n", S[:K])
	}

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


Measured memory_bytes: 1760
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    ll sum = 0;
    rep(i, n)
    {
        cin >> a[i];
        sum += a[i];
    }
    vector<ll> div;
    for (ll i = 1; i * i < sum; i++)
    {
        if (sum % i == 0)
        {
            div.push_back(i);
            div.push_back(sum / i);
        }
    }
    sort(div.begin(), div.end());
    ll ans = 0;
    for (auto d : div)
    {
        ll c = 0;
        ll s = 0;
        vector<ll> posi;
        vector<ll> nega;
        ll zero = 0;
        rep(i, n)
        {
            ll x = a[i] % d;
            ll y = d - a[i] % d;
            if (x == 0)
            {
                zero++;
            }
            else if (x < y)
            {
                nega.push_back(x);
                c += x;
                s -= x;
            }
            else
            {
                posi.push_back(y);
                c += y;
                s += y;
            }
        }
        if (c > k * 2)
        {
            continue;
        }
        if (s % d != 0)
        {
            continue;
        }
        if (s > 0)
        {
            //posi to nega
            sort(posi.begin(), posi.end(), greater<ll>());
            for (auto j : posi)
            {
                if (c > k * 2)
                {
                    break;
                }
                if (s == 0)
                {
                    ans = d;
                    break;
                }
                s -= d;
                c += (d - j * 2);
            }
            if (s * 2 < 2 * k - c)
            {
                ans = d;
            }
        }
        else
        {
            //nega to posi
            sort(nega.begin(), nega.end(), greater<ll>());
            for (auto j : nega)
            {
                if (c > k * 2)
                {
                    break;
                }
                if (s == 0)
                {
                    ans = d;
                    break;
                }
                s += d;
                c += (d - j * 2);
            }
            if (-s * 2 < 2 * k - c)
            {
                ans = d;
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;

const int N = 200010;

int n;
int p[N];
pair<pair<int, int>, int> c[N];
pair< int, pair<int, int> > e[N];

int group(int a) {
  if (p[a] == -1) {
    return a;
  }
  return p[a] = group(p[a]);
}

int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    c[i] = make_pair(make_pair(x, y), i);
  }
  for (int it = 0; it < 2; it++) {
    sort(c, c + n);
    for (int i = 0; i < n - 1; i++) {
      int x = c[i].second;
      int y = c[i + 1].second;
      int d = abs(c[i + 1].first.first - c[i].first.first);
      e[it * (n - 1) + i] = make_pair(d, make_pair(x, y));
    }
    for (int i = 0; i < n; i++) {
      swap(c[i].first.first, c[i].first.second);
    }
  }
  sort(e, e + 2 * n - 2);
  fill_n(p, n, -1);
  long long ans = 0;
  for (int i = 0; i < 2 * n - 2; i++) {
    int x = group(e[i].second.first);
    int y = group(e[i].second.second);
    int d = e[i].first;
    if (x == y) {
      continue;
    }
    p[x] = y;
    ans += d;
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>

using ll = long long;
const ll INF = __LONG_LONG_MAX__;

using namespace std;

int main() {
    int N, D;
    cin >> N >> D;

    int d = 2*D + 1;

    cout << (N + d - 1) / d << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>

using namespace std;

int main(void){

    int n;
    vector<int> num;
    vector<bool> numFlag;
    bool flag = true;

    cin >> n;

    for(int i = 0;i < n;i++){
        int x;
        cin >> x;
        num.push_back(x);
        numFlag.push_back(true);
    }

    int i = 0;
    while(i < n-1){
        //cout << i << " : " << num[i] << "    " << i+1 << " : " << num[i+1] << "  numFlag : " << i << " " << numFlag[i] <<"  flag : " << flag << endl;
        if(num[i] <= num[i+1]){
            //cout << "a";
            i++;
        }else if(flag == true && numFlag[i] == true && num[i] > num[i+1]){
            flag = true;
            num[i]--;
            numFlag[i] = false;
            i--;
            //cout << "b";
        }else{
            flag = false;
            //cout << "c";
            i++;
        }
        //cout << i << " : " << num[i] << "    " << i+1 << " : " << num[i+1] << "  numFlag : " << i << " " << numFlag[i]<<"  flag : " << flag << endl;
        //cout << endl;
        
    }

    cout << (flag==true ? "Yes" : "No") << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 1010;
int n, m, nxt[N];
bool chosen[N], inpath[N];
vector<int> adj[N], viv, loop;

bool visit(int u, vector<int>& ver) {
	chosen[u] = true; inpath[u] = true; ver.push_back(u); 
	for (int v : adj[u])
		if (inpath[v]) {
			int z;
			do {
				z = viv.back(); viv.pop_back();
				loop.push_back(z);
			} while (z != v);
			for (int x : viv) inpath[x] = false;
			reverse(loop.begin(), loop.end());
			return true;
		}
		else if (!chosen[v] && visit(v, ver)) return true;

	ver.pop_back(); inpath[u] = false;
	return false;
}


int main() {
	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
	}
	for (int i = 1; i <= n; ++i) 
		if (visit(i, viv)) {
			int k = loop.size(), u=loop[0];
			for (int i = 0; i < k; ++i) nxt[loop[i]] = loop[(i + 1) % k];
			int timeLeft = n;
			for (; timeLeft>0; --timeLeft, u = nxt[u]) {
				int vtag = -1;
				for (int v : adj[u])
					if (inpath[v] && v != nxt[u]) {
						vtag = v;
						break;
					}
				if (vtag != -1) {
					for (int j = nxt[u]; j != vtag; j = nxt[j]) {
						inpath[j] = false; --k;
					}
					nxt[u] = vtag;
					timeLeft += k;
				}
			}
			cout << k << endl;
			for (int i = 1; i <= n; ++i) if (inpath[i]) cout << i << endl;
			return 0;
		}
	cout << -1 << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include<cstdio>
using namespace std;
const int INF = (1 << 21);
static int G[100][100];

void AskSSSP(int n){
    
    const int BLACK = 2,GRAY = 1,WHITE =  0;
    int color[n],d[n];
    for(int i = 0;i < n;++i){
        d[i] = INF;
        color[i] = WHITE;
    }
    d[0] = 0;
    int min,u;
    while(1){
        int min = INF;
        for(int i=0;i < n;++i){
            if(color[i] != BLACK && d[i] < min){
                min = d[i];
                u = i;
            }
        }
        if(min == INF) break;
        color[u] = BLACK;
        for(int i=0;i < n;++i){
            if(color[i] != BLACK && G[u][i] != INF){
                if(d[u] + G[u][i] < d[i]){
                    d[i] = d[u] + G[u][i];
                    color[i] = GRAY;
                }
            }
        }
        
    }
    for(int i = 0;i < n;++i) printf("%d %d\n",i,d[i]);

}

int main(void){
    int n,t,k,v,u;
    scanf("%d",&n);
    for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
            G[i][j] = INF;
        }
    }
    for(int i = 0;i < n;++i){
        scanf("%d %d",&t,&k);
        for(int j = 0;j < k;j++){
            scanf("%d %d",&v,&u);
            G[t][v] = u;
        }
    }
    AskSSSP(n);
    
}





Measured memory_bytes: 3236
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
typedef long long ll;
const int mod=1e9+7;
#define lol(i,n) for(int i=0;i<n;i++)

using namespace std;
int n,a,b,c;
int main() {
    cin >>n>>a>>b>>c;
    int k=a+b-c;
    cout << n-k<< endl;
}



Measured memory_bytes: 3124
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(n / 2);
	x %= mod;
	x *= x;
	x %= mod;
	if (n % 2 == 1)x *= 2;
	x %= mod;
	return x;
}
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
char a[501][501];
bool seen[1000][1000] = { false };
void dfs(int x,int y,int h,int w) {
	seen[x][y] = true;
	for (int i = 0; i < 4; i++) {
		int Nx = x + dx[i];
		int Ny = y + dy[i];
		if (Nx >= h || Ny >= w || seen[Nx][Ny] || a[Nx][Ny] == '#' || Nx < 0 || Ny < 0)continue;
		dfs(Nx, Ny,h,w);
	}
}
int main() {
	double a;
	cin >> a;
	double ans = 3.14159265 * a * 2;
	cout << keta(15) << ans << endl;
	return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string S;
  cin >> S;
  
  int N = S.size();
  
  int f=0;
  
  for(int i=0; i<N ; i++){
    if(S[i]==S[N-i-1]){
      f+=0;
    }
    
    else{
      f++;
    }
    
    
  }
  
  
    cout << f/2 << endl;
  
  
  
}

Measured memory_bytes: 256
#include<stdio.h>


#include<stack>



using namespace std;



struct NoeSis
{
	int x;
	int y;
} Sis;



int mx[] = { 0 ,1 };
int my[] = { 1 ,0 };


int ans;




int over_check(int, int, int);



int main()
{
	int i, j;


	int w, h;

	int n;

	int stop_x, stop_y;

	while (scanf("%d %d", &w, &h), w | h)
	{
		NoeSis Noe = { 1 ,1 };


		bool map[16 + 1][16 + 1] = { false };


		ans = 0;


		scanf("%d", &n);


		for (i = 0; i < n; ++i)
		{
			scanf("%d %d", &stop_x, &stop_y);


			map[stop_y][stop_x] = true;
		}



		stack< NoeSis > que;


		que.push(Noe);



		while (!que.empty())
		{
			Sis = que.top();

			que.pop();


			if (Sis.x == w && Sis.y == h)
			{
				++ans;
			}


			else
			{
				for (i = 0; i < 2; ++i)
				{
					if (over_check(w, h, i) & map[Sis.y + my[i]][Sis.x + mx[i]] == false)
					{
						Noe = Sis;

						Noe.x += mx[i];
						Noe.y += my[i];


						que.push(Noe);
					}
				}
			}
		}



		printf("%d\n", ans);
	}



	return 0;
}





int over_check(int w, int h, int i)
{
	++w;
	++h;

	return ((Sis.x + mx[i] < w) + (Sis.y + my[i] < h)) / 2;
}

Measured memory_bytes: 2732