akhauriyash/Code-Regression huggingface dataset:
# 想定解法

N = int(input())
D = list(map(int, input().split()))
num_time = [0] * 13
num_time[0] = 2
num_time[12] = 1

fixed = [0]
unfixed = []
for d in D:
  num_time[d] += 1
  if d == 12:
    fixed.append(12)
  if num_time[d] >= 3:
    print(0)
    quit()

for t in range(1, 12):
  if num_time[t] == 2:
    fixed.extend([t, 24 - t])
  elif num_time[t] == 1:
    unfixed.append(t)

ans = 0
n = len(unfixed)
for i in range(2**n):
  t = fixed.copy() + [24]
  # bitが0のものはt, 1のものは24-tとして設定する
  for j in range(n):
    if i >> j & 1:
      t.append(unfixed[j])
    else:
      t.append(24 - unfixed[j])
  t.sort()
  s = 24
  m = len(t)
  for k in range(m-1):
    _s = t[k+1] - t[k]
    s = min(s, _s)
  ans = max(ans, s)

print(ans)

Measured memory_bytes: 3064
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

c = 0
c += a1*t1-b1*t1
c += a2*t2-b2*t2

#print(c)
if c == 0:
    print('infinity')
    exit()

if c > 0:
    if b1*t1-a1*t1 < 0:
        ans = 0
    else:
        q, r = divmod(b1*t1-a1*t1, c)
        if r == 0:
            ans = 2*q
        else:
            ans = 2*q+1
else:
    c *= (-1)
    if -b1*t1+a1*t1 < 0:
        ans = 0
    else:
        q, r = divmod(-b1*t1+a1*t1, c)
        if r == 0:
            ans = 2*q
        else:
            ans = 2*q+1
print(ans)


Measured memory_bytes: 61932
#include <bits/stdc++.h>
#include <cxxabi.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    ((ll)1ll<60)
#define INF     ((int)1<<30)
#define EPS     (1e-9)
#define MOD     (1000000007)
template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool b=1;for(auto s:t)os<<(exchange(b,0)||strlen(abi::__cxa_demangle(typeid(S).name(),0,0,0))>20?"":" ")<<s;return os<<endl;}

using Node=tuple<int,int,int,double>; //L,R,W,X


vector<Node> node;
vvi edge;

bool isStable(int p){
	int L,R,W;
	double X;
	tie(L,R,W,X)=node[p];
	X*=W;
	bool ok=true;
	for(auto child:edge[p]){
		int l,r,w;
		double x;
		ok&=isStable(child);
		tie(l,r,w,x)=node[child];
		W+=w;
		X+=w*x;
	}
	X/=W;
	node[p]=Node(L,R,W,X);
	return ok and L<X and X<R;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int w,h;
	while(cin>>w>>h,w){
		node.clear();
		edge.clear();
		vector<string> input(h);
		vvi field(h,vi(w,-1));
		
		rep(i,h)cin>>input[i];
		rep(i,h)rep(j,w)if(input[i][j]!='.'){
		    int L=100,R=0,W=0;
		    double X=0;
		    char tgt=input[i][j];
		    queue<pii> q; q.emplace(i,j);
		    while(!q.empty()){
		        int y,x; tie(y,x)=q.front(); q.pop();
		        if(input[y][x]=='.') continue;
		        W++;
		        X+=(x+0.5);
		        input[y][x]='.';
		        field[y][x]=node.size();
		        int v[]={1,0,-1,0};
		        rep(k,4){
		            int ny=y+v[k], nx=x+v[k^1];
		            if(ny<0 or nx<0 or ny>=h or nx>=w or input[ny][nx]!=tgt) continue;
		            q.emplace(ny,nx);
		        }
		    }
		    node.emplace_back(L,R,W,X/W);
		}
		int n=node.size(),p=-1;
		edge.resize(n);
		range(i,1,h)rep(j,w){
		    if(field[i][j]!=-1 and field[i-1][j]!=-1 and field[i-1][j]!=field[i][j]){
		        edge[field[i][j]].push_back(field[i-1][j]);
				get<0>(node[field[i-1][j]])=min(get<0>(node[field[i-1][j]]),j);
				get<1>(node[field[i-1][j]])=max(get<1>(node[field[i-1][j]]),j+1);
		    }
			if(i==h-1 and field[i][j]!=-1){
				p=field[i][j];
				get<0>(node[p])=min(get<0>(node[p]),j);
				get<1>(node[p])=max(get<1>(node[p]),j+1);
			}
		}
		for(auto &e:edge){
		    sort(all(e));
			e.erase(unique(all(e)),e.end());
		}
		cout<<(isStable(p)?"STABLE":"UNSTABLE")<<endl;
	}
	return 0;
}
 



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

int main() {
  int a, b;
  cin >> a >> b;

  if ((a * b) % 2 == 0) {
    cout << "Even" << endl;
  }
  if ((a * b) % 2 == 1) {
    cout << "Odd" << endl;
  }
}

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

int A[32]={
  1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};
int main()
{
  int a;
  cin>>a;
  cout<<A[a-1]<<endl;
  return 0;
}

