akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>

using namespace std;
#define N 4
#define N2 16

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle{ int f[N2], space, MD;
	int cost;

	bool operator < (const Puzzle &p) const{
		for(int i=0;i<N2;i++){
			if(f[i] == p.f[i]) continue;
			return f[i] < p.f[i];
		}
		return false;
	}
};

struct State{
	Puzzle puzzle;
	int estimated;
	bool operator < (const State &s) const{
		return estimated > s.estimated;
	}
};

int getAllMD(Puzzle pz){
	int sum = 0;
	for(int i=0;i<N2;i++){
		if(pz.f[i] == N2) continue;
		sum += MDT[i][pz.f[i] - 1];
	}
	return sum;
}

int astar(Puzzle s){
	priority_queue<State> PQ;
	s.MD = getAllMD(s);
	s.cost = 0;
	map<Puzzle, bool> V;
	Puzzle u, v;
	State initial;
	initial.puzzle = s;
	initial.estimated = getAllMD(s);
	PQ.push(initial);

	while(!PQ.empty()){
		State st = PQ.top(); PQ.pop();
		u = st.puzzle;

		if(u.MD == 0) return u.cost;
		V[u] = true;

		int sx = u.space / N;
		int sy = u.space % N;

		for(int r = 0; r < 4; r++){
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
			v = u;

			v.MD -= MDT[tx * N + ty][v.f[tx * N + ty] - 1];
			v.MD += MDT[sx * N + sy][v.f[tx * N + ty] - 1];

			swap(v.f[sx * N + sy], v.f[tx * N + ty]);
			v.space = tx * N + ty;
			if(!V[v]){
				v.cost++;
				State news;
				news.puzzle = v;
				news.estimated = v.cost + v.MD;
				PQ.push(news);
			}
		}
	}
	return -1;
}

int main(){
	for(int i=0;i<N2;i++)
		for(int j=0;j<N2;j++)
			MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);

	Puzzle in;

	for(int i=0;i<N2;i++){
		cin >> in.f[i];
		if(in.f[i] == 0){
			in.f[i] = N2;
			in.space = i;
		}
	}
	cout << astar(in) << endl;

	return 0;
}

Measured memory_bytes: 257580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
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; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




// けんちょんさんの記事

ll dp[2004][2004];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int n, m;
    cin >> n >> m;
    
    vector<int> s(n), t(m);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];
    
    
    rep(i, n + 1) dp[i][0] = 1;
    rep(j, m + 1) dp[0][j] = 1;
    
    rep(i, n + 1) rep(j, m + 1) {
        (dp[i + 1][j + 1] += dp[i + 1][j]) %= inf;
        (dp[i + 1][j + 1] += dp[i][j + 1]) %= inf;
        if (s[i] == t[j]) {
            (dp[i + 1][j + 1] += dp[i][j]) %= inf;
        }
        (dp[i + 1][j + 1] += -dp[i][j] + inf) %= inf;
    }
    // rep(i, n + 1) { rep(j, m + 1) cout << dp[i][j] << " "; cout << endl; }
    cout << dp[n][m] << endl;
}




Measured memory_bytes: 31616
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    ll e,y;
    cin >> e >> y;
    vector<ll> a{1868,1912,1926,1989,2017};
    vector<char> b{'M','T','S','H'};
    if (e == 0){
        rep(i,4){
            if (a[i] <= y && y < a[i+1]){
                printf("%c%ld\n",b[i],y-a[i]+1);
            }
        }
    }
    else{
        PRINT(y+a[e-1]-1);
    }
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
int dy[]={0,-1,0,1},dx[]={1,0,-1,0};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w; cin>>h>>w;
	vector<string>s(h); for(auto&&i:s)cin>>i;
	for(int y=0;y<h;++y){
		for(int x=0;x<w;++x){
			if(s.at(y).at(x)=='.')continue;
			bool yes=false;
			for(int i=0;i<4;++i){
				int ny=y+dy[i],nx=x+dx[i];
				if(ny<0||nx<0||ny>=h||nx>=w||s.at(ny).at(nx)=='.')continue;
				yes=true;
				break;
			}
			if(!yes){
				cout<<"No\n"s;
				return 0;
			}
		}
	}
	cout<<"Yes\n"s;
}


