akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    string s; cin >> s;

    string ans;
    for (auto c : s) {
        if ('0' == c) ans.push_back('0');
        if ('1' == c) ans.push_back('1');
        if ('B' == c) {
            if (ans.empty()) continue;
            ans.pop_back();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

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 nextDoutble(){return Double.parseDouble(next());}
}
public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int h = fs.nextInt();
        int w = fs.nextInt();
        char[][] a = new char[h][w];
        long[][] dp = new long[h][w];
        for(int i=0;i<h;i++){
            a[i] = fs.next().toCharArray();
        }
        int mod = 1000000007;
        dp[0][0] = 1;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(a[i][j]=='#')continue;
                if(j+1 < w && a[i][j+1]!='#'){
                    dp[i][j+1]+=dp[i][j];
                    dp[i][j+1]%=mod;
                }
                if(i+1 < h && a[i+1][j]!='#'){
                    dp[i+1][j]+=dp[i][j];
                    dp[i+1][j]%=mod;
                }
            }
        }
        System.out.println(dp[h-1][w-1]);
        
    }
}

Measured memory_bytes: 49148
#include<stdio.h>
#include<math.h>

int main(){

  int a,b;
  double c,s,l,h;

  scanf("%d %d %lf", &a, &b, &c);
  c=c*M_PI/180;
  s=0.5*a*b*sin(c);
  l=a+b+sqrt((a*a)+(b*b)-2*a*b*cos(c));
  h=2*s/a;

  printf("%f %f %f\n", s, l, h);


  return 0;
}

Measured memory_bytes: 1992
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

int main(){
	int n, m, a, b;
	scanf("%d%d", &n, &m);
	vector<int> cnt(n + 1);
	vector<vector<int> > G(n + 1);
	for(int i = 0; i < m; ++i){
		scanf("%d%d", &a, &b);
		G[a].push_back(b);
		++cnt[b];
	}

	queue<int> q;
	for(int i = 1; i <= n; ++i){
		if(!cnt[i]){
			q.push(i);
		}
	}

	vector<int> ans;
	ans.reserve(n);
	int other = 0;
	while(!q.empty()){
		if(q.size() > 1){
			other = 1;
		}
		a = q.front();
		q.pop();
		ans.push_back(a);
		for(size_t i = 0; i < G[a].size(); ++i){
			b = G[a][i];
			if(!--cnt[b]){
				q.push(b);
			}
		}
	}
	
	for(int i = 0; i < n; ++i){
		printf("%d\n", ans[i]);
	}
	printf("%d\n", other);
}

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

string s, ans;
int cnt[3];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> s;
	for (int i = 0; i < s.size(); ++i) cnt[s[i]-'a']++;

	int fi = -1, se = -1;
	for (int i = 0; i < s.size(); ++i) {
		int ch = -1, mx = 0;
		for (int nxt = 0; nxt < 3; ++nxt) if (nxt != fi && nxt != se) {
			if (cnt[nxt] > mx) {
				ch = nxt; mx = cnt[nxt];
			}
		}
		if (ch >= 0) swap(fi, se), se = ch, cnt[ch]--;
		else return cout << "NO\n", 0;
	}

	cout << "YES\n";
}

Measured memory_bytes: 512
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int maxflow(vector<vector<int>> E_, vector<vector<int>> F_, int s, int t)
{
    int n = (int)E_.size();

    vector<vector<int>> E(n), F(n), R(n);
    for (int i=0; i<n; i++)
    for (int j=0; j<(int)E_[i].size(); j++)
    {
        int v = E_[i][j];
        R[i].push_back(int(E[v].size()));
        R[v].push_back(int(E[i].size()));
        E[i].push_back(v);
        E[v].push_back(i);
        F[i].push_back(F_[i][j]);
        F[v].push_back(0);
    }
    vector<bool> U(n);
    function<int (int, int)> dfs = [&](int p, int f)
    {
        if (p==t)
            return f;
        U[p] = true;
        for (int i=0; i<(int)E[p].size(); i++)
        if (!U[E[p][i]] && F[p][i]>0)
        {
            int t = dfs(E[p][i], min(f, F[p][i]));
            if (t>0)
            {
                F[p][i] -= t;
                F[E[p][i]][R[p][i]] += t;
                return t;
            }
        }
        return 0;
    };

    int flow = 0;
    while (true)
    {
        for (int i=0; i<n; i++)
            U[i] = false;
        int f = dfs(s, 0x7fffffff);
        if (f==0)
            break;
        flow += f;
    }

    return flow;
}

