akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>

#define EPS (1e-8)

using namespace std;

int main() {
  int n;
  double x1, x2, x3, y1, y2, y3;
  double a1, a2, b1, b2, c1, c2;
  double x, y, r;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    a1 = 2*(x2 - x1);
    b1 = 2*(y2 - y1);
    c1 = x1*x1 - x2*x2 + y1*y1 - y2*y2;

    a2 = 2*(x3 - x1);
    b2 = 2*(y3 - y1);
    c2 = x1*x1 - x3*x3 + y1*y1 - y3*y3;

    x = (b1*c2 - b2 * c1) / (a1*b2 - a2*b1) + EPS;
    y = (c1*a2 - c2*a1) / (a1*b2 - a2*b1) + EPS;
    r = sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1)) + EPS;
    cout << fixed << setprecision(3) << x << " " << y << " " << r << endl;
  }
  return 0;
}

Measured memory_bytes: 1288
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

#Union-Find ****0スタートなので注意！****
class UnionFind():
  # 作りたい要素数（ノードの数）nで初期化
  # 使用するインスタンス変数の初期化
  def __init__(self, n):
    self.n = n
    # root[x]<0ならそのノードが根かつその値が木の要素数
    # rootノードでその木の要素数を記録する
    self.root = [-1]*(n) #元々はn+1になっていたが、nに直した
    # 木をくっつける時にアンバランスにならないように調整する
    self.rnk = [0]*(n) #元々はn+1になっていたが、nに直した

  # ノードxのrootノードを見つける
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
      # ついでに経路圧縮（調べた辺を根に直接つなぎ直す）をかけておく
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

  # 木の併合、入力は併合したい集合に属する各ノード
  def Unite(self, x, y):
    # 入力ノードのrootノードを見つける
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    # すでに同じ木に属していた場合、何もしないで返す
    if(x == y):
      return
    # 違う木に属していた場合rnkを見てくっつける方を決める
    elif(self.rnk[x] > self.rnk[y]):
      self.root[x] += self.root[y] #要素数を足す(根のrootは"-要素数")
      self.root[y] = x #ノードyの親をx（新しい集合の根）とする
    else:
      self.root[y] += self.root[x] #要素数を足す
      self.root[x] = y
      # rnkが同じ（深さに差がない場合）は1増やす（根(rnk1)+繋げる集合のrnkということで、1増えることになる）
      if(self.rnk[x] == self.rnk[y]):
          self.rnk[y] += 1

  # xとyが同じグループに属するか判断
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  # ノードxが属する木のサイズを返す（根ノードの.root[idx]を-符号を外して返すだけ
  def Count(self, x):
    return -self.root[self.Find_Root(x)] #-符号を外す

  # 木の数（＝集合の数）を返す（根の数=rootに-符号を持つものの数を返すだけ）
  def Count_Trees(self):
    treecnt = 0
    for eachroot in self.root:
      if eachroot < 0: treecnt += 1
    return treecnt
#------Union-Findおわり-------------#

import collections

N = int(input())
XYs = [tuple(mi()) for _ in range(N)]

if N==1:
  print(1)
  exit()
if N==2:
  print(1)
  exit()

sa_list = []
cmb_with_same_diff = collections.defaultdict(list)
import itertools
diffidx = 0
for a in range(0, N):
  for b in range(0, N):
    if a>=b: continue
    #ここでa, bは各ボールのidx
    ax, ay = XYs[a]
    bx, by = XYs[b]
    if ax-bx==0: nowsa = (ax-bx,abs(ay-by))
    elif ay-by==0: nowsa = (abs(ax-bx), ay-by)
    elif ax-bx>0: nowsa = (ax-bx,ay-by)
    else: nowsa = (-(ax-bx),-(ay-by))
    sa_list.append(nowsa)
    cmb_with_same_diff[nowsa].append((a, b))

#print(sa_list)
#print(cmb_with_same_diff)

#最も多い差の個数（これ-1を短縮できるはず）
print(N-collections.Counter(sa_list).most_common()[0][1])

#[((x, y), 回数), ...]　多い順で入っている
#sa_sorted = collections.Counter(sa_list).most_common()

ans = N
for each_samesa_list in cmb_with_same_diff.values():
  UF = UnionFind(N) #ノード数はボールの数
#  print(each_samesa_list, 'における処理前の木の数は', UF.Count_Trees())
  for a, b in each_samesa_list:
    UF.Unite(a, b)
#  print(each_samesa_list, 'における処理後の木の数は', UF.Count_Trees())
  ans = min(ans, UF.Count_Trees())

#print(ans)



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

///////////////////////////////////////////
//const long long int INF = 1000000000000000000LL;
const long long int INF = 1000000;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(    v[0])>()) //降順でVをソート
///////////////////////////////////////////