Measured memory_bytes: 256
#https://atcoder.jp/contests/abc141/tasks/abc141_b

c = input()

ans = "Yes"
odd = ['R','U','D']
eval = ['L','U','D']
for i in range(len(c)):
    if i % 2 == 0 and not c[i] in odd:
        ans = "No"
    elif i % 2 == 1 and not c[i] in eval:
        ans = "No"
print(ans)


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

int main(){
    int n,k; cin >> n >> k;
    vector<ll> sum(n+1);
    sum[0] = 0;
    rep(i,n) {
        int p; cin >> p;
        sum[i+1] = sum[i] + p+1;
    }
    ll ans = 0;
    rep(i,n-k+1) {
        ans = max(ans,sum[i+k]-sum[i]);
    }
    cout << fixed << setprecision(10) << (double)ans/2 << endl;
}

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

#define ll long long

ll n,a,cnt;
map <ll, ll> mm;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		mm[a]++;
	}
	for(auto i: mm)
	{
		if(i.second%2==1) cnt++;
	}
	cout<<cnt<<endl;
	return 0;	
}

Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {

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

		int N = Integer.parseInt(sc.next());
//		int[] H = new int[N];
		int idx;
		int highest = 0;
		boolean result = true;
		int H;

		for (idx = 0; idx < N; idx++) {
//			H[idx] = Integer.parseInt(sc.next());
			H = Integer.parseInt(sc.next());

			if (H < highest - 1) {
				result = false;
				break;
			}

			if (H > highest) {
				highest = H;
			}
		}

		if (result) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 46776
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  vector<int64> a(100);
  a[0] = 2; a[1] = 1;
  for (int i = 2; i < 100; ++i) {
    a[i] = a[i - 1] + a[i - 2];
  }
  int n;
  cin >> n;
  cout << a[n] << endl;
  return 0;
}


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

int main(){
    using namespace std;
    unsigned long N, M;
    cin >> N >> M;
    vector<unsigned long> uf(N), sz(N, 1);
    iota(begin(uf), end(uf), 0UL);
    const auto& find = [&uf](auto i) -> unsigned long {
        while(uf[i] != i)i = uf[i] = uf[uf[i]];
        return i;
    };
    const auto& unite = [&uf, &sz, &find](auto i, auto j) -> unsigned long {
        i = find(i);
        j = find(j);
        if(i == j)return 0;
        if(sz[i] < sz[j])swap(i, j);
        sz[i] += sz[j];
        uf[j] = i;
        return sz[i];
    };
    unsigned long ans{1};
    for(unsigned long i{0}, a, b; i < M; ++i){
        cin >> a >> b;
        ans = max(ans, unite(--a, --b));
    }
    cout << ans << endl;
    return 0;
}

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

#define MAXN 305
#define MAXK 1000000
#define int long long
#define LL long long
#define pii pair<long, long>
#define fi first
#define se second
#define fastio ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
using namespace std;

int N;
int mod = 1e9+7;
int cnt[4];
double dp[MAXN][MAXN][MAXN];

signed main() {
    fastio;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        int x ;
        cin >> x;
        cnt[x]++;
    }
    for (int i3 = 0; i3 <= cnt[3]; i3++) {
        for (int i2 = 0; i2+i3 <= N; i2++) {
            for (int i1 = 0; i1+i2+i3 <= N; i1++) {
                double total = 0;
                if (i3)
                    dp[i1][i2][i3] += (double)i3 / (double)N * (dp[i1][i2+1][i3-1] + 1), total += (double)i3 / (double) N;
                if (i2)
                    dp[i1][i2][i3] += (double)i2 / (double)N * (dp[i1+1][i2-1][i3] + 1), total += (double)i2 / (double) N;
                if (i1)
                    dp[i1][i2][i3] += (double)i1 / (double)N * (dp[i1-1][i2][i3] + 1), total += (double)i1 / (double) N;
                if (i1+i2+i3==0) continue;
                dp[i1][i2][i3] = (dp[i1][i2][i3] + (1 - total)) / total;
            }
        }
    }
    cout << fixed << setprecision(15) << dp[cnt[1]][cnt[2]][cnt[3]] << endl;
    return 0;
}

Measured memory_bytes: 219392
#include<iostream>
#include<string>

const char c[5]={'M','A','R','C','H'};

using namespace std;

int main(){
  int n;
  cin >> n;
  
  string s;
  long cnt[5]={0};
  for(int i=0;i<n;i++){
   cin >> s;
   for(int j=0;j<5;j++){
    if(s[0]==c[j]) cnt[j]++;
   } 
  }
  
  long long res=0;
  
  for(int i=0;i<5;i++){
   for(int j=i+1;j<5;j++){
    for(int k=j+1;k<5;k++){
     res=res+cnt[i]*cnt[j]*cnt[k];
    }
   }
  }

 cout << res << endl;

}

Measured memory_bytes: 256
n = int(input())
nums = [int(x) for x in input().split()]
nums_v2 = []
nums_v3 = []

for i in range(len(nums)):
      if (i+1)%2 == 1:
            nums_v2.append(nums[i])