int bipartite(vector<vector<int>> M)
{
    int n = (int)M.size();
    int m = 0;
    for (int i=0; i<n; i++)
        for (int j=0; j<(int)M[i].size(); j++)
            m = max(m, M[i][j]+1);

    vector<vector<int>> E(n+m+2), F(n+m+2);

    for (int i=0; i<n; i++)
    for (int j=0; j<(int)M[i].size(); j++)
        E[i].push_back(n+M[i][j]),
        F[i].push_back(1);
    for (int i=0; i<n; i++)
        E[n+m].push_back(i),
        F[n+m].push_back(1);
    for (int i=0; i<m; i++)
        E[n+i].push_back(n+m+1),
        F[n+i].push_back(1);

    return maxflow(E, F, n+m, n+m+1);
}

#include <iostream>

int main()
{
    int N;
    cin>>N;
    vector<int> a(N), b(N), c(N), d(N);
    for (int i=0; i<N; i++)
        cin>>a[i]>>b[i];
    for (int i=0; i<N; i++)
        cin>>c[i]>>d[i];
    vector<vector<int>> M(N);
    for (int i=0; i<N; i++)
        for (int j=0; j<N; j++)
            if (a[i]<c[j] && b[i]<d[j])
                M[i].push_back(j);
    cout<<bipartite(M)<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll N, K; cin >> N >> K;

    vector<ll> X(N);
    for (ll i = 0; i < N; i++) {
        cin >> X[i];
    }

    ll c;
    c = lower_bound(ALL(X), 0) - X.begin();

    ll ans = INF;
    for (ll a = 1; a < K; a++) {
        if(c + a - 1 <= N-1 && c - K + a >= 0){
            ans = min(ans, min(X[c+a-1], -X[c-K+a]) + X[c+a-1] - X[c-K+a]);
        }
    }

    if(c-K >= 0){
        ans = min(ans, -X[c-K]);
    }
    if(c+K-1 <= N-1){
        ans = min(ans, X[c+K-1]);
    }
    printf("%lld\n", ans);

}


Measured memory_bytes: 3988
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

long double r;

const long double pi = acos(-1.0);

int main() {
    std::cin >> r;
    printf("%.10Lf\n", r * 2 * pi);
    return 0;
}

Measured memory_bytes: 3792
open Printf open Scanf
open Array

let binary_search ng ok f = let d = if ng < ok then 1 else -1 in
  let rec f0 ng ok =
    if abs (ok - ng) <= 1 then ok
    else let mid = ng + (ok - ng) / 2 in if f mid then f0 ng mid else f0 mid ok
  in f0 (ng-d) (ok+d)

let () = scanf " %d %d" @@ fun n k ->
  let a = init n (fun _ -> scanf " %d" @@ fun v -> v) in
  sort compare a;
  print_int @@ binary_search 0 (n-1) (fun i ->
    let u = a.(i) in
    if u >= k then true
    else (
      let f = ref false in
      let dp = make (k+1) false in
      iteri (fun j v ->
        if j=i then ()
        else (
          for w=k downto 1 do
            if dp.(w) then (
              if k-u <= w+v && w+v < k then
                f := true
              else if w+v < k then
                dp.(w+v) <- true
            )
          done;
          if v<k then dp.(v) <- true
        );
      ) a; !f
    )
  )





Measured memory_bytes: 3968
n = int(input())
a = [int(x) for x in input().split()]
abs_a = [abs(x) for x in a]
parity_a = len([x for x in a if x < 0]) % 2

if parity_a == 0:
  print(sum(abs_a))
else:
  print(sum(abs_a) - 2 * min(abs_a))

Measured memory_bytes: 14412
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int n; cin >> n;
    int ans = 0;
    if(n <= 9){
        ans = n;
        cout << ans << endl;
        return 0;
    }
    else ans += 9;
    if(n <= 99){
        cout << ans << endl;
        return 0;
    }
    else if(n <= 999){
        ans += (n-99);
        cout << ans << endl;
        return 0;
    }
    else ans += 900;
    if(n <= 9999){
        cout << ans << endl;
        return 0;
    }
    else if(n <= 99999){
        ans += (n-9999);
        cout << ans << endl;
        return 0;
    }
    else if(n == 100000){
        ans += 90000;
        cout << ans << endl;
        return 0;
    }
    return 0;
} 


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

// void chmod(ll &M){
//     if(M >= mod) M %= mod;
//     else if(M < 0){
//         M += (abs(M)/mod + 1)*mod;
//         M %= mod;
//     }
// }

