akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

struct edge{
    int to;
    int cost;
};

vector<int> colors;
vector<vector<edge>> edges;

void dfs(int vertex, int color, int parent=-1){
    colors[vertex] = color;

    for (auto e : edges[vertex]){
        if (e.to == parent) continue;
        int next_color = color;
        if (e.cost == 1) next_color = 1 - color;
        dfs(e.to, next_color, vertex);
    }

}

int main(){

    int N; cin >> N;
    colors.assign(N,0);
    edges.assign(N, vector<edge>());
    rep(i,N-1){
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        w = w % 2;
        edges[u].push_back(edge{v,w});
        edges[v].push_back(edge{u,w});
        //edges[u].emplace_back(v,w);
        //edges[v].emplace_back(u,w);
    }

    dfs(0,0);

    rep(i,N){
        cout << colors[i] << endl;
    }

}

Measured memory_bytes: 11712
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    ll n, a, b, k;
    vector<pair<ll, ll>> v;
    cin >> n >> k;
    rep(i, n) {
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    }
    sort(v.begin(), v.end());
    rep(i, v.size()) {
        k -= v[i].second;
        if(k <= 0) {
            cout << v[i].first;
            break;
        }
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 2420
r=lambda :map(int,input().split())
n,x=r()
*a,=r()
dp=[[0]*n for _ in range(n)]
for i,j in enumerate(a):
  dp[0][i]=j
for i in range(1,n):
  for j in range(n):
    dp[i][j]=min(dp[i-1][j],a[(j-i)%n])
print(min(i*x+sum(j) for i,j in enumerate(dp)))

Measured memory_bytes: 73436
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long LL;

const int maxn = 2e5 + 5;
LL a[maxn];

int main(){
	int n; scanf("%d",&n);
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	LL cnt = 0; int l = 1, r = 1;
	LL now = 0;
	while(l <= r) {
		while(r <= n && (now ^ a[r]) == now + a[r]) {
			now ^= a[r++];
		}
		cnt += (r - l);
		now ^= a[l++];
	}
/*	while(r < n && sum == ans){
		sum += a[++r];
		ans ^= a[r];
	}
	if(sum != ans){
		sum -= a[r];
		ans ^= a[r];
		r--;
	}
	cnt += r;
	for(int l = 2;l <= n;l++){
		sum -= a[l - 1];
		ans ^= a[l - 1];
		while(r < n && sum == ans){
			sum += a[++r];
			ans ^= a[r];
		}
		if(sum != ans){
			sum -= a[r];
			ans ^= a[r];
			r--;
		}
		cnt += (r - l + 1);
	}*/
	printf("%lld\n",cnt);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i,k) for(auto& i:k)
#define all(a) a.begin(),a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
ll prime(double a,double n){
	ll tmp=a;
	ll tmp1=n;
	for(ll i=static_cast<ll>(pow(a,(1.0/n)))+1;i>0;i--){
		if(tmp%(static_cast<ll>(pow(i,n)))==0){
			return i;
		}
	}
}
signed main() {
	double n,p;
	cin >> n >> p;
	ll ans=prime(p,n);
	cout << ans << endl;
}

Measured memory_bytes: 256
main(){
	long long i,n,a[100001],b[100001],ans=0;
	scanf("%lld",&n);
	for(i=0;i<n;i++)scanf("%lld%lld",&a[i],&b[i]);
	for(i=n-1;i>=0;i--)if(b[i]-1)ans+=(b[i]-(a[i]+ans)%b[i])%b[i];
	printf("%lld",ans);
}

Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String x = br.readLine();
		String[] num = x.split(" ");
		String y;

		int a = num[0].charAt(0);
		int b = num[1].charAt(0);

		if (a > b) {
			y = ">";
		} else if (a < b) {
			y = "<";
		} else {
			y = "=";
		}
		System.out.println(y);
	}
}


Measured memory_bytes: 21204
package main

import (
	"fmt"
)

func main() {
	var w, h, x, y float64
	fmt.Scan(&w, &h, &x, &y)

	ans0 := w * h / 2
	var ans1 int
	if (w/2 == x) && (h/2 == y) {
		ans1 = 1
	} else {
		ans1 = 0
	}
	fmt.Println(ans0, ans1)
}

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

const int N = 100005;
const int INF = 0x3f3f3f3f;

int n, m, id, a[N], b[N];
int sz[N * 2], f[N * 2][2], nxt[N * 2][3];
vector<int> val;

void dfs(int u, int x, int cnt) {
    if (u <= n) {
        if (b[u]) {
            bool t = (b[u] >= x);
            f[u][t] = t;
        }
        else f[u][0] = 0, f[u][1] = 1;
        //cout << u << ' ' << f[u][0] << ' ' << f[u][1] << '\n';
        return;
    }
    sz[u] = 0;
    for (int i = 0; i < 3; ++i) {
        //cout << u << ' ' << nxt[u][i] << '\n';
        dfs(nxt[u][i], x, cnt), sz[u] += sz[nxt[u][i]];
    }
    for (int i = 0; i < (1 << 3); ++i) {
        int sum = 0, cnt1 = 0, ok = 1;
        for (int j = 0; j < 3; ++j) {
            bool t = i >> j & 1;
            if (t) cnt1++;
            if (f[nxt[u][j]][t] == INF) {
                ok = 0; break;
            }
            sum += f[nxt[u][j]][t];
        }
        bool t = 0;
        if (cnt1 >= 2) t = 1;
        if (!ok) continue;
        f[u][t] = min(f[u][t], sum);
    }
    //cout << u << ' ' << f[u][0] << ' ' << f[u][1] << '\n';
    int gap = (sz[u] - f[u][0]) - (n - cnt);
    f[u][0] += max(0, gap);
}