for i in range(len(nums_v2)):
      if nums_v2[i]%2 == 1:
            nums_v3.append(nums_v2[i])

print(len(nums_v3))

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (1e9)

typedef struct { char suit, value; } Card;

void bubbleSort(Card a[], int n) {
  for(int i = 0; i < n; i++) {
    for (int j = n-1; j > i; j--) {
      if(a[j].value < a[j-1].value) {
        swap(a[j], a[j-1]);
      }
    }
  }
}

void selectionSort(Card a[], int n) {
  for(int i = 0; i < n-1; i++) {
    int minj = i;
    for(int j = i; j < n; j++) {
      if(a[j].value < a[minj].value) {
        minj = j;
      }
    }
    swap(a[minj], a[i]);
  }
}

bool isStable(Card b[], Card s[], int n) {
  for(int i = 0; i < n; i++) {
    if(b[i].suit != s[i].suit) {
      return false;
    }
  }
  return true;
}

int main(){
  int n;
  Card b[40], s[40];
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> b[i].suit >> b[i].value;
  }

  for(int i = 0; i < n; i++) {
    s[i] = b[i];
  }

  bubbleSort(b, n);
  selectionSort(s, n);

  cout << b[0].suit << b[0].value;
  for(int i = 1; i < n; i++) {
    cout << " " << b[i].suit << b[i].value;
  }
  cout << endl << "Stable" << endl;

  cout << s[0].suit << s[0].value;
  for(int i = 1; i < n; i++) {
    cout << " " << s[i].suit << s[i].value;
  }
  cout << endl;

  cout << (isStable(b, s, n) ? "Stable" : "Not stable") << endl;

  return 0;
}


Measured memory_bytes: 3108
#include<stdio.h>
int main()
{
    int a[20000],b[20000],i;
    char m[20000],o[20000];
    for(i=1;i<=20000;i++)
    {
        scanf("%d",&a[i]);
        scanf("%c%c",&m[i],&o[i]);
        scanf("%d",&b[i]);
        if(o[i]=='?')
            break;
    }
    for(i=1;i<20000;i++)
    {
        if(o[i]=='+')
            printf("%d\n",a[i]+b[i]);
        else if(o[i]=='-')
            printf("%d\n",a[i]-b[i]);
        else if(o[i]=='*')
            printf("%d\n",a[i]*b[i]);
        else if(o[i]=='/')
            printf("%d\n",a[i]/b[i]);
        else if(o[i]=='?')
            break;
    }
    return 0;
}



Measured memory_bytes: 2120
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int64_t H, W;
  cin >> H >> W;
  if (H > 1 && W > 1)cout << (H * W / 2 + (H * W % 2 ? 1 : 0)) << endl;
  else cout << 1 << endl;
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

bool is2n(LL N){
  while(N%2==0){
    N /= 2;
  }
  return N == 1;
}

LL jouibit(LL N){
  LL x = 1;
  while(x<=N){
    x *= 2;
  }
  return x / 2;
}

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

  LL N;
  cin >> N;
  if(is2n(N)){
    cout << "No" << endl;
  }else{
    LL joui = -1;
    LL a = -1;
    if (N % 2 == 1)
    {
      
    }else{
      joui = jouibit(N);
      a = N - joui + 1;
    }
    
    cout << "Yes" << endl;
    cout << N + 1 SP N + 3 << endl;
    FOR(i,2,N+1){
      if(i==N&&N%2==0){
          cout << i SP joui << endl;
          cout << i+N SP a << endl;
        }
      else{
        cout << 1 SP i << endl;
        if (i % 2 == 0)
        {
          cout << i SP i + 1 + N << endl;
        }else{
          cout << i SP i - 1 + N << endl;
        }
      }
    }
  }
}


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

typedef long long W;

const W INF = 1LL << 50;

struct edge {
	int to;
	W cost;
	int id;
};
typedef pair<W, int> P;
typedef vector<vector <edge > > Graph;

void dijkstra(int s, const Graph& G, vector<W>& d) {
	priority_queue< P, vector<P>, greater<P> > que;
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	que.push(P(0, s));
	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

typedef pair<W, int> P;
bool check[200000];

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

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

	ll wsum = 0;
	Graph G(N);
	for(int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		G[a].push_back({ b, c, i });
		G[b].push_back({ a, c, i });
		wsum += c;
	}

	vector<W> d(N);
	dijkstra(0, G, d);

	vector<P> ord(N);
	for(int i = 0; i < N; i++) {
		ord[i] = { d[i], i };
	}
	sort(ord.begin(), ord.end());

	ll ans = INF;
	for(int i = 0; i < N; i++) {
		int v = ord[i].second;
		ll x = ord[i].first;
		for(auto e : G[v]) {
			if(d[e.to] <= x && !check[e.id]) {
				check[e.id] = 1;
				wsum -= e.cost;
			}
		}
		ans = min(ans, wsum + x * C);
	}
	cout << ans << endl;
}