int main(){
    int N; cin >> N;
    vector<int> a(N), b(N);
    for(int i=0; i<N; ++i) cin >> a[i];
    for(int i=0; i<N; ++i) cin >> b[i];

    int ans = 0;

    for(int k=28; k>=0; --k){
        int T = 1<<k;
        for(int i=0; i<N; ++i) {
            a[i] %= 2*T;
            b[i] %= 2*T;
        }
        sort(b.begin(), b.end());
        ll cnt = 0;
        for(int i=0; i<N; ++i){
            cnt += lower_bound(b.begin(), b.end(), 2*T-a[i]) - lower_bound(b.begin(), b.end(), T-a[i]);
            cnt += lower_bound(b.begin(), b.end(), 4*T-a[i]) - lower_bound(b.begin(), b.end(), 3*T-a[i]);
        }
        if(cnt%2 == 1) ans += T;
    }

    cout << ans << endl;
}

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

const int MAXN = 2e5 + 5;

int n, a[MAXN];

long long gao(long long x) {
  long long cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] < 0) {
      if (1LL * a[n - 1] * a[i] > x) continue;
      int l = 0, r = n - 1, ans = n - 1;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (1LL * a[mid] * a[i] <= x) {
          ans = mid;
          r = mid - 1;
        } else {
          l = mid + 1;
        }
      }
      cnt += n - ans;
      if (i >= ans) --cnt;
    } else if (a[i] > 0) {
      if (1LL * a[0] * a[i] > x) continue;
      int l = 0, r = n - 1, ans = 0;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (1LL * a[mid] * a[i] <= x) {
          ans = mid;
          l = mid + 1;
        } else {
          r = mid - 1;
        }
      }
      cnt += ans + 1;
      if (i <= ans) --cnt;
    } else {
      if (x >= 0) cnt += n - 1;
    }
  }
  // if (cnt & 1) cerr << cnt << endl;
  return cnt / 2;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  long long l = -1e18, r = 1e18, ans, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);

  // for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
  // cerr << endl;
  // cerr << gao(448283280358331064ll) << endl;
  // cerr << gao(448283280358331064ll + 1) << endl;

  while (l <= r) {
    long long mid = (l + r) / 2;
    if (gao(mid) >= k) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int LCS[3002][3002];
char s[3002];
char t[3002];
int max(int a,int b){
    return a>b?a:b;
}
int main() {
	// your code goes her
	int i,j,k,n,m;
	vector<char> v;
	cin>>s;
	cin>>t;
	int maxx=0,imax,jmax;
	n=strlen(s);
	m=strlen(t);
	for(i=n;i>=1;i--)
	    s[i]=s[i-1];
	for(i=m;i>=1;i--)
	    t[i]=t[i-1];
	for(i=1;i<=n;i++){
	    for(j=1;j<=m;j++){
	        if(s[i]==t[j])
	            LCS[i][j]=LCS[i-1][j-1]+1;
	        else
	            LCS[i][j]=max(LCS[i][j-1],LCS[i-1][j]);
	    }
	}
	i=n;j=m;
    while(i!=0 && j!=0){
        if(LCS[i][j]==LCS[i-1][j]){
            i=i-1;
            continue;
        }
        else if(LCS[i][j]==LCS[i][j-1]){
            j=j-1;
            continue;
        }
        else{
            v.push_back(s[i]);
            i--;
            j--;
        }
    }
    reverse(v.begin(),v.end());
    for(i=0;i<v.size();i++)
        cout<<v[i];
}


Measured memory_bytes: 35456
A,B=map(int,input().split())
S=input()
f=True
if len(S)!=A+B+1:
    f=False
num=[chr(i) for i in range(ord('0'),ord('9')+1)]
for i,c in enumerate(S):
    if (i!=A and c not in num) or (i==A and c!='-'):
        f=False
        break
print('Yes' if f else 'No')

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

ll mod=1e9+7;

ll mod_pow(int x, int n)
{
    ll pw[31];
    pw[0]=x;
    for(int i=1; i<31; ++i) pw[i]=(pw[i-1]*pw[i-1])%mod;

    ll ret=1;
    rep(i,31)
    {
        if(n&(1<<i)) (ret*=pw[i])%=mod;
    }
    return ret;
}

ll mod_inv(int x)
{
    return mod_pow(x,mod-2);
}

ll dp[5001][5001]={0};

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

    int S=s.size();

    dp[0][0]=1;
    rep(i,n)rep(j,i+1)
    {
        (dp[i+1][j+1]+=(dp[i][j]*2)%mod)%=mod;
        (dp[i+1][max(0,j-1)]+=dp[i][j])%=mod;
    }

    ll ans=dp[n][S];
    ans*=mod_inv(mod_pow(2,S));
    cout << ans%mod << endl;
    return 0;
}