bool check(int x) {
    memset(f, INF, sizeof f);
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        cnt += a[i] >= x, sz[i] = 1;
    }
    dfs(id, x, cnt);
    return f[id][1] <= cnt;
}

void prep() {
    vector<int> go;
    for (int i = 1; i <= n; ++i) go.push_back(i);
    id = n;
    while (go.size() > 1) {
        vector<int> tmp;
        for (int i = 0; i < go.size() % 3; ++i) {
            tmp.push_back(go[go.size() - 1 - i]);
        }
        for (int i = 0; i + 2 < go.size(); i += 3) {
            tmp.push_back(++id);
            for (int j = 0; j < 3; ++j) nxt[id][j] = go[i + j];
        }
        go = tmp;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int p; cin >> a[i] >> p; b[p] = a[i];
        val.push_back(a[i]);
    }
    for (int i = m + 1; i <= n; ++i) {
        cin >> a[i]; val.push_back(a[i]);
    }
    sort(val.begin(), val.end());
    prep();
    int l = 0, r = n - 1;
    while (l < r) {
        int mid = (l + r + 1) >> 1;
        if (check(val[mid])) l = mid;
        else r = mid - 1;
    }
    cout << val[l] << '\n';
}

/*
7 2
6 5
1 2
4
7
5
2
3
*/

Measured memory_bytes: 6980
package main

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

func main() {
	sc := newScanner()
	var s = sc.readString()
	var cnt int
	for a := range s {
		if s[a] == 'R' {
			cnt++
		}
	}
	if s == "RSR" {
		fmt.Println("1")
	} else {
		fmt.Println(cnt)
	}

}

//////////////////
//////////////////
//////////////////

func abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func pow(base, exponent int) int {
	if exponent < 0 {
		panic(fmt.Sprintf("exponent (%d) should not be a minus", exponent))
	}

	answer := 1
	for i := 0; i < exponent; i++ {
		answer *= base
	}
	return answer
}

func ceil(divident, dividor int) int {
	if dividor == 0 {
		panic("dividor should not be 0")
	}

	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// -   sortutil

func reverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func reverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// -   io

type scanner struct {
	bufScanner *bufio.Scanner
}

func newScanner() *scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &scanner{bufSc}
}

func (sc *scanner) readString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *scanner) readInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}