Measured memory_bytes: 22496
#include<stdio.h>
#include<math.h>
int ifcl(int p0[2],int p1[2],int p2[2],int p3[2]){
  long long x=p0[0],x0=p1[0]-x,x1=p2[0]-x,x2=p3[0]-x,x3=x2-x1,x4=x1-x0,x5=x2-x0;
  long long y=p0[1],y0=p1[1]-y,y1=p2[1]-y,y2=p3[1]-y,y3=y2-y1,y4=y1-y0,y5=y2-y0;
  long long c1=(x0*y1-y0*x1)*(x0*y2-y0*x2),c2=(x3*y4-y3*x4)*(x3*y1-y3*x1);
  long long d1=x1*x4+y1*y4,d2=x4*x5+y4*y5,d3=x2*x5+y2*y5,d4=x1*x2+y1*y2;
  return c1||c2?(c1<=0&&c2<=0?1:0):(d1>0&&d2>0&&d3>0&&d4>0?0:1);
}
int main(){
  int p[4][2],n,i;
  scanf("%d",&n);
  while(n--){
    for(i=0;i<8;i++)scanf(" %d",&p[i/2][i%2]);
    printf("%d\n",ifcl(p[0],p[1],p[2],p[3]));
  }
  return 0;
}

Measured memory_bytes: 600
x,y=map(int,input().split())
if x<y:
    temp=x
    x=y
    y=temp
if x%y==0:
    print(str(y))
else:
    r=x%y
    while True:
        x=y
        y=r
        r=x%y
        if(r==0):
            print(str(y))
            break


Measured memory_bytes: 5592
#include <stdio.h>
#include <vector>
#include <utility>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, m, a, b, c;
  scanf("%lld%lld", &n, &m);
  vector< pair<ll, ll> > vec[n];
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld%lld", &a, &b, &c);
    a--, b--;
    vec[a].push_back(make_pair(b, -c));
  }
  ll dis[n];
  for(i = 0; i < n; ++i) dis[i] = 1e15;
  dis[0] = 0;
  for(i = 0; 1; ++i) {
    bool flg = true;
    ll now = dis[n - 1];
    for(j = 0; j < n; ++j) for(k = 0; k < vec[j].size(); ++k) if(dis[vec[j][k].first] > dis[j] + vec[j][k].second) dis[vec[j][k].first] = dis[j] + vec[j][k].second, flg = false;
    if(flg) break;
    else if(i == n) {
      if(now != dis[n - 1]) {
        printf("inf");
        return 0;
      } else break;
    }
  }
  printf("%lld", -dis[n - 1]);
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val a = 0.until(n).map {
        readLine()?.toInt() ?: return
    }
    val aa = a.sortedDescending()
    val f = aa[0]
    val s = aa[1]
    buildString {
        a.forEach {
            if (it == f) {
                appendln(s.toString())
            } else {
                appendln(f.toString())
            }
        }
    }.let {
        println(it.trimIndent())
    }
}


Measured memory_bytes: 106028
n = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0

before = -1

for a in A:
    ans += B[a-1]
    if before + 1 == a:
        ans += C[before-1]
    before = a
print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;

const int MAXN = 105, MAXV = 100005;
const ll inf = 0x3f3f3f3f3f3f3f3f;

ll dp[MAXN][MAXV];
ll weight[MAXN];
ll value[MAXN];
int object_count, max_weight;

void solve() {
    for (int v = 1; v < MAXV; ++v) dp[0][v] = inf;
    for (int i = 1; i <= object_count; ++i) {
        dp[i][0] = 0;
        for (int v = 1; v < MAXV; ++v) dp[i][v] = inf;
        for (int v = 1; v < MAXV; ++v) {
            if (v >= value[i]) {
                dp[i][v] = min(dp[i - 1][v], dp[i - 1][v - value[i]] + weight[i]);
            } else {
                dp[i][v] = dp[i - 1][v];
            }
        }
    }
}

void debug() {
    for (int i = 1; i <= object_count; ++i, putchar('\n')) {
        for (int v = 0; v < 20; ++v) {
            printf("%20lld", dp[i][v]);
        }
    }
}

int main() {
    scanf("%d%d", &object_count, &max_weight);
    for (int i = 1; i <= object_count; ++i) {
        scanf("%lld%lld", weight + i, value + i);
    }
    solve();
    for (int v = MAXV - 1; ~v; --v) {
        if (dp[object_count][v] && dp[object_count][v] <= max_weight) {
            printf("%d\n", v);
            return 0;
        }
    }
}

Measured memory_bytes: 80000
s=input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])

if a+b+c+d==7:
  print("%d+%d+%d+%d=7"%(a,b,c,d))
  exit()
if a+b+c-d==7:
  print("%d+%d+%d-%d=7"%(a,b,c,d))
  exit()
if a+b-c+d==7:
  print("%d+%d-%d+%d=7"%(a,b,c,d))
  exit()
if a+b-c-d==7:
  print("%d+%d-%d-%d=7"%(a,b,c,d))
  exit()  
if a-b+c+d==7:
  print("%d-%d+%d+%d=7"%(a,b,c,d))
  exit()
if a-b+c-d==7:
  print("%d-%d+%d-%d=7"%(a,b,c,d))
  exit()
if a-b-c+d==7:
  print("%d-%d-%d+%d=7"%(a,b,c,d))
  exit()
