akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long N;
    cin >> N;
    string S;
    cin >> S;
    long long sum = 0;
    long long divide = (N / 2) - 1;
    if (N != 1){
        if (N % 2 == 0) {
            for (long long i = 0; i <= divide; ++i) {
                if (S[i] == S[i + N / 2]) {
                    sum += 1;
                }
            }
        }
    }
    if (sum == (N / 2.0)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
P = [ int(x) for x in input().split() ]
Q = [ int(x) for x in input().split() ]

#Pind = []
#Qind = []
R = []
for i in range(N):
#    Pind.append( P.index(i+1) )
#    Qind.append( Q.index(i+1) ) 
    R.append( i+1 ) 
#print(Pind)
#print(Qind)
#print(R)

import itertools
cnt = 1
for v in itertools.permutations(R, N): 
#    print(list(v))
    if list(v) == P: 
       Porder = cnt
    if list(v) == Q: 
       Qorder = cnt
    cnt += 1
#print(Qorder)
#print(Porder)
sol = abs(Qorder-Porder)
print(sol)

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

int d[31];

void print(void){
  for(int i=0;i<31;i++){
    cout << d[i];
    if(d[i+1])cout << " ";
    else break;
  }
  cout << endl;
}

void square(int pos,int lim,int r){
  for(int i=d[pos-1];i>0;i--){
    if(i>lim){
      if(lim>r){
	d[pos] = r;
	print();
	d[pos] = 0;
      }else{
	d[pos] = lim;
	square(pos+1,lim,r-lim);
	d[pos] = 0;
      }
    }else{
      if(i==r){
	d[pos] = r;
	print();
	d[pos] = 0;
      }else if(i<r){
	d[pos] = i;
	square(pos+1,i,r-i);
	d[pos] = 0;
      }
    }
  }
}

int main(){
  int n;

  while(1){
    cin >> n;
    if(!n)break;

    cout << n << endl;
    for(int j=n;j>0;j--){
      for(int i=0;i<=n;i++)d[i] = 0;
      d[0] = j;
      square(1,j,n-j);
    }
  }
}

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

int main() {
 ll n,cnt=0;cin >> n;

 vector<pair<ll, ll>> p(n);
 for(int i=0;i<n;i++){
 cin >> p[i].second >> p[i].first;
   }
   sort(p.begin(), p.end());

   bool ans=1;
   for(int i=0;i<n;i++){
     cnt+=p[i].second;
     if(cnt>p[i].first){
       ans=0; break;
     }
   }
   cout <<(ans ? "Yes" : "No") << endl;

}


Measured memory_bytes: 3328
#include <iostream>

int main(void){
  unsigned long int a[6],min;
  for(int i = 0; i < 6; i++)
    std::cin >> a[i];
  min = a[1];
  for(int i = 2; i < 6; i++)
    if(min > a[i])
      min = a[i];

  std::cout << 4 + (( a[0] % min == 0)? a[0] / min : a[0] / min + 1) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n],b[n],c[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    ll dp[n][3];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(ll i=1;i<n;i++)
    {
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

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

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

ll n,a,b;
ll h[100010],k[100010];

bool isOK(ll x){//x回の爆発で全部倒せるかどうか
  ll sum = 0;
  rep(i,n){
    k[i] -= b*x;
  }
  rep(i,n){
    if(k[i] > 0){
      sum += (k[i]+a-b-1)/(a-b);
    }
  }
  return sum <= x;
}
int main(){
  cin >> n >> a >> b;
  rep(i,n){
    cin >> h[i];
  }

  ll ok = 2000000010, ng = 0;
  while(abs(ok-ng)>1){
    rep(i,n){
      k[i] = h[i];
    }
    ll mid = (ok+ng)/2;
    if(isOK(mid)){
      ok = mid;
    }else{
      ng = mid;
    }
  }
  cout << ok << endl;
}

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

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;}

//INSERT ABOVE HERE
signed main(){
  vector<Int> a(3);
  for(Int i=0;i<3;i++) cin>>a[i];
  Int ans=1e9;
  sort(a.begin(),a.end());
  do{
    Int res=abs(a[1]-a[0])+abs(a[2]-a[1]);
    chmin(ans,res);
  }while(next_permutation(a.begin(),a.end()));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
# Sum of Consecutive Integers

ans = []

while True:
    n = int(input())

    if n == 0:
        break
    s = 0
    for i in range(1, n // 2 + 3):
        tmp = i
        for j in range(i + 1, n // 2 + 3):
            tmp += j
            if tmp == n:
                s += 1
                break
            elif tmp > n:
                break

    ans.append(s)

for i in ans:
    print(i)



Measured memory_bytes: 5604
#include<stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31))

ll x[60],y[60];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	rep(i,0,n)scanf("%lld%lld",x+i,y+i);
	ll ans=INF;
	rep(i1,0,n)rep(i2,0,n)rep(i3,0,n)rep(i4,0,n){
		ll lx=min(x[i1],min(x[i2],min(x[i3],x[i4])));
		ll rx=max(x[i1],max(x[i2],max(x[i3],x[i4])));
		ll ly=min(y[i1],min(y[i2],min(y[i3],y[i4])));
		ll ry=max(y[i1],max(y[i2],max(y[i3],y[i4])));
		int cnt=0;
		rep(i,0,n)if(lx<=x[i]&&x[i]<=rx&&ly<=y[i]&&y[i]<=ry)cnt++;
		if(cnt>=k)ans=min(ans,(rx-lx)*(ry-ly));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
char s[19];
cin >> s;
s[5] = ' ';
s[13] = ' ';
REP(i,19) {
  cout << s[i];
}
cout << endl;
return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc170/tasks/abc170_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X, Y;
    cin >> X >> Y;
    bool flag = false;
    REP(i, X + 1) {
        int t = 2 * i + 4 * (X - i);
        if (t == Y) {
            flag = true;
        }
    }
    if (flag) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        List<Integer> sum =  new ArrayList<>();
        sum.add(scan.nextInt());
        for(int i=1;i<n;i++){
            sum.add(sum.get(i-1)+scan.nextInt());
        }
        int min = Integer.MAX_VALUE;
        for(int j=0;j<n;j++){
                min = Math.min(min,Math.abs(sum.get(j)-(sum.get(n-1)-sum.get(j))));
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
using  namespace std;
int main()
{
	int n,s=0;
	cin>>n;
	int a[n+1];
	a[0]=0;
	for(int i=1;i<=n;i++)
	{
        cin>>a[i];
        if(a[i]>a[i-1])
           s+=a[i]-a[i-1];
	} 
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define ll long long
using namespace std;

ll i,j,k;
const ll MOD = 1000000000 + 7;

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

    
    cout<<dp[n]<<'\n';

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1
#define FALSE 0
#define TRUE 1
int row[N],col[N],dpos[2*N -1],dneg[2*N-1];
int X[N][N];
 
void initialize(){
  int i;
  for(i=0;i<N;i++){
    row[i]=0;
    col[i]=0;
  }
  for(i=0;i<2*N-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
}
void print(){
  int i;
  int j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++)
      {
    if(X[i][j]!=0){
      if(row[i]!=j) return ;
    }
      }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
  }
void recursive(int i){
  int j;
   if(i==N){
     print();
    return ;
   }
     for(j=0;j<N;j++){
    if(col[j] == NOT_FREE||dpos[i+j]==NOT_FREE||dneg[i-j+N-1]==NOT_FREE)continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    recursive(i+1);
    col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
     
  }
}
int main(){
  int i,j;
  int k,r,c;
  initialize();//?????????
  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      X[i][j]=FALSE;
      scanf("%d",&k);
      for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    X[r][c]=TRUE;
      }
      recursive(0);
      return 0;
}

Measured memory_bytes: 572
#include <iostream>
using namespace std;
int main() 
{ 
  int n,m,k,a[30],cnt[30]={0},sum=0;
  cin>>n>>m;
  for (int i=0;i<n;i++)
  {
  	cin>>k;
  	for (int j=0;j<k;j++)
  	{
	cin>>a[j];
  	cnt[a[j]]++;
    }
  }
  for (int i=1;i<=m;i++)
  {
  	if(cnt[i]>=n)
  	  sum++;
  }
  cout<<sum;
  return 0;
}


Measured memory_bytes: 256
n,m,x = map(int,input().split())

ca=[list(map(int,input().split())) for _ in range(n)]

res=float('inf')

for i in range(2**n):
  sc=0
  a=[0]*m
  for j in range(n):
    if ((i >> j) & 1) :
      sc+=ca[j][0]
      for k in range(m):
        a[k]+=ca[j][k+1]
  if min(a)>=x:
    res=min(sc,res)

if res == float('inf'):
    print(-1)
else:
    print(res)


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;


int main(){
    int k;
    string s;
    cin >> k;
    cin >> s;
    string ans;
    if (s.size()>k) {
        rep(i, k) {
            ans += s[i];
        }
        ans += "...";
    }
    else ans = s;
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
 
int main() {
	int n;
	cin >> n;
	vector<ll> l(87);
	l[0] = 2;
	l[1] = 1;
 
	for (int i = 2; i < 87; i++) {
		l[i] = l[i - 1] + l[i - 2];
	}
	
	dunk(l[n]);
 
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long a, b, c;
  cin >> a >> b >> c;
  cout << a * b / 2 << endl;
}

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


Measured memory_bytes: 256
H, W = map(int, input().split())
Maze = [[1 if a == "#" else 0 for a in input()] for _ in range(H)]

DP = [[float('inf')] * W for _ in range(H)]

if Maze[0][0] == 1:
    DP[0][0] = 1
else:
    DP[0][0] = 0

for i in range(H):
    for j in range(W):
        if Maze[i][j] == 1:
            if i + 1 < H:
                DP[i+1][j] = DP[i][j]
            if j + 1 < W:
                DP[i][j+1] = min(DP[i][j+1], DP[i][j])
        if Maze[i][j] == 0:
            if i + 1 < H:
                if Maze[i+1][j] != 1:
                    DP[i + 1][j] = DP[i][j]
                else:
                    DP[i + 1][j] = DP[i][j] + 1
            if j + 1 < W:
                if Maze[i][j + 1] != 1:
                    DP[i][j + 1] = min(DP[i][j + 1], DP[i][j])
                else:
                    DP[i][j + 1] = min(DP[i][j + 1], DP[i][j]+1)

print(DP[H-1][W-1])


Measured memory_bytes: 43244
r,cr,c = map(int,input().split())

matrix_a = [list(map(int,input().split())) for i in range(r)]
matrix_b = [list(map(int,input().split())) for i in range(cr)]
matrix_c = [ [0 for a in range(c)] for b in range(r)]

for j in range(r):
    for k in range(c):
        for l in range(cr):
            matrix_c[j][k] += matrix_a[j][l]*matrix_b[l][k]

for x in matrix_c:
    print(" ".join(list(map(str,x))))

Measured memory_bytes: 8940
S = list(input())+['R']

new_S = ['0']*len(S)
s = 'R'
a = 0
b = 0
for i, ss in enumerate(S):
    if i % 2 == 0:
        flag = 'a'
    else:
        flag = 'b'
    if s == 'R' and ss == 'R':
        if flag == 'a':
            a += 1
        else:
            b += 1
    elif s == 'R' and ss == 'L':
        r_index = i-1
        l_index = i
        l_flag = flag
        if flag == 'a':
            a += 1
        else:
            b += 1
    elif s == 'L' and ss == 'L':
        if flag == 'a':
            a += 1
        else:
            b += 1
    elif s == 'L' and ss == 'R':
        if l_flag == 'a':
            new_S[r_index] = str(b)
            new_S[l_index] = str(a)
        else:
            new_S[r_index] = str(a)
            new_S[l_index] = str(b)
        a = 0
        b = 0
        if flag == 'a':
            a += 1
        else:
            b += 1
    s = ss
print(' '.join(new_S[:-1]))

Measured memory_bytes: 11284
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        List<int> a = new List<int>();
        
        while (true)
        {
            string s = Console.ReadLine();
            if (s == "0") break;
            a.Add(int.Parse(s));
        }
        for (int i = 0; i < a.Count; i ++)
        {
            Console.WriteLine("Case {0}: {1}", i + 1, a[i]);
        }
    }
}


Measured memory_bytes: 20012
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 int MAX_V = 1001;
const int MAX_E = 2001;
const ll INF = 1e18;

struct edge{
    int from, to;
    ll cost;
};

edge es[MAX_E];

ll d[MAX_V];
int V, E;
bool update;
bool negative[MAX_V];

void bellmanford(int s){
    for(int i = 1; i <= V; i++) d[i] = INF;
    d[s] = 0;
    for(int j = 0; j < V-1; j++){
        update = false;
        for(int i = 0; i < E; i++){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if(!update) break;
    }
    for(int j = 0; j < V; j++){
        for(int i = 0; i < E; i++){
            edge e = es[i];
            if(d[e.from] == INF) continue;
            if(d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                negative[e.to] = true;
            }
            if(negative[e.from]) negative[e.to] = true;
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> V >> E;
    for(int i = 0; i < E; i++){
        int from, to;
        ll cost;
        cin >> from >> to >> cost;
        es[i] = edge{from, to, -cost};
    }
    bellmanford(1);
    if(negative[V]) cout << "inf" << endl;
    else cout << -d[V] << endl;
    return 0;
}

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

#define FOR(x, a, b) for (int x = a; x <= b; ++x)
#define FOD(x, a, b) for (int x = a; x >= b; --x)
#define REP(x, a, b) for (int x = a; x < b; ++x)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A, n) { cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl; }
#define PR0(A, n)  { cout << #A << " = "; REP(_, 0, n) cout << A[_] << " "; cout << endl; }

using namespace std;

typedef long long LL;
typedef pair <int, int> II;

const int N = 1500 + 10;
const int INF = 0x3f3f3f3f;

int n, m;
int d[N][N];

bool ban[N], fre[N];

II V[2 * N];

vector <II> adj[N];
priority_queue <II> pq;

void Dijkstra(int *d, int s) {
    d[s] = 0; pq.push(II(-d[s], s));
    while (pq.size()) {
        int u = pq.top().second, w = -pq.top().first; pq.pop();
        if (w > d[u]) continue;
        REP(k, 0, adj[u].size()) {
            int v = adj[u][k].first, w = adj[u][k].second;
            if (d[v] > d[u] + w) {
                d[v] = d[u] + w;
                pq.push(II(-d[v], v));
            }
        }
    }
}

int main() {
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // LOCAL
    scanf("%d%d", &n, &m);
    FOR(i, 1, m) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        adj[u].push_back(II(v, w));
        adj[v].push_back(II(u, w));
        //cout << u << " " << v << " " << w << endl;
    }
    memset(d, INF, sizeof d);
    FOR(i, 1, n) {
        Dijkstra(d[i], i);
    }
    int maxDist = -INF;
    FOR(i, 1, n)
        FOR(j, 1, n) maxDist = max(maxDist, d[i][j]);
    int VSize = 0;
    FOR(i, 1, n) ban[i] = true;
    FOR(i, 1, n)
        FOR(j, 1, n) if (d[i][j] == maxDist) {
            V[++VSize] = II(i, j);
            ban[i] = false;
            ban[j] = false;
        }
    FOR(i, 1, n) if (ban[i] == true) {
        FOR(j, 1, VSize) {
            int x = V[j].first, y = V[j].second;
            if (d[x][i] + d[i][y] == maxDist) ban[i] = false;
        }
    }
    int sz = 0;
    FOR(i, 1, n) if (ban[i]) ++sz;
    printf("%d\n", sz);
    FOR(i, 1, n) if (ban[i]) printf("%d\n", i);
    return 0;
}



Measured memory_bytes: 12300
#include<bits/stdc++.h>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	priority_queue<int>q;    //优先队列自动从大到小排序
	int m,n,t;
	cin >>n>>m;
	for(int i=0;i<n;i++){
		cin>>t;
		q.push(t);    //每输入一个数都入队
	}
	long long sum=0;
	while(m){
		t=q.top()/2;
		q.pop();
		q.push(t);
		m--;
	}
	while(!q.empty()){
		sum+=q.top();
		q.pop();
	}
	cout<<sum;    //输出都处理完的总和
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>

using namespace std;

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

const ll MOD = 1000000007;
const ll inf = (ll) 1e18;

vector<vector<ll> > warshallFloyd(const vector<set<Pii> > &edge) {
  int n = edge.size();
  vector<vector<ll> > d(n, vector<ll>(n, inf));
  for (int i = 0; i < n; i++) {
    d[i][i] = 0;
    for (Pii x : edge[i]) {
      d[i][x.first] = x.second;
    }
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  return d;
}

vector<ll> dijkstraDistOnly(const vector<set<Pii> > &edge, int start) {
  vector<ll> length(edge.size(), inf);
  vector<bool> visited(edge.size(), false);
  priority_queue<pair<ll, int> > que;
  que.push(pair<ll, int>(0, start)); // negative distance
  length[start] = 0;
  while (!que.empty()) {
    auto now = que.top();
    que.pop();
    if (visited[now.second]) continue;
    visited[now.second] = true;
    for (auto x : edge[now.second]) {
      if (visited[x.first]) continue;
      ll d = -now.first + x.second;
      if (d < length[x.first]) {
        length[x.first] = d;
        que.push(pair<ll, int>(-d, x.first));
      }
    }
  }
  return length;
}

vector<vector<ll> > dijkstraAll(const vector<set<Pii> > &edge) {
  int n = edge.size();
  vector<vector<ll> > d;
  for (int i = 0; i < n; i++) {
    d.push_back(dijkstraDistOnly(edge, i));
  }
  return d;
}

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

  int N, M, R;
  cin >> N >> M >> R;
  vector<int> r;
  for (int i = 0; i < R; i++) {
    int buf;
    cin >> buf;
    r.push_back(buf-1); // zero index
  }
  vector<set<Pii> > edge;
  for (int i = 0; i < N; i++) edge.push_back(set<Pii>());
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edge[a-1].insert(Pii(b-1, c)); // zero index
    edge[b-1].insert(Pii(a-1, c)); // zero index
  }

  vector<vector<ll> > distanceMatrix = warshallFloyd(edge);
  //vector<vector<ll> > distanceMatrix = dijkstraAll(edge);
  ll shortest = inf;
  stack<vector<int> > st;
  st.push(vector<int>());
  while (!st.empty()) {
    vector<int> now = st.top();
    st.pop();
    if (now.size() == R) {
      ll dist = 0;
      for (int i = 0; i < R-1; i++) dist += distanceMatrix[now[i]][now[i+1]];
      if (dist < shortest) shortest = dist;
      continue;
    }
    set<int> contain;
    for (int x : now) contain.insert(x);
    for (int x : r) {
      auto it = contain.find(x);
      if (it == contain.end()) {
        vector<int> next = now;
        next.push_back(x);
        st.push(next);
      }
    }
  }

  cout << shortest << endl;
  return 0;
}


Measured memory_bytes: 2432
from collections import Counter

class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
                
n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.union(a, b)

for i in range(n):
    uf.find(i)

c = Counter(uf.par)
print(max(c.values()))

Measured memory_bytes: 33736
from collections import deque

n, m = map(int, input().split())

x = deque(range(1, n + 1))
aaa = []
bbb = []
flag = True

if n % 2 == 1:
    for i in range(m):
        a = x.popleft()
        aaa.append(a)
        b = x.pop()
        bbb.append(b)

else:
    for i in range(m):
        # ｎが偶数の場合は途中で1個捨てる
        a = x.popleft()
        aaa.append(a)
        b = x.pop()
        bbb.append(b)
        if x[-1] - x[0] <= n // 2 and flag:
            a = x.popleft()
            flag = False

for aa, bb in zip(aaa, bbb):
    print(aa, bb)

Measured memory_bytes: 17676
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int dy = y2-y1;
  int dx = x2-x1;
  cout << x2-dy << " " << y2+dx << " " << x1-dy << " " << y1+dx << endl;
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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; }

#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  int vec[100]={0};
  while(cin>>x){
    vec[x]++;
  }
  int ma=0;
  rep(i,100){
    ma = max(ma,vec[i]);
  }
  rep(i,100){
    if(vec[i]==ma) cout<<i<<endl;
  }
      
  return 0;
}


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

int main(){
    int n,m,ret=0,s,t;
    cin >> n >> m;
    for(int i=0;i<n;i++){
        t=0;
        for(int j=0;j<m;j++){
            cin >> s;
            t += s;
        }
        ret = max(ret, t);
    }
    cout << ret << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a;
	cin>>b;
	if(a=="H"&&b=="H"){
	
		printf("H\n");
}
	else if(a=="D"&&b=="D"){
	
	printf("H\n");
}
	else{
	
		printf("D\n");
	
}
}


Measured memory_bytes: 256
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N;
vector<int> B;

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        int v; cin >> v;
        B.push_back(v);
    }

    vector<int> rev;
    for (int i = 0; i < N; ++i) {
        int v = -1;
        for (int j = 0; j < N-i; ++j) {
            if (B[j] == j+1) v = j;
        }

        if (v == -1) {
            cout << -1 << endl;
            return 0;
        }

        B.erase(B.begin() + v);
        rev.push_back(v+1);
    }
    reverse(rev.begin(), rev.end());
    for (int v : rev) {
        cout << v << endl;
    }
    return 0;
}


Measured memory_bytes: 256
use std::collections::HashSet;
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut split = buf.split_whitespace();
    let (h, w, m): (usize, usize, usize) = (split.next().unwrap().parse().unwrap(), split.next().unwrap().parse().unwrap(), split.next().unwrap().parse().unwrap());
    let bombsites: HashSet<_> = (0..m).map(|_| {
        buf.clear();
        io::stdin().read_line(&mut buf).unwrap();
        let mut split = buf.split_whitespace();
        (split.next().unwrap().parse::<usize>().unwrap() - 1, split.next().unwrap().parse::<usize>().unwrap() - 1)
    }).collect();
    let mut h_cnt = vec![0usize; h];
    let mut w_cnt = vec![0usize; w];
    for &(x, y) in bombsites.iter() {
        h_cnt[x] += 1;
        w_cnt[y] += 1;
    }
    let h_max = h_cnt.iter().cloned().max().unwrap();
    let w_max = w_cnt.iter().cloned().max().unwrap();
    let blocked = bombsites.iter().filter(|&&(x, y)| h_cnt[x] == h_max && w_cnt[y] == w_max).count();
    let cand = h_cnt.iter().filter(|&&x| x == h_max).count() * w_cnt.iter().filter(|&&x| x == w_max).count();
    if blocked == cand {
        println!("{}", h_max + w_max - 1);
    } else {
        println!("{}", h_max + w_max);
    }
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

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

const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int ans[212345];

int main() {
	int N, x; cin >> N >> x;
	
	if (x == 1|| x == 2 * N - 1) puts("No");
	else {
		puts("Yes");
		
		if (N == 2) {
			REP(i, 3) ans[i] = i + 1;
		}
		else {
			set<int> ss;
			if (x >= 3) {
				ans[N - 2] = x - 2;
				ans[N - 1] = x;
				ans[N] = x + 1;
				ans[N + 1] = x - 1;
				REP(i, 4) ss.insert(x - 2 + i);
			}
			else {
				ans[N - 2] = x + 2;
				ans[N - 1] = x;
				ans[N] = x - 1;
				ans[N + 1] = x + 1;
				REP(i, 4) ss.insert(x + 2 - i);
			}
			
			int now = 1;
			REP(i, N - 2) {
				while (ss.find(now) != ss.end()) now++;
				ans[i] = now++;
			}
			FOR(i, N + 2, 2 * N - 1) {
				while (ss.find(now) != ss.end()) now++;
				ans[i] = now++;
			}
		}
		
		REP(i, 2 * N - 1) printf("%d\n", ans[i]);
	}
	return 0;
}


Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {
  public static void main(String args[]) {

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int h[] = new int[N];
    int count = 0;

    for (int i = 0; i < N; i++) {
      h[i] = sc.nextInt();
    }

    for (int i = 0; i < N; i++) {
      if (h[i] >= K) {
        count++;
      }
    }

    System.out.println(count);
    sc.close();
  }
}


Measured memory_bytes: 49576
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
double a, b, h, m;
signed main() {
	cin >> a >> b >> h >> m;
	double p = 5.5 * m - 30 * h;
	p = acos(-1) * p / 180.0;
	cout << setprecision(10) << sqrt(a * a + b * b - 2 * a * b * cos(p)) << endl;
	ggr
}


Measured memory_bytes: 4220
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

ll Pow(ll x, ll n){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return Pow(x * x, n / 2);
  else
    return x * Pow(x, n - 1);
}

vector<int> sieve(int n){
  vector<int> ret;
  bool is_prime[n+1];
  memset(is_prime, true, sizeof(is_prime));
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<n+1;i++){
    if(is_prime[i]){
      ret.push_back(i);
      for(int j=2*i;j<n+1;j+=i)is_prime[j]=false;
    }
  }
  return ret;
}

int main(){
  ll N, P;
  
  cin >> N >> P;
  if(N == 1){
    cout << P << endl;
    return 0;
  }

  vector<int> prime = sieve(sqrt(P));

  ll ans = 1;
  for(auto x : prime){
    ll tmp = pow(x, N);
    // cerr << "tmp: " << tmp << endl;
    if(P < tmp)break;
    while(1){
      if(P % tmp == 0){
	// cerr << tmp << " " << ans << endl;
	ans *= x;
	P /= tmp;
      }else{break;}
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1916
import itertools
n,k = map(int,input().split())
li = list(map(int,input().split()))
se = list(map(str,set([i for i in range(0,10)]) - set(li)))
lee = len(str(n))
ans = 999999999999999999999
tmp = ''
kumi_li = list(itertools.product(se, repeat=lee+1))
kumi_2_li = list(itertools.product(se, repeat=lee))
for k in kumi_li:
    #print(k)
    suuji = int(''.join(k))
    if suuji <= ans and suuji >= n:
        ans = suuji
for k in kumi_2_li:
    suuji = int(''.join(k))
    if suuji <= ans and suuji >= n:
        ans = suuji
print(ans)

Measured memory_bytes: 48556
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin, n, k;
    vector<int> a(n);
    REP(i, 0, n) {
        cin, a[i];
    }
    REP(t, 0, k) {
        vector<int> imos(n, 0);
        REP(i, 0, n) {
            int l = max(0, i - a[i]);
            int r = min(n, i + a[i] + 1);
            imos[l]++;
            if (r != n) {
                imos[r]--;
            }
        }
        REP(i, 0, n - 1) {
            imos[i + 1] += imos[i];
        }
        a = move(imos);
        bool ok = true;
        REP(i, 0, n) {
            if (a[i] != n) ok = false;
        }
        if (ok) {
            dump(t);
            break;
        }
    }
    REP(i, 0, n) {
        cout << a[i] << " \n"[i + 1 == n];
    }

    return 0;
}


Measured memory_bytes: 4784
#include <iostream>
#include <algorithm>
#include <map>
#define MAX_N 100005
using namespace std;


class Union_Find {
  int par[MAX_N];  // 親
  int rank[MAX_N]; // 木の深さ
  int w[MAX_N];
public:
  // n要素で初期化
  void init(int n) {
    for(int i = 0; i < n; ++i) {
      par[i] = i;
      rank[i] = 0;
      w[i] = 0;
    }
  }
  
  // 木の根を求める
  pair<int,int> find(int x) {
    if(par[x] == x) {
      return make_pair(x, 0);
    } else  {
      pair<int,int> p = find(par[x]);
      par[x] = p.first;
      p.second += w[x];
      w[x] = p.second;
      return p;
    }
  }
  
  // xとyの属する集合を併合
  void unite(int x, int y, int dw) { // dw = wy - wx
    pair<int,int> px = find(x);
    pair<int,int> py = find(y);
    x = px.first;
    y = py.first;
    int wx = px.second;
    int wy = py.second;
    dw = dw - wx + wy;
    if(x == y) return;
    
    if(rank[x] < rank[y]) {
      par[x] = y;
      w[x] = dw;
    } else {
      par[y] = x;
      w[y] = -dw;
      if(rank[x] == rank[y]) ++rank[x];
    }
  }
  
  // xとyが同じ集合に属するか否か
  bool same(int x, int y) {
    return find(x).first == find(y).first;
  }
};

int main() {
  int N, M;
  while(cin >> N >> M && (N|M)) {
    Union_Find uf;
    uf.init(N);  
    while(M--) {
      char c;
      int a, b, w;
      cin >> c;
      if(c == '!') {
        cin >> a >> b >> w;
        --a; --b;
        uf.unite(a, b, w);
      } else {
        cin >> a >> b;
        --a; --b;
        if(uf.same(a, b)) {
          cout << uf.find(a).second - uf.find(b).second << endl;
        } else {
          cout << "UNKNOWN" << endl;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 2332
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

 int top;
 int S[1000];

void push(int x){
      S[++top] = x;
  }

int pop(){
      top--;
      return S[top+1];
  }
  
  
int main(){
  
  int a,b;
  top = 0;
  char s[100];
  
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
        a = pop();
        b = pop();
        push(a+b);

    } else if ( s[0] == '-' ){
        
        b = pop();
        a = pop();
        push(a-b);

    } else if ( s[0] == '*' ){
        b = pop();
        a = pop();
        push(a*b);

    } else {
      push(atoi(s));

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

  return 0;
}


Measured memory_bytes: 2108
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
n = int(input())
a = (make_divisors(n))
ans = 100000000000000
for i in a:
  if(ans > i+int(n/i)-2):ans = i+int(n/i)-2
print(ans)
	

Measured memory_bytes: 39408
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp,x,y;
string str;
set<ll> s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	vector<ll> p(n);
	vector<ll> q(n);
	vector<ll> ans(n);
	read(p);
	read(q);
	for(int i=0;i<n;i++)
	ans[i]=i+1;
	int count=1;
	if(p==ans)
	a=count;
	if(q==ans)
	b=count;
	while(next_permutation(ans.begin(),ans.end())!=-1)
	{
	    count++;
	    if(a && b)
	    break;
	    if(ans==p)
	    a=count;
	    if(ans==q)
	    b=count;
	}
	if(a>b)
	swap(a,b);
	cout<<b-a;
	
	
}

Measured memory_bytes: 256
H, W = map(int,input().split())
S = [list(input()) for i in range(H)] #リストを二重にする
#print(S)
for i in range(H): #すべてのマスを探索する
  for j in range(W):
    if S[i][j] == ".": #行列の中の点(なんもない地帯)を0に変換する
      S[i][j] = 0
#print(S)
for i in range(H): #すべてのマスを探索する
  for j in range(W):
    if S[i][j] == "#": #爆弾マスに当たった場合以下の処理が起きてそれ以外は何もおきない
       for k in range(-1, 2): #爆弾マスの横軸の行3マス分
          for l in range(-1, 2): #爆弾マスの縦軸の列3マス分
            ni = i+k 
            nj = j+l #爆弾マスの詳しい座標情報
            if (0 <= ni < H) and (0 <= nj < W) and \
               (S[ni][nj] != '#') and (S[ni][nj] != '.'): 
                #在りもしないマスで無いかの条件式
                #そのマスが数字であるかの条件式
              S[ni][nj] += 1
for i in range(H): #リストの文字列を連結・結合
    print(''.join(map(str, S[i]))) #二重リストであることに注意、改行すると余計ややこしくなる

Measured memory_bytes: 3064
s = input()
n = int(input())
for i in range(n):
    command = input().split()
    (a, b) = map(lambda x: int(x), command[1:3])
    s1, s2, s3 = s[:a], s[a:b + 1], s[b + 1:]
    if command[0] == "print":
        print(s2)
    elif command[0] == "reverse":
        s = s1 + s2[::-1] + s3
    elif command[0] == "replace":
        s = s1 + command[3] + s3



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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
using P = pair<int,int>;
//Write From this Line

int n, m, q;
int ans = 0;
vector<int> a, b, c, d;

void dfs(vector<int> A) {
	if(A.size() == n) {
		// calc score
		int now = 0;
		rep(i,q){
			if(A[b[i]-1] - A[a[i]-1] == c[i]) now += d[i];
		}
		ans = max(ans, now);
		return ;
	}

	A.push_back(A.back());
	while(A.back() <= m){
		dfs(A);
		A.back()++;
	}
}
int main()
{
	cin >> n >> m >> q;

	a = b = c = d = vector<int> (q);
	rep(i,q){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	dfs(vector<int> (1,1));
	cout << ans << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
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;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    bool check = false;
    for (int i = A; i <= B; i++) {
        if (i % K == 0) check = true;
    }
    cout << (check ? "OK" : "NG") << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0
 
#define putb push_back
#define f first
#define s second
 
#define putf push_front
#define gainb pop_back
 
#define gainf pop_front
#define len(x) (ll)x.size()
 
typedef double db;
typedef long long ll;
 
const ll ary=1e5+5;
const ll mod=1e9+7;
const ll inf=1e18;
 
using namespace std;
ll n;
string s;
int main(){
	cin>>n>>s;
	string t="",p="";
	for(int i=0;i<len(s)/2;i++){
		t+=s[i];
	}
	for(int i=len(s)/2;i<len(s);i++){
		p+=s[i];
	}
	if(t==p){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.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;

ll mod=1000000007;

const ll INF = 1LL << 60;

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 sum,s5,s3,s15;

int main() {
  int n;cin>>n;
  reps(i,n){
    if(i%3==0)s3+=i;
    if(i%5==0)s5+=i;
    if(i%15==0)s15+=i;
    sum+=i;
  }
  ll ans=sum-s3-s5+s15;
  cout<< ans;
}

Measured memory_bytes: 3624
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T& a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T& b,T a){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}

string str;
void input(){
    cin>>str;
}
void src(){
    map<char,int> m;
    for(auto s:str){
        m[s]++;
    }
    cout<<(m.size()==2 and all_of(m.begin(),m.end(),
        [](auto x)->bool{return(x.second==2);})? "Yes":"No" );
    return;
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int N, A[100], count, flag, x;
	count = 0;
	flag = 1;
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}

	while (flag) {
		flag = 0;
		for (int j = N - 1;j >= 1;j--) {
			if (A[j] < A[j - 1]) {
				x = A[j];
				A[j] = A[j - 1];
				A[j - 1] = x;
				flag = 1;
				count++;
			}
		}
	}

	for (int i = 0;i < N-1;i++) {
		cout << A[i]<<" ";
	}
	cout << A[N-1] << endl;
	cout << count << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	ll n,p;cin>>n>>p;
	ll ans=0; ll s=1;
	if(n==1){
		ans = p;
	}
	else{
		while(pow(s,n)<=p){
			ll x = pow(s,n);
			if(p%x==0){
				ans = s;
			}
			s++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MAX 10000007
#define PI acos(-1)
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define endl "\n"
#define MEM(a,x) memset(a,x,sizeof(a))

using namespace std;
typedef long long ll ;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<long long,null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
{
    return (a.second<b.second);
}
*/
int dp[MAX];
int num[10]= {0,2,5,5,4,5,6,3,7,6};
ll ara[15];
bool use[10];

const int INF=1e9+7;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.tie(NULL);
    int n,m;
    cin>>n>>m;

    MEM(dp,-INF);

    for(int i=0; i<m; i++)
    {
        cin>>ara[i];
        use[ara[i]]=true;
    }

    dp[0]=0;

    for(int i=0; i<m; i++) //digits that can be used
    {
        for(int j=0; j<=n; j++) //no of match sticks
        {
            if(j>=num[ara[i]])//if stick no is greater than required stick, we can use build this digit
            {
                dp[j]=max(dp[j],dp[j-num[ara[i]]]+1);
            }
        }
    }

    int temp=dp[n];

    for(int i=1;i<=temp;i++)
    {
        for(int j=9;j>=1;j--)
        {
            if(use[j]==true && num[j]<=n && dp[n-num[j]]==dp[n]-1)
            {
                cout<<j;
                n-=num[j];
                break;
            }
        }
    }

    cout<<endl;


    return 0;
}


Measured memory_bytes: 39296
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;

int main(){
long N, X;
cin >> N >> X;
vector<long> L(N+1);
long sum = 0;
long cnt = 1;
erep(i, N){
    cin >> L[i];
}
erep(i, N){
    sum += L[i];
    if(sum > X) break;
    cnt++;
}
show(cnt);

return 0;
}

Measured memory_bytes: 256