Measured memory_bytes: 3668
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	double N;
	cin>>N;
	vector<ll> array(N);
	double mean = 0.0;
	rep(i,N){
		cin>>array[i];
		mean += array[i];
	}
	mean /= N;
	ll upper = 0;
	ll lower = 0;
	rep(i,N){
		upper += pow(ceil(mean)-array[i], 2);
		lower += pow(floor(mean)-array[i], 2);
	}
	cout<<min(upper, lower)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using pii  = pair<int,int>;
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main(){
    ll n,v;
    map<ll,ll> o,e;
    cin >> n;
    rep(i,n){
        cin >> v;
        if(i%2==0){
            e[v]++;
        }
        else{
            o[v]++;
        }
    }
    vector<pair<ll,ll>> E(2),O(2);
    for(auto P : e){
        E.push_back(make_pair(P.second,P.first));
    }
    for(auto P : o){
        O.push_back(make_pair(P.second,P.first));
    }
    sort(E.begin(),E.end());
    sort(O.begin(),O.end());
    if(E[E.size()-1].second!=O[O.size()-1].second){
        cout << n-E[E.size()-1].first-O[O.size()-1].first << endl;
    }
    else{
        cout << min(n-E[E.size()-2].first-O[O.size()-1].first,n-E[E.size()-1].first-O[O.size()-2].first)<< endl;
    }
}

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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define int long long
const int inf = 1e9, maxn = 2e5, mod = 998244353;

struct Vector
{
    int x, y;
    Vector(int _x = 0, int _y = 0) : x(_x), y(_y) {}
};
int operator * (Vector a, Vector b)
{
    return a.x * b.x + a.y * b.y;
}
int operator % (Vector a, Vector b)
{
    return a.x * b.y - a.y * b.x;
}
Vector operator - (Vector a)
{
    return Vector(-a.x, -a.y);
}
bool operator == (Vector a, Vector b)
{
    return ((a * b) > 0) && ((a % b) == 0);
}
void solve(int ci)
{
    int n;
    cin >> n;
    sc(l, n + 1)
    int s = -1, ans = 0;
    f(n + 1) s += l[i], ans += l[i];
    int v[n + 1], k[n];
    if(l[0] > 1)
    {
        cout << -1;
        return;
    }
    v[0] = 1 - l[0];
    for(int i = 1; i <= n; i++)
    {
        k[i - 1] = min(v[i - 1], s);
        s -= k[i - 1];
        if(l[i] > v[i - 1] + k[i - 1])
        {
            cout << -1;
            return;
        }
        v[i] = v[i - 1] + k[i - 1] - l[i];
        ans += v[i];
    }
    //pri(v, n + 1)
    cout << ans + v[0];
}
main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    f(t) solve(i + 1);
}


Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  double r;
  cin >> r;
  printf("%.10f\n", 2 * r * 3.1415926535);
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int fini(int i)
{
    return (i + 9) / 10 * 10;
}

int modtime(int i)
{
    return fini(i) - i;
}

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


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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        double T = cin.nextDouble();
        double X = cin.nextDouble();
        Console.WriteLine(T / X);
    }
}


class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


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

int n;

bool solve(int c) {
  if (c<0) return false;
  if (c==0) return true;
  return (solve(c-4) || solve(c-7));
}

int main() {
  cin >> n;
  if (solve(n)) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
for i in S:
    i.insert(0, '.')
    i.append('.')
S.insert(0, ['.' for _ in range(W+2)])
S.append(['.' for _ in range(W+2)])

for i in range(1, H+1):
    for j in range(1, W+1):
        x = []
        if S[i][j] == '.':
            #周囲を全探索
            for di in range(-1, 2):
                for dj in range(-1, 2):
                    x.append(S[i+di][j+dj])
            print(x.count("#"), end="")
        else:
            print('#', end="")
    print("\n")


Measured memory_bytes: 3444
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);

        int a=scan.nextInt();
        int b=scan.nextInt();
        String ans;
        ans=a+b<10?Integer.toString(a+b):"error";

        System.out.println(ans);
    }
}


Measured memory_bytes: 22100
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve(){
	int r, g; cin >> r >> g;
	cout << 2 * g - r << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())

import heapq
def dijkstra_heap(s):
  #始点sから各頂点への最短距離
  dist=[float("inf")]*size_v
  used=[False]*size_v
  dist[s]=0
  used[s]=True

  hq_edge=[]
  for v,w,i in graph[s]:
    heapq.heappush(hq_edge,(w,v,i))

  while hq_edge:
    min_w,min_v,i=heapq.heappop(hq_edge)
    #まだ使われてない頂点の中から最小の距離のものを探す
    if used[min_v]:
      continue

    dist[min_v]=min_w
    used[min_v]=True
    prev[min_v]=i
    for v,w,i2 in graph[min_v]:
      if not used[v]:
        heapq.heappush(hq_edge,(min_w+w,v,i2))

  return dist