if a-b-c-d==7:
  print("%d-%d-%d-%d=7"%(a,b,c,d))
  exit()

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfr(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto sttart = high_resolution_clock::now()
#define etime auto sttop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; for(ll caseno= 1 ;caseno <= testcases; caseno++)
#define ptime auto z1z = duration_cast<microseconds>(sttop-sttart); cout<<"\nTime taken : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
const ll maxN = 1e5 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = MOD) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}
ll n;
ll h[maxN];
ll dp[maxN];

ll solve(ll pos) { // pos will be 0 indexing based
	if (pos <= 0) {
		return 0;
	}
	if (pos == 1) {
		return dp[pos] = abs(h[pos - 1] - h[pos]);
	}
	ll v1 = dp[pos - 1] == -1 ? dp[pos - 1] = solve(pos - 1) : dp[pos - 1];
	ll v2 = dp[pos - 2] == -1 ? dp[pos - 2] = solve(pos - 2) : dp[pos - 2];
	return dp[pos] = min(dp[pos - 1] + abs(h[pos] - h[pos - 1]), dp[pos - 2] + abs(h[pos] - h[pos - 2]));
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	FIO
	cin >> n;
	FOR(i, n) cin >> h[i];
	FOR(i, maxN) dp[i] = -1;
	dp[0] = 0;
	cout << solve(n - 1);
	return 0;
}


Measured memory_bytes: 9872
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	int N, K, ans = 0;
    	ArrayDeque<Integer> deque = new ArrayDeque<>();
    	PriorityQueue<Integer> atHand;
    	
    	void setMax() {
    		for (int l = 0; l <= K; ++l) {
    			int r = K - l;
    			for (int get_l = 0; get_l <= Math.min(l, N); ++get_l) {
    				for (int get_r = 0; get_r <= Math.min(r, N - get_l); ++get_r) {
    					Deque<Integer> dq = deque.clone();
    					atHand = new PriorityQueue<>();
    					int back_l = l - get_l;
    					int back_r = r - get_r;
    					
	    				for (int t = 0; t < get_l; ++t) {
	    					atHand.add(dq.pollFirst());
	    				}
	    				
						for (int t = 0; t < get_r; ++t) {
							atHand.add(dq.pollLast());
						}
						
						for (int t = 0; t < back_l + back_r; ++t) {
							if (!atHand.isEmpty() && atHand.peek() < 0) atHand.poll();
						}
	    				
	    				int sum = 0;
	    				for (int item : atHand) {
	    					sum += item;
	    				}
	    				ans = Math.max(ans, sum);
    					
    				}
    			}
    		}
    	}
    	
        void solve(InputReader in, PrintWriter out) {
        	N = in.nextInt();
        	K = in.nextInt();
        	for (int i = 0; i < N; ++i) {
        		deque.add(in.nextInt());
        	}
        	
        	setMax();
        	out.println(ans);
        }
        
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 43316
#include <bits/stdc++.h>
#define Mashu cout << "UUZ ate it." << endl
#define RE register int
#define ll long long
using namespace std;

