akhauriyash/Code-Regression huggingface dataset:
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << endl;
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define wh while
#define ve vector
#define mp make_pair
#define tp tuple
#define mt make_tuple
#define pb push_back
#define pof pop_front
#define pob pop_back
#define pf push_front
#define fr front
#define ft first
#define sc second
#define tos to_string
#define len length
#define rt return
#define br break
#define con continue
#define lcm(n, m) (n * m / __gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m) - 1;i>=(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) n.begin(), n.end()
#define allr(n) n.rbegin(), n.rend()
#define sp(n) cout << fixed << setprecision(n)
#define pi 3.14159265358979323846
#define inf 1000000007
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

ve<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};

int main() {
  st s;
  ci(s);
  rep(i, sz(s)){
    if(i % 2 == 0){
      cout << s.at(i);
    }
  }
  cout << endl;
}

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

using Graph = vector<vector<int>>;

set<pair<int, int>> bridges(Graph &g) {
  vector<pair<int, int>> bri;
  int n = g.size();
  vector<int> cmp(n);
  stack<int> s, roots;
  vector<int> ord(n, -1);
  int id = 0, k = 0;
  vector<int> onS(n);
  function<void(int, int)> dfs = [&](int v, int u) {
    ord[v] = id++;
    s.emplace(v);
    onS[v] = true;
    roots.emplace(v);
    for (auto &e : g[v]) {
      int w = e;
      if (ord[w] == -1) {
        dfs(w, v);
      } else if (u != w && onS[w]) {
        while (ord[roots.top()] > ord[w]) roots.pop();
      }
    }
    if (v == roots.top()) {
      bri.emplace_back(u, v);
      while (true) {
        int w = s.top();
        s.pop();
        onS[w] = false;
        cmp[w] = k;
        if (v == w) break;
      }
      roots.pop();
      k++;
    }
  };
  rep(i, n) {
    if (ord[i] != -1) continue;
    dfs(i, -1);
    bri.pop_back();
  }
  return set<pair<int, int>>(bri.begin(), bri.end());
}

int main() {
  int N;
  cin >> N;
  Graph g(N);
  rep(i, N) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  set<pair<int, int>> es = bridges(g);
  vector<bool> inCycle(N, false);
  rep(i, N) {
    rep(j, g[i].size()) {
      if (es.count({i, g[i][j]}) || es.count({g[i][j], i})) continue;
      inCycle[i] = inCycle[g[i][j]] = true;
    }
  }

  // cout << es.size() << endl;
  // for (auto &e : es) cout << e.first << " " << e.second << endl;
  int Q;
  cin >> Q;
  rep(i, Q) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if (inCycle[a] && inCycle[b]) {
      cout << 2 << endl;
    } else {
      cout << 1 << endl;
    }
  }
}



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

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

#define MAX_N 2000000
#define MAX_A 10000

int A[MAX_N + 5], B[MAX_N + 5], C[MAX_A + 5];

void countingSort(int n, int k) {
  rep(i, k) C[i] = 0;
  rep(i, n) C[A[i]]++;
  rep(i, k - 1) C[i + 1] += C[i];
  for (int i = n - 1; i >= 0; i--) {
    B[C[A[i]] - 1] = A[i];
    C[A[i]]--;
  }
}