ablist=[]
graph=[[] for _ in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  graph[a].append((b,1,i))
  graph[b].append((a,1,i))
  ablist.append((a,b))
#print(graph)

size_v=N+1
prev=[None]*size_v
dist=dijkstra_heap(1)
#print(dist)
#print(prev)

print("Yes")
for i in range(2,N+1):
  prev_e=ablist[prev[i]]
  if i==prev_e[0]:
    print(prev_e[1])
  else:
    print(prev_e[0])


Measured memory_bytes: 170820
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int n,a,b;cin>>n>>a>>b;
	string s;cin>>s;
	int ans[n]; int count=0;
	int rank=0;
	for(int i=0;i<n;i++){
		if(s[i]=='a'){
			if(count<a+b){
				ans[i] = 1;
				count++;
			}
			else{
				ans[i] = 0;
			}
		}
		else if(s[i]=='b'){
			rank++;
			if(count<a+b){
				if(rank<=b){
					ans[i] = 1;
					count++;
				}
				else{
					ans[i] = 0;
				}
			}
			else{
				ans[i] = 0;
			}
		}
		else{
			ans[i] = 0;
		}
	}
	for(int i=0;i<n;i++){
		if(ans[i]==1){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 1e5 + 10;

int n, a[N], b[N], sum, ans;

int c[N], d[N];

int t[N << 1], m, fa[N];

int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }

void unit(int x, int y)
{
	if (find(x) != find(y))
		fa[find(x)] = find(y);
}

int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) gi(a[i]), sum ^= a[i];
	a[n + 1] = sum, sum = 0;
	for (int i = 1; i <= n; ++i) gi(b[i]), sum ^= b[i];
	b[n + 1] = sum, sum = 0;
	++n;
	for (int i = 1; i <= n; ++i) c[i] = a[i], d[i] = b[i];
	sort(c + 1, c + n + 1);
	sort(d + 1, d + n + 1);
	for (int i = 1; i <= n; ++i)
		if (c[i] != d[i])
		{
			puts("-1");
			return 0;
		}
	for (int i = 1; i <= n; ++i)
	{
		if (a[i] != b[i] && i < n) ++ans;
		if (a[i] != b[i] || i == n) t[++m] = a[i], t[++m] = b[i];
	}
	if (!ans)
	{
		puts("0");
		return 0;
	}
	sort(t + 1, t + m + 1);
	m = unique(t + 1, t + m + 1) - t - 1;
	for (int i = 1; i <= m; ++i) fa[i] = i;
	for (int i = 1; i <= n; ++i)
		if (a[i] != b[i]) unit(lower_bound(t + 1, t + m + 1, a[i]) - t, lower_bound(t + 1, t + m + 1, b[i]) - t);
	for (int i = 1; i <= m; ++i)
		if (find(i) == i) ++ans;
	printf("%d\n", ans - 1);
	return 0;
}

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

typedef pair <int, int> pii; 

const int N = 6000; 
const int INF = 1 << 30;

int n, lenS = 0, lenT = 0; 

pii s[N], t[N];
// <type, pos> 

string strS, strT;

inline void init_string( pii *a, string str, int &len )
{
	len = 0; int last = str[0] - '0'; 
	
	a[++len] = make_pair( last ^ 1, 0 ); 
	
	for( int i = 2; i <= n; i ++ )
	{
		if( last == str[i-1] - '0' ) continue;
		
		last ^= 1; 
		a[++len] = make_pair( last ^ 1, i - 1 ); 
	}
	
	a[++len] = make_pair( last, n ); 
} 

inline int calc_ans( int st )
{
	int ret = 0;

	// clear 1 -> st
	for( int i = 1; i < st; i ++ )
		ret += s[i].second; 

	for( int i = 1; i <= lenT; i ++ )
	{
		if( st < 1 ) {
			ret += t[i].second; st ++; continue;
		}
		
		if( st > lenS ) {
			ret += n - t[i].second; st ++; continue;
		}
		 
		if( t[i].first != s[st].first ) return INF;
		ret += abs( t[i].second - s[st].second ); 		
		st ++; 
	}
	
	// clear st -> n 
	for( int i = st; i <= lenS; i ++ )
		ret += n - s[i].second; 

	return ret;
}