inline int read(){
	char ch=getchar();
	int x=0,cf=1;
	while(ch<'0'||ch>'9') {
		if(ch=='-') cf=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return x*cf;
}

int G[55];
template<class T> inline void write(T x){
	int g=0;
	do{G[++g]=x%10;x/=10;}while(x);
	for(int i=g;i>=1;--i)putchar('0'+G[i]);putchar('\n');
}

int main(){
	int n;
	long long d;
	cin >> n >> d;
	int cnt = 0;
	for (int i = 1; i <= n; i++){
		long long x, y;
		cin >> x >> y;
		if (x * x + y * y <= d * d){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
	Mashu;
}


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;

    cout << a*b << " " << a*2 + b*2 << endl;


    return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>

int main (void)
{
    int n, d, x, i;
    int a;

    scanf("%d", &n);
    scanf("%d %d", &d, &x);
    for (i = 0; i < n; ++i) {
        scanf("%d", &a);
        x += (d - 1) / a + 1;
    }

    printf("%d\n", x);
}


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

typedef long long ll;

int main(int argc, char const *argv[]) {
    int a;
    string s;
    cin >> a;
    cin >> s;
    if(a >= 3200){
        cout << s;
    }else{
        cout << "red";
    }
    return 0;
}


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

int main(void){
  int N;

  scanf("%d",&N);
  int A[N];
  int i,j;  
 
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  int max = 0;
  
  for(i = 0; i < N; i++){
  	for(j = i;j < N;j++ ){
    max = abs(A[i] - A[j]) > max ? abs(A[i] - A[j]):max;
    }
  }
   printf("%d",max);
  return 0;
}

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

int par[100005];
int rnk[100005];
int cnt[100005];

void init(int n) {
  for (int i=0; i<n; i++) {
    par[i]=i;
    rnk[i]=0;
    cnt[i]=1;
  }
}
int find(int x) {
  if (par[x]==x) {
    return x;
  }
  else {
    return par[x]=find(par[x]);
  }
}

void unite(int x,int y) {
  x=find(x);
  y=find(y);
  if (x==y) return;
  if (rnk[x]<rnk[y]) {
    par[x]=y;
    cnt[y]+=cnt[x];
  }
  else {
    par[y]=x;
    cnt[x]+=cnt[y];
    if (rnk[x]==rnk[y]) rnk[x]++;
  }
}

bool same(int x, int y) {
  return find(x)==find(y);
}


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

  init(n);
  ll ans=(ll)n*(n-1)/2;
  ll memo[100005];
  memo[m-1]=ans;
  int a[100005],b[100005];
  rep(i,m) {
    cin>>a[i]>>b[i];
    a[i]--; b[i]--;
  }
  reverse(a,a+m); reverse(b,b+m);
  rep(i,m-1) {
    if (!same(a[i],b[i])) {
      ans-=(ll)cnt[find(a[i])]*cnt[find(b[i])];
    }
    unite(a[i],b[i]);
    memo[m-2-i]=ans;
  }
  rep(i,m) cout<<memo[i]<<endl;
  return 0;
}

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

int dp[2][9][9][2];
char s[200000];
int main(){
	while(1){
		scanf("%s",s);
		if(s[0]=='#')break;
		int n=strlen(s);
		rep(i,n){
			s[i]-='1';
		}
		rep(i,9)rep(j,9)rep(k,2){
			if(j==4||k==4)dp[0][i][j][k]=INF;
			else dp[0][i][j][k]=0;
		}
		rep(l,n){
			int i=l%2;
			rep(j,9)rep(k,9)rep(t,2)dp[!i][j][k][t]=INF;
			rep(j,9)rep(k,9)rep(t,2){
				if(s[l]%3<=k%3){
					dp[!i][s[l]][k][0]=min(dp[!i][s[l]][k][0],dp[i][j][k][t]+(t==0));
				}
				if(j%3<=s[l]%3){
					dp[!i][j][s[l]][1]=min(dp[!i][j][s[l]][1],dp[i][j][k][t]+(t==1));
				}
			}
		}
		int Min=INF;
		rep(i,9)rep(j,9)rep(k,2)Min=min(Min,dp[n%2][i][j][k]);
		printf("%d\n",Min);
	}
}
//0,3,6
//1,7
//2,
//1,2,0
//1+2,2+2,0+2
//0,1,2

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    cout << "ABC" << n << endl;
    return 0;
}


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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1e9 + 7;
const int N = 1e6 + 5;

typedef long long ll;

ll a[N], ans = 1;
string s;

int main()
{
      cin >> s;

      for(int i = 0; i < s.size(); i ++)
            a[s[i] - 'a' + 1] ++;
      for(int i = 0; i < s.size(); i ++)
      {
            for(int j = 1; j <= 26; j ++)
                  if((s[i] - 'a' + 1) != j)
                        ans += a[j];
            a[s[i] - 'a' + 1] --;
      }

      cout << ans << endl;
}


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

int main(){
	int i,o;
	while ( cin >> i >> o ){
		if ( i != 0 || o != 0){
			if ( i <= o){
				cout << i << " " << o << endl;
			}
			else {
				cout << o << " " << i << endl;
			}
		}
		else {
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3020
nq = gets.split.map(&:to_i)
ary = Array.new(nq[0]){[]}

nq[1].times do
  odr = gets.split.map(&:to_i)
  case odr[0]
  when 0
    ary[odr[1]] << odr[2]
  when 1
    unless (ary[odr[1]][-1]).nil?
      puts(ary[odr[1]][-1])
    end
  when 2
    ary[odr[1]].pop
  end
end


Measured memory_bytes: 8552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}

};

int main() {
	int n;
	cin >> n;
	cout << (n+110)/111*111 << endl;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  string s,t;
  cin>>s>>t;
  int ans = 0;
  rep(i,size(s))if(s[i]!=t[i])ans++;
  cout<<(ans)<<endl;

}

Measured memory_bytes: 3916
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int f[100002][2];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin >> s;

	int n = s.length();
	f[0][1-(s[0]-'0')] = 1;

	for (int i = 1; i < n; ++i) {
		int cur = s[i] - '0';

		for (int j = 0; j <= 1; ++j)
			f[i][j] = f[i-1][1-j] + 1 - (cur == j);
	}

	cout << min(f[n-1][0], f[n-1][1]) << endl;

	return 0;
}

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

int main() {
    string sa, sb, sc;
    cin >> sa >> sb >> sc;

    int a = 0, b = 0, c = 0;

    char turn = 'a';
    while (true)
    {
        if(turn == 'a'){
            if(a == sa.size()) {
                cout << "A" << endl;
                break;
            }
            turn = sa[a];
            a++;
        }
        else if(turn == 'b'){
            if(b == sb.size()) {
                cout << "B" << endl;
                break;
            }
            turn = sb[b];
            b++;
        }
        else{
            if(c == sc.size()) {
                cout << "C" << endl;
                break;
            }
            turn = sc[c];
            c++;
        }
    }

}

Measured memory_bytes: 256
import numpy as np

N = int(input())
data = list(map(int, input().split()))
pn = [x for x in range(1, N-1)]

cnt = 0
for p in pn:
    p_t = np.sort([data[p - 1], data[p], data[p + 1]])
    cnt = cnt + 1 if p_t[1] == data[p] else cnt
    
print(cnt)

Measured memory_bytes: 22300
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  bool ok = false;

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      int sum = i * m + j * (n - i);
      sum -= (n - (n - i)) * j;
      if (sum == k) ok = true;
    }
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
} 