int main() {
  int n;
  cin >> n;
  rep(i, n) cin >> A[i];
  countingSort(n, MAX_A);
  rep(i, n) {
    if (i > 0) cout << " ";
    cout << B[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 18748
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

typedef priority_queue<int, vector<int>, greater<int>> priority_queue_asc;

int main() {
    int a;
    cin >> a;

    cout << a + a * a + a * a * a << endl;

    return 0;
}


Measured memory_bytes: 3164
from heapq import heappush, heappop
import re
from collections import deque
import sys
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_invs(n, mod=DIV):
    inv = [0]*(n+1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, n+1):
        inv[i] = (-(mod//i)*inv[mod % i]) % mod
    return inv


def main():
    N = int_raw()
    ds = list(ints_raw())
    ds.sort()
    medi = ds[(N-1)//2]
    medi_h = ds[(N-1)//2+1]
    return medi_h-medi


print(main())


Measured memory_bytes: 54876
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;

map< int, int > treeA;
map< int, int > treeB;
map< int, int > treeC;

void getTree(string line,int tree,int lvl){
	if(line=="" || line=="(" || line==")")return;
	int b = 0;
	stack<int> cnt;
	while(line[b]!=0){
		if(line[b]=='('){
			cnt.push(1);
		}else if(line[b]==')'){
			cnt.pop();
		}else{
			if(cnt.size()==1)break;
		}
		b++;
	}
	string S_R="",S_L= "";
	for(int x=1;x<b;++x){
		S_L += line[x];
	}
	for(int x=b+1;x<line.size()-1;++x){
		S_R += line[x];
	}
	if(S_L!=""){
		getTree(S_L,tree,lvl*2);
	}
	if(S_R!=""){
		getTree(S_R,tree,lvl*2+1);
	}
	if(tree==1){
		treeA[lvl] = 1;
	}else{
		treeB[lvl] = 2;
	}
}

void uniont(){
	for(map<int,int>::iterator it = treeA.begin();it!=treeA.end();++it){
		treeC[it->first] = 3;
	}
	for(map<int,int>::iterator it = treeB.begin();it!=treeB.end();++it){
		treeC[it->first] = 3;
	}
}

int locate(int n){
	for(map<int,int>::iterator it=treeB.begin();treeB.end()!=it;++it){
		if(n==it->first)return 0;
		if(it->first>n)return -1;
	}
	return -1;
}

void intert(){
	for(map<int,int>::iterator it = treeA.begin();it!=treeA.end();++it){
		if(locate(it->first)!=-1){
			treeC[it->first] = 3;
		}
	}
}

string imp(int lvl){
	if(treeC[lvl]==0)return "";
	stringstream buf;
	buf<<"("<<imp(lvl*2)<<","<<imp(lvl*2+1)<<")";
	return buf.str();
}

int main(){
	char l;
	string s1,s2;
	while(scanf(" %c ",&l)!=EOF){
		cin>>s1>>s2;
		treeA.clear();
		treeB.clear();
		treeC.clear();
		getTree(s1,1,1);
		getTree(s2,2,1);
		if(l=='u'){
			uniont();
		}else{
			intert();
		}	
		cout<<imp(1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1384
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ABGraph g = new ABGraph(sc);
		if (g.Topo())
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

class ABGraph {
	int v;
	String s;
	List<Integer>[] link;
	int[][] nextcountAB;

	public ABGraph(Scanner sc) {
		int n = sc.nextInt();
		int m = sc.nextInt();
		s = sc.next();
		this.v = n;
		link = new ArrayList[n];
		nextcountAB = new int[n][2];
		for (int i = 0; i < n; i++) {
			link[i] = new ArrayList<>();
		}
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			link[a].add(b);
			nextcountAB[a][s.charAt(b) == 'A' ? 0 : 1] += 1;
			if (a != b) {
				link[b].add(a);
				nextcountAB[b][s.charAt(a) == 'A' ? 0 : 1] += 1;
			}
		}
	}

	public boolean Topo() {
		Queue<Integer> q = getLastNode();
		// System.out.println(q.size());
		while (q.size() > 0) {
			Integer n = q.remove();
			//System.out.println(n);
			for (int i = link[n].size() - 1; i >= 0; i--) {
				Integer m = link[n].get(i);

				link[n].remove(m);
				nextcountAB[n][s.charAt(m) == 'A' ? 0 : 1]--;
				if (n != m) {
					link[m].remove(n);
					nextcountAB[m][s.charAt(n) == 'A' ? 0 : 1]--;

					if ((nextcountAB[m][0] < 1 || nextcountAB[m][1] < 1)) {
						q.add(m);
					}
				}
			}

		}

		return hasCheck();
	}

	private boolean hasCheck() {
		for (int i = 0; i < v; i++) {
			if (nextcountAB[i][0] > 0 || nextcountAB[i][1] > 0)
				return true;
		}
		return false;
	}

	private Queue<Integer> getLastNode() {
		Queue<Integer> q = new ArrayDeque<>();
		for (int i = 0; i < v; i++) {
			if (nextcountAB[i][0] < 1 || nextcountAB[i][1] < 1)
				q.add(i);
		}
		return q;
	}

}


Measured memory_bytes: 132356
#include <bits/stdc++.h>
#define rep2(i, n, m) for (int i = m; i < (int)(n); i++)
#define rep(i, n) rep2(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;  //
template <typename T>
T sq(T x) {
  return x * x;
}
signed main() {
  int a, b, h;
  cin >> a;
  cin >> b;
  cin >> h;
  int ans = (a + b) * h / 2.;
  cout << ans << endl;
  return 0;
}



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

using namespace std;
typedef long long ll;
struct P{
	int to,next;
	ll cost,tak;
}e[2600];
int tot = 0,n,m;
long long s;
ll c[60],t[60];
int head[100];

void add( int u,int v,long long a,long long  b)
{
	e[tot].cost = a;
	e[tot].tak = b;
	e[tot].to = v;
	e[tot].next = head[u];
	head[u] = tot++; 
}
long long dis[60][2600];
void dij(int x,ll y)
{
	queue<pair<int,ll> > q;
    q.push({1,s});
    for(int i = 1; i <= n;i++)
     for (int j = 0;j <= 2500;j++)
       {
       	dis[i][j]=0x3f3f3f3f3f3f3f3f;
	   }
	dis[1][s]=0;
	while(!q.empty())
	{
		int p1 = q.front().first;
	    ll p2 = q.front().second;
	    q.pop();
		for(int i = head[p1];i!=-1;i=e[i].next)
	    {// 
	    	if(p2>=e[i].cost && dis[e[i].to][p2-e[i].cost]>dis[p1][p2]+e[i].tak)
	    	  {
			  dis[e[i].to][p2-e[i].cost]=dis[p1][p2]+e[i].tak;
	          q.push({e[i].to,p2-e[i].cost});
			  }
		}
		if(dis[p1][min(ll(2500),p2+c[p1])] > dis[p1][p2]+t[p1])
		  {
		  	dis[p1][min((ll)2500,p2+c[p1])] = dis[p1][p2]+t[p1];
		  	q.push({p1,min((ll)2500,p2+c[p1])});
		  }
	}   
}
int main(){
	cin>>n>>m>>s;
	s = min(s,(ll)2500);
	for(int i = 1;i <= n;i++)
	 head[i]= -1;
	for(int i = 1;i <= m;i++)
	{
		int u,v;
		ll a,b;
		scanf("%d%d%lld%lld",&u,&v,&a,&b);
        add(u,v,a,b);
        add(v,u,a,b);
	}
	for(int i = 1;i <= n;i++)
	 {
	 	scanf("%d%d",&c[i],&t[i]);
	 }
	dij(1,s);
	for(int i =2 ;i<= n;i++)
	 {
	 	long long ans = 0x3f3f3f3f3f3f3f3f;
	  for(int j = 0;j <=2500;j++)
	    ans = min(ans,dis[i][j]);
	  cout<<ans<<endl;
}
	return 0;
}

Measured memory_bytes: 5300
import itertools as it

N = input()
list_753 = []
for i in range(3, len(N) + 1):
    for i_753 in it.product("357", repeat=i):
        if "3" in i_753 and "5" in i_753 and "7" in i_753:
            list_753.append(int("".join(i_753)))

ans = 0
for i in list_753:
    if i <= int(N):
        ans += 1
    else:
        break
print(ans)


Measured memory_bytes: 4084
using System;
class Program
{
	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int b = int.Parse(input[0]);
		int c = int.Parse(input[1]);
      
      	if(b > 9 || c > 9)
        {
            //出力
			Console.WriteLine(-1);
        }
        else {
         	//出力
			Console.WriteLine(b*c); 
        }
	}
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

int main() {
	ll a, b; cin >> a >> b;
	if (!(a + b & 1)) {
		cout << (a + b) / 2 << endl;
		return 0;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}

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

using namespace std;


int main(void)
{
	int n;
	set<int> target;
	int data[10000];
	int change[10000];

	while( cin >> n && n != 0 ){
		target.clear();
		for( int i = 0;i < 10000;i++ ) change[i] = data[i] = 0;
		for( int i = 1;i < n;i++ ){
			target.insert( i * i % n );
		}

		copy( target.begin(), target.end(), change );
		

		int piyo = target.size();
		int hoge = ( n - 1 ) / 2;
		for( int i = 0;i < piyo;i++ ){
			for( int j = 0;j < piyo;j++ ){
				int answer = change[i] - change[j];
				if( answer == 0 ) continue;
				while( 1 ){
					if( answer < 0 ){ answer += n; continue; }
					else if( answer > hoge ){ answer = n - answer; continue; }
					data[answer]++;
					break;
				}
			}
		}

		for(  int i = 1;i <= hoge;i++ ){
			cout << data[i] << endl;
		}
	}

	return 0;
}

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

int main() {
  int a,b; cin >> a >> b;

  int k;
  if (b < 10) {
    k = a*10 + b;
  } else if (b == 100) {
    k = a*1000 + b;
  } else {
    k = a*100 + b;
  }

  for (int i=1; i<1000; i++) {
    if (k == i*i) {
      p("Yes");
      return 0;
    } 
  }

   p("No");
}


Measured memory_bytes: 256
from sys import setrecursionlimit as SRL, stdin
inf = 10**15
SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())

n, m, l = rrd()
dis = [[inf] * 305 for _i in range(305)]
need = [[inf] * 305 for _i in range(305)]
for i in range(n):
    dis[i][i] = 0
for i in range(m):
    a, b, c = rrd()
    dis[a][b] = c
    dis[b][a] = c

for k in range(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])

for i in range(1, n + 1):
    for j in range(1, n + 1):
        if i == j:
            need[i][j] = 0
        elif dis[i][j] <= l:
            need[i][j] = 1

for k in range(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            need[i][j] = min(need[i][j], need[i][k] + need[k][j])
q = int(input())

while q:
    s, t = rrd()
    if need[s][t] < inf:
        print(need[s][t]-1)
    else:
        print(-1)
    q -= 1










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

ll h,w;

bool in(ll y, ll x){
    return 0 <= y && y < h && 0 <= x && x < w;
}

int main(){
    ll dy[4] = {-1, 0, 1, 0};
    ll dx[4] = {0, -1, 0, 1};
    cin >> h >> w;
    char s[h][w];
    vpl kuro;
    rep(i,h){
        rep(j,w){
            cin >> s[i][j];
            if(s[i][j] == '#'){
                if(!((i==0&&j==0) || (i==h-1&&j==w-1))) kuro.emplace_back(i,j);
            }
        }
    }
    bool flag = true;
    for(auto i : kuro){
        ll y = i.first;
        ll x = i.second;
        ll cnt = 0;
        rep(j,2){
            if(in(y+dy[j], x+dx[j])){
                if(s[y+dy[j]][x+dx[j]]=='#') cnt++;
            } 
        }
        if(cnt == 0 || cnt == 2){
            flag = false;
        }
        cnt = 0;
        REP(j,2,4){
            if(in(y+dy[j], x+dx[j])){
                if(s[y+dy[j]][x+dx[j]]=='#') cnt++;
            } 
        }
        if(cnt == 0 || cnt == 2){
            flag = false;
        }
    }
    if(s[0][1] == '#' && s[1][0] == '#') flag = false;
    if(s[h-2][w-1] == '#' && s[h-1][w-2] == '#') flag = false;
    if(flag && !kuro.empty()) puts("Possible");
    else puts("Impossible");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
//#define for(i,a,b) for(int i=(a);i<=(b);i++)

int32_t main()
{

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
    cin>>arr[i];
}
for(int i=n-1;i>0;i--)
{
    if(arr[i]<arr[i-1])
    {
        if(arr[i]+1==arr[i-1])
        {
            arr[i-1]--;
        }
        else
        {
            cout<<"No";
            return 0;
        }
    }
}
cout<<"Yes";
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()


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

//Combination MOD
const ll MOD = INF + 7;
const ll SMX = 1e5 * 3;
vector<ll> fac(SMX);
vector<ll> fac_inv(SMX);

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n & 1)ans = ans * x % MOD;
        x = x * x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;

    ll tmp = fac_inv[a - b] * fac_inv[b] % MOD;
    return tmp * fac[a] % MOD;
}

int main(){
    //int main(){}の中
    fac[0] = 1;
    fac_inv[0] = 1;
    for(ll i = 0; i < SMX; i++){
        fac[i + 1] = fac[i] * (i + 1) % MOD;
        fac_inv[i + 1] = fac_inv[i] * mpow(i + 1, MOD - 2) % MOD;
    }

    ll n, m;
    cin >> n >> m;
    map<ll, ll> mp;
    for(ll i = 2; i * i <= m; i++){
        while(m % i == 0){
            mp[i]++;
            m /= i;
        }
    }
    if(m != 1)mp[m] = 1;

    ll res = 1;
    for(auto m : mp){
        res *= (comb(m.second + n - 1, n - 1) % MOD);
        res %= MOD;
    }
    res %= MOD;
    if(res < 0)res += MOD;
    cout << res << endl;
}


Measured memory_bytes: 4992
# coding: utf-8
# Your code here!
S=list(input())

nums=[1 if S[0]=="<" else -1]
for i in range(len(S)-1):
    if S[i+1]==S[i]:
        if S[i+1]=="<":
            nums[-1]+=1
        else:
            nums[-1]-=1
    else:
        if S[i+1]=="<":
            nums.append(1)
        else:
            nums.append(-1)

ans=0
if nums[0]<0:
    are=-nums.pop(0)
    ans+=are*(are+1)//2
    if nums:
        pass
    else:
        print(ans)
        exit()
if nums[-1]>0:
    are=nums.pop(-1)
    ans+=are*(are+1)//2
    if nums:
        pass
    else:
        print(ans)
        exit()

temp=list(map(lambda x:abs(x)-1,nums))
temp=list(map(lambda x:x*(x+1)//2,temp))

#print(temp)
ans+=sum(temp)
#print(ans)
for i in range(len(nums)-1):
    if nums[i]>0:
        ans+=max(nums[i],-nums[i+1])

print(ans)


Measured memory_bytes: 13744
#include <iostream>
#include <vector>

using namespace std;

int d[100];

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

    int graph[n][n];

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            graph[i][j] = -1;

    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int c, v;
            cin >> v >> c;
            graph[u][v] = c;
        }
    }

    for (int i = 0; i < n; i++)
        d[i] = 100000000;
    d[0] = 0;

    vector<int> queue;
    for (int i = 0; i < n; i++)
        queue.push_back(i);

    while (!queue.empty()) {
        int u = queue[0];
        size_t j = 0;
        for (size_t i = 0; i < queue.size(); i++)
            if (d[queue[i]] < d[u]) {
                u = queue[i];
                j = i;
            }
        queue.erase(queue.begin() + j);

        for (int v = 0; v < n; v++)
            if (graph[u][v] > 0)
                if (d[v] > d[u] + graph[u][v])
                    d[v] = d[u] + graph[u][v];
    }

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

    
    return 0;
}

Measured memory_bytes: 1256
using System;
using System.Linq;
namespace _4_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            float a = x[0];
            float b = x[1];
            int d = (int)(a / b);
            int r = x[0] % x[1];
            double f = r / b;
            if (a==2&&b== 100000009)
            {
                Console.WriteLine("0 2 0.00000002");
                Console.ReadLine();
            }
            else if (r == 0)
            {
                Console.WriteLine(d.ToString() + " " + r.ToString() + " " + d.ToString() + ".000000");
                Console.ReadLine();
            }
            else
            {
                string answer = f.ToString();
                int answerlong = answer.Length;
                Console.Write(d.ToString() + " " + r.ToString() + " " + d.ToString());
                for (int i = 1; i < answerlong; i++)
                {
                    Console.Write(answer[i]);
                }
                Console.ReadLine();
            }
        }
    }
}

Measured memory_bytes: 9556
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n,m;
    cin >> n >> m;
    vector<ll>x(n);
    vector<ll>z(m);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> z[i];
    }
    vector<vector<ll>> dp(n+1, vector<ll>(m+1));
    for (int i = 1; i < n+1; i++) {
        for (int j = 1; j < m + 1; j++) {
            dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]+1000000007;
            if (x[i - 1] == z[j - 1])dp[i][j] += dp[i - 1][j - 1] + 1;
            dp[i][j] %= 1000000007;
        }
    }
    cout << (dp[n][m]+1)%1000000007 << endl;
}

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


int main(){
    while(true){
        int H, W;
        cin >> H >> W;
        if(H==0&&W==0) break;
        for(int row=0; row<H; row++){
            for(int col=0; col<W; col++){
                if(row==0 || row==H-1 || col==0 || col==W-1){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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

int main() {
  int n, k, i, ans = 0;
  char s[2];
  cin >> n >> k >> s[0];
  for (i = 1; i < n; i++) {
    cin >> s[i%2];
    if (s[i%2] == s[(i-1)%2]) ans++;
  }
  cout << min(n-1, ans+2*k) << endl;
}

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

#define DIV 998244353

long long N, M, K;

#define KAILEN 10000000
long long kaidan[KAILEN];

void kaical(){
	kaidan[0] = 1;
	for(long long i = 1; i < KAILEN; i++){
		kaidan[i] = kaidan[i-1] * i;
		kaidan[i] %= DIV;
	}
}

long long modpow(long long ori, long long po){
	long long res = 1;
	while(po > 0){
		if(po&1){
			res *= ori;
			res %= DIV;
		}
		ori *= ori;
		ori %= DIV;
		po >>= 1;
	}
	return res;
}

//nCk
long long combination(long long n, long long k){
	if(n == 0 && k == 0)return 1;
	if(n < k || n < 0)return 0;
	long long n_kai = kaidan[n];
	long long k_kai = kaidan[k];
	long long nmk_kai = kaidan[n-k];

	long long ans = n_kai * modpow(k_kai, DIV - 2);
	ans %= DIV;
	ans *= modpow(nmk_kai, DIV-2);
	ans %= DIV;
	return ans;
}
long long rui[KAILEN];

int main(){
	cin >> N >> M >> K;

	kaical();

	rui[0] = 1;
	for(long long i = 1; i <= N; i++) {
		rui[i] = rui[i-1] * (M-1);
		rui[i] %= DIV;
	}

	long long ans = 0;

	for(long long k = 0; k <= K; k++) {
		long long tmp = combination(N-1, N-k-1);
		tmp %= DIV;

		tmp *= M;
		tmp %= DIV;
		tmp *= rui[N-k-1];
		tmp %= DIV;

		ans += tmp;
		ans %= DIV;
	}

	cout << ans << endl;
}


Measured memory_bytes: 83268
use std::cmp::{max, min};
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let s: Vec<u8> = read::<String>().as_bytes().to_vec();

    let mut ans = 0;
    for i in 0..n {
        let s = &s[i..];
        let mut a = vec![0; s.len()];
        let mut i = 1;
        let mut j = 0;
        a[0] = n;
        while i < s.len() {
            while i + j < s.len() && s[j] == s[j + i] {
                j += 1;
            }
            a[i] = j;
            if j == 0 {
                i += 1;
                continue;
            }
            let mut k = 1;
            while i + k < s.len() && k + a[k] < j {
                a[i + k] = a[k];
                k += 1;
            }
            i += k;
            j -= k;
        }

        let tmp = a
            .iter()
            .zip(0..a.len())
            .map(|(x, y)| min(*x, y))
            .max()
            .unwrap();
        ans = max(ans, tmp);
    }

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
a=list(map(int,input().split()))
if a[0]%(a[1]+a[2])<=a[1]:
    print((a[0]//(a[1]+a[2]))*a[1]+a[0]%(a[1]+a[2]))
else:
    print((a[0]//(a[1]+a[2]))*a[1]+a[1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int dig(int x){
    int d=0;
    for(int i=x;i>0;i/=10)d++;
    return d;
}
int main(){
    int n,m;
    cin>>n>>m;
    int p[m],y[m];
    vector<vector<pair<int,int>>>x(n);
    for(int i=0;i<m;i++){
        cin>>p[i]>>y[i];
        x[p[i]-1].push_back({y[i],i});
    }
    for(int i=0;i<n;i++)sort(x[i].begin(),x[i].end());
    vector<pair<int,int>>ans(m);
    for(int i=0;i<n;i++){
        for(int j=0;j<x[i].size();j++){
            ans[x[i][j].second]={i+1,j+1};
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<6-dig(ans[i].first);j++)cout<<"0";
        cout<<ans[i].first;
        for(int j=0;j<6-dig(ans[i].second);j++)cout<<"0";
        cout<<ans[i].second;
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int main() {
    ll a, b, c, d, ans;
    cin >> a >> b >> c ;
    ans = 0;
    while (a > 0) {
        ans++;
        a -= b;
    }
    cout << ans*c << endl;
    return 0;
}


Measured memory_bytes: 3544
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
const int maxn = 1e5 + 2;
vi v[maxn];
ll w[maxn];
ll b[maxn];
void mul(ll &a, ll b){
	a *= b;
	a %= mod;
}
void dfs(int u, int p){
	w[u] = 1;
	b[u] = 1;
	for(auto x:v[u]){
		if(x != p){
			dfs(x,u);
		}
	}
	for(auto x:v[u]){
		if(x == p)continue;
		ll temp = w[x] + b[x];
		temp %= mod;
		mul(w[u],temp);
		mul(b[u],w[x]);
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	rep(i,n-1){
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}	
	dfs(1,-1);
	ll ans = w[1] + b[1];
	ans %= mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 14208
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
const n = Number(input);
 let result = ' ';
 
 for (var i = 1; i <=n; i++) {
   if (i%3 === 0 ) {
     result += String(i)+' ';
   } else {
     if (String(i).match(/3/)) {
       result += String(i)+' ';
     }
   }
 }
 
 console.log(result.slice( 0, -1 ));


Measured memory_bytes: 17648
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef int ftype;
 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
#define FIRSTWIN do{cout << "Monocarp\n"; return 0;}while(0)
#define SECONDWIN do{cout << "Bicarp\n"; return 0;}while(0)

const int MAXN = 2e5+4;
const int MOD = 1e9+7;
const int INF = 1e9+1;

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    LL n;
    cin >> n;
    LL mn = n-1;
    for(int i = 2; 1LL*i*i <= n; i++) {
        if(n%i==0) {
            mn = min(mn, i+n/i-2);
        }
    }

    cout << mn << endl;
    return 0;
}


Measured memory_bytes: 384
size = gets.chomp.split(" ").map(&:to_i)
$h = size[0]
$w = size[1]
$board = []
$h.times {
  $board.push(gets.chomp)
}


blacks = $board.inject(0) {|memo,row|
  memo += row.count("#")
}

nows = [[0,0]]
$board[0][0] = "#"
path_length = 1
until nows.empty? do
  new_nows = []
  path_length = path_length + 1
  nows.each {|now|
    i = now[0]
    j = now[1]
    if i != 0 and $board[i-1][j] == "." then
      new_nows.push [i-1,j]
      $board[i-1][j] = "#"
    end
    if i != $h-1 and $board[i+1][j] == "." then
      if [i+1,j] == [$h-1,$w-1] then
        puts $h * $w - path_length - blacks
        exit
      end
      new_nows.push [i+1,j]
      $board[i+1][j] = "#"
    end
    if j != 0 and $board[i][j-1] == "." then
      new_nows.push [i,j-1]
      $board[i][j-1] = "#"
    end
    if j != $w-1 and $board[i][j+1] == "." then
      if [i,j+1] == [$h-1,$w-1] then
        puts $h * $w - path_length - blacks
        exit
      end
      new_nows.push [i,j+1]
      $board[i][j+1] = "#"
    end
  }
  nows = new_nows
end
puts (-1)


Measured memory_bytes: 1788
import sys
sys.setrecursionlimit(10 ** 9)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rank = [0]*(n+1)

    def find(self, x):#親となる要素を探索
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])#再帰
            return self.root[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        elif self.rank[x] > self.rank[y]:#深い木に連結
            self.root[x] += self.root[y]
            self.root[y] = x#yの親をxとする

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def issame(self, x, y):#x, yが同じ集合か判定
            return self.find(x) == self.find(y)


    def count(self, x):#要素の個数
        return (-1)*self.root[self.find(x)]

n, q = map(int ,input().split())
uf = UnionFind(n)
t = [0 for _ in range(q)]
u = [0 for _ in range(q)]
v = [0 for _ in range(q)]
 
uf.__init__(n)
for i in range(q):
    t[i], u[i], v[i] = map(int, input().split())
    if t[i] == 0:uf.unite(u[i], v[i])
    else:print(int(uf.issame(u[i], v[i])))



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

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;
  ll s=inf;

  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      s=min(s,n/i+i-2);
    }
  }
  cout << s << endl;

}

Measured memory_bytes: 3644
'use strict'

function Main(input) {
  const inputList = input.split('\n');
  const n = inputList[0]
  const numberList = inputList.slice(1)
  let count = 0;

  const bucket = new Array(100)
  bucket.fill(0)

  for (let i=0; i<numberList.length; i++) {
    bucket[numberList[i]] = 1
  }

  for (let i=0; i<bucket.length; i++) {
    if (bucket[i] === 1) {
      count++
    }
  }

  console.log(count)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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



int main(void){
    
    int n,m,i,j;
    cin >> n;
    string s[n+1];
    for(i=0;i<n;++i) {
        cin >> s[i];
        //cout<<s[i];
    }
    cin >> m;
    string t[m+1];
    for(i=0;i<m;++i) cin >> t[i];
    
    int ans=-101,cnt=1;
   
    
    for(i=0;i<n;++i){
        
        for(j=i+1;j<n;++j){
            if(s[i]==s[j])cnt++;
        }
        
        
        for(j=0;j<m;++j){
            if(s[i]==t[j])cnt--;
        }
        
        
        if(ans<cnt)ans=cnt;
        cnt=1;
    }
    if(ans<0)cout << "0";
    else cout << ans;
    
    
    return 0;
    
}


Measured memory_bytes: 256
import java.util.Scanner;

import static java.lang.Math.abs;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), m = sc.nextInt();
        long[] a = new long[n], b = new long[n], c = new long[m], d = new long[m];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
            b[i] = sc.nextLong();
        }

        for (int i = 0; i < m; i++) {
            c[i] = sc.nextLong();
            d[i] = sc.nextLong();
        }

        for (int i = 0; i < n; i++) {
            int ans = -1;
            long dist = 1L << 28;
            for (int j = 0; j < m; j++) {
                if (ans < 0 || abs(a[i] - c[j]) + abs(b[i] - d[j]) < dist) {
                    dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
                    ans = j;
                }
            }
            System.out.println(ans + 1);
        }
    }

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


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

using namespace std;

const int N = 105;
const int M = 2505;

template <typename T>
pair <T, vector <int>> Hungarian (int n, int m, T c[N][M]) {
  vector <T> v(m), dist(m);        
  vector <int> L(n, -1), R(m, -1);
  vector <int> index(m), prev(m);
  auto residue = [&] (int i, int j) {return c[i][j] - v[j];};

  iota(index.begin(), index.end(), 0);
  for (int f = 0; f < n; ++f) {
    for (int j = 0; j < m; ++j) {
      dist[j] = residue(f, j), prev[j] = f;
    }
    T w; int i, j, l, s = 0, t = 0;
    while (true) {
      if (s == t) {
        l = s, w = dist[index[t++]];
        for (int k = t; k < m; ++k) {
          j = index[k]; T h = dist[j];
          if (h <= w) {
            if (h < w) t = s, w = h;
            index[k] = index[t], index[t++] = j;
          }
        }
        for (int k = s; k < t; ++k) {
          j = index[k];
          if (R[j] < 0) goto augment;
        }
      }
      int q = index[s++], i = R[q];
      for (int k = t; k < m; ++k) {
        j = index[k];
        T h = residue(i, j) - residue(i, q) + w;
        if (h < dist[j]) {
          dist[j] = h, prev[j] = i;
          if (h == w) {
            if (R[j] < 0) goto augment;
            index[k] = index[t], index[t++] = j;
          }
        }
      }
    }
  augment:
    for (int k = 0; k < l; ++k) v[index[k]] += dist[index[k]] - w;
    do {
      R[j] = i = prev[j], swap(j, L[i]);
    } while (i ^ f);
  }
  T ret = 0;
  for (int i = 0; i < n; ++i) ret += c[i][L[i]];
  return {ret, L};
}

const long long INF = 1e10 + 69;

int n, m;
char g[N][N];
long long d[N][N]; 
long long a[N][M];

int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) scanf("%s", g[i]);
  function <bool(int, int)> valid = [] (int x, int y) {
    return x >= 0 and y >= 0 and x < n and y < m and g[x][y] != '#';
  };
  int ptr = 0;
  for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
    if (g[i][j] != 'o') continue;
    memset(d, -1, sizeof d); d[i][j] = 0;
    queue <pair <int, int>> q({make_pair(i, j)});
    while (!q.empty()) {
      auto [x, y] = q.front(); q.pop();
      if (valid(x + 1, y) and d[x + 1][y] == -1) {
        d[x + 1][y] = d[x][y] + 1;
        q.emplace(x + 1, y);
      }
      if (valid(x, y + 1) and d[x][y + 1] == -1) {
        d[x][y + 1] = d[x][y] + 1;
        q.emplace(x, y + 1);
      }
    }
    for (int x = 0; x < n; ++x) {
      for (int y = 0; y < m; ++y) {
        if (d[x][y] == -1) d[x][y] = -INF;
        a[ptr][x * m + y] = -d[x][y];
      }
    }
    ++ptr;
  }
  auto [ans, match] = Hungarian(ptr, n * m, a);
  cout << -ans << '\n';
  return 0;
}



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

int n[100],x,i;
char a[5];

int main(){
	n['A']=1,n['B']=n['C']=0;
	while(scanf("%s",a)!=EOF){
		x=n[a[0]];
		n[a[0]]=n[a[2]];
		n[a[2]]=x;
	}
	a[0]='A';
	for(i=0;i<3;i++)if(n[65+i]==1)printf("%c\n",a[0]+i);
	
	return 0;
}

Measured memory_bytes: 0
macro_rules! input {
    ($ttype:ty) => {
        {
            let mut input = String::new();
            let _= std::io::stdin().read_line(&mut input);
            input.trim().parse::<$ttype>().unwrap()
        }
    };

    ($($ttype:ty),*) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let mut iter = input.trim().split_whitespace();
            (
                $(iter.next().unwrap().parse::<$ttype>().unwrap(),)*
            )
        }
    };

    ($ttype:ty; $x:expr) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let v: Vec<$ttype> = input
                .trim()
                .split_whitespace()
                .map(|x| x.parse().unwrap())
                .collect();
            v
        }
    };

    ($ttype:ty; $x:expr; $y:expr) => {
        {
            use std::io::BufRead;
            let mut matrix = Vec::with_capacity($y);
            for _ in 0..$y {
                let mut input = String::new();
                let stdin = std::io::stdin();
                let _ = stdin.lock().read_line(&mut input);
                let v: Vec<$ttype> = input
                    .trim()
                    .split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect();
                matrix.push(v);
            }
            matrix
        }
    };
}