Measured memory_bytes: 116864
package main

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

func main() {
	N := ReadInt()
	a := 1 << 62
	for i := 0; i < N; i++ {
		v := ReadInt()
		v &= -v
		if a > v {
			a = v
		}
	}
	c := 0
	for a > 1 {
		a >>= 1
		c++
	}
	fmt.Println(c)
}

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: 1840
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    const int INF = 100000000;
    int n, m;
    cin >> n >> m;
    int a[1000], b[1000], c[1000];
    int dist[100][100];
    REP(i, m)
    {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
    }

    REP(i, n)
    {
        REP(j, n)
        {
            if (i == j)
                dist[i][j] = 0;
            else
            {
                dist[i][j] = INF;
            }
        }
    }

    REP(i, m)
    {
        dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
        dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
    }
    REP(k, n)
    {
        REP(i, n)
        {
            REP(j, n)
            {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int ans = m;
    REP(i, m)
    {
        bool shortest = false;
        REP(j, n)
        {
            if (dist[j][a[i]] + c[i] == dist[j][b[i]])
                shortest = true;
        }
        if (shortest)
            ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

    int root(int x)
    {
        if (par[x] < 0)
            return x;
        return par[x] = root(par[x]);
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }
    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x; //大きさが正になるよ
        return true;
    }
    int size(int x)
    {
        return -par[root(x)];
    }
};
 int n,m;
   int x[100010], y[100010];
   int z[100010];
map<int, int> mp;
   int main()
   {
       cin >> n >> m;
       UnionFind uni(n);
       for (int i = 0; i < m; i++)
       {
           cin >> x[i] >> y[i] >> z[i];
           x[i]--, y[i]--;
           mp[x[i]]++;
           mp[y[i]]++;
       }
       //cout << x[0] << endl;
       ll cnt = 0;
       for (int i = 0; i < m; i++)
       {
           uni.merge(x[i], y[i]);
       }
       set<int> st;
       for (int i = 0; i < n; i++)
       {    if(mp[i]!=0) st.insert(uni.root(i));
            else
               cnt++;
       }

       cout << st.size()+cnt << endl;
    


}

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

int main() {
	int a,b;
	
	while(cin >> a >> b){
		if(a == 0 && b == 0) break;
		int count = 0;
		if(b<a){
			int temp = b;
			b = a;
			a = temp;
		}
		while(a != 0){
			int temp = a;
			a = b%a;
			b = temp;
			count++;
		}
		cout << b << " " << count << endl; 
	}
	return 0;
}


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

const int maxN = 2e5 + 10;

int main(){
    int l, r, d, cnt = 0;
    int a[100];
    cin >> l >> r >> d;
    for(int i = 0; i < 100; i++){
        a[i] = d*(i+1);
    }
    for(int i = l; i <= r; i++){
        for(int j = 0; j < 100; j++){
            if(a[j] == i) cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3616
//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
//#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
typedef long long int  bigint ;
typedef std::vector< int > vi;
typedef std::vector< long long int > vll;
typedef std::vector< vi > vvi;
 
using namespace std;

int main(){
    FAST() ;
    int N ; cin >> N ;
    int arr[N] ;
    for( int i = 1 ; i <= N ; i++ )
        cin >> arr[i] ;
    bool dp[N+1] ;
    memset(dp, 0, sizeof(dp) );
    int cnt = 0 , i = 1 ;
    while( true ){
    if( dp[i] == true ){
        cnt = -1 ;
        break ;
        }
        cnt++ ;
        dp[i] = true ;
        if( arr[i] == 2 )
            break ;
        i = arr[i] ;
    }
    cout << cnt << endl ;
    return 0 ;
}


Measured memory_bytes: 768
// abc075_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> rank;
    vector<int> size; // size[i]: iが親なら連結成分の数

    UnionFind(int N) : par(N), rank(N), size(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) {par[i] = i; rank[i] = 0; size[i] = 1;}
    }

    int find(int x) { // データxが属する木の根を再帰で得る：find(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = find(x); //xの根をrx
        int ry = find(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま

        // rank[rx] >= rank[ry] となるように rx と ry を swap
        if(rank[rx] < rank[ry]) swap(rx, ry);

        // 同じ高さだったならばまとめたことによって高さ +1
        if(rank[rx] == rank[ry]) ++rank[rx];

        par[ry] = rx; // root rx に ry の木をつなぐ
        size[rx] += size[ry];
        size[ry] = 0;

    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = find(x);
        int ry = find(y);
        return rx == ry;
    }

    int get_size(int x){
        int rx = find(x);
        return size[rx];
    }
};


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

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

    vector<int> A(M), B(M);
    REP(i, M) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    int ans = 0;
    REP(m, M){
        UnionFind uf(N);
        REP(i, M){
            if (i == m) continue;
            uf.unite(A[i], B[i]);
        }

        if (uf.get_size(0) < N) {
            ans++;
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();

        System.out.println((n - h + 1) * (n - w + 1));
    }

}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    cout << (a[n - m] >= accumulate(a.begin(), a.end(), 0.0) / (double)(4 * m) ? "Yes" : "No") << endl;
}


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

int main()
{
	char str[20];

	for(int i=0;i<12;i++) cin >> str[i];
	for(int i=0;i<4;i++) cout << str[i];
		cout << " " ;
	for(int i=4;i<12;i++) cout << str[i];
		cout << endl; 

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#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 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(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    string S,T;
    cin >> S >> T;
    int cnt=0;
    if(S.at(0)==T.at(0))cnt++;
    if(S.at(1)==T.at(1))cnt++;
    if(S.at(2)==T.at(2))cnt++;

    cout << cnt <<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort(reverse=True)

ans = 0
if n % 2 == 0:
    plus = a[:n//2]
    minus = a[n//2:]
    ans = (2*sum(plus)-plus[-1]) - (2*sum(minus)-minus[0])
else:
    ans1 = 0
    plus = a[:n//2]
    minus = a[n//2:]
    ans1 = (2*sum(plus)) - (2*sum(minus)-minus[0]-minus[1])

    ans2 = 0
    plus = a[:(n+1)//2]
    minus = a[(n+1)//2:]
    minus.sort()
    ans2 = (2*sum(plus)-plus[-1]-plus[-2]) - (2*sum(minus))

    ans = max(ans1, ans2)

print(ans)

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

using namespace std;

typedef long long ll;

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

    ll N, M, S;
    cin >> N >> M >> S;
    vector<vector<ll>> shortest(N+1, vector<ll>(2501, LLONG_MAX));
    vector<vector<vector<ll>>> g(N+1);
    vector<vector<ll>> ex(N+1);
    for(int i = 0 ; i < M ; ++i){
        ll u, v, a, b;
        // a - cost , b - time
        cin >> u >> v >> a >> b;
        vector<ll> v1 = {v, a, b};
        vector<ll> v2 = {u, a, b};
        g[u].push_back(v1);
        g[v].push_back(v2);
    }
    for(int i = 1; i < N+1; ++i){
        ll c, d;
        cin >> c >> d;
        // c - silver, d - time
        ex[i].push_back(c);
        ex[i].push_back(d);
    }

    priority_queue<vector<ll>, vector<vector<ll>>, greater<vector<ll>>> pq;
    // time, city, silver
    vector<ll> start = {0, 1, S};
    pq.push(start);
    unordered_set<int> visited;
    while(pq.size() > 0){
        vector<ll> here = pq.top();
        pq.pop();
        ll time = here[0];
        ll city = here[1];
        ll silver = here[2];
        visited.insert(city);
        if(visited.size() == N){
            break;
        }
        if(silver < 2500){
            ll nexts = min(silver + ex[city][0],(ll)2500);
            ll nextt = time + ex[city][1];
            if(shortest[city][nexts] > nextt){
                shortest[city][nexts] = nextt;
                vector<ll> there = {nextt, city, nexts};
                pq.push(there);
            }
        }
        for(int i = 0 ; i < g[city].size(); ++i){
            ll nextc = g[city][i][0];
            ll nexts = min(silver - g[city][i][1],(ll)2500);
            ll nextt = time + g[city][i][2];
            if(nexts < 0){
                continue;
            }
            if(shortest[nextc][nexts] > nextt){
                shortest[nextc][nexts] = nextt;
                vector<ll> there = {nextt, nextc, nexts};
                pq.push(there);
            }
        }
    }


    vector<ll> ret(N+1, LLONG_MAX);
    for(int i = 2; i < N+1; ++i){
        for(int j = 0 ; j <= 2500; ++j){
            ret[i] = min(ret[i], shortest[i][j]);
        }
        cout << ret[i] << endl;
    }

    return 0;

}





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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define repr(i, n) for (ll i = n - 1; i >= 0; --i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll cta = 0;
    rep(i, n)
    {
        if (a[i] % 2 == 1)
        {
            cout << "first" << endl;
            return;
        }
    }
    cout << "second" << endl;
}
int main(void)
{
    solve();
}

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

int main() {
    int a, b, c, d, x=0;
    cin >> a >> b >> c;
  	d = b - a;
    for(int i =0;i <= d;i++){
        if(c % a == 0){
          x++;
        }
      a+=1;
    }
  cout << x << endl;
} 


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,i;cin>>n>>i;
  cout<<n-i+1<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
// Seiranchan!
    string S;
    cin >> S;
    string ans="AC";
    int L = S.size();

    if(S[0]!='A'){
        ans = "WA";
    }
    int cnt =0;
    FOR(i,1,L){
        if(isupper(S[i])){
            if(i==1||i==L-1||S[i]!='C'){
                ans = "WA";
            }
            cnt++;
        }
    }
    if(cnt!=1) ans ="WA";

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;
string w = "YAKI";
 
bool check(string s){
 
	if (s.size() < w.size())
		return false;
	for (int i = 0; i < w.size(); ++i){
		
		if (s[i] != w[i])
			return false;
	}
 
	return true;
}
int main(){
 
	//freopen("Text.txt","r",stdin);
	string s;
 
	int n,m,k;
 
	cin >> n >> m >> k;
 
	for (int i = 0; i <= n; ++i){
 
		for (int j = 0; j <= m; ++j){
			long long res = n*j+ m*i - 2 * (i*j);
 
			if (res == k){
				cout << "Yes";
				return 0;
			}
		}
	}
 
 
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = []
c = max(a)
d = -100
for i in range(n):

    if a[i] != c:

        if d == -100:

            d = abs((c/2)-a[i])
            e = i 

        else:

            if abs((c/2)-a[i]) < d:

                d = abs((c/2)-a[i]) 
                e = i 
        
        
print('{} {}'.format(c,a[e]))


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){

  ll A, B;
  IN(A,B);
  if(A<10 && B<10){
    OUT(A*B);
  }else{
    OUT(-1);
  }

  return 0;
}

Measured memory_bytes: 256
from operator import itemgetter, attrgetter
import sys
readlines = sys.stdin.readlines
input = sys.stdin.readline
 
class RadixHeap:
    def __init__(self, C=1 << 31):
        self.last = 0
        self.size = 0
        self.v = [[] for _ in range(C.bit_length()+1)]
 
    def push(self, key, val):
        self.size += 1
        self.v[(key ^ self.last).bit_length()].append((key, val))
 
    def pop(self):
        v = self.v
        if not v[0]:
            i = 1
            while not v[i]:
                i += 1
            vi = v[i]
            new_last, _ = min(vi, key=itemgetter(0))
            for key, val in vi:
                v[(key ^ new_last).bit_length()].append((key, val))
            self.last = new_last
            vi.clear()
        self.size -= 1
        return v[0].pop()
 
    def __len__(self): return self.size

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1;Cw -= 1
Dh -= 1;Dw -= 1
S = readlines()
 
INF = 10**10
D = [[INF]*W for _ in [0]*H]
 
q = RadixHeap()
q.push(0, Ch*W+Cw)
 
while q:
    d, ij = q.pop()
    i, j = divmod(ij, W)
 
    for di in range(-2, 3):
        for dj in range(-2, 3):
            if di == dj == 0:
                continue
            I = i+di
            J = j+dj
            if 0 <= I < H and 0 <= J < W and S[I][J] == '.':
                if abs(di)+abs(dj) == 1:
                    if D[I][J] <= d:
                        continue
                    D[I][J] = d
                    q.push(d, I*W+J)
                else:
                    if D[I][J] <= d+1:
                        continue
                    D[I][J] = d+1
                    q.push(d+1, I*W+J)
 
ans = D[Dh][Dw]
print(ans if ans < INF else -1)

Measured memory_bytes: 92720
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int D;
    cin >> D;
    vector<int> c(D), cc(D);
    rep(i, D) {
        cin >> c[i];
        cc[i] = c[i];
    }
    vector<vector<int>> s(D);
    rep(i, D) {
        s[i].resize(26);
        rep(j, 26) cin >> s[i][j];
    }

    rep(d, D) {
        int x = -1;
        int best = -1000000;
        rep(i, 26) {
            int tmp = s[d][i] - cc[i];
            if (best < tmp) {
                x = i;
                best = tmp;
            }
        }
        cout << (x+1) << endl;
        rep(i, 26) {
            if (i == x) {
                cc[i] = c[i];
            } else {
                cc[i] += c[i];
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] data = new int[2][N];
		
		for(int i = 0; i < data.length; i++) {
			for(int j = 0; j < data[i].length; j++) {
				data[i][j] = sc.nextInt();
			}
		}
		
		int max = 0;
		
		for(int i = 0; i < N; i++) {
			int cnt = 0;
			for(int j = 0; j <= i; j++) {
				cnt += data[0][j];
			}
			for(int j = i; j < N; j++) {
				cnt += data[1][j];
			}
			if(max < cnt) max = cnt;
		}
		
		System.out.println(max);
		
		sc.close();

	}

}

Measured memory_bytes: 25172
import java.util.*;

public class Main {
    static int MOD = 1000000007;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int n = str.length();
        char c[] = str.toCharArray();
        
        // dp[i][j] = i文字目までの値xを、13で割った余りがjになるパターン数
        // 初期段階(1通り)を入れる
        long[][] dp = new long[n + 1][13];
        dp[0][0] = 1;
        
        // 1?2?3: 0 -> 1 -> 1? -> 1?2 -> ...
        for (int i = 0; i < n; i++) {
            if (c[i] == '?') {
                for (int k = 0; k <= 9; k++) {
                    // 余りjの集団を余り「(jを10倍してkを足した数) % 13」に遷移させる
                    // ex.余り2の集団は、10倍されると余り7へ移動する
                    // [2,15,132] -> [20, 150, 1320]
                    for (int j = 0; j < 13; j++) { 
                        dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
                        dp[i + 1][(j * 10 + k) % 13] %= MOD;
                    }
                }
            } else {
                int k = c[i] - '0';
                    for (int j = 0; j < 13; j++) {
                        dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
                        dp[i + 1][(j * 10 + k) % 13] %= MOD;
                    }
            }
        }
        
        // 13で割って5余るパターン数を出力
        System.out.println(dp[n][5]);
    }
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    sort(A, A + N, greater<ll>());
    priority_queue<ll, vector<ll>> q;
    ll ans = 0;
    q.push(A[0]);
    FOR(i, N, 1) {
        ll t = q.top();
        q.pop();
        ans += t;
        q.push(A[i]);
        q.push(A[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6852
import java.util.Scanner;

public class Main {
	static int Ante[] = new int[5];
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		for(int i=0;i<5;i++)Ante[i] = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		sc.close();

		String res = "Yay!";
		for(int i=0;i<4;i++) {
			for(int j=i+1;j<5;j++) {
				if(Ante[j]-Ante[i]>k) {
					res = ":(";
				}
			}
		}

		System.out.println(res);
	}

}


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

#define ll long long
#define siz 100005
typedef pair<int ,int> pii;

int main(){

    ios_base::sync_with_stdio(0);
    //freopen("overcode.in","r",stdin);
    //freopen("out.txt","w",stdout);

    ll dp[siz];
    ll h[siz];
    int n,k; cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>h[i];
        dp[i]=1e10;
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
        ll cost=1e9;
        for(int j=1;j<=k;j++){
            if(i-j<0) break;
            cost=min(cost,dp[i-j]+(abs(h[i]-h[i-j])));
        }
        dp[i]=cost;
    }
    cout<<dp[n-1];

    return 0;
}


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

int main()
{ll n;
cin>>n;
bool ar[n+1]={0};
ll arr[n+1]={0};
vector<ll> v[n+1];
ll m;
cin>>m;
queue<ll> q;
for(ll i=0;i<m;i++)
{
    ll a,b;
    cin>>a>>b;
    v[a].push_back(b);
    v[b].push_back(a);
    
    if(a==1)
    {
        
        arr[b]=1;
        ar[b]=1;
        q.push(b);
        
    }
    if (b==1)
    {
        arr[a]=1;
        ar[a]=1;
        q.push(a);
    }
}
arr[1]=1;
ar[1]=1;
    ll x;
    while(!q.empty())
    {   x=q.front();
        //ar[x]=1;
        //cout<<x<<" ";
        q.pop();
        for(ll j=0;j<v[x].size();j++)
        {
            if(ar[v[x][j]]==0)
            {
                ar[v[x][j]]=1;
                q.push(v[x][j]);
                //cout<<v[x][j]<<" ";
                arr[v[x][j]]=x;
            }
        }
    }
    ll f=0;
    for(ll i=2;i<=n;i++)
    {
        if(ar[i]==0)
        {f=1;break;}
    }
    if(f)
    cout<<"No";
    else
    {
        cout<<"Yes"<<endl;
        for(ll i=2;i<=n;i++)
        cout<<arr[i]<<endl;
    }



    return 0;
}


Measured memory_bytes: 13032
#include <iostream>

using namespace std;

int n, pre, now, ans;

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> now;
		if (now > pre) ans += now - pre;
		pre = now;
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
K = int(input())

extra = 7 % K

#あまり0と出会う前にが同じあまりのものと合うと終わりなのでそれをチェック。
seen = set()
ans = 1

while extra not in seen:
    if extra == 0:
        print(ans)
        exit()
    seen.add(extra)
    extra = (extra*10 + 7) % K
    ans += 1
print(-1)    

Measured memory_bytes: 156704
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = set([input() for _ in range(N)])
    print(len(S))


if __name__ == "__main__":
    main()


Measured memory_bytes: 35592
//
// B - Template Matching
//

#include <iostream>
#include <vector>

using namespace std;

int main() {

    int N, M;
    vector<string> A;
    vector<string> B;

    cin >> N >> M;

    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        A.push_back(s);
    }

    for (int i = 0; i < M; i++) {
        string s;
        cin >> s;
        B.push_back(s);
    }

    //
    bool ans;

    for (int i = 0; i <= N - M; i++) {
        for (int j = 0; j <= N - M; j++) {
            ans = true;
            for (int k = 0; k < M; k++) {
                if (A[i + k].substr(j, M) == B[k]) {
                    ans &= true;
                } else {
                    ans = false;
                }
            }
            if (ans) goto outer;
        }
    }
    outer:

    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 888
def main():
    N = int(input())
    words = []
    record = []
    previous = ''
    for i in range(N):
        words.append(str(input()))
    for i in range(N):
        if i == 0:
            record.append(words[i])
            previous = words[i]
        elif not words[i] in record and previous[-1] == words[i][0] and i != 0:
            record.append(words[i])
            previous = words[i]
        else:
            print('No')
            return
    print('Yes')
main()  

Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}
int cnt[100006], q, l, r;
signed main() {
	for (int i = 2; i <= 100000; i++) {
		cnt[i] = cnt[i - 1];
		if (prime(i) && prime((i + 1) / 2))cnt[i]++;
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> l >> r;
		cout << cnt[r] - cnt[l - 1] << endl;
	}
	endre;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define C 1000000000000000001ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.14159265358979323

ll dp[4096][4096];

int main() 
{
    FAST;
    for(int i=0;i<4096;i++)
    	for(int j=1;j<4096;j++)
    		dp[i][j]=C;
    ll m,n;
    cin>>n>>m;
    ll a,b,c;
    for(int i=0;i<m;i++)
    {
    	cin>>a>>b;
    	ll x=0;
    	for(int j=0;j<b;j++)
    	{
    		cin>>c;
    		x+=powl(2,c-1);
    	}	
    	if(i==0)
    		dp[i][x]=a;
    	else
    	{
    		for(int j=0;j<4096;j++)
	    		if(dp[i-1][j]!=C && (j|x)<4096)
	    			dp[i][j|x]=min(dp[i][j|x],(dp[i-1][j]+a));
	    	for(int j=0;j<4096;j++)
				dp[i][j]=min(dp[i][j],dp[i-1][j]);
    	}
    }
    ll ans=LLONG_MAX;
    c=powl(2,n)-1;
    for(int i=0;i<m;i++)
    	ans=min(ans,dp[i][c]);
    if(ans==C)
    	cout<<-1;
    else
    	cout<<ans;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

int main(){
  long long q,h,s,d,n;
  cin >> q >> h >> s >> d >> n;
  long long ans = 0;
  long long one = min(2 * q, h);
  long long l = min(2 * one, s);
  if(d >= 2 * l){
    cout << n * l << endl;
  }else{
    cout << (n / 2) * d + (n % 2) * l << endl;
  }
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
int d[d5];
vector<pair<int,int>> edge[d5];

void dfs(int i){
    for(auto it:edge[i]){
        if(d[it.first]!=-1)
            continue;
        d[it.first] = (d[i] + it.second) % 2;
        dfs(it.first);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    fill(d, d + d5, -1);
    d[0] = 0;
    int n;
    cin>>n;
    for (int i = 0;i<n-1;i++){
        int u,v,w;
        cin>>u>>v>>w;
        u--;
        v--;
        edge[u].push_back(make_pair(v, w));
        edge[v].push_back(make_pair(u, w));
    }
    dfs(0);
    for(int i=0;i<n;i++){
        cout << d[i] << endl;
    }
}

Measured memory_bytes: 9472