Measured memory_bytes: 3636
#include<stdio.h>

int main(void){

   int a,b,c,d,s1,s2,s3;
   scanf("%d",&a);
   scanf("%d",&b);
   scanf("%d",&c);
   scanf("%d",&d);

   if(a>=b){
      s1=b;
}
   else{
      s1=a;
   }

   if(c>=d){
      s2=d;
}
   else{
      s2=c;
   }

   s3=s1+s2;

   printf("%d\n",s3);

   return 0;
}


Measured memory_bytes: 128
def main():
    a, b, k = map(int, input().split())
    r = set()
    for i1 in range(a, min(a + k, b)):
        r.add(i1)
    for i2 in range(max(a, b - k + 1), b + 1):
        r.add(i2)
    r = list(r)
    r.sort()
    for j in r:
        print(j)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        Scanner stdIn = new Scanner(System.in);

        while (true) {
            int a = stdIn.nextInt();
            int b = stdIn.nextInt();
            if (a == 0 && b == 0) {
                break;
            }

            for (int i = 0; i < a; i++) {
                for (int j = 0; j < b; j++) {
                    System.out.printf("#");
                }
                System.out.println();
            }
            System.out.println();
        }


    }
}


Measured memory_bytes: 60380
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;

int main(void) {

	string s1,s2,s3;
	
	cin >> s1 >> s2 >> s3;




	cout << s1[0] << s2[1] << s3[2] << endl;


	


	return 0;




}


Measured memory_bytes: 256
months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
input_line = input()
if (''.join(input_line[:2]) in months) and (''.join(input_line[2:]) in months):
    print('AMBIGUOUS')
elif ''.join(input_line[:2]) in months:
    print('MMYY')
elif ''.join(input_line[2:]) in months:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int V, E;
    cin >> V >> E;
    vector<vector<int>> G(V, vector<int>(V, -1));
    for(int i = 0; i < E; ++i){
        int s, t, d;
        cin >> s >> t >> d;
        G[s][t] = d;
    }

    // dp[mask][i][j]
    // := 訪問済み頂点集合が mask, (終点, 始点) = (i, j) であるときの最短経路
    // 始点は最初の訪問時に mask に入れる (遷移時に始点に戻るのを防ぐために)
    vector<vector<vector<int>>> dp(1 << V, vector<vector<int>>(V, vector<int>(V, INF)));
    for(int i = 0; i < V; ++i)  dp[1 << i][i][i] = 0;
    for(int mask = 1; mask < (1 << V); ++mask){
        for(int i = 0; i < V; ++i){
            for(int j = 0; j < V; ++j){
                if(dp[mask][j][i] == INF)   continue;
                for(int k = 0; k < V; ++k){
                    if(G[j][k] < 0 || mask >> k & 1)   continue;
                    chmin(dp[mask ^ (1 << k)][k][i], dp[mask][j][i] + G[j][k]);
                }
            }
        }
    }

    int ans = INF;
    for(int i = 0; i < V; ++i){
        for(int j = 0; j < V; ++j){
            if(G[i][j] >= 0)    chmin(ans, dp[(1 << V) - 1][i][j] + G[i][j]);
        }
    }
    if(ans == INF)  ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 53636
#include <bits/stdc++.h>
using namespace std;
#define oo 2000000000
const int N = 200010;
char s[N];
int frq[26];
int main(){
 	//freopen("in.txt","r",stdin);
	scanf(" %s",s);
	int n =strlen(s);
	int a = 0 ;
	for(int i=0;i<n;i++){
		frq[s[i]-'a']++;
	}
	long long ans =1  ;
	for(int i=0;i<26;i++){
		n-=frq[i];
		ans+= (long long)frq[i] * (long long)n;
	}
	cout << ans << endl;
	return 0;
}

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

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) (v.size())
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

LL MOD = 1000000007; 

using namespace std;


int main(int argc, char *argv[]) {
    int N, a;
    cin >> N;
    map<int, int> m;
    FOR(_, 0, N) {
        cin >> a; 
        m[a]++;
    }
    
    int num_of_two = 0;
    FOE(p, m) {
        if (p.second > 2) {
            std::cout << 0 << std::endl;
            return 0;
        }
        num_of_two += !(p.second % 2);
    }

    bool ok = true;
    if (N % 2 == 0) {
        for(int i = N - 1; i >= 0; i -= 2) {
            ok &= (m[i] == 2);
        }
    }
    else {
        ok &= (m[0] == 1);
        for(int i = N - 1; i >= 1; i -= 2) {
            ok &= (m[i] == 2);
        }
    }
    
    if (!ok) {
        std::cout << 0 << std::endl;
        return 0;
    }
    
    LL ans = 1;
    FOR(i, 0, num_of_two) {
        ans *= 2;
        ans %= MOD;
    }
    std::cout << ans << std::endl;
    
    
    return 0;
}

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