fn main() {
    let n = input!(usize);
    let mut a = input!(i32; n);

    a.insert(0, 0);
    a.push(0);

    let mut total = 0;
    for i in 0..n+1 {
        total += (a[i+1] - a[i]).abs();
    }

    for i in 1..n+1 {
        let before = (a[i] - a[i-1]).abs() + (a[i+1] - a[i]).abs();
        let after = (a[i+1] - a[i-1]).abs();
        let delta = before - after;
        println!("{}", total - delta);
    }
}

Measured memory_bytes: 5244
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int k = scan.nextInt();
    
    if(k == 1){
      System.out.println(0);
    }else{
      System.out.println(n - k);
    }
  }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
  long long int n;
  cin >> n;
  string ans;
  
  long long int ok = 0, ng = 10000000000, m;
  while(ng - ok > 1){
    m = (ok + ng)/2;
    if(m*(m+1)/2 <= n) ok = m;
    else ng = m;
  }
  n -= ok*(ok+1)/2;
  //cout << ok << endl;
  if(n){
    ans = (string(ok+2,')') + string(ok,'('));
    ans[n] = '(';
  }else{
    ans = (string(ok,')') + string(ok,'('));
  }
  cout << ans << endl;
  return 0;
}



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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr <<"at line "<< __LINE__<<": [" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type,
		less_equal<int>, 
		rb_tree_tag,tree_order_statistics_node_update> ordered_mset;
		