func (sc *scanner) readInt64() int64 {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.ParseInt(text, 10, 64)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1776
import fractions

n = int(input())
a = [int(i) for i in input().split()]
ans = a[0]
x = a[0]

if n==2:
  print(max(a[0],a[1]))
  exit()
elif n==3:
  print(max(fractions.gcd(a[0],a[1]),fractions.gcd(a[0],a[2]),fractions.gcd(a[1],a[2])))
  exit()

for i in range(n):
  temp = fractions.gcd(ans,a[i])
  if temp != ans:
    ans = max(temp,x)
    x= fractions.gcd(temp,x)

print(ans)

Measured memory_bytes: 16124
class UnionFind
  def initialize
    @obj_to_node = {}
  end

  class UnionFind::Node
    def initialize(obj)
      @obj = obj
      @parent = self
      @rank = 0
    end

    def root
      return self if @parent == self
      @parent = @parent.root
    end  

    attr_accessor :parent, :rank
  end

  def unite(x, y)
    u = (@obj_to_node[x] ||= UnionFind::Node.new(x)).root
    v = (@obj_to_node[y] ||= UnionFind::Node.new(y)).root
    return if u == v
    if u.rank > v.rank
      v.parent = u
    elsif v.rank > u.rank
      u.parent = v
    else
      u.parent = v
      v.rank += 1
    end
  end

  def same?(x, y)
    return false unless u = @obj_to_node[x]
    return false unless v = @obj_to_node[y]
    u.root == v.root
  end
end

n, q = gets.split.map(&:to_i)
uf = UnionFind.new
q.times do
  c, x, y = gets.split.map(&:to_i)
  if c == 0
    uf.unite(x, y)
  else
    puts uf.same?(x, y) ? '1' : '0'
  end
end


Measured memory_bytes: 7400
import Control.Monad
type I3 = (Int, Int, Int)
type B2 = (Bool, Bool)

main = do
    n <- readLn
    ss <- replicateM n getLine
    print . f $ map count ss

f :: [(I3, Int)] -> Int
f rs = sum ns + g (nft, ntf, ntt) where
    (cs, ns) = unzip rs
    (nft, ntf, ntt) = foldl1 add3 cs

g :: I3 -> Int
g (nft, ntf, 0) = min nft ntf
g (nft, ntf, ntt) = if ntt > 0
    then if nft > 0
        then if ntf > 0
            then ntt + 1 + min (nft - 1) (ntf - 1)
            else ntt
        else if ntf > 0
            then ntt
            else ntt - 1
    else min nft ntf

add3 :: I3 -> I3 -> I3
add3 (l1,l2,l3) (r1,r2,r3) = (l1+r1,l2+r2,l3+r3)

count :: String -> (I3, Int)
count (s0:s) = (count' (na, nb), n) where
    na = last s == 'A'
    nb = s0 == 'B'
    n = length [() | (c1, c2) <- zip (s0:s) s, c1 == 'A' && c2 == 'B']
    count' (False,False) = (0,0,0)
    count' (False, True) = (1,0,0)
    count' ( True,False) = (0,1,0)
    count' ( True, True) = (0,0,1)


Measured memory_bytes: 7036
n = int(input())
t = [[0]*9 for i in range(9)]
for j in range(1, n+1):
    if int(str(j)[-1])==0:
        continue
    t[int(str(j)[0])-1][int(str(j)[-1])-1]+=1
ans = 0
for i in range(9):
    for j in range(9):
        ans += t[i][j]*t[j][i]
print(ans)
            

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    string C[2];
    cin >> C[0];
    cin >> C[1];

    for(int i = 0; i < 3; i++)
        if(C[0][i] != C[1][3 - i - 1]){
            cout << "NO" << endl;
            return 0;
        }
    cout << "YES" << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
#define INF INT_MAX/2
int N, Z, W;
int A[2010];
int memo[2010][2];
int f(int id, int turn, int x, int y) {
  if (id == N) return abs(x - y);

  if (0 <= memo[id][turn]) return memo[id][turn];

  if (turn == 0) {
    int ma = -1;
    for(int i = id; i<N; i++) {
      ma = max(ma, f(i + 1, 1 - turn, A[i], y));
    }
    return memo[id][turn] = ma;
  } else {
    int mi = INF;
    for(int i = id; i<N; i++) {
      mi = min(mi, f(i + 1, 1 - turn, x, A[i]));
    }
    return memo[id][turn] = mi;
  }
}

int main() {
  cin >> N >> Z >> W;
  for(int i = 0; i<N; i++) {
    cin >> A[i];
  }
  for(int i = 0; i<N; i++) {
    for(int t = 0; t<2; t++) {
      memo[i][t] = -1;
    }
  }
  cout << f(0, 0, Z, W) << endl;
  return 0;
}

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

int main(){
  double r;
  cin>>r;
  double ans = 2*r*3.141592;
  cout << ans << endl;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI acos(-1)
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


using namespace std;
typedef long long int ll;


ll inf = 1e12 + 5;

int main(){
    FIN;
    //freopen("../../input.txt", "r", stdin);freopen("../../output.txt", "w", stdout); 
    int n,w;cin>>n>>w;
    int N = n*1000 + 1;
    ll dp[n+1][N];

    fore(i,0,n+1){
        fore(j,0,N){
            dp[i][j] = inf;
        }
    }
    vector<pair<int,int>> values;
    fore(i,0,n){
        int wi,vi;cin>>wi>>vi;
        values.pb({wi,vi});
    }

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

    

    fore(i,1,n+1){
        int wi = values[i-1].first;
        int vi = values[i-1].second;
        dp[i-1][0] = 0;
        fore(j,1,N){
            dp[i][j] = min(dp[i-1][max(j-vi,0)]+wi,dp[i-1][j]);
        }
    }

    /*fore(i,0,n+1){
        fore(j,0,N){
            if(dp[i][j] != inf){
                cout<<dp[i][j]<<" ("<<j<<") ";
            }else{
                cout<<"-1 ";
            }

        }cout<<"\n";
    }*/

    ll ans = 0;
    for(int j = N-1; j>=0 ;j--){
        bool posible = false;

        fore(i,0,n+1){
            if(dp[i][j]<=w){
                posible = true;
            }
        }
        if(posible){
            ans = j;
            break;
        }
    }
    cout<<ans;
    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove reader 
// - fastio
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?, is MAXN correct?)
// - special cases (n=1, graph not connected?)
// - re-initialize efficiently between test cases


Measured memory_bytes: 82580
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


template<typename T>
struct edge {
  int u, v; T w;
  edge(int v, T w) : u(-1), v(v), w(w) {}
  edge(int u, int v, T w) : u(u), v(v), w(w) {}
  operator int() const { return v; }
};
template<typename T>
using Graph = vector<vector<edge<T>>>;


template<typename T>
vector<T> dijkstra(Graph<T> &G, int s) {
  const auto INF = numeric_limits<T>::max();
  vector<T> dist(G.size(), INF);

  using PTi = pair<T, int>;
  priority_queue<PTi, vector<PTi>, greater<PTi>> pq;
  dist[s] = 0;
  pq.emplace(dist[s], s);

  while (!pq.empty()) {
    T cost; int u;
    tie(cost, u) = pq.top(); pq.pop();
    if (dist[u] < cost) continue;
    for (auto &e : G[u]) {
      auto n_cost = cost + e.w;
      if (dist[e.v] <= n_cost) continue;
      dist[e.v] = n_cost;
      pq.emplace(dist[e.v], e.v);
    }
  }
  return dist;
}


int main() {
  int N, M, s, t; cin >> N >> M >> s >> t;
  s--; t--;

  Graph<ll> Ga(N), Gb(N);
  for (int i = 0; i < M; ++i) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--; v--;
    Ga[u].push_back(edge<ll>(v, a));
    Ga[v].push_back(edge<ll>(u, a));
    Gb[u].push_back(edge<ll>(v, b));
    Gb[v].push_back(edge<ll>(u, b));
  }

  Vll da = dijkstra(Ga, s);
  Vll db = dijkstra(Gb, t);
  
  Vll ans(N+1);
  ans[N] = INFll;
  rep(i, N) {
    ans[N-i-1] = min(ans[N-i], da[N-i-1] + db[N-i-1]);
  }
  rep(i, N) cout << (ll(1e15) - ans[i]) << endl;
  return 0;
}


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

int main(void) {
    int N;cin>>N;
    double sum = 0;
    for (int i = 1; i <= N; i++) {
        double A;cin>>A;
        sum += 1.0 / A;
    }
    printf("%.6f\n", 1.0 / sum);
    return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int H = sc.nextInt();
		int W = sc.nextInt();

		Deque<int[]> q = new ArrayDeque<>();
		
		int[][] A = new int[H+2][W+2];
		for(int i=0;i<A.length;i++) {
			Arrays.fill(A[i], -1);
		}
		for(int i=1;i<=H;i++) {
			String s = sc.next();
			for(int j=1;j<=W;j++) {
				if(s.charAt(j-1) == '#') {
					q.add(new int[] {i,j, 0});
				}
			}
		}
		
		sc.close();
		
		while(!q.isEmpty()) {
			int[] yx = q.poll();
			int y = yx[0];
			int x = yx[1];
			int c = yx[2];

			if(y == 0 || y == H+1 || x==0 || x == W+1) {
				continue;
			}
			if(A[y][x] >= 0) {
				//すでに処理済み。
				continue;
			}
			
			A[y][x] = c;
			if(A[y+1][x] == -1) q.add(new int[] {y+1, x, c+1});
			if(A[y-1][x] == -1) q.add(new int[] {y-1, x, c+1});
			if(A[y][x+1] == -1) q.add(new int[] {y, x+1, c+1});
			if(A[y][x-1] == -1) q.add(new int[] {y, x-1, c+1});
			
		}
		
		int ans = 0;
		for(int i=1;i<=H;i++) {
			for(int j=1;j<=W;j++) {
				ans = Math.max(ans, A[i][j]);
			}
		}
		
		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
	
	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 154064
#include <iostream>
using namespace std;;
int main(){
int h1,m1,s1,h2,m2,s2;
for(int i=0;i<3;i++){
cin>>h1>>m1>>s1>>h2>>m2>>s2;
int A=h1*3600+m1*60+s1;
int B=h2*3600+m2*60+s2;
int C=B-A;
int D=C/3600;
int E=(C/60)%60;
int F=C%60;
cout<<D<<" "<<E<<" "<<F<<endl;
}
return 0;
}



Measured memory_bytes: 3076
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define all(c) begin(c),end(c)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
using ll = long long;
using vi = vector<int>; using vs = vector<string>;
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑

vector<vector<int>> G;
vector<ll> dp;
vector<ll> ans;
int M;
ll calc(int u, int p)
{
	dp[u] = 1L;
	for(int v : G[u])
	{
		if (v == p)
		{
			continue;
		}
		dp[u] *= calc(v, u) + 1;
		dp[u] %= M;
	}
	return dp[u];
}
void zenhoui(int u, int p)
{
	int N = G[u].size();
	vector<ll> L(N);
	vector<ll> R(N);
	for (int i = 0; i < N; i++)
	{
		L[i] = R[i] = dp[G[u][i]] + 1;
	}
	for (int i = 1; i < N; i++)
	{
		L[i] *= L[i - 1];
		L[i] %= M;
	}
	for (int i = N - 2; i >= 0; i--)
	{
		R[i] *= R[i + 1];
		R[i] %= M;
	}

	for (int i = 0; i < N; i++)
	{
		int v = G[u][i]; //ans[v]を求める
		if (v == p)
		{
			continue;
		}
		dp[u] = 1L;
		if (0 <= i - 1)
		{
			dp[u] *= L[i - 1];
		}
		if (i + 1 < N)
		{
			dp[u] *= R[i + 1];
		}
		dp[u] = dp[u] % M;
		ans[v] = dp[v] * (dp[u] + 1) % M;
		zenhoui(v, u);
	}
}
void solve()
{
	int N;
	cin >> N >> M;
	G = vector<vector<int>>(N);
	for (int i = 0; i < N - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
	}
	dp = vector<ll>(N);
	calc(0, -1);
	ans = vector<ll>(N);
	ans[0] = dp[0];
	zenhoui(0, -1);
	for (int i = 0; i < N; i++)
	{
		cout << ans[i] << "\n";
	}
}

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

Measured memory_bytes: 19456
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read() {
	int x=0;
	char ch=' ';
	bool flag=false;
	while(ch<'0' || ch>'9') {
		if(ch=='-')flag=true;
		ch=getchar();
	}
	while(ch>='0' && ch<='9') {
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return flag?-x:x;
}
const int MAX_N=100005;
int rec[2][MAX_N];
int v[MAX_N];
vecP sol[2];
int n;
int main() {
	cin>>n;
	rep(i,0,n)rec[i%2][v[i]=read()]++;
	rep(i,0,2)rep(j,0,MAX_N) {
		sol[i%2].pb(mp(rec[i%2][j],j));
		sort(all(sol[i%2]));
		reverse(all(sol[i%2]));
		if(sol[i%2].size()>2)sol[i%2].pop_back();
	}
	int ans=n;
	rep(i,0,sol[0].size()) {
		rep(j,0,sol[1].size()) {
			if(sol[0][i].se!=sol[1][j].se) {
				ans=min(ans,n-sol[0][i].fi-sol[1][j].fi);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <iterator>
#include <random>
#include <fstream>
#include <chrono>
#include <math.h>
#include <cctype>
using namespace std;
#define int long long
#define forn(i, n) for (int i = 0; i < n; ++i)
int32_t main() {
    ios::sync_with_stdio(false);
    string x, y;
    cin >> x;
    cin >> y;
    int n = x.size();
    int ans = 0;
    forn(i,n){
        if(x.at(i)!=y.at(i))
            ans++;
    }
    cout << ans << "\n";
    return 0;
}

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

const int N = 2e5+5 , INF = 20000;

int n  , m ;

int main() {

    cin>>n>> m;

    for(int i = m-n+1;i<m+n;i++)
    {
        cout<<i<<" ";
    }

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

int main()
{
	string s0, s1, s2;
	cin >> s0 >> s1 >> s2;

	string res = "ABC";
	res[1] = s1[0];
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
	int sum, A, B, C, X, i, j, k, cnt=0;
	cin >> A; cin >> B; cin >> C; cin >> X;

	for (i = 0; i <= A; i++) {
		for (j = 0; j <= B; j++) {
			for (k = 0; k <= C; k++) {
				sum = i * 500 + j * 100 + k * 50;
				if (sum == X)
					cnt++;
			}
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MX 100005
int N, W;
int A[MX][2];
ll dp[101][MX];

ll go(int pos, int weight){
    if (pos > N) return 0;
    if (dp[pos][weight] != -1) return dp[pos][weight];

    ll ans = 0;
    if (A[pos][0] <= weight) ans = A[pos][1] + go(pos+1, weight - A[pos][0]);
    ans = max(ans, go(pos+1, weight));
    return dp[pos][weight] = ans;
}

int main()
{
    memset(dp, -1, sizeof(dp));
    scanf("%d%d", &N, &W);
    for (int i = 1; i <= N; i++)
        scanf("%d%d", &A[i][0], &A[i][1]);
    ll res = go(1, W);
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin>>n;
	vector<int> v;
	for(int i=1;i<=n;i++) v.pb(i);
	sort(all(v));
	vector<int> a,b;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.pb(x);
	}
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		b.pb(x);
	}
	int cnt=1;
	int ans1=-1,ans2=-1;
	do{
		if(v==a) ans1=cnt;
		if(v==b) ans2=cnt;
		cnt++;
	}while(next_permutation(all(v)));
	cout<<abs(ans1-ans2);
}  
// I never lose. I either win or I learn

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 500050;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;


double dist(double x1, double x2, double y1, double y2) {
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
double dist(P &p1, P &p2) {
	double x1 = p1.first, x2 = p2.first, y1 = p1.second, y2 = p2.second;
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}


void solve() {
	int N; cin >> N;
	vector<int>v(N);
	REP(i, N)cin >> v[i];
	int mn = 1e9;
	int ans = 0;
	REP(i, N) {
		if (v[i] <= mn) {
			ans++;
			mn = v[i];
		}
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




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

#ifdef DEBUG
#define PRINT(x)\
    cout << "func " << __func__ << ": line " << __LINE__ << ": " << #x << " = " << (x) << endl;
#define PRINTA(a, begin, end)\
    cout << "func " << __func__ << ": line " << __LINE__ << ": " << #a << "[" << (begin) << ", " << (end) << ")" << endl;\
    for (int i = (begin); i < (end); ++i) {\
        cout << #a << "[" << i << "] = " << (a)[i] << endl;\
    }
#else
#define PRINT(x)
#define PRINTA(a, begin, end)
#endif

#define MAX_N 500

using namespace std;

int N;
int C[MAX_N];
int S[MAX_N];
int F[MAX_N];

int f(int time, int station) {
    if (time < S[station]) {
        time = S[station];
    }
    while (time % F[station] != 0) {
        time++;
    }
    time += C[station];
    return time;
}

int main(void)
{
    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        cin >> C[i] >> S[i] >> F[i];
    }
    for (int i = 0; i < N; i++) {
        int station = i;
        int time = 0;
        while (station != N - 1) {
            time = f(time, station);
            station++;
        }
        cout << time << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace atcoder.abc172.a
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = getIntParam();

            Console.WriteLine(a + Math.Pow(a, 2) + Math.Pow(a, 3));
        }

        //↓↓↓ shared function ↓↓↓
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }
    }
}


Measured memory_bytes: 27588
class UnionFind:
 
    def __init__(self, size):
        # 負の値はルート (集合の代表) で集合の個数
        # 正の値は次の要素を表す
        self.size = size
        self.table = [-1 for _ in range(size)]
 
    def find(self, x):
        # 集合の代表を求める
        children = []
        while self.table[x] >= 0:
            children.append(x)
            x = self.table[x]
        for c in children:
            self.table[c] = x
        return x
 
    def union(self, x, y):
        # 併合
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] >= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
        return self.table[s1]
 
n,k,l= map(int, input().split())
road = UnionFind(n+1)
train = UnionFind(n+1)
for i in range(k):
    p,q = map(int, input().split())
    road.union(p, q)
for i in range(l):
    p,q = map(int, input().split())
    train.union(p,q)
import collections
d = collections.defaultdict(int)
for i in range(1,n+1):
    r = road.find(i)
    t = train.find(i)
    d[(r,t)] += 1
res = [d[(road.find(i), train.find(i))] for i in range(1,n+1)]

print(*res, sep=' ')

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

enum NEXT {
  MINUS = -1,
  ZERO = 0,
  PLUS = 1,
  };

int main() {
  int N, i, j; cin >> N;
  vector<int> a(N);
  rep (i, N)
    cin >> a.at(i);
  NEXT next = ZERO;
  int group = 0; i = 0;
  rep (i, N-1) {
    int inc = a.at(i+1) - a.at(i);
    if (next == ZERO && inc > 0)
      next = PLUS;
    if (next == ZERO && inc < 0)
      next = MINUS;
    if (next == PLUS && inc < 0) {
      next = ZERO;
      group ++;
    }
    if (next == MINUS && inc > 0) {
      next = ZERO;
      group ++;
    }
    
  }
  cout << group + 1 << endl;
  return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

int p_inv[MAXN];

void solve(){
	int n, t, f, a;
	scanf("%d", &n);
	REPN(i, 1, n) {
		scanf("%d", &a);
		p_inv[a] = i;
	}
	t = f = 0;
	for(int i = n - 1; i >= 1; i--) {
		if (t == 0) {
			if (p_inv[i] > p_inv[i + 1]) {
				t = 1;
				f = i + 1;
			}
		} else {
			if (!(p_inv[f] < p_inv[i] && p_inv[i] < p_inv[i + 1]
				|| p_inv[i] < p_inv[i + 1] && p_inv[i + 1] < p_inv[f]
				|| p_inv[i + 1] < p_inv[f] && p_inv[f] < p_inv[i])) {
					t++;
					f = i + 1;
				}
		}
	}
	printf("%d\n", t);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int A[100];

void outputArray(int A[], int N) {
    cout<<A[0];
    for (int i = 1; i < N; ++i) {
        cout<<' '<<A[i];
    }
    cout<<endl;
}

void insertionSort(int A[], int N) {
    for (int i = 0; i < N; ++i) {
        int v = A[i];
        int j = i-1;
        while (j >= 0&&A[j]>v) {
            A[j+1]=A[j];
            j--;
        }
        A[j+1] = v;
        outputArray(A,N);
    }
}
int main() {
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i) cin>>A[i];
    insertionSort(A,n);
    return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
#define P pair<int,int>
typedef long long ll;
using namespace std;

int main(){
    int r; cin >> r;
    cout << 3*r*r << endl;
return 0;
}


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

using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define fill(a, x) memset(a, x, sizeof(a))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
long long MOD=1e9+7;


int main()
{	
	ios_base:: sync_with_stdio(0);
	cin.tie(0);
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int i,j,a,b,k=-1,x,n,l,r,lf,rf;
	cin>>x>>n;
	vi art;
	for(i=0;i<n;i++){
		cin>>a;
		art.push_back(a);
	}
	sort(all(art));
	for(i=0;i<n;i++){
		if(art[i]==x){
			k = i;
			break;
		}
	}

	if(k==-1){
		cout<<x;
		return 0;
	}
	l = x-1;
	r = x+1;
	lf = k-1;
	rf = k+1;
	while(1){
		if(lf<0) {
			cout<<l;
			return 0;
		} 
		
		if(l!=art[lf]){
			cout<<l;
			return 0;
		}
		else{
			lf-=1;
			l-=1;
		}
		if(rf>=n) {
			cout<<r;
			return 0;
		}
		
		if(r!=art[rf]){
			cout<<r;
			return 0;
		}
		else{
			rf+=1;
			r+=1;
		}


	}

}



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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

#define int ll

const int inf = 1ll<<62;
const int mod = 1e9+7;

main(){
  int a, b; cin >> a >> b;
  if(a <= 0 and 0 <= b) cout << "Zero\n";
  else if(a < 0){
    if(abs(a - min(-1ll, b)) % 2 == 0) cout << "Negative\n";
    else cout << "Positive\n";
  }else cout << "Positive\n";
}

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

int main()
{
	int N;
	cin >> N;
	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S.at(i);
	}
	int countA = 0;
	int countW = 0;
	int countT = 0;
	int countR = 0;
	for (int i = 0; i < N; i++) {
		if (S.at(i) == "AC") {
			countA++;
		}
		if (S.at(i) == "WA") {
			countW++;
		}
		if (S.at(i) == "TLE") {
			countT++;
		}
		if (S.at(i) == "RE") {
			countR++;
		}
	}
	cout << "AC x " << countA << endl;
	cout << "WA x " << countW << endl;
	cout << "TLE x " << countT << endl;
	cout << "RE x " << countR;
}

Measured memory_bytes: 6420
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
    int n, f, b;
    cin >> n;
    string s;
    vector<vector<int>> c(10, vector<int>(10, 0));
    for (int i = 1; i <= n; i++){
        s = to_string(i);
        f = s.front() - '0';
        b = s.back() - '0';
        c[f][b] += 1;
    }

    int ans = 0;
    for (int i = 1; i < 10; i++){
        ans += c[i][i] * c[i][i];
        for (int j = i + 1; j < 10; j++){
            ans += 2 * c[i][j] * c[j][i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000000007;


ll ans=0;
//dp
ll dp1[1123456];
ll dp2[1123456];
signed main(){
    string n;
    cin>>n;

    dp1[1]=1;
    dp2[1]=2;

    for(int i=2;i<=n.size();i++){
        if(n[i-1]=='1'){
            dp1[i]=(dp1[i-1]*3+dp2[i-1])%mod;
            dp2[i]=dp2[i-1]*2%mod;
        }else{
            dp1[i]=dp1[i-1]*3%mod;
            dp2[i]=dp2[i-1];
        }
    }

    cout<<(dp1[n.size()]+dp2[n.size()])%mod<<endl;









    

 
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long int
const ll mod = 1e9 + 7;

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, i, ans = 0;
	cin >> n >> k;
	vector<int> v(n);
	for (i=0; i<n; ++i) cin >> v[i];
	sort(v.begin(), v.end());
	cout << accumulate(v.begin(), v.begin() + k, ans);
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define rep(i, x) for (ll i = 0; i < (x); i++)

using namespace std;
typedef long long int ll;

ll num[200000];
ll N, Q, s;

int main(void) {
  cin >> N;
  rep(i, N) {
    ll x;
    cin >> x;
    num[x]++;
    s += x;
  }
  cin >> Q;
  while (Q--) {
    ll b, c;
    cin >> b >> c;
    s = s - num[b] * b + num[b] * c;
    num[c] += num[b];
    num[b] = 0;
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 4404
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int64_t> cards(n);
    for (int i = 0; i < n; i += 1) {
        cin >> cards[i];
        if (i > 0) {
            cards[i] += cards[i - 1];
        }
    }

    int64_t res = abs(2 * cards[0] - cards[n - 1]);
    for (int i = 1; i + 1 < n; i += 1) {
        auto x = cards[i];
        auto y = cards[n - 1] - cards[i];
        res = min(res, abs(x - y));
    }

    cout << res << "\n";
    return 0;
}


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

void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (1) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
vector<int>E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000], cnt = 1;
bool b[200000], ok[100000];
queue<int>que;

void bfs(int u, int t) {
	que.push(u);
	while (!que.empty()) {
		int p = que.front(); que.pop(); for (int v : E[p]) {
			if (t) {
				if (d[v] > d[p] && !ok[v]) {
					ok[v] = 1; cnt++; que.push(v);
				}
			}
			else if (!~d[v]) {
				d[v] = d[p] + 1; que.push(v);
			}
		}
	}
}
int main() {
	int n, m, q; reader(&n); reader(&m); reader(&q);
	rep(i, m) {
		reader(&u[i]); reader(&v[i]);
		u[i]--; v[i]--;
		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);
	}
	memset(d, -1, sizeof(d));
	d[0] = 0; bfs(0, 0);
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, n)E[i].clear();
	rep(i, q) {
		reader(&r[i]); r[i]--;
		b[r[i]] = true;
	}
	ok[0] = true;
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] - d[u[i]] == 1) {
				E[u[i]].emplace_back(v[i]);
			}
		}
	}
	bfs(0, 1);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] - d[u[r[i]]] == 1 && !ok[v[r[i]]]) {
			E[u[r[i]]].emplace_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = true;
				bfs(v[r[i]], 1);
			}
		}
	}
	rep(i, q)printf("%d\n", ans[i]);
}

Measured memory_bytes: 13628
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)
max = 0;min = a[0];now = 0
n.times do |x|
if a[x] > max
	max = a[x]
end
if a[x] <  min
	min = a[x]
end
end
ans = 0
min.step(max) do |y|
  now = 0
  n.times do |z|
  now = now + ((a[z] - y)*(a[z] - y))
  end
  if ans == 0 || now < ans
    ans = now
  end
end
puts ans

Measured memory_bytes: 1788
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <complex>
#include <cctype>
#include <cassert>

using namespace std;

int n;
string S;
int cur;

int digit(){
	assert(isdigit(S[cur]));
	int n = S[cur] - '0';
	cur++;
	return n;
}

int number(){
	int n = digit();
	while(cur < S.size() && isdigit(S[cur])){
		n = n * 10 + digit();
	}
	return n;
}

int expression();
int factor(){
	if (S[cur] != '(') return number();
	cur++;
	int n = expression();
	cur++;
	return n;	
}

int term(){
	int sum = factor();
	while(cur < S.size() && (S[cur] == '*' || S[cur] == '/')){
		char op = S[cur];
		cur++;
		int b = factor();
		if(op == '*') sum *= b;
		else sum /= b;
	}
	return sum;
}

int expression(){
	int sum = term();
	while(cur < S.size() && (S[cur] == '+' || S[cur] == '-')){
		char op = S[cur];
		cur++;
		int b = term();
		if(op == '+') sum += b;
		else sum -= b;
	}
	return sum;
	
}


int main(void){

	cin >> n;

	for(int i = 0; i < n; i++){
		cur = 0;
		cin >> S;
		S.resize(S.size()-1);
		cout << expression() << endl;
	}
	
    return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long int ll;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pow2(i) (1 << (i))
#define modi(a,b) ((a%b+b)%b)
#define uni(a,b) (((a+b)*(a+b+1)/2)+b)
const int MAXN=1e9+7;
ll int_pow(ll base, ll exp){
	ll result=1;
	while (exp){
		if (exp & 1)
		   result *= base;
		exp/=2;
		base*=base;
	}
	return result;
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,s=0,a;cin >> n;
	for (ll i=0;i<n;i++){
		cin >> a;
		s+=a;
	}
	if (s%2!=0)cout << "NO";
	else cout << "YES";
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

map<ll, ll> calc_cache;

ll calc(ll x) {
  if (x == 0) return 0;
  if (calc_cache.count(x) == 0) {
    calc_cache[x] = 1 + calc(x % __builtin_popcount(x));
  }
  return calc_cache[x];
}

int main() {
  in(ll, n);
  in(string, x);
  ll p = 0;
  for (char xi : x)
    if (xi == '1') ++p;

  map<ll, vector<ll>> mods_cache;
  function<map<ll, vector<ll>>::iterator(ll)> getMods = [&](ll mod) {
    if (mods_cache.count(mod) == 0) {
      vector<ll> m(n);
      m[0] = 1 % mod;
      for (ll i = 1; i < n; ++i) {
        m[i] = (m[i - 1] << 1) % mod;
      }
      mods_cache[mod] = m;
    }
    return mods_cache.find(mod);
  };

  function<ll(ll, ll)> getMod = [&](ll i, ll mod) {
    return getMods(mod)->second[n - 1 - i];
  };

  map<ll, ll> get_sum_cache;
  auto getSum = [&](ll mod) {
    if (get_sum_cache.count(mod) == 0) {
      ll sum = 0;
      rep(i, n) if (x[i] == '1') {
        sum += getMod(i, mod);
        // sum %= mod;
      }
      get_sum_cache[mod] = sum;
    }
    return get_sum_cache[mod];
  };
  /*
  dbg(p);
  dbg(getMod(0, 3));
  dbg(getMod(0, 10));
  dbg(getMod(1, 10));
  dbg(getMod(2, 10));
  dbg(getSum(3));
  dbg(getMod(0, 3));
  */
  rep(i, n) {
    if (x[i] == '1') {
      if (p == 1) {
        out(0);
      } else {
        ll sum = getSum(p - 1);
        // dbg(sum);
        sum -= getMod(i, p - 1);
        // dbg(i, sum, p - 1);
        sum %= p - 1;
        dbg(i, p - 1, sum);
        if (sum == 0) {
          out(1);
        } else {
          out(1 + calc(sum));
        }
      }
    } else {
      ll sum = getSum(p + 1);
      // dbg(sum);
      sum += getMod(i, p + 1);
      // dbg(i, sum, p + 1);
      sum %= p + 1;
      dbg(i, p + 1, sum);
      if (sum == 0) {
        out(1);
      } else {
        out(1 + calc(sum));
      }
    }
  }
}


Measured memory_bytes: 8156
N = int(input())
towns = [tuple(map(int, input().split())) for _ in range(N)]

total_distance = 0
count = 0
for start in range(N-1):
    for end in range(start+1, N):
        start_x, start_y = towns[start]
        end_x, end_y = towns[end]

        total_distance += ((end_x - start_x)**2 + (end_y - start_y)**2)**0.5
        count += 1

answer = total_distance * ((N - 1) / count)
print(answer)

Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
    ll n;
    cin >> n;
    ll h[n];
    for(ll i=0;i<n;i++)
        cin >> h[i];
    
    ll dp[n] = {0};
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(ll i=2;i<n;i++){
        dp[i] = min((dp[i-2]+abs(h[i]-h[i-2])),(dp[i-1]+abs(h[i]-h[i-1])));
    }
    
    cout << dp[n-1];
	return 0;
}

Measured memory_bytes: 1792