int main() {
  
  int N  ;
  cin >> N  ;
  vector<int> A(N) ;
  rep(i,N) cin >> A.at(i) ;
  sort(A.begin(),A.end()) ; 
  //rep(i,N) cout << A.at(i) << ' ' ;
  int count = 0 ;
  for(int i = 0 ; i < N-2 ; i++ ){
    for(int j = i+1 ; j < N-1 ; j++ ){
      for(int k = j+1 ; k < N   ;  k++ ){
    if( A.at(i) + A.at(j)  > A.at(k) ) count++ ;
      		}
    	}
    }
  cout << endl ;
  cout << count << endl ;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <assert.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
using namespace std;

// #define __DEBUG__

#ifdef __DEBUG__
bool debug_disabled = false;
#else
bool debug_disabled = true;
#endif

#define dbg if (debug_disabled) {} else cerr

void solve() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    for (int i = 0; ; ++i) {
        if (i % 2 == 0) {
            C -= B;
            if (C <= 0) {
                cout << "Yes" << endl;
                return;
            }
        } else {
            A -= D;
            if (A <= 0) {
                cout << "No" << endl;
                return;
            }
        }
    }
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve();
    }

    return 0;
}


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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N + 1);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        B[A[i]] = i + 1;
    }
    for (int i = 1; i <= N; ++i) {
        cout << B[i] << " ";
    }
    cout << "\n";
    
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>

int main() {
    int n, a, tmp, ret;
    std::cin >> n;
    std::vector<int> t(n), b(n);
    std::cin >> t[0];
    for (auto i = 1; i < n; i++) {
        std::cin >> tmp;
        t[i] = t[i-1] + tmp;

    }
    std::cin >> b[0];
    for (auto i = 1; i < n; i++) {
        std::cin >> tmp;
        b[i] = b[i-1] + tmp;
    }

    ret = t[0] + b[n-1];
    for (auto i = 1; i < n; i++) {
        ret = std::max(ret, t[i] + b[n-1] - b[i-1]);
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 256
/*
 * Linear Search.c
 *
 *  Created on: 2015/02/15
 */
#include <stdio.h>

int S[10000]={0},T[1000]={0};
int flag[1000]={0};

void printarray(int a[],int n){
	int i;
	for(i=0;i<n;i++){
		printf("%d ",a[i]);
	}printf("\n");
}

int main(){
	int n,q;
	int i,j,counter=0;

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

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

	for(i=0;i<q;i++){
		for(j=0;j<n;j++){
			if(S[j] == T[i]) flag[i]=1;
		}
	}

	for(i=0;i<q;i++){
		if(flag[i]==1)counter++;
	}
	printf("%d\n",counter);

	return 0;
}

Measured memory_bytes: 644
N=int(input())
S=input()
PIN=[]
b1=[]
for i in range(N-2):
    Ein=S[i]
    b2=[]
    if Ein in b1:
        continue
    else:
        b1.append(Ein)
    for j in range(i+1,N-1):
        b3=[]
        Zwei=S[j]
        if Zwei in b2:
            continue
        else:
            b2.append(Zwei)
        for k in range(j+1,N):
            Drei=S[k]
            if Drei in b3:
                continue
            else:
                b3.append(Drei)
                cand=Ein+Zwei+Drei
            if cand in PIN:
                continue
            else:
                PIN.append(cand)
print(len(PIN))

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

int main()
{
	int32_t N, M;
	cin >> N;

	set<string> unique_string;
	unique_string.insert("");

	vector<string> s(N);
	for (int32_t n = 0; n < N; n++) {
		cin >> s[n];
		unique_string.insert(s[n]);
	}

	cin >> M;
	vector<string> t(M);
	for (int32_t m = 0; m < M; m++) {
		cin >> t[m];
		unique_string.insert(t[m]);
	}

	int32_t res = 0;
	for (auto itr = unique_string.begin(); itr != unique_string.end(); ++itr) {
		int32_t total = 0;

		for (int32_t n = 0; n < N; n++) {
			if (*itr == s[n])
				total++;
		}
		for (int32_t m = 0; m < M; m++) {
			if (*itr == t[m])
				total--;
		}

		res = max(res, total);
	}

	cout << res << endl;

	return 0;
}

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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

int main() {
    ll n, h;
    cin >> n;

    ll ma = 0;
    for(ll i = 0; i < n; i++) {
        cin >> h;
        ma = max(ma, h);
        if(ma - 1 > h) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if((a <= b)&&(a <= c)){
        if(b < c){
            cout << a << " " << b << " " << c << endl;
        } else {
            cout << a << " " << c << " " << b << endl;
        }
    } else if((b <= a)&&(b <= c)){
        if(a < c){
            cout << b << " " << a << " " << c << endl;
        } else {
            cout << b << " " << c << " " << a << endl;
        }
    } else {
        if(a < b){
            cout << c << " " << a << " " << b << endl;
        } else {
            cout << c << " " << b << " " << a << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3072