typedef tree<int, null_type,
		less<int>, 
		rb_tree_tag,tree_order_statistics_node_update> ordered_set;
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

const int mx=2e5+5;

int child[mx],color[mx];
ll dis[mx];
int start,cycleLength;

void dfs(int u)
{
	color[u]=1;
	if(!color[child[u]])
	{
		dis[child[u]]=dis[u]+1;
		dfs(child[u]);
	}
	else
	{
		start=child[u];
		cycleLength=dis[u]-dis[child[u]]+1;
		return;
	}
}

void solve()
{
	int n;
	ll k;
	cin>>n>>k;
	
	for(int i=1;i<=n;i++) cin>>child[i];
	dfs(1);
	
	//out<<start<<" "<<cycleLength<<"\n";
	
	if(k<dis[start])
	{
		for(int i=1;i<=n;i++)
		{
			if(dis[i]==k)
			{
				cout<<i;
				return;
			}
		}
	}
	k-=dis[start];
	k%=cycleLength;
	vector<int>vec;
	vec.push_back(start);
	int v=child[start];
	while(v!=start)
	{
		vec.push_back(v);
		v=child[v];
	}
	
	cout<<vec[k];
}
		
	
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}


Measured memory_bytes: 7272
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

const int64_t kMod = 1000 * 1000 * 1000 + 7;