int main()
{
//	freopen( "e.in", "r", stdin ); 
	
	cin >> n >> strS >> strT; 
	
	init_string( s, strS, lenS );
	init_string( t, strT, lenT );  

	int ans = INF;
	for( int i = 1 - lenT; i <= lenS; i ++ )
		ans = min( ans, calc_ans( i ) ) ;

	cout << ans << endl;

	return 0; 
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;
const int M = 2e6 + 5;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   if(pow < 0) return 0;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;ll c = (a * b)%mod;return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(2e6 + 7)] , inv_fac[(int)(2e6 + 7)];
void precomp_factorial(){fac[0] = 1;for(ll i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(ll i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};

map <pair<int,int>,int> mp;
int main(void)
{
    int n,l;
    cin >> n >> l;
    int ans = 1e9, ind = 0;
    for(int i = 1; i <= n; i++){
        int val = l + i-1;
        if(abs(val) < ans){
            ans = abs(val);
            ind = i; 
        }
    }
    int sum = 0;
    //cout << ans << " " << ind << endl;
    for(int i = 1; i <= n; i++){
         int val = l + i-1;
        if(i != ind) sum += val;
    }
    cout << sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <set>
#define N 200005
using namespace std;

typedef long long ll;
ll n, ans, l, r, a[N];
set<ll> s;
int main()
{
	ll i, t;
	cin >> n;
	for (i = 1; i <= n; i++) scanf("%lld", &t), a[t] = i;
	s.insert(0), s.insert(n + 1);
	for (i = 1; i <= n; i++) {
		l = *--s.lower_bound(a[i]);
		r = *s.lower_bound(a[i]);
		ans += (a[i] - l) * (r - a[i]) * i;
		s.insert(a[i]);
	}
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1E9 + 7;
long long solve(vector<long long> v, int k)
{
	int n = v.size();
	sort(v.begin(), v.end());
	long long pro = 1;
	if (v[n - 1] == 0 && (k & 1))
		return 0;
	if (v[n - 1] <= 0 && (k & 1))
	{
		for (int i = n - 1; i >= n - k; --i)
		{
			pro = ((pro * v[i]) % MOD + MOD) % MOD;
		}
		return pro;
	}
	long long i = 0, j = n - 1;
	if (k & 1)
	{
		pro *= v[j];
		j --;
		k --;
	}
	k >>= 1;
	for (int idx = 0; idx < k; ++idx)
	{
		long long lp = v[i] * v[i + 1];
		long long rp = v[j] * v[j - 1];
		if (lp > rp)
		{
			pro = ((pro * ((lp + MOD) % MOD)) % MOD + MOD) % MOD;
			i += 2;
		}
		else
		{
			pro = ((pro * ((rp + MOD) % MOD)) % MOD + MOD) % MOD;
			j -= 2;
		}
	}
	return pro;

}
int main(int argc, char const *argv[])
{
	int n, k;
	cin >> n >> k;
	vector<long long> a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	cout << solve(a, k) << '\n';

	return 0;
}

Measured memory_bytes: 6336
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define min(a,b) ((a)<(b) ? (a):(b))
#define max(a,b) ((a)>(b) ? (a):(b))

int gcd(int a, int b){
    while( b ){
        int m = a % b;
        a = b;
        b = m;
    }
    return a;
}

int lcm(int a, int  b){
    return (a*b)/gcd(a,b);
}

int isPrim(int a){
    if(a==1){
        return 0;
    }
    for(int i=2;i<=(a+1)/2;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}

long long mod_pow(long long x, long long n, long long mod){
    //xのn乗を計算するのにn乗を2進表記にして計算
    //x^22 = x^16 + x^4 + x^2
    long long ret=1;
    while(n>0){
        if(n%2==1){
            ret=(ret*x)%mod;//答えに付加
        }
        x=(x*x)%mod;//2乗
        n=n/2;
    }
    return ret;
}

struct VV{
    int x;
    int y;
    int z;
};

class LessInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        if(riLeft.x == riRight.x){
            return riLeft.y > riRight.y;
        }
        return riLeft.x > riRight.x;
        
    }
};

class indInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        return riLeft.x < riRight.x;
        
    }
};

struct XX{
    int zenbu=0;
    int kidoku=0;
};

class xxIntu {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        //第1条件
        if(riLeft.z != riRight.z){
            return riLeft.z > riRight.z;//<:昇順(小さい順)、>:降順(大きい順)
        }
        //第2条件
        return riLeft.y < riRight.y;
    }
};
bool operator< (const VV &riLeft, const VV &riRight){
    return riLeft.z < riRight.z;
};
/*bool operator> (const XX &riLeft, const XX &riRight){
    return riLeft.a > riRight.a;
};*/



int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //getline(cin, target);
    //cin >> x >> y;
    //ここから
    
    int N;
    int a[100];
    cin >>N;
    
    for(int i=0;i<N;i++){
        cin >> a[i];
    }

    int min=2000000;
    for(int i=-100;i<=100;i++){
        
        int tmp=0;
        for(int j=0;j<N;j++){
            tmp=tmp+pow(i-a[j],2);
            
        }
        if(min>tmp){
            min=tmp;
        }
    }

    cout << min << endl;
    
    //ここまで
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}

