akhauriyash/Code-Regression huggingface dataset:
#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) a.begin(), a.end()
#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> pii;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-10;
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); }

/*--------------------template--------------------*/

typedef int Weight;
struct Edge
{
	int to; Weight cost;
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ to, cost });
}
void dijkstra(Graph &g, Array &d, int s)
{
	d.assign(g.size(), INF);
	d[s] = 0;
	typedef pair<Weight, int> P;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, s));
	while (!que.empty())
	{
		Weight dist = que.top().first;
		int v = que.top().second;
		que.pop();
		if (d[v] < dist) continue;
		REP(i, g[v].size())
		{
			Edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

struct D { int a, b, c, h, r; };
int main()
{
	int n, m, h, k;
	while (cin >> n >> m >> h >> k, n)
	{
		vector<D> v;
		REP(i, m)
		{
			int a, b, c, h, r;
			cin >> a >> b >> c >> h >> r;
			a--; b--; r--;
			v.push_back({ a,b,c,h,r });
		}
		int s, t;
		cin >> s >> t;
		s--; t--;
		vi cost(1 << k, INF);
		REP(ii, 1 << k)
		{
			Graph g(n*(h + 1));
			REP(i, m)
			{
				bool f = (ii >> v[i].r) & 1;
				REP(j, h - v[i].h + 1)
				{
					add_edge(g, v[i].a + n*j, v[i].b + n*(j + v[i].h), f ? 0 : v[i].c);
					add_edge(g, v[i].b + n*j, v[i].a + n*(j + v[i].h), f ? 0 : v[i].c);
				}
			}
			Array d;
			dijkstra(g, d, s);
			REP(i, h + 1) chmin(cost[ii], d[t + i*n]);
		}
		int p; cin >> p;
		vector<pii> pass;
		REP(i, p)
		{
			int l, d; cin >> l >> d;
			int bit = 0;
			REP(j, l)
			{
				int a; cin >> a; a--;
				bit |= (1 << a);
			}
			pass.emplace_back(bit, d);
		}
		Graph g(1 << k);
		Matrix mat(333, Array(333, INF));
		REP(i, 1 << k)
		{
			REP(j, p)
			{
				int to = i | pass[j].first;
				chmin(mat[i][to], pass[j].second);
			}
		}
		
		REP(i, 1 << k)REP(j, 1 << k)
		{
			if (mat[i][j] < INF) add_edge(g, i, j, mat[i][j]);
		}
		
		Array price;
		dijkstra(g, price, 0);
		int ans = INF;
		REP(i, 1 << k)
		{
			chmin(ans, cost[i] + price[i]);
		}
		if (ans >= INF) puts("-1");
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3520
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = scan.next();
        boolean yymm = is_yymm(s);
        boolean mmyy = is_mmyy(s);
        String answer = "NA";
        if (yymm && mmyy) {
            answer = "AMBIGUOUS";
        } else if (yymm) {
            answer = "YYMM";
        } else if (mmyy) {
            answer = "MMYY";
        }
        System.out.println(answer);
    }
    public static boolean is_yymm(String s) throws Exception {
        return is_year(s.substring(0,2)) && is_month(s.substring(2,4));
    }
    public static boolean is_mmyy(String s) throws Exception {
        return is_month(s.substring(0,2)) && is_year(s.substring(2,4));
    }
    private static boolean is_month(String month) throws Exception {
        int x = Integer.parseInt(month, 10);
        if (x < 1) {
            return false;
        }
        if (12 < x) {
            return false;
        }
        return true;
    }
    private static boolean is_year(String month) throws Exception {
        int x = Integer.parseInt(month, 10);
        if (x < 0) {
            return false;
        }
        if (99 < x) {
            return false;
        }
        return true;
    }
}


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

int main() {
  int N; cin >> N;
  string S; cin >> S;
  int ans = N;
  int sumE = 0;
  int sumW = 0;

  for(int i=1; i<N; i++){  //(0)がリーダー
    if(S.at(i)=='E') sumE++;
  }
  ans = min(sumE, ans);   
  for(int i=1; i<N; i++){ //(1からNがリーダー
    if(S.at(i-1) == 'W') sumW++;
    if(S.at(i) == 'E') sumE--;
    int tans = sumE + sumW;
    ans = min(tans, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3916
s=input()
cnt=0
ans=0
for i in range(len(s)):
  if i%2==0:
    if s[i]=='0':
      cnt+=1
  else:
    if s[i]=='1':
      cnt+=1
for i in range(len(s)):
  if i%2==0:
    if s[i]=='1':
      ans+=1
  else:
    if s[i]=='0':
      ans+=1
print(min(cnt,ans))

Measured memory_bytes: 3188
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long[] x = new long[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextLong();
        }
        long[] dp = new long[n];
        for (int i = 1; i < n; i++) {
            // System.out.println("x = " + x[i - 1]);
            // System.out.println("x = " + x[i]);
            dp[i] = Math.min(dp[i - 1] + a * (x[i] - x[i - 1]), dp[i - 1] + b);
            // System.out.printf("dp[%d] = %d %n", i, dp[i]);
        }
        // System.out.println(Arrays.toString(dp));
        System.out.println(dp[n - 1]);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

int main(){
    int K, S;
    int x, y;
    int ans = 0;

    cin >> K >> S;

    for(x=0; x<=K; x++){
        for(y=0; y<=K; y++){
            if(S-x-y>=0 && S-x-y<=K) ans++; 
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	cin >> N >> K;
	vpll P(N);
	for (i = 0; i < N; i++) {
		cin >> P[i].first >> P[i].second;
	}
	sort(P.begin(), P.end());
	ans = INF;
	vl X(N), Y(N);
	for (i = 0; i < N; i++) {
		X[i] = P[i].first;
		Y[i] = P[i].second;
	}
	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	for (i = 0; i < N; i++) {
		for (j = i; j < N; j++) {
			for (k = 0; k < N; k++) {
				for (l = k; l < N; l++) {
					ll count = 0;
					for (ll p = 0; p < N; p++) {
						ll x = P[p].first;
						ll y = P[p].second;
						if (X[i] <= x && x <= X[j] && Y[k] <= y && y <= Y[l]) {
							count++;
						}
					}
					if (count >= K) ans = min(ans, (X[j] - X[i]) * (Y[l] - Y[k]));
				}
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
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));
        int n = Integer.parseInt(br.readLine());
        String[] str_as = br.readLine().split(" ");
        int[] as = new int[n];
        int count = 0;
        boolean change = false;
        
        for (int i = 0; i < n; i++) {
            as[i] = Integer.parseInt(str_as[i]);
        }
        
        for (int i = 1; i < n; i++) {
            if (as[i] == as[i-1] && !change) {
                count++;
                change = true;
            }
            else change = false;
        }
        
        System.out.println(count);
    }
}


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

LL ec = 1,to[600005],nxt[600005],hed[300005] = {0};
LL col[600005] = {0};
LL deg[300005] = {0};
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

void dfs(LL u,LL f){
	LL cnt = 1;
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if((i ^ 1) == f) continue;
		if(cnt == col[f]) cnt ++;
		col[i] = cnt; cnt ++;
		dfs(v,i);
	}
}

int main(){
	LL n,u,v,id = 0;
	cin >> n;
	for(LL i = 1;i < n;i ++){
		cin >> u >> v;
		deg[u] ++; deg[v] ++;
		add_edge(u,v);
		add_edge(v,u);
	}
	for(LL i = 1;i <= n;i ++) if(deg[i] > deg[id]) id = i;
	cout << deg[id] << endl;
	dfs(id,0);
	for(LL i = 1;i < n;i ++) cout << max(col[i * 2],col[i * 2 + 1]) << endl;
	return 0;
}

Measured memory_bytes: 14976
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int n,k,a[100005],dp[100005];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
	    scanf("%d",&a[i]);
	for(int i=0;i<n;i++)
	    dp[i]=2e9;
	dp[0]=0;
	for(int i=1;i<n;i++)
	    for(int j=1;j<=k;j++)
	    {
	    	//cout<<i<<' '<<j<<endl;
	    	if(i>=j)
	            dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
		} 	        
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h> 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vv = vector<vector<int>>;
using P = pair<int,int>;

double kaijo( double x,int y ){
  if( y == 0 ) return 1;
  return x*kaijo(x,y-1);
}

int func( int x ,int k ){
  if( x >= k ) return 0;
  return 1+func(x*2,k);
}

int main(){
  double n; int k;
  cin >> n >> k;
  double ans=0;
  for(int i=1;i<=n;i++){
    ans += kaijo(0.5,func(i,k));
  }
  
  
  printf("%.9lf",ans/n);
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int V[21], C[21];
int main() {
    //cout << fixed << setprecision(8);
   
    int N; cin >> N;
    REP(i, N) cin >> V[i];
    REP(i, N) cin >> C[i];
    
    int a[21]={0};
    for(int i=0; i<N; ++i){
        a[i] = V[i]-C[i];
    }
    sort(a, a+N);
    reverse(a, a+N);
    int ans=0;
    for(int i=0; i<N; ++i){
        if(a[i]<=0) break;
        ans += a[i];
    }
    cout << ans << endl;
	return 0;
}

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

int main(){
    int n, A[100], c = 0;
    cin >> n;
    for ( int i = 0; i < n; i++) cin >> A[i];

    for ( int i = 0; i < n-1; i++){
        int minj = i;
        for ( int j = i; j< n; j++){
            if ( A[j] < A[minj]) minj = j;
        }
        if ( i != minj){
            swap(A[i], A[minj]);
            c++;
        }
    }

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

    cout << c << endl;

    return 0;
}


Measured memory_bytes: 3104
import sys
sys.setrecursionlimit(100000)
n = int(input())
stones = list(map(int, input().split()))
stones.reverse()

bottum_up = [-1 for i in range(n)]
bottum_up[0] = 0
bottum_up[1] = abs(stones[0] - stones[1])

for i in range(2,len(stones)):
    score_1 = abs(stones[i] - stones[i-1]) + bottum_up[i-1]
    score_2 = abs(stones[i] - stones[i-2]) + bottum_up[i-2] 
    bottum_up[i] = min(score_1, score_2)

print(bottum_up[-1])

Measured memory_bytes: 13976
open System

let n = Console.ReadLine() |> int

let testimonies: (int * int) list list =
    [ for i in 1 .. n do
        let a = Console.ReadLine() |> int
        yield [ for j in 1 .. a do
                    let xy = Console.ReadLine().Split(' ') |> Array.map int
                    yield xy.[0] - 1, xy.[1] ] ]

let ans =
    let rec dfs is rest =
        match rest with
        | [] ->
            let set = Set is

            let ok =
                is
                |> List.map (fun i -> testimonies.[i])
                |> List.map (fun testimonies ->
                    testimonies
                    |> List.forall (fun testimony ->
                        let x, y = testimony
                        (y = 0 && not (set.Contains x)) || (y = 1 && set.Contains x)))
                |> List.forall (fun b -> b)

            if ok then List.length is else 0
        | i :: rest ->
            max (dfs is rest) (dfs (i :: is) rest)

    dfs [] [ 0 .. n - 1 ]

ans |> Console.WriteLine


Measured memory_bytes: 18528
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

int main(){
    long n;
    long a[5];
    long t[5];
    long x[5];

    cin >> n;
    for(int i=0; i<5; i++){
        cin >> a[i];
    }

    long result;
    long through=a[0]+1;
    for(int i=0; i<5; i++){
        if( through > a[i]) through=a[i];
    }
    result = 5+(n/through);
    if( n%through == 0) result--;
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
ll a[100000];
ll dom[100001];

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

int main(){
  ll n;
  cin>>n;
  ll ans=n-1;
  for(ll i=2;i*i<=n;i++){
    if(n%i==0){
      ll x=i-1;
      ll y=n/i-1;
      ans=min(ans,x+y);
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
ll a,b,k;
int main(){
    scanf("%lld%lld%lld",&a,&b,&k);
    ll mx;
    mx=min(a,k);
    a-=mx,k-=mx;
    mx=min(b,k);
    b-=mx,k-=mx;
    printf("%lld %lld\n",a,b);
    return 0;
}

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

int main() {
  vector<int> vec(4);
	for (int i = 0; i < 4; i++) {
  	cin >> vec.at(i);
	}
  auto beg = vec.begin();
  auto end = vec.end();
  if(
  count(beg,end,1) == 1 &&
  count(beg,end,9) == 1 &&
  count(beg,end,7) == 1 &&
  count(beg,end,4) == 1
    ){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    vector <string> ss;
    vector <ll> times;
    REP(i, n){
        string s; cin >> s;
        ss.push_back(s);
        ll t; cin >> t;
        times.push_back(t);
    }
    string neru; cin >> neru;
    bool fell = false;
    ll ans = 0;
    REP(i, n){
        if (fell){
            ans += times[i];
        }
        if (ss[i] == neru){
            fell = true;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;

typedef long long ll;

const int N = 155;
int a[N + 5];

vector<pair<int,int> > lst;

void hora(int tc) {
	int n;
	cin>>n;
	for(int i = 1;i < n;i++) {
		int x;
		cin>>x;
		lst.pb({x, i});
	}
	sort(lst.begin(), lst.end());
	memset(a, -1, sizeof a);
	int tot = 0;
	for(int i = 0;i < lst.size();i++) {
		int val = lst[i].F;
		int id = lst[i].S;
		if(a[id] == -1) tot += val, a[id] = val;
		if(a[id + 1] == -1) tot += val, a[id + 1] = val;
	}
	cout<<tot<<endl;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.setf(ios::showpoint), cout.precision(10);
	int ntc = 1;
//	cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) {
		hora(tc);
	}
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 3e5 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;

ll n,k,sum,a[N],i;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>k;
    for (i = 1;i <= n;i++) cin>>a[i];
    sort(a + 1,a + n + 1);
    for (i = 1;i <= k;i++) sum += a[i];
    cout<<sum;
}


Measured memory_bytes: 3644
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int v[] = new int[n];
    int c[] = new int[n];
    int ans = 0;
    for(int i=0;i<n;i++){
      v[i] = sc.nextInt();
    }
    for(int j=0;j<n;j++){
      c[j] = sc.nextInt();
    }
    for(int k=0;k<n;k++){
      if(v[k]-c[k] >= 0){
        ans += v[k]-c[k];
      }
    }
    System.out.println(ans);
  }
}
      

Measured memory_bytes: 21844
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc179
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
            solve_abc179C();
            Console.Out.Flush();
        }
        public static void solve_abc179C()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int cnt = 0;
            for (int i = 1; i <= 1000000; i++)
            {
                for (int j = 1; j <= 1000000; j++)
                {
                    if (i * j < n)
                    {
                        cnt++;
                        //Console.WriteLine("{0} * {1} = {2}, {3} - {2} = {4}", i, j, i * j, n, n - (i * j));
                    }
                    else
                    {
                        break;
                    }
                }
            }
            Console.WriteLine(cnt);
        }

        public static void solve_abc179B()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            int cnt = 0;
            int max = 0;
            while (t-- > 0)
            {
                int[] d = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                if (d[0] == d[1])
                {
                    cnt++;
                }
                else
                {
                    cnt = 0;
                }
                max = Math.Max(max, cnt);
            }
            Console.WriteLine(max >= 3 ? "Yes" : "No");
        }

        public static void solve_abc179A()
        {
            string s = Console.ReadLine();
            Console.WriteLine(s.EndsWith('s') ? s + "es" : s + "s");
        }
    }
}

Measured memory_bytes: 28480
from collections import Counter
N = int(input())
factors = []
for i in range(N):
    T = N-i
    d = 2
    while d**2<=T:
        if T%d==0:
            factors.append(d)
            T//=d
        else:
            d+=1
    if T!=1:
        factors.append(T)
factors = Counter(factors)
ans = 1
for v in factors.values():
    ans *= (v+1)
mod = 10**9 +7
print(ans%mod)

Measured memory_bytes: 39408
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main = do
    [n] <- readInt
    putStrLn $ solve n

solve n | null m    = ":("
        | otherwise = show $ head m
  where
    ns = [floor (fromIntegral n * 100 / 108) .. n]
    m  = filter (\x -> floor (fromIntegral x * 1.08) == n) ns


Measured memory_bytes: 380
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
using namespace std;
typedef long long ll;
const int maxn=200050;
int pre[maxn],sz[maxn];
int n,m;

void init(){
	for(int i=1;i<=n;i++){
		pre[i]=i;sz[i]=1;
	}
}
int find(int x){
	if(pre[x]==x)	return x;
	pre[x]=find(pre[x]);
	return pre[x];
	return (pre[x]==x)?x:pre[x]=find(pre[x]);
}
void join(int x,int y){
	x=find(x);y=find(y);
	if(x==y)	return;
	pre[x]=y;sz[y]+=sz[x];
}
void solve(){
	scanf("%d %d",&n,&m);
	init();
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		join(u,v);
	}
	int res=0;
	for(int i=1;i<=n;i++){
		if(pre[i]==i)	res=max(res,sz[i]);
	}
	printf("%d\n",res);
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 5344
#include<iostream>
#include<vector>
#define ll long long
using namespace std;
const int INF=1e9L+5;
int main()
{
  ll n;
  scanf("%d",&n);
  vector<ll>h(n);
  for(ll& x: h)
     scanf("%d",&x);
  vector<ll>dp(n,INF);
  dp[0]=0;
  for(ll i=0;i<n;i++){
    for(ll j:{i+1,i+2}){
      if(j<n)
        dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
    }
  }
  printf("%lld\n",dp[n-1]);
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;

bool f(){
    for(int i=0;i<3;++i){
        if(S[i] == S[i + 1]){
            return true;
        }
    }

    return false;
}

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

    std::cin >> S;

    if(f()){
        std::cout << "Bad" << std::endl;
    }else{
        std::cout << "Good" << std::endl;
    }
}


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

using namespace std;

int main(){
  int a,b; cin>>a>>b;
  if(a==b){ cout<<"Draw";
           
          }else if(a!=1 && b!=1){
    (a<b)? cout<<"Bob":cout<<"Alice";
  }
  else if(a==1) cout<<"Alice";
  else if(b==1) cout<<"Bob";
  
  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 INF 114514810
#define MOD 1000000007
#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;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

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

int main()
{
	int a, b;
	cin >> a >> b;
	cout << gcd(a, b) << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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 long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N;
        cin >> N;
        vector<int> L(N);
        rep(i, 0, N) cin >> L[i];

        sort(all(L));
        int large = L.back();
        int sum = accumulate(all(L) - 1, 0);
        if (sum > large) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 384
N = int(input())
S = input()
ans = 0
anslst = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            anslst.append(str(i) + str(j) + str(k))

tmp = ans
for i in anslst:
    a, b, c = i
    index1 = S.find(a)
    index2 = S.find(b, index1 + 1)
    index3 = S.find(c, index2 + 1)
    if index1 != -1 and index2 != -1 and index3 != -1:
        ans += 1
print(ans)

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

int main() {
  int a = 0;
  int b = 0;
  cin >> a >> b;
  double mean = (a + b) / 2.0;
  int result = 0;
  int mean10 = mean * 10;
  if (mean10 % 10 != 0){
    result = mean + 1;
  }else{
    result = mean;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
n = gets.to_i

firstB, lastA = 0, 0
count = 0
duplicate = 0

n.times do |i|
  tmp = gets.chomp
  firstB += 1 if tmp[0] == "B"
  lastA += 1 if tmp[-1] == "A"
  duplicate += 1 if tmp[0] == "B" && tmp[-1] == "A"
  count += tmp.scan("AB").length
end

#puts "firstB:#{firstB}, lastA:#{lastA}, dup:#{duplicate}"

if duplicate == 0
  count += [firstB, lastA].min
else
  if firstB == duplicate && lastA == duplicate
    count += duplicate - 1
  else
    count += [firstB, lastA].min
  end
end
puts count

Measured memory_bytes: 3836
#include <stdio.h>

int main(void)
{
    int n,m,l;
    int i,j,k;
    int sumA[101][101]={},sumB[101][101]={};
    long int sumC[101][101]={};
    
    scanf("%d %d %d",&n,&m,&l);
    
    for(i=0;i<=n;i++){
        for(k=0;k<m;k++){
            if(i<n)scanf("%d",&sumA[i][k]);
            
                if(i==n){
                    for(j=0;j<l;j++){
                        scanf("%d",&sumB[k][j]);
                    }
                }
        }
    }
    
    for(j=0;j<l;j++){
        for(i=0;i<n;i++){
            for(k=0;k<m;k++){
                sumC[i][j]+=sumA[i][k]*sumB[k][j];
            }
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            printf("%ld",sumC[i][j]);
            if(j<l-1){
                printf(" ");
            }else{
                printf("\n");
        }
    }
    }
    return 0;
}


Measured memory_bytes: 2088
import java.util.Scanner;

/**
 * https://abc065.contest.atcoder.jp/tasks/arc076_a
 */
public class Main {
	
	static final int MOD = 1000000007;

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		sc.close();
		
		long ans = 0;
		if(Math.abs(N-M)<=1){
			ans = getFactorial(N)*getFactorial(M)%MOD;
			if(N==M){
				ans = ans*2%MOD;
			}
		}
		
		System.out.println(ans);

	}
	
	static long getFactorial(long n){
		long a = 1;
		for(long i=1; i<=n; i++){
			a = a*i%MOD;
		}
		return a;
	}

}

Measured memory_bytes: 23764
import java.util.*;
import java.math.*;
public class Main {
	static int[] color;
	static int[] component;
	static int component_count;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		color = new int[n];
		component = new int[n];
		component_count = 1;
		User[] user = new User[n];
		for(int i = 0; i < n; i++) user[i] = new User(i);
		for(int i = 0; i < m; i++) {
			int x = in.nextInt() - 1;
			int y = in.nextInt() - 1;
			user[x].rel.add(y);
			user[y].rel.add(x);
		}
		for(int i = 0; i < k; i++) {
			int x = in.nextInt() - 1;
			int y = in.nextInt() - 1;
			user[x].blck.add(y);
			user[y].blck.add(x);
		}
		int comp_num = 0;
		int[] num_user_comp = new int[n];
		for(int i = 0; i < n; i++) {
			if(color[i] == 0) {
				component_count = 1;
				dfs(user[i], user, comp_num);
				num_user_comp[comp_num] = component_count;
				comp_num += 1;
			}
		}
		for(int i = 0; i < n; i++) {
			int ans = num_user_comp[component[i]] - 1;
			ans -= user[i].rel.size();
			for(int x : user[i].blck) {
				if(component[i] == component[x]) ans -= 1;
			}
			if(i > 0) System.out.print(" ");
			System.out.print(ans);
		}
		System.out.print("\n");
	}
	static void dfs(User root, User[] user, int comp_num) {
		color[root.id] = 1;
		component[root.id] = comp_num;
		for(int x : root.rel) {
			if(color[x] == 0) {
				dfs(user[x], user, comp_num);
				component_count += 1;
			}
		}
	}
} 
class User {
	List<Integer> rel = new ArrayList<>();
	List<Integer> blck = new ArrayList<>();
	int id;
	public User(int id) {
		this.id = id;
	}
}

Measured memory_bytes: 164112
n=int(input())
p=input().rstrip().split(' ')
o=int(input())
for i in range(0,o):
    d=0;
    C=list(p)
    h=input().rstrip().split(' ')
    C[int(h[0])-1] = int(h[1])
    for j in range(0,len(p)):
        d=d+int(C[j])
    print(d)

Measured memory_bytes: 38512
package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	var n int
	fmt.Fscanf(in, "%d", &n)

	p := make([]int, n)
	sum := 0
	pmax := 0
	for i := range p {
		fmt.Fscanf(in, "%d", &p[i])
		if p[i] > pmax {
			pmax = p[i]
		}
		sum += p[i]
	}
	sum -= pmax / 2
	fmt.Fprintln(out, sum)
}


Measured memory_bytes: 512
N = int(input())
A=[int(i) for i in input().split()]
L = []
asum=A[0]
axor=A[0] 
i=0
j=0
while (i<N):
    while (asum ==axor) and (j<N-1):
        j = j+1
        asum += A[j]
        axor ^= A[j]
    if (j<N-1):
        L.append((i,j-1))
        asum -= A[i]
        axor ^= A[i] 
        i += 1
    elif (asum ==axor):
        L.append((i,N-1))
        i += 1 
    else:
        L.append((i,j-1))
        asum -= A[i]
        axor ^= A[i] 
        i += 1
ans = 0
for l,r in L:
    ans += r-l+1
print(ans)

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


int main(){
    long long n;
    long long a,b;
    cin>>n>>a>>b;
    long long c=b-a;
    if(c%2==0) cout<<c/2<<endl;
    else{
        long long tail=n-b, head=a-1;
        if(head<=tail) {
            b=b-head-1;
            a=1;
            c=(b-a)/2+head+1;
        }
        else {
            b=n;
            a=a+tail+1;
            c=(b-a)/2+tail+1;
        }
        cout<<c<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 384
package main

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

func main() {
	K := ReadInt()
	sum := 0
	for a := 1; a <= K; a++ {
		for b := 1; b <= K; b++ {
			for c := 1; c <= K; c++ {
				sum += GCD(GCD(a, b), c)
			}
		}
	}
	fmt.Println(sum)
}

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 1868
N, M, Q = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for _ in range(M)]
PQ = [[int(_) for _ in input().split()] for _ in range(Q)]
cumsum = [[0] * (N + 2) for _ in range(N + 2)]
for l, r in LR:
    cumsum[l][r + 1] += 1
for i in range(1, N + 2):
    for j in range(1, N + 2):
        cumsum[i][j] += cumsum[i][j - 1]
for j in range(1, N + 2):
    for i in range(1, N + 2):
        cumsum[i][j] += cumsum[i - 1][j]
for p, q in PQ:
    print(cumsum[q][q + 1] - cumsum[p - 1][q + 1])


Measured memory_bytes: 58496
#include<stdio.h>
#define N 500000
#define S 1000000000
int count;
int L[N/2+2],R[N/2+2];
void merge(int A[],int left ,int mid,int right){
  int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<=n2-1;i++){
    R[i]=A[mid+i];
  }
  L[n1]=S;
  R[n2]=S;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
    count++;
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }
    else {
      A[k]=R[j];
      j++;
    }
  }
}

void mergeSort(int A[],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){
  int A[N],i,n;
  scanf("%d",&n);
  count=0;
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(A[i]>=S) break;
  }
  mergeSort(A,0,n);
  
  for(i=0;i<n;i++){
    if(i!=0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}
  
    



Measured memory_bytes: 5688
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;

int main()
{
	int c[3][3];
	rep(i, 3)rep(j, 3)cin >> c[i][j];
	int a[3], b[3];
	a[0] = 0;
	rep(i, 3)b[i] = c[0][i];
	a[1] = c[1][0] - b[0];
	a[2] = c[2][0] - b[0];

	rep(i,3)
	{
		rep(j, 3)
		{
			if (a[i] + b[j] != c[i][j])
			{
				co("No");
				return 0;
			}
		}
	}
	co("Yes");
	return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
max_l = 0
min_r = 100000
for i in range(m):
  l,r = map(int,input().split())
  max_l = max(l, max_l)
  min_r = min(r, min_r)
print(max(0, min_r-max_l+1))

Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define tr(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
#define MOD 1000000007
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/

const int N=2e3+10;
vector<pair<int,int>> adj[N];

int ans[N];

void dijkstra(int source)
{
	int n=N;
	int var[n];
	int fix[n];
	for(int i=0;i<n;i++)
	{
		var[i]=inf;
	}
	memset(fix,-1,sizeof(fix));
	set<pair<int,int>> s;
	s.insert({0,source});
	fix[source]=0;
	var[source]=0;
	while(s.size())
	{
		pair<int,int> cur=*(s.begin());
		s.erase(cur);
		fix[cur.second]=cur.first;
		for(auto x: adj[cur.second])
		{
			if(var[x.first]>cur.first+x.second)
			{
				s.erase({var[x.first],x.first});
				var[x.first]=cur.first+x.second;
				s.insert({var[x.first],x.first});
			}
		}
	}
	for(int i=1;i<n;i++)
	{
		ans[fix[i]]++;
	}
}

int32_t main()
{
	fastio();
	int n;
	cin>>n;
	int x,y;
	cin>>x>>y;
	for(int i=1;i<n;i++)
	{
		adj[i].push_back({i+1,1});
		adj[i+1].push_back({i,1});
	}
	adj[x].push_back({y,1});
	adj[y].push_back({x,1});
	for(int i=1;i<=n;i++)
	{
		dijkstra(i);
	}
	for(int i=1;i<n;i++)
	{
		cout<<ans[i]/2<<endl;
	}
}


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

int main (void) {
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  A--;
  B--;
  C--;
  D--;

  string S;
  cin >> S;

  // 2連続の岩がゴールより手前にあったらアウト
  for (int i = A; i < max(C, D) - 1; i++) {
    if (S[i] == '#' && S[i + 1] == '#') {
      cout << "No" << endl;
      return 0;
    }
  }

  // C < D ならそのままOK
  if (C < D) {
    cout << "Yes" << endl;
    return 0;
  }

  // C > D
  // ...
  // AB.
  // .BA
  // B-1より先で追い越せる場所がDまでにあるならOK
  for (int i = B - 1; i < D; i++) {
    if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


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

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int H , W ; cin >> H >> W ;
  deque<bool> board(H*W,false);
  vector<int> dilate(H*W,-1);
  queue<pair<int,int>> rest;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      char c; cin >> c;
      if(c=='#'){
        board[j+i*W] = true;
        dilate[j+i*W] = 0;
        rest.emplace(i,j);
      }
    }
  }
  
  int offx[4] = {-1,1,0,0};
  int offy[4] = {0,0,-1,1};
  int num=0;
  while(!rest.empty()){
    pair<int,int> next = rest.front();
    int ci = next.first,cj = next.second;
    rest.pop();
    for(int n=0;n<4;n++){
      int i = ci+offy[n];
      int j = cj+offx[n];
      if(i>=0 && i<H && j>=0 && j<W && !board[j+i*W] && dilate[j+i*W]==-1){
        dilate[j+i*W] = dilate[cj+ci*W]+1;
        rest.emplace(i,j);
      }
    }
  }
  printf("%d",*max_element(dilate.begin(),dilate.end()));
  return 0;
}


Measured memory_bytes: 13328
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;


int main(){
    ll A, B, C;
    cin >> A >> B >> C;
    if(A + B >= C - 1) cout << B + C << endl;
    else{
        cout << A + 2 * B + 1 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define int long long
using namespace std;
const int maxn = 2e5+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n,d;
struct node{
	int x,h;
}a[maxn];
int w[maxn],p[maxn];
int cmp(node x,node y){
	return x.x<y.x;
}
signed main(){
	n=read();d=read();k=read();
	for(register int i=1;i<=n;i++){
		a[i].x=read();a[i].h=read();
	}
	sort(a+1,a+n+1,cmp);
	for(register int i=1;i<=n;i++)p[i]=a[i].x;
	int ans=0,sum=0;
	for(register int i=1;i<=n;i++){
		sum+=w[i];
		if(a[i].h<=sum*k)continue;
		a[i].h-=sum*k;
		int num=(a[i].h-1)/k+1;ans+=num;
		int x=upper_bound(p+1,p+n+1,a[i].x+d*2)-p;
		w[i+1]+=num;
		w[x]-=num;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[100005][3];

int dp[100005][4];

int solve(int i, int prev){
	if(i == n) return 0;
	if(dp[i][prev] != -1) return dp[i][prev];

	dp[i][prev] = -1e7;
	int a = 0, b = 0, c = 0;
	if(prev != 0)
		a = solve(i+1, 0) + arr[i][0];
	if(prev != 1)
		b = solve(i+1, 1) + arr[i][1];
	if(prev != 2)
		c = solve(i+1, 2) + arr[i][2];

	dp[i][prev] = max(a, max(b, c));
	return dp[i][prev];
}

int main(){
	cin>>n;
	for (int i = 0; i < n; ++i)
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];

	memset(dp, -1, sizeof dp);
	cout<<solve(0, 3)<<endl;
	return 0;
}

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

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (input[0] % 2 == input[1] % 2)
            {
                Console.WriteLine((input[0] + input[1]) / 2);
            }
            else
            {
                Console.WriteLine("IMPOSSIBLE");
            }
        }
    }
}


Measured memory_bytes: 13396