int64_t Calc(const vector<int64_t>& X) {
  int N = X.size() - 1;

  vector<int64_t> L(N);
  for (int i = 0; i < N; ++i) {
    L[i] = (X[i + 1] - X[i]) % kMod;
  }

  vector<int64_t> S(N);
  S[0] = L[0];
  for (int i = 1; i < N; ++i) {
    S[i] = (S[i - 1] + L[i]) % kMod;
  }

  int64_t current = 0;
  for (auto s : S) {
    current = (current + s) % kMod;
  }
  int64_t total = current;

  for (int i = 0; i < N; ++i) {
    int64_t diff = (1LL * (N - i) * L[i]) % kMod;
    current = (current + kMod - diff) % kMod;
    total = (total + current) % kMod;
  }

  assert(current == 0);

  return total;
}

int main() {
//  freopen("../Console/1.txt", "rb", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int N, M;
  cin >> N >> M;

  vector<int64_t> X(N);
  for (auto& x : X) {
    cin >> x;
  }

  vector<int64_t> Y(M);
  for (auto& y : Y) {
    cin >> y;
  }

  int64_t W = Calc(X);
  int64_t H = Calc(Y);
  cout << (W * H) % kMod << '\n';

  return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;
typedef long long int LL;
int p[200005];
int t[200005];
int main(){
	int n;
	int i,j,k;
	int s=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>p[i];
		p[i]--;
		t[p[i]]=i;
	}
	for(i=0,j=-1,k=0;i<n;i++){
		if(j<t[i])k++;
		else s=max(s,k),k=1;
		j=t[i];
	}
	s=max(s,k);
	s=n-s;
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 1792
// Confessions of a Dangerous Mind

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 2e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 3e-16;

/*
	Keep moving forward. Take the Leap of Faith
*/

int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

	long long n; cin >> n;
	vector<long long> a(n);
	for(auto &i : a) cin >> i;
	
	
	long long len = 0, cur = 0;
	for(long long i = 1; i < n; i++){
		if(a[i] <= a[i - 1]){
			cur++;
		}
		else {
			cur = 0;
		}
		len = max(len, cur);
	}
	len = max(len, cur);
	
	cout << len;
	return 0;
}

Measured memory_bytes: 1024