Measured memory_bytes: 256
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_099_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 ablen PIC 9(2) VALUE 2.
    01 cur PIC 9(2) VALUE 1.
    01 INP PIC X(19).
    01 i PIC 9(18) VALUE 1.
    01 j PIC 9(18).
    01 len PIC 9(2).
    01 ab.
        03 ab1 OCCURS 2.
            05 ab11 PIC 9(18).
    01 div PIC 9(18).
    01 s PIC 9(18).
    01 t PIC 9(18).
    01 ans PIC Z(18).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    PERFORM ablen TIMES

        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO ab11(i)

        COMPUTE cur = j + 1

        ADD 1 TO i

    END-PERFORM.

    COMPUTE div = ab11(2) - ab11(1).

    MOVE 0 TO s.
    MOVE 1 TO i.

    PERFORM div TIMES
        ADD i TO s
        ADD 1 TO i
    END-PERFORM.

    COMPUTE t = s - ab11(2).

    MOVE t TO ans.

    DISPLAY ans.
    STOP RUN.


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n;
char s[200],t[200];

int main(){
  cin>>n;
  cin>>s>>t;
  int ans = 2*n;

  for(int i=n-1;i>=0;i--){
    int j=0;
    while(j<n-i){
      if(s[i+j]!=t[j]) break;
      j++;
    }
    if(j==n-i)
      ans = n+i;
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
# SからTの長さが3の倍数の最短バスを求める
N, M = map(int, input().split())
G = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)

S, T = map(int, input().split())
S -= 1
T -= 1

from collections import deque

def bfs(start, terminal):
    q = deque([(start, 0)])
    color = [[0]*3 for _ in range(N)]
    d = [[-1]*3 for _ in range(N)]
    d[start][0] = 0
    l = 0
    while len(q) > 0:
        u, l = q.popleft()
        nl = (l + 1) % 3
        for v in G[u]:
            if color[v][nl] == 0:
                q.append((v, nl))
                color[v][nl] = 1
                d[v][nl] = d[u][l] + 1
    
    if d[terminal][0] == -1:
        return -1
    else:
        return d[terminal][0] // 3 

print(bfs(S, T))

Measured memory_bytes: 48376
"use strict"

const main = lines => {
  const line = lines[0].split(' ').map(x => parseInt(x))
  console.log(line[0] * line[1] < line[2] ? line[0] * line[1] : line[2])
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'))

Measured memory_bytes: 7372
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long p, q;
long long solve(long long now_p, long long now_q, long long limit, long long cnter,long long now_see) {
	//first we have to see it
	long long top = now_p;
	long long bot = p;
	top *= q;
	bot *= now_q;
	if (top == bot) return 1; //done
	if (top > bot) return 0; // Impossible
	if (now_q * now_see > limit) return 0; // impossible
	if (cnter == 0) return 0; //impossible
	long long ans = solve(now_p, now_q, limit, cnter, now_see + 1);
	ans += solve(now_q + now_see * now_p, now_see * now_q, limit, cnter - 1, now_see);
	return ans;
}
int main() {
	iostream::sync_with_stdio(false);
	while (true) {
		long long a, n;
		cin >> p >> q >> a >> n;
		if (p == 0) return 0;
		cout << solve(0, 1, a, n,1) << endl;
	}
}


Measured memory_bytes: 4204
#include<bits/stdc++.h>
using namespace std;
int main() {
    string S; cin>>S;
    int ans=0;
    for(int i=0;i<=3;i++){
        if(S[i]=='+'){
            ans=ans+1;
        }
        else{
            ans=ans-1;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  long long int x;
  cin>>x;
  long long int d = 100;
  long long int cnt = 0;
  while(d<x)
  {
    d = d + (d*0.01);
    cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 3672
a = input()
b = input()
s = 0 
for i in range(len(a)):
    b = b[-1] + b[:-1]
    if a == b:
        s = 1
def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')
y(s,1)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h = S / 3600;
		S = S % 3600;
		int m = S / 60;
		int s = S % 60;
		System.out.println(h +":"+ m +":"+ s);
	}

}

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

int main() {
    int x, y;
    cin >> x >> y;
    if(x == 1 && y == 2){
        cout << "Yes" << endl;
        return 0;
    }
    if(x == 1 && y == 4){
        cout << "Yes" << endl;
        return 0;
    }
    if(x > 50){
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < 100; i++){
        for (int j = 0; j < 100; j++){
            if(i * 4 + j * 2 == y && i + j == x){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
import scala.io.Source
import math.pow
object Main {
  def main(args: Array[String]) {
    val s = Source.stdin.getLines.toSeq.head.split(" ")
    val (n, k) = (s(0).toInt, s(1).toInt)
    println(k * pow(k-1, n-1).toInt)
  }
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    if (a >= b)
        OP("delicious");
    else if (b <= a + x)
        OP("safe");
    else
        OP("dangerous");

    return 0;
}

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

void dfs1(int &u, int nowcost, int &dis, int node, vector<bool> &used, vector<vector<pair<int, int> > > &adj){
    used[node] = true;
    if(dis < nowcost){
        dis = nowcost;
        u = node;
    }
    //cout << node << " " << nowcost << endl;
    for(int i = 0; i < (int)adj[node].size(); i++){
        //cout << "ok" << endl;
        int to = adj[node][i].first;
        int cost = adj[node][i].second;
        if(!used[to]){
            dfs1(u, nowcost + cost, dis, to, used, adj);
        }
    }    
}

void dfs2(int nowcost, int &dis, int node, vector<bool> &used, vector<vector<pair<int, int> > > &adj){
    used[node] = true;
    dis = max(dis, nowcost);
    //cout << node << " " << nowcost << endl;
    for(int i = 0; i < (int)adj[node].size(); i++){
        //cout << "ok" << endl;
        int to = adj[node][i].first;
        int cost = adj[node][i].second;
        if(!used[to]){
            dfs2(nowcost + cost, dis, to, used, adj);
        }
    }    
}

int main(){
    int n; cin >> n;
    if(n == 1) return !printf("0\n");
    vector<vector<pair<int, int> > > adj(n);
    for(int i = 0; i < n - 1; i++){
        int a, b, c; cin >> a >> b >> c;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
    }

    int u;
    int dis = 0;
    vector<bool> used(n, false);
    dfs1(u, 0, dis, 0, used, adj);
    for(int i = 0; i < n; i++) used[i] = false;
    dis = 0;
    dfs2(0, dis, u, used, adj);
    cout << dis << endl;
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < n;i++)

int main()
{
    char c1, c2, c3;
    cin >> c1 >> c2 >> c2 >> c2 >> c2 >> c3 >> c3 >> c3 >> c3;
    cout << c1 << c2 << c3 << endl;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

ll mod=1000000007;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

ll dp[55];

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

  if(s1[0]==s2[0])dp[0]=3;
  else dp[0]=6;

  reps(i,n){
    if(s1[i]==s1[i-1])dp[i]=dp[i-1];
    else if(s1[i-1]==s2[i-1])dp[i]=(dp[i-1]*2)%mod;
    else if(s1[i-1]!=s2[i-1]){
      if(s1[i]==s2[i])dp[i]=dp[i-1];
      else dp[i]=(dp[i-1]*3)%mod;
    }
  }
  cout<<dp[n-1];
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]+n<=90)
        {
            s[i]=s[i]+n;
        }
        else{
            s[i]=(n-(90-s[i]))+64;
        }
        cout<<s[i];


    }
    return 0;

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    int sum = 0;
    vector<int> w(n);
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        sum += w[i];
    }
    // left:[0,n),right:[i,n)
    vector<int> left(n + 1, 0), right(n + 1, 0);
    for (int i = 0; i < n; i++) {
        left[i + 1] = left[i] + w[i];
        right[i] = sum - left[i];
    }
    int ans = INT_MAX;
    for (int i = 1; i < n; i++) {
        ans = min(ans, abs(left[i] - right[i]));
    }
    cout << ans << endl;
}

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

int main() {
  double n;
  cin >> n;
  int i;
  for (i = 0; i < n + 1; i++) {
    if ((int)(i * 1.08) == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
def isOK(s,t):
  m = [None] * 26
  for i,j in zip(s,t):
    num = ord(i) - ord("a")
    if m[num] == None:
      m[num] = j
    else:
      if m[num] != j:
        return False
  return True

s = input()
t = input()
if isOK(s,t) and isOK(t,s):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3632
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var vals []string
	for {
		v := nextString(sc)
		if v == "0" {
			break
		}
		vals = append(vals, v)
	}

	for _, v := range vals {
		var sum int64
		for _, w := range v {
			sum += int64(w - '0')
		}
		fmt.Println(sum)
	}
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}



Measured memory_bytes: 1100
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, m, k;
	cin >> n >> m >> k;
	vector<vector<int>> by_row(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			if (c == '#') {
				by_row[i].push_back(j);
			}
		}
	}
	vector<vector<int>> ans(n, vector<int> (m, -1));
	int p = 0;
	for (int i = 0; i < n; i++) {
		if (by_row[i].empty()) {
			continue;
		}
		for (int j = 0; j <= by_row[i].front(); j++) {
			ans[i][j] = p;
		} 
		p++;
		for (int j = 0; j + 1 < (int)by_row[i].size(); j++) {
			for (int x = by_row[i][j] + 1; x <= by_row[i][j + 1]; x++) {
				ans[i][x] = p;
			}
			p++;
		}
		for (int j = by_row[i].back(); j < m; j++) {
			ans[i][j] = p - 1;
		}
	}
	for (int i = n - 2; i >= 0; i--) {
		for (int j = 0; j < m; j++) {
			if (ans[i][j] == -1 && ans[i + 1][j] != -1) {
				ans[i][j] = ans[i + 1][j];
			}
		}
	}
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (ans[i][j] == -1 && ans[i - 1][j] != -1) {
				ans[i][j] = ans[i - 1][j];
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << ans[i][j] + 1 << ' ';
		}
		cout << '\n';
	}
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define N 101000
int f[N];
vector<int> A[N];

int fa(int x) {
	if (f[x] == x) return x;
	f[x] = fa(f[x]);
	return f[x];
}

int n, m;

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i ++) f[i] = i;
	for (int i = 0; i < n; i ++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j ++) {
			int x; cin >> x;
			x --;
			A[x].pb(i);
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 1; j < (int) A[i].size(); j ++) {
			f[fa(A[i][j-1])] = fa(A[i][j]);
		}
	}
	int S = fa(0);
	bool F = true;
	for (int i = 0; i < n; i++)
		if (fa(i) != S) F = false;
	puts (F?"YES":"NO");
	return 0;
}

Measured memory_bytes: 5372
#include <iostream>
#include <queue>

using namespace std;

struct Point{int x,y;};

int main(){
  int t[30][30]={{}};
  int y[30][30]={{}};
  int dp[30][30]={{}};
  int w,h,c=0,i,j,k;
  int inf = 1000000;
  Point p,b;
  queue <Point> q; 
  cin >> w >> h;
  while(w!=0||h!=0){
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	dp[j][i] = inf;
      }
    }
    dp[0][0]=0;
      
    for(i=0;i<h-1;i++){
      for(j=0;j<w-1;j++){
	cin >> y[j][i];
      }
      for(j=0;j<w;j++){
	cin >> t[j][i];
      }
    }
    for(j=0;j<w-1;j++){
	cin >> y[j][h-1];
    }
    p.x=0;p.y=0;
    q.push(p);
    while(!q.empty()){
      p = q.front();
      q.pop();
      if(p.x+1<w&&y[p.x][p.y]==0){
	if(dp[p.x+1][p.y]>dp[p.x][p.y]+1){
	  dp[p.x+1][p.y]=dp[p.x][p.y]+1;
	  b.x=p.x+1;b.y=p.y;
	  q.push(b);
	}
      }
      if(p.x-1>=0&&y[p.x-1][p.y]==0){
	if(dp[p.x-1][p.y]>dp[p.x][p.y]+1){
	  dp[p.x-1][p.y]=dp[p.x][p.y]+1;
	  b.x=p.x-1;b.y=p.y;
	  q.push(b);
	}
      }
      if(p.y+1<h&&t[p.x][p.y]==0){
	if(dp[p.x][p.y+1]>dp[p.x][p.y]+1){
	  dp[p.x][p.y+1]=dp[p.x][p.y]+1;
	  b.x=p.x;b.y=p.y+1;
	  q.push(b);
	}
      }
      if(p.y-1>=0&&t[p.x][p.y-1]==0){
	if(dp[p.x][p.y-1]>dp[p.x][p.y]+1){
	  dp[p.x][p.y-1]=dp[p.x][p.y]+1;
	  b.x=p.x;b.y=p.y-1;
	  q.push(b);
	}
      }
    }
    
    c = (dp[w-1][h-1]==inf) ? 0:dp[w-1][h-1]+1;
    cout << c << endl;
    cin >> w >> h;
  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define ALL(C) (C).begin(),(C).end()
#define INPUT(P) std::cin>>(P)
#define INPUT2(P1,P2) std::cin>>(P1)>>(P2)
#define INPUT3(P1,P2,P3) std::cin>>(P1)>>(P2)>>(P3)
#define INPUTS(I,N,V) REP(I,N) std::cin>>V[I]
#define OUTPUT(P) std::cout<<P<<std::endl
#define OUTPUT2(P1,P2) std::cout<<P1<<" "<<P2<<std::endl
#define OUTPUT3(P1,P2,P3) std::cout<<P1<<" "<<P2<<" "<<P3<<std::endl
#define OUTPUTS(I,N,V) REP(I,N) std::cout<<V[i]<<std::endl
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ul;
using namespace std;
int i,j,k;
int n;
int odd_cnt[100001];
int even_cnt[100001];
int t;
int odd_mode1,odd_mode2;
int even_mode1,even_mode2;
int odd_mode,even_mode;
inline void solve(){
  INPUT(n);
  REP(i,n){
    cin>>t;
    if(i&1)even_cnt[t]++;
    else odd_cnt[t]++;
  }
  REP(i,100001){
    if(even_mode1<even_cnt[i]){
      even_mode2=even_mode1;
      even_mode1=even_cnt[i];
      even_mode=i;
    }else if(even_mode2<even_cnt[i]){
      even_mode2=even_cnt[i];
    }
    if(odd_mode1<odd_cnt[i]){
      odd_mode2=odd_mode1;
      odd_mode1=odd_cnt[i];
      odd_mode=i;
    }else if(odd_mode2<odd_cnt[i]){
      odd_mode2=odd_cnt[i];
    }
  }
  if(even_mode!=odd_mode)OUTPUT(n-even_mode1-odd_mode1);
  else OUTPUT(n-max(even_mode1+odd_mode2,even_mode2+odd_mode1));
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

int main() {
  int64_t n,a,b,aa,bb,c,ans;
  cin >> n >> a >> b ;
  
  c = b - a;
  
  if(c % 2 == 0){
    ans = c / 2;
  }
  else{
    ans = min(n - b,a - 1) + 1 + (c-1)/2;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
class Node:
    def __init__(self, key):
        self.right = None
        self.left = None
        self.parent = None
        self.key = key

    def preorder(self):
        ret = [self.key]
        if self.left:
            ret += self.left.preorder()
        if self.right:
            ret += self.right.preorder()
        return ret

    def inorder(self):
        ret = []
        if self.left:
            ret += self.left.inorder()
        ret += [self.key]
        if self.right:
            ret += self.right.inorder()
        return ret


class Tree:
    def __init__(self):
        self.root = None

    def insert(self, k):
        z = Node(k)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y is None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def print(self):
        print('', ' '.join(map(str, self.root.inorder())))
        print('', ' '.join(map(str, self.root.preorder())))


m = int(input())
tree = Tree()
for _ in range(m):
    s = input().split()
    if s[0] == "insert":
        tree.insert(int(s[1]))
    else:
        tree.print()


Measured memory_bytes: 142392
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

MOD = 10**9 + 7
N, K = map(int, read().split())

is_prime = np.zeros(K + 10, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, K + 10, 2):
    if p * p > K:
        break
    if is_prime[p]:
        is_prime[p * p:: p + p] = 0
primes = np.where(is_prime)[0]


A = [0] * (K + 1)
for d in range(1, K + 1):
    A[d] = pow(K // d, N, MOD)

for p in primes.tolist():
    for i in range(K // p + 1):
        A[i] -= A[i * p]

answer = sum(i * x for i, x in enumerate(A))
print(answer % MOD)


Measured memory_bytes: 29640
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  string ans = "No";
  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= 3)) ans = "Yes";
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long res, n, z, w, a[2005];

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

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

	res = abs(a[n-1] - w);
	if (n > 1)
		res = max(res, abs(a[n-1] - a[n-2]));

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 2000000
#define INFTY (1<<30)

int n,A[N+1];
void swap(int *a, int *b){
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
 
}
void maxh(int i){
  int left,right,large;
  left = 2 * i;
  right = 2 * i + 1;
  if(left <= n && A[left] > A[i]) large = left;
  else large = i;
  if(right <= n && A[right] > A[large])large = right;

  if(large != i){
    swap(&A[i],&A[large]);
    maxh(large);
  }
}
int extra(){
  int max;
  if(n < 1)return -INFTY;
  max = A[1];
  A[1] = A[n--];
  maxh(1);
  return max;
}
void increase(int i,int key){
  if(key < A[i])return ;
  A[i] = key;
  while(i > 1 && A[i/2] < A[i]){
    swap(&A[i],&A[i/2]);
    i = i/2;
  }
}
void insert(int key){
  n++;
  A[n] = -INFTY;
  increase(n,key);
}
int main(){
  int key;
  char x[10];
  while(1){
    scanf("%s",x);
    if(x[0] == 'e' && x[1] == 'n')break;
    if(x[0] == 'i'){
      scanf("%d", &key);
      insert(key);
    }
    else printf("%d\n",extra());
  }
  return 0;
}
  

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

int main()
{
    string s;
    string t[4] = {"maerd","remaerd","esare","resare"};
    while(cin >> s)
    {
        reverse(s.begin(),s.end());
        int i,j;
        bool flag = 0;
        int sz = s.size();
        for(i = 0;i < sz;i++)
        {
            flag = 0;
            for(j = 0;j < 4;j++)
            {
                if(s.substr(i,t[j].size()) == t[j])
                {
                    i += t[j].size() - 1;
                    flag = 1;
                }
            }
            if(flag == 0)
            {
                cout << "NO" << endl;
                break;
            }
        }
        if(flag)
        cout << "YES" << endl;
    }
    return 0;
}


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

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


int main(){
    ll A, B;  cin >> A >> B;
    cout << A / gcd(A, B) * B << endl;
}

Measured memory_bytes: 256