int main(){
    int a,b;cin>>a>>b;
    if((a*b) % 2 == 1){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
    author:@bhaskar_8998
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds; 
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;  
typedef long long i64;
typedef vector<int> vi;
typedef vector<long> vl;
typedef pair<int,int>pii;
#define all(A) (A).begin(),(A).end()
#define pb push_back
#define MOD 1000000007
#define fastio() {ios_base::sync_with_stdio(false);cin.tie(NULL);}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    fastio();
    i64 ss[31];
    for(int i=1,ts=2;i<=30;i++){
        ss[i]=ts;
        ts*=2;
    }
    clock_t beg=clock();
    int t=1;
    // cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        int h[n];
        for(int i=0;i<n;i++)cin>>h[i];
        vector<vi> v(n);
        for(int i=0;i<m;i++){
            int a,b;
            cin>>a>>b;
            v[a-1].pb(h[b-1]);
            v[b-1].pb(h[a-1]);
        }
        for(int i=0;i<n;i++)sort(all(v[i]),greater<int>());
        int ans=0;
        for(int i=0;i<n;i++){
            if(v[i].size()==0){
                ans+=1;
                continue;
            }
            if(h[i]>v[i][0])ans+=1;
        }     
        cout<<ans;

    }

    clock_t end=clock(); 
    fprintf(stderr, "\n%lf sec\n", (double)(end-beg)/(CLOCKS_PER_SEC));
    return 0;
}


    

Measured memory_bytes: 8712
#include<stdio.h>
#include<stdlib.h>
#define N 3
#define D 100

struct node{
  int data[N][N];
  struct node *p;
};
struct xy{
  int x;
  int y;
};

struct node root;
int mv[4][2]={0,1,0,-1,-1,0,1,0};

int man(int n,int x,int y){
  int nx, ny;

  nx=(n-1)%N;
  ny=(n-1)/N;
  x=x-nx;
  if(x<0)
   x*=-1;
 y=y-ny;
 if(y<0)
   y*=-1;
 return x+y;
}

int judge(struct node *n){
  int i, j=0;
  if(n==NULL)
   return -1;
 for(i=0;i<N*N;i++){
  if(n->data[i%N][i/N]==0)
   continue;
 if(n->data[i%N][i/N]!=i+1) 
  j+=man(n->data[i%N][i/N],i%N,i/N);
}

return j;
}

struct xy blank(struct node *n){
  struct xy ddd;
  int i;

  for(i=0;i<N*N;i++)
    if(n->data[i%N][i/N]==0)
     break;

   ddd.x=i%N;
   ddd.y=i/N;

   return ddd;
 }

struct node *mk(struct node *n,struct xy b, struct xy m){
  struct node *aaa;
  int i;
  
  aaa=malloc(sizeof(struct node));

  for(i=0;i<N*N;i++) 
    aaa->data[i%N][i/N]=n->data[i%N][i/N];
  
  aaa->data[b.x][b.y]=aaa->data[m.x][m.y];
  aaa->data[m.x][m.y]=0;
  aaa->p=n;
  return aaa;
}

int puzzle(struct node *n,struct node *bp, int g,int d){
  int h=judge(n), i, j;
  struct xy bl, m;
  struct node *mm;
  
  if(h==0)
   return g;
 if(g+h>d) 
  return -1;
bl=blank(n);
for(i=0;i<4;i++){
  m.x=bl.x+mv[i][0];
  m.y=bl.y+mv[i][1];
  if(m.x<0 || m.y<0 || m.x==N || m.y==N ) 
    continue;
  mm=mk(n,bl,m);
  if(bp!=NULL){
    for(j=0;j<N*N;j++)
      if(mm->data[j%N][j/N]!=bp->data[j%N][j/N])
       break;
     if(j==N*N){
      free(mm);
      continue;
    }
  }  
  j=puzzle(mm,mm->p,g+1,d);
  if(j>0) return j;
}
return -1;
}

int main(){
  int i, ans;
  struct node *n, *m;
  for(i=0;i<N*N;i++)
   scanf("%d",&root.data[i%N][i/N]);
 root.p=NULL;
 for(i=judge(&root);i<=D;i++){
  ans=puzzle(&root,NULL,0,i);
  if(ans>0) break;
}
printf("%d\n",ans);
return 0;
}



Measured memory_bytes: 6896
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
		int c = x;
		for (int i = 1; i < 11; i++) {
			System.out.println(r * c - d);
			c = r * c - d;
		}

	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int N,a,X[100003];
int main(){
    scanf("%d",&N);
    for(int i{};i<N;++i){
        scanf("%d",&a);
        ++X[a],++X[a+1],++X[a+2];
    }
    printf("%d\n",*max_element(X,X+100003));
}


Measured memory_bytes: 640
def input_one_number():
    return int(input())
 
def input_multiple_number():
    return map(int, input().split())
 
def input_multiple_number_as_list():
    return list(map(int, input().split()))
MOD=1000000000 + 7
ans=0
a_min=0

n=input_one_number()
a=input_multiple_number_as_list()
a_sum=sum(a)
for i in range(n):
    a_min+=a[i]
    ans+=a[i]*(a_sum-a_min)
    ans=ans%MOD
print(ans)

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

int main(){
  int x;
  cin >> x;
  if(x < 600) cout << 8 << endl;
  else if(x < 800) cout << 7 << endl;
  else if(x < 1000) cout << 6<< endl;
  else if(x < 1200) cout << 5<< endl;
  else if(x < 1400) cout << 4<< endl;
  else if(x < 1600) cout << 3 <<endl;
  else if(x < 1800) cout << 2 << endl;
  else cout << 1 << endl;
  
  return 0;
}


Measured memory_bytes: 3544
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 要素の入力、格納
		String ans = "Three";
		int N = sc.nextInt();
		for (int i = 0; i < N; i++) {
			if (sc.next().equals("Y")) {
				ans = "Four";
			}

		}

		// 出力
		System.out.println(ans);
	}
}


Measured memory_bytes: 22868
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバルに持っていく
// 深さ優先探索
using Graph=vector<vector<ll>>;
vector<bool> seen;
vector<ll> a;
vector<ll> dp; //dp

stack<pair<ll,ll>> sta;
vector<ll> ans;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする
    ll idx=lower_bound(dp.begin(),dp.end(),a[v])-dp.begin();
    ll tmp=dp[idx];
    dp[idx] = a[v];
    
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
    ans[v]=lower_bound(dp.begin(),dp.end(),INF)-dp.begin();
    dp[idx]=tmp;
    
}


int main(){
    ll N;
    cin>>N;
    Graph G(N);
    a.assign(N, 0);
    REP(i,N) cin>>a[i];
    REP(i,N-1){
        ll u,v;
        cin>>u>>v;
        u--;
        v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    // 頂点0スタート
    seen.assign(N, false); // 全頂点を「未訪問」に初期化
    dp.assign(N+1, INF);
    ans.assign(N+1, 1);
    dfs(G, 0);
    REP(i,N){
        cout<<ans[i]<<endl;
    }
}


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

int main() {
  int N;
  cin >> N;
  const int N_max = 110;
  int d, e[N_max];

  for (int i=0; i < N_max; ++i) e[i] = 0;
  
// read
  for (int i=0; i < N; ++i) {
    cin >> d;
    e[d] = 1;
  }
  //sort(d, d + N, greater<int>());
  int cnt = 0;
  for (int i=0; i < N_max; ++i) {
    if (e[i] > 0) cnt += e[i];
  }
    cout << cnt << endl;
  return 0;
}


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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define mp make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front 
#define pb push_back
#define pp push
#define lb lower_bound 
#define ub upper_bound

const int MOD=1e9+7;



ll  n, m, p;
ll Ext_gcd(ll a, ll b, ll &x, ll &y) 
{
	if (b == 0) { x = 1, y = 0; return a; }
	ll ret = Ext_gcd(b, a%b, y, x);
	y -= a / b * x;
	return ret;
}
ll Inv(ll a, int m) 
{   
	ll d, x, y, t = (ll)m;
	d = Ext_gcd(a, t, x, y);
	if (d == 1) return (x%t + t) % t;
	return -1;
}
 
ll Cm(ll n, ll m, ll p)  
{
	ll a = 1, b = 1;
	if (m > n) return 0;
	while (m)
	{
		a = (a*n) % p;
		b = (b*m) % p;
		m--;
		n--;
	}
	return (ll)a*Inv(b, p) % p;  
}
 
int Lucas(ll n, ll m, ll p)  
{
	if (m == 0) return 1;
	return (ll)Cm(n%p, m%p, p)*(ll)Lucas(n / p, m / p, p) % p;
}

ull fast_mi(int p)
{
	if(p==0)
		return 1LL;
	ull tmp=fast_mi(p>>1);
	tmp*=tmp;
	tmp%=MOD;
	if(p&1)
		tmp*=2LL;
	tmp%=MOD;
	return tmp;
}

int n2,a,b;

int main() {
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>n2>>a>>b;
    ull ans=fast_mi(n2);
    ans=(ans-Lucas(n2,a,MOD)+MOD)%MOD;
	ans=(ans-Lucas(n2,b,MOD)+MOD)%MOD;
	ans=(ans-1LL+MOD)%MOD;
	cout<<ans<<endl; 
    /* end code */
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;
struct edge
{
	int to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
//int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
//bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
//int index(int x, int y, int w) { return w*x + y; }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

typedef complex<double> Point;
struct Circle
{
	Point p; double r; int color;
	Circle(Point a, double b, int c) :p(a), r(b), color(c) {};
};

bool isis_cc(Circle c1, Circle c2)
{
	double d = abs(c1.p - c2.p);
	return (d-c1.r-c2.r < -EPS);
}

int n;
vector<Circle> cs;
map<int, int> mp;

int solve(int bit)
{
	if (mp.find(bit) != mp.end()) return mp[bit];
	vector<vi> v(4);
	vi c;
	REP(i, n)
	{
		if ((bit >> i) & 1) c.push_back(i);
	}
	for (int i = c.size() - 1; i >= 0; i--)
	{
		Circle tmp = cs[c[i]];
		bool f = true;
		FOR(j, i + 1, c.size())
		{
			if (isis_cc(tmp, cs[c[j]])) f = false;
		}
		if (f) v[tmp.color].push_back(c[i]);
	}
	bool isend = true;
	REP(i, 4)
	{
		if (v[i].size() > 1) isend = false;
	}
	if (isend) return 0;
	int res = 0;
	REP(i, 4)REP(j, v[i].size())REP(k, j)
	{
		int copy = bit;
		copy ^= (1 << v[i][j]);
		copy ^= (1 << v[i][k]);
		chmax(res, solve(copy) + 2);
	}
	return mp[bit] = res;
}

int main()
{
	while (cin >> n, n)
	{
		cs.clear();
		mp.clear();
		REP(i, n)
		{
			int x, y, r, c;
			cin >> x >> y >> r >> c;
			c--;
			cs.push_back(Circle(Point(x, y), r, c));
		}
		reverse(ALL(cs));
		int bit = (1 << n) - 1;
		cout << solve(bit) << endl;
	}
	return 0;
}

Measured memory_bytes: 50416
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
#define ALL(x) (x).begin(),(x).end()
const int INF = INT_MAX;

signed main(){
	int N;
	cin >> N;
	vector<vector<int>> edge(N);
	for(int i=0;i<N;i++) {
		string s;
		cin >> s;
		for(int j=i+1;j<N;j++) {
			if(s[j] == '1') {
				edge[i].push_back(j);
				edge[j].push_back(i);
			}
		}
	}
	int ans = -1;
	for(int st=0;st<N;st++) {
		bool flag = true;
		queue<pii> q;
		vector<int> dist(N, INF);
		q.push({st,1});
		while(!q.empty()) {
			int now = q.front().first;
			int v = q.front().second;
			q.pop();
			// cout << now << " " << v << endl;
			if(dist[now] != INF) {
				if((v + dist[now]) % 2 != 0) {
					flag = false;
					break;
				}
				continue;
			}
			dist[now] = v;
			for(int i=0;i<edge[now].size();i++) {
				int next = edge[now][i];
				q.push({next, v + 1});
			}
		}
		if(!flag) break;
		int tmp_ans = -1;
		for(int j=0;j<N;j++) {
			tmp_ans = max(tmp_ans, dist[j]);
		}
		ans = max(ans, tmp_ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 768
def calc(N):
    L=[]
    for i in range(1,int(N**0.5) + 1):
        if(N%i==0):
            L.append(i)
            if(N//i>i):
                L.append(N//i)
    L=sorted(L)
    return L

N=int(input())
L=calc(N)
s=0
for num in L:
    if(num<=2):
        continue
    if(N//(num-1)==N%(num-1)):
        s+=(num-1)

print(s)


Measured memory_bytes: 39152
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n;
ll h[N];
ll dp[N];

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   dp[1] = 0;
   for (int i = 1; i <= n; i ++) cin >> h[i];
   for (int i = 2; i <= n; i ++) dp[i] = inf;
   for (int i = 1; i <= n; i ++) {
      if (i + 1 <= n) dp[i + 1] = min (dp[i + 1], dp[i] + abs (h[i] - h[i + 1]));
      if (i + 2 <= n) dp[i + 2] = min (dp[i + 2], dp[i] + abs (h[i] - h[i + 2]));
   }
   cout << dp[n];
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 3072
#include <stdio.h>


int main()
{
    int i,N,k,h,s=0;
    scanf("%d %d", &N, &k);
    int polje[N];
    for (i=0;i<N;i++){
        scanf("%d", &polje[i]); 
    }
    for (i=0;i<N;i++){
       if (polje[i]>=k) s++;
       }
    printf("%d", s);   
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mods = 1E9 + 7;
int frac[200500] = {1}, ifac[200500];
signed main()
{
	int n = 0, m = 0, a = 0, b = 0;
	cin >> n >> m >> a >> b;
	for(int i = 1; i <= 200000; i++) frac[i] = frac[i - 1] * i % mods;
	ifac[200000] = 1; for(int i = frac[200000]; i > 1; i = mods % i) ifac[200000] = ifac[200000] * (mods - mods / i) % mods;
	for(int i = 200000; i; i--) ifac[i - 1] = ifac[i] * i % mods;
	#define C(a,b) (frac[(a)+(b)]*ifac[a]%mods*ifac[b]%mods)
	int ans = C(n - 1, m - 1);
	for(int i = 1; i <= b; i++)
		ans = (ans + mods - C(n - a - 1, i - 1) * C(a - 1, m - i) % mods) % mods;
	cout << ans << endl;
	return 0;
}

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

typedef long long int integer;

integer dp[108][21];

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }

  dp[0][v[0]] = 1;
  for (int i = 1; i < N - 1; i++) {
    for (int j = 0; j < 21; j++) {
      if (j + v[i] <= 20) {
        dp[i][j+v[i]] += dp[i-1][j];
      }

      if (j - v[i] >= 0) {
        dp[i][j-v[i]] += dp[i-1][j];
      }
    }
  }

  cout << dp[N - 2][v[N-1]] << endl;
}

Measured memory_bytes: 1208
--import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU

main = do
    [n,x,y] <- map read.words <$> getLine :: IO [Int]
    VU.mapM_ print $ answer n x y

answer :: Int -> Int -> Int-> VU.Vector Int
answer n x y = VU.accum (+) (VU.replicate (n-1) 0) [len (i,j) | i <- [1..n-1], j <- [(i+1)..n]] where
    len (i,j) = (minimum [abs (j-i), routexy, routeyx]-1, 1) where
        routexy = abs (x-i) + 1 + abs (y-j)
        routeyx = abs (y-i) + 1 + abs (x-j)

Measured memory_bytes: 2428
'use strict';

function Main(INPUT) {
    const input = INPUT.split("\n")[0].split(" ");
    const A = parseInt(input[0], 10);
    const B = parseInt(input[1], 10);
    const C = parseInt(input[2], 10);
    if (C >= A && C <= B) {
        console.log("Yes");
    } else {
        console.log("No");
    }
}

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


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

int main() {
  int x1, y1, x2, y2, x3, y3, x4, y4;
  cin >> x1;
  cin >> y1;
  cin >> x2;
  cin >> y2;

  // ベクトルを計算する
  int dx = x2 - x1;
  int dy = y2 - y1;

  // 三つめの点はベクトルを 2/pi 回転させたものなので
  x3 = x2 - dy;
  y3 = y2 + dx;

  // 四つめの点はベクトルを pi 回転させたものなので
  x4 = x3 - dx;
  y4 = y3 - dy;

  cout << x3 << " " << y3 << " " << x4 << " " << y4 <<  endl;
  return 0;
}


Measured memory_bytes: 256
var a:array[1..100]of longint;
    n,m,s,i,x,y:longint;
begin
 readln(n);
 for i:=1 to n do begin read(a[i]); s:=s+a[i]; end;
 readln;
 readln(m);
 for i:=1 to m do begin readln(x,y); writeln(s+(y-a[x])); end;
end.

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

struct UF{
    const int node_num;
    vector<int> parent;
    vector<int> size;

    UF(int N) : node_num(N), parent(N), size(N, 1) {
        for(int i = 0; i < N; ++i) parent[i] = i;
    }

    //xの根を得る
    int root(int x){
        if(parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }

    //xが属する木とyが属する木を一つに合わせる
    void unite(int x, int y){
        int root_x = root(x);
        int root_y = root(y);
        if(root_x == root_y) return;
        parent[root_y] = root_x;
        size[root_x] += size[root_y];
    }

    //xとyが属する木が同じならtrueを返す
    bool same(int x, int y){
        int root_x = root(x);
        int root_y = root(y);
        return root_x == root_y;
    }

    //xと同じ木に属する要素の数を返す
    int same_size(int x){
        int root_x = root(x);
        return size[root_x];
    }
};

int main(){
    Stream io;
    
    char a, b;
    io.read(a, b);
    char ans = 'H';
    if(a == 'H' && b == 'D'){
        ans = 'D';
    }
    else if(a == 'D' && b == 'H'){
        ans = 'D';
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); i++)
#define RREP(i, a, b) for(int i=(int)(a); i>=(int)(b); i--)
#define ALL(v) v.begin(), v.end()
#define INF 2e9
#define MOD 1000000007
typedef long long ll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return 1;}return 0;}


using namespace std;

int dp[111111];

int main(void)
{
    int N, M;
    cin >> N >> M;
    REP(i, 0, M){
        int ind;
        cin >> ind;
        dp[ind] = -1;
    }
    dp[0] = 1;
    REP(i, 0, N){
        if(dp[i] == -1)continue;
        if(dp[i+1] != -1)dp[i+1] = (dp[i+1]+dp[i])%MOD;
        if(dp[i+2] != -1)dp[i+2] += (dp[i+2]+dp[i])%MOD;
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 640
x, n = map(int, input().split())
l = list(map(int, input().split()))
flg = False
t = x
while flg == False:
  if t in l:
    t -= 1
  else:
    ans = t
    flg = True
flg = False
t = x
while flg == False:
  if t in l:
    t += 1
  else:
    if abs(x-ans) > abs(x-t):
      ans = t
    flg = True
print(ans)


Measured memory_bytes: 9196
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>


using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;

const ll inf=1000000000LL*2000+1;

struct q_t
{
	int a, step;
	ll c;
	bool operator<(const q_t& r) const
	{
		return step>r.step;
	}
};


priority_queue<q_t> que;


void push(int a, ll c, int step)
{
	que.push((q_t){a, step, c});
}


int pop(int& a, ll& c, int& step)
{
	if(que.empty()) return 0;
	a=que.top().a;
	c=que.top().c;
	step=que.top().step;
	que.pop();
	return 1;
}


ll solve(vector<vector<pii> >& v)
{
	int n=v.size()-1;
	vector<pair<ll,int> > dp;
	int a=1, step=0;
	ll c=0;

	dp.clear();
	dp.resize(v.size(), make_pair(-inf, 0));
	push(a, c, step);
	while(pop(a, c, step))
	{
		if(c<=dp[a].first) continue;
		dp[a].first=c;
		dp[a].second=step;

		for(auto e: v[a])
		{
			int na=e.first;
			ll nc=c+e.second;

			if(dp[na].first<nc && dp[na].second<2001)
			{
				push(na, nc, step+1);
			}
		}
	}
	if(dp[n].second>2000) return inf;
	return dp[n].first;
}


int main(void)
{
	int n, m;
	vector<vector<pii> > v;
	ll result;

	while(scanf("%d%d", &n, &m)==2)
	{
		v.clear();
		v.resize(n+1);
		for(int i=0;i<m;i++)
		{
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			v[a].push_back(make_pair(b, c));
		}
		result=solve(v);
		if(result==inf) printf("inf\n");
		else printf("%lld\n", result);
	}

	return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


char t[MAX], d[MAX];

bool f(ll cur) {
  ma = -inf;
  mi = inf;
  rep(i, m) {
    if (s[cur] == t[i]) {
      if (d[i] == 'L') cur--;
      else cur++;
    }
    ma = max(ma, cur);
    mi = min(mi, cur);
    if (ma >= n || mi < 0) break;
  }
  if (ma >= n || mi < 0) return false;
  else return true;
}




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



  cin >> n >> m;
  cin >> s;
  rep(i, m) cin >> t[i] >> d[i];
  ll le, ri, mid;
  if (f(n / 2)) {
    if (!f(0)) {
      le = 0;
      ri = n / 2;
      while (ri - le > 1) {
        mid = (le + ri) / 2;
        if (f(mid)) ri = mid;
        else le = mid;
      }
      ans += le + 1;
    }
    if (!f(n - 1)) {
      le = n / 2;
      ri = n - 1;
      while (ri - le > 1) {
        mid = (le + ri) / 2;
        if (!f(mid)) ri = mid;
        else le = mid;
      }
      ans += n - ri;
    }
  }
  else {
    if (!f(0) && !f(n - 1)) {
      ans = n;
    }
    else if (f(0)) {
      le = 0;
      ri = n - 1;
      while (ri - le > 1) {
        mid = (le + ri) / 2;
        if (f(mid)) le = mid;
        else ri = mid;
      }
      ans = le + 1;
    }
    else {
      le = 0;
      ri = n - 1;
      while (ri - le > 1) {
        mid = (le + ri) / 2;
        if (!f(mid)) le = mid;
        else ri = mid;
      }
      ans = n - ri;
    }
  }

  cout << n - ans << endl;


  return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
class Edge {
public:
    Edge(){};
    Edge(int s, int t, int w) : s {s}, t {t}, w {w} {};
    int s;
    int t;
    int w;
};

class UnionFindTree {
public:
    UnionFindTree(int n) : ps {vector<int>()}, rs {vector<int>(n, 0)} {
        for(int i = 0; i < n; ++i){
            ps.push_back(i);
        }
    };
    void unite(int x, int y){
        int px = find(x);
        int py = find(y);
        if(px == py){
            return;
        }
        if(rs[x] < rs[y]){
            ps[px] = py;
        } else if(rs[y] < rs[x]){
            ps[py] = px;
        } else {
            ps[px] = py;
            ++rs[py];
        }
    };
    int find(int x){
        return (x == ps[x]) ? x : (ps[x] = find(ps[x]));
    };
private:
    vector<int> ps;
    vector<int> rs;
};
int kruskal(int v, vector<Edge> es){
    auto uft = UnionFindTree(v);
    sort(es.begin(), es.end(), [](Edge a, Edge b){
            return a.w < b.w;
         });
    int n = 0;
    int sum = 0;
    for(auto it = es.begin(); it != es.end(); ++it){
        Edge e = *it;
        if(uft.find(e.s) == uft.find(e.t)){
            continue;
        }
        uft.unite(e.s, e.t);
        sum += e.w;
        ++n;
        if(n == v){
            break;
        }
    }
    return sum;
}

int main(){
    ios_base::sync_with_stdio(false);
    int v, e;
    cin >> v >> e;
    auto es = vector<Edge>();
    int s, t, w;
    for(int i = 0; i < e; ++i){
        cin >> s >> t >> w;
        es.push_back(Edge(s, t, w));
    }
    cout << kruskal(v, es) << endl;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ans = max(0,c-a+b);
    cout << ans << endl;
}

Measured memory_bytes: 3608
import sys
from bisect import bisect_left
sys.setrecursionlimit(10**7)
def lmi(): return list(map(int, input().split()))

h, w = lmi()
s = [input() for i in range(h)]

a = [[] for i in range(h)]
#al = [[] for i in range(h)]
b = [[] for i in range(w)]
bl = [[] for i in range(w)]
for i in range(h):
    k = 0
    for j in range(w):
        if s[i][j] == '.':
            k += 1
            if j == w-1:
                a[i].append(k)
                #al[i].append(j)
        elif j != 0 and s[i][j-1] == '.':
            a[i].append(k)
            #al[i].append(j-1)
            k = 0

for i in range(w):
    k = 0
    for j in range(h):
        if s[j][i] == '.':
            k += 1
            if j == h-1:
                b[i].append(k)
                bl[i].append(j)
        elif j != 0 and s[j-1][i] == '.':
            b[i].append(k)
            bl[i].append(j-1)
            k = 0
'''
print(a)
print(al)
print(b)
print(bl)
'''

ans = 0
for i in range(h):
    k = 0
    c = -1
    for j in range(w):
        if s[i][j] == '.':
            c = a[i][k]
            d = b[j][bisect_left(bl[j], i)]
            #print(c,d)
            ans = max(ans, c+d-1)
        elif j != 0 and s[i][j-1] == '.' and c != -1:
                k += 1
print(ans)


Measured memory_bytes: 91352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  char c; cin >> c;
  printf("%c",c+1);
return 0;
}


Measured memory_bytes: 256
x=int(input())
if x>=2100:
  print(1)
  exit()

ans=[0]*2100
for a in range(22):
  for b in range(22):
    for c in range(22):
      for d in range(22):
        for e in range(22):
          for f in range(21):
            y=a*100+b*101+c*102+d*103+e*104+f*105
            if y<=2099:
              ans[y]=1
            
print(ans[x])

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


int main() {
  int r, g;
  cin >> r >> g;
  int b = 2*g-r;
  cout << b << endl;
  return 0;
}

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

const int MAXN = 1e5 + 10;
int N;
int A[MAXN];

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

int main() {
	// freopen("./input.txt", "r", stdin);
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    int ans = gcd(A[0], A[1]);
    for (int i = 2; i < N; ++i) {
        ans = gcd(ans, A[i]);
    }
    cout << ans << endl;
    
 	return 0;
}

Measured memory_bytes: 1024
package main

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

func main() {
	sc := NewScanner()
	N, H, W := sc.NextInt(), sc.NextInt(), sc.NextInt()
	fmt.Println((N - H + 1) * (N - W + 1))
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int n, m, i, t;
	int gyou[100][100];
	int retu[100];
	int sum[100] = { 0 };

	scanf("%d%d", &n, &m);

	for (i = 0; i<n; i++) {
		for (t = 0; t<m; t++) {
			scanf("%d", &gyou[i][t]);
		}
		
	}

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

	for (i = 0; i<n; i++) {
		for (t = 0; t<m; t++) {
			sum[i] += gyou[i][t] * retu[t];
		}
	}
	for (i = 0; i<n; i++) {
		printf("%d\n", sum[i]);
	}

    return 0;
}


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

typedef struct{
  int dt;
  int idx;
}data;

long half (long x){
  if(x == 1){
    return 0;
  }else{
    return x/2;
  }
}

int main() {
  int h,a;
  cin >> h >> a;
  int ans = 1;
  while(1){
    if(h - a > 0){
      h-=a;
      ans++;
    }else{
      break;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int n, m, l, q;
  cin >> n >> m >> l;
  long long distance[n][n];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      distance[i][j] = numeric_limits<long long>::max();
    }
    distance[i][i] = 0;
  }
  for (int i = 0, a, b, c; i < m; ++i) {
    cin >> a >> b >> c;
    distance[a - 1][b - 1] = c;
    distance[b - 1][a - 1] = c;
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (distance[i][j] - distance[k][j] > distance[i][k]) {
          distance[i][j] = distance[i][k] + distance[k][j];
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (distance[i][j] <= l) {
        distance[i][j] = 1;
      } else {
        distance[i][j] = numeric_limits<long long>::max();
      }
    }
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (distance[i][j] - distance[k][j] > distance[i][k]) {
          distance[i][j] = distance[i][k] + distance[k][j];
        }
      }
    }
  }
  cin >> q;
  for (int s, t; cin >> s >> t; cout << '\n') {
    if (distance[s - 1][t - 1] != numeric_limits<long long>::max()) {
      cout << distance[s - 1][t - 1] - 1;
    } else {
      cout << -1;
    }
  }
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define maxn 200005
#define MOD 1000000007
#define INF 10000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}


void solve(){
    ll n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<ll> v1, v2;
    ll pos = c, kk = 0;
    for(ll i = 0; i < n && kk < k; i++){
        if(pos == c){
            if(s[i] == 'o'){
                kk++; v1.push_back(i); pos = 0; //cout << i << " ";
            }
        }
        else{
            pos++;
        }
    }
    pos = c, kk = 0;
    for(ll i = n-1; i >= 0 && kk < k; i--){
        if(pos == c){
            if(s[i] == 'o'){
                kk++; v2.push_back(i); pos = 0; //cout << i << " ";
            }
        }
        else{
            pos++;
        }
    }
    reverse(v2.begin(), v2.end());
    for(ll i = 0; i < v1.size(); i++){
        if(v1[i] == v2[i]) cout << v1[i]+1 << endl;
    }

}

int main()
{
    solve();
}



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

cnt = 0
k1 = k - a
if k1 > 0:
    cnt += a
else:
    print(k)
    exit(0)

k2 = k1 - b
if k2 > 0:
    pass
else:
    print(cnt)
    exit(0)

k3 = k2 - c
if k3 > 0:
    cnt -= k3
else:
    cnt -= k2

print(cnt)


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

using namespace std;
typedef long long I64;
const I64 NMAX = 200000;
const I64 MOD  = 1000000007;

multiset<I64> ST;
multiset<I64>::iterator it;

bool cmp( pair<pair<I64,I64>, I64> A, pair<pair<I64,I64>, I64> B ) {
    return (A.first.second < B.first.second || (A.first.second==B.first.second && A.first.first < B.first.first));
}

I64 N = 0, Ans = 0;
vector< pair<pair<I64,I64>, I64> > v;
vector< pair<I64, pair<I64,I64>> > edg;

I64 tt[NMAX+2], gr[NMAX+2];

I64 ROOT(I64 nod) {
    if( nod == tt[nod] ) return nod;
    return tt[nod] = ROOT(tt[nod]);
}

void UNION(  I64 x, I64 y ) {
    x = ROOT(x);
    y = ROOT(y);
    if  ( gr[x] > gr[y] ) {
        gr[x] += gr[y];
        tt[y] = x;
    }
    else {
        gr[y] += gr[x];
        tt[x] = y;
    }
}

int main() {
    cin >> N;
    for( I64 i = 1;  i <= N;  ++i ) {
        tt[i] = i;
        gr[i] = 1;
        I64 x,y;
        cin >> x >> y;
        v.push_back( {{x,y}, i} );
    }
    sort( v.begin(), v.end() );
    for( I64 i = 1;  i < (I64)v.size();  ++i ) {
        I64 lg = v[i].first.first - v[i-1].first.first;
        edg.push_back( {lg, {v[i].second, v[i-1].second}} );
    }
    sort( v.begin(), v.end(), cmp );
    for( I64 i = 1;  i < (I64)v.size();  ++i ) {
        I64 lg = v[i].first.second - v[i-1].first.second;
        edg.push_back( {lg, {v[i].second, v[i-1].second}} );
    }

    sort( edg.begin(), edg.end() );
    for( auto pp : edg ) {
        I64 x = pp.second.first;
        I64 y = pp.second.second;
        I64 lg = pp.first;
        if( ROOT(x) != ROOT(y) ) {
            Ans += lg;
            UNION(x,y);
        }
    }

    cout << Ans << '\n';
    return 0;
}


Measured memory_bytes: 12528
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
int cost[100005],h[100005];

int  fun(int n)
{
	if(n==0)
	{
		cost[0]=0;
		return 0;
	}
	if(n==1)
	{
		cost[1]=abs(h[1]-h[0]);
		return cost[1];
	}
	if(cost[n]!=-1)
		return cost[n];
   cost[n]=min(fun(n-1)+abs(h[n]-h[n-1]),fun(n-2)+abs(h[n]-h[n-2]));

   return cost[n];

}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>h[i];
for(int i=0;i<n;i++)
cost[i]=-1;
fun(n-1);
cout<<cost[n-1]<<endl;

return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#pragma warning (disable:4996)

#define MAX_BUILD	(4)
#define MAX_FLOAR	(3)
#define MAX_ROOM	(10)


int builiding_data_array[MAX_BUILD][MAX_FLOAR][MAX_ROOM];

int main(void)
{
	int input_num = 0;
	int input_building = 0;
	int input_floar = 0;
	int input_room = 0;
	int input_residents = 0;
	int loop1 = 0;
	int loop2 = 0;
	int loop3 = 0;

	/* ????????? */
	for(loop1 = 0; loop1 < MAX_BUILD; loop1++){
		for(loop2 = 0; loop2 < MAX_FLOAR; loop2++){
			for(loop3 = 0; loop3 < MAX_FLOAR; loop3++){
				builiding_data_array[loop1][loop2][loop3] = 0;
			}
		}
	}

	scanf("%d", &input_num);

	/* ??\??? */
	for(loop1 = 0; loop1 < input_num; loop1++){
		scanf("%d %d %d %d", &input_building, &input_floar, &input_room, &input_residents );
		builiding_data_array[input_building - 1][input_floar - 1][input_room - 1] += input_residents;
	}

	/* ?????? */
	for(loop1 = 0; loop1 < MAX_BUILD; loop1++){
		for(loop2 = 0; loop2 < MAX_FLOAR; loop2++){
			for(loop3 = 0; loop3 < MAX_ROOM; loop3++){
				if(loop3 == MAX_ROOM - 1){
					printf(" %d\n", builiding_data_array[loop1][loop2][loop3]);
				}else{
					printf(" %d", builiding_data_array[loop1][loop2][loop3]);
				}
			}
		}
		if(loop1 != MAX_BUILD - 1){
			printf("####################\n");
		}
	}

	return 0;
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n + 1);
    vector<int> c(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> p[i];
    for (int i = 1; i <= n; i++)
        cin >> c[i];

    ll ans = -0x3f3f3f3f3f3f3f3f;
    for (int i = 1; i <= n; i++)
    {
        vector<bool> visited(n + 1, 0);
        int num = 0;
        int next = p[i];
        vector<ll> tmax(n + 1, -0x3f3f3f3f3f3f3f3f);
        ll score = 0;
        while (!visited[next])
        {
            score += c[p[next]];
            visited[next] = 1;
            next = p[next];
            num++;
            tmax[num] = max(tmax[num - 1], score);
        }
        if (score < 0)
            score = tmax[min(k, num)];
        else
        {
            if (num >= k)
                score = tmax[k];
            else
                score = max((k / num) * score + max(0ll, tmax[k % num]), (k / num - 1) * score + max(0ll, tmax[num]));
        }
        ans = max(ans, score);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3672