akhauriyash/Code-Regression huggingface dataset:
// B - Picture Frame
#include <bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<(n);++i)
using VC = vector<char>;

int main(){
	int H,W; cin>>H>>W;

	vector<VC> A(H+2, VC(W+2, '#'));
	rp(i, H) rp(j, W) cin>>A[i+1][j+1];

	for(auto v:A){
		for(auto a:v) cout<<a;
		puts("");
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<ll> v(N);
  ll ans = 0;
  rep(i,N){
    ll A,B;cin >> A >> B;
    ans -= B;
    v[i] = A+B;
  }
  sort(all(v),greater<ll>());
  rep(i,N){
    if(i%2==0) ans += v[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
using ar=array<ull,26>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
int main(){
	string s1,s2;
	ar ht; ht[0]=1;
	rep(i,25) ht[i+1]=ht[i]*10007;
	
	while(cin>>s1>>s2){
		if(s1.size()>s2.size()) swap(s1,s2);
		int n1=s1.size(), n2=s2.size();
		unordered_set<ull> lst;
		vector<ull> p1(1,0),p2(1,0),p3(n1+1),p4(n2+1);
		for(auto c:s1)p1.push_back(ht[c-'a']);
		for(auto c:s2)p2.push_back(ht[c-'a']);
		partial_sum(p1.begin(), p1.end(), p3.begin());
		partial_sum(p2.begin(), p2.end(), p4.begin());
		
		for(int l=n1;l>=1;l--){
			lst.clear();
			ull tmp=p3[l-1];
			range(i,l,n1+1) {
				tmp+=p1[i]-p1[i-l];
				lst.insert(tmp);
			}
			tmp=p4[l-1];
			range(i,l,n2+1){
				tmp+=p2[i]-p2[i-l];
				if(lst.find(tmp) != lst.end()){
					cout<<l<<endl;
					goto end;
				}
			}
		}
		cout<<0<<endl;
		end: ;
	}
	return 0;
}



Measured memory_bytes: 3308
#include<iostream>
#include<vector>
#include<utility>
using namespace std;

int bubbleSort(vector<int>& a) {
	int n = a.size();
	int cnt = 0;
	bool flag = true;
	while (flag) {
		flag = false;
		for (int j = n - 1; j >= 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				cnt++;
				flag = true;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (!i) cout << a[i];
		else cout << " " << a[i];
	}
	cout << endl;
	return cnt;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	
	cout << bubbleSort(a) << endl;
	return 0; 
}



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

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

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

int N;

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

  std::cin >> N;

  int res = (N - 1) / 2;
  std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;
 
int32_t main(){
    N4RUTO;
    int t;
    t=1;
    // cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        set<int> ans;
        while(k--){
            int d;
            cin>>d;
            loop(i,0,d-1){
                int x;
                cin>>x;
                ans.insert(x);
            }
        }
        cout<<n-ans.size()<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(a * b % 2 == 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 998244353;


long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
    int t; cin >> t;
    rep(i, t) {
        ll a, b, c, d; cin >> a >> b >> c >> d;
        if (b > d) {
            cout << "No" << endl;
            continue;
        }
        if (a < b) {
            cout << "No" << endl;
            continue;
        }
        if (c+1 >= b) {
            cout << "Yes" << endl;
            continue;
        }
        ll p = (a - c - 1) / b;
        p++;
        a -= b * p;
        if (a < 0) {
            cout << "No" << endl;
            continue;
        }
        
        // c+1 ~ b-1 にきたらNo
        // 0~c ならd足す
        // 毎回 b引く
        // 現在a (次d足す)

        // 毎回bでmodをとるのと同じ。c+1 ~ b-1 になるとNo。
        d = d % b;
        // 任意の非負整数xについて(a + d * x) % b <= c ならYes、それ以外ならNo。
        ll g = GCD(b, d);
        p = (b-1 - (a % g)) / g;
        if (p * g + (a % g) <= c) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


    

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;

int min(int a, int b)
{
    if(a<b)
    {
        return a;
    }
    else{
        return b;
    }
}

int main() {
	
    string odd;
    string even;
    cin>>odd;
    cin>>even;
    string password;
    int n1 = odd.size();
    int n2 = even.size();
    int i =0;
    while(i<min(n1,n2))
    {
        password.push_back(odd[i]);
        password.push_back(even[i]);
        i++;
    }
    int j = i;
    while((n1-i)>0)
    {
        password.push_back(odd[i]);
        i++;
    }
    i =j;
    while((n2-i)>0)
    {
        password.push_back(even[i]);
        i++;
    }
    cout<<password;
    
	return 0;
}

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

void solve()
{
    int N;
    cin>>N;

    vector<pair<int,int>>V;
    
    for(int i = 0;i < N; i++)
    {
        int a,b;
        cin>>a>>b;
        V.pb(make_pair(a,b));
    }

    for(int i = 0; i <= N - 3; i++)
    {
        if(V[i].first == V[i].second)
        {
            if(V[i+1].first ==  V[i+1].second)
            {
                if(V[i+2].first == V[i+2].second)
                {
                    cout<<"Yes"<<endl;
                    return;
                }
            }
        } 
    }

    cout<<"No"<<endl;
}

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

    return 0;
}

Measured memory_bytes: 3628
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){
    int n = 0,l = 0;

    scanf("%d%d",&n,&l);

    string str[100];

    for(int i=0;i<n;i++){
        char tmp[256];

        scanf("%s",tmp);

        str[i] = tmp;
    }

    sort(str,str+n);

    string ans = "";

    for(int i=0;i<n;i++)
        ans += str[i];

    printf("%s\n",ans.c_str());

    return 0;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n, x;
bool a[105];
int main() {
   cin >> x >> n;
   for (int i=0; i<n; i++) {
       int t; cin >> t; a[t]=1;
   }
   int d=0;
   while (true) {
       if (!a[x-d]) {cout << x-d; return 0;}
       if (!a[x+d]) {cout << x+d; return 0;}
       d++;
   }
}

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll N, X;
VL d;

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

int main() {
    cin >> N >> X;
    ll ans = 0;
    REP(i, N) { ans = gcd(abs(IN() - X), ans); }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <cstdio>

typedef long long ll;

const int MaxN = 18, MaxS = 1 << MaxN;
const int cIz = 998244353;

inline int add(int a, int b) {
	return (a += b) < cIz ? a : a - cIz;
}
inline int sub(int a, int b) {
	return (a -= b) < 0 ? a + cIz : a;
}

inline int Pow(int a, int b) {
	int res = 1;
	for (; b; b >>= 1) {
		if (b & 1) res = (ll)res * a % cIz;
		a = (ll)a * a % cIz;
	}
	return res;
}
inline int Inv(int a) {
	return Pow(a, cIz - 2);
}

void FWT(int *f, int n) {
	for (int i = 1; i < n; i <<= 1) {
		for (int j = 0; j < n; j += i << 1) {
			for (int k = 0; k < i; ++k) {
				int a = f[j + k], b = f[j + k + i];
				f[j + k] = add(a, b);
				f[j + k + i] = sub(a, b);
			}
		}
	}
}

int n, A[MaxS], B[MaxS];

int main() {
	scanf("%d", &n);
	int N = 1 << n;
	int sum = 0;
	for (int i = 0; i < N; ++i) {
		scanf("%d", A + i);
		sum += A[i];
	}
	int inv_sum = Inv(sum);
	for (int i = 0; i < N; ++i) A[i] = (ll)A[i] * inv_sum % cIz;
	A[0] = sub(A[0], 1);
	FWT(A, N);
	B[0] = 1;
	for (int i = 1; i < N; ++i) B[i] = (ll)B[i - 1] * A[i] % cIz;
	int imul = Inv(B[N - 1]);
	for (int i = N; --i; ) {
		B[i] = (ll)imul * B[i - 1] % cIz;
		imul = (ll)imul * A[i] % cIz;
	}
	FWT(B, N);
	int delta = B[0];
	for (int i = 0; i < N; ++i) printf("%d\n", sub(B[i], delta));
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;


int main(){

double a, b, n;
cin >> n ;


int tem = n/2;


cout << fixed << setprecision(10);
cout << (n-tem)/n << endl;


return 0;
}


Measured memory_bytes: 256
use std::io;
use std::io::BufRead;

struct Graph {
    n: usize,
    adj: Vec<Vec<usize>>,
}

fn read_graph() -> Graph {
    let stdin = io::stdin();
    let lock = stdin.lock();
    let mut lines = lock.lines();
    let n = lines.next().unwrap().unwrap().parse().unwrap();
    let mut adj = Vec::new();

    for line in lines {
        let parsed: Vec<usize> = line
            .unwrap()
            .split_whitespace()
            .map(|s| s.parse().unwrap())
            .collect();

        adj.push(parsed[2..].iter().map(|x| x - 1).collect());
    }

    Graph { n, adj }
}

fn dfs(g: &Graph, d: &mut Vec<usize>, f: &mut Vec<usize>, t: &mut usize, i: usize) {
    *t += 1;
    d[i] = *t;
    for &next_i in g.adj[i].iter() {
        if d[next_i] == 0 {
            dfs(g, d, f, t, next_i);
        }
    }
    *t += 1;
    f[i] = *t;
}

fn main() {
    let graph = read_graph();

    let mut d = vec![0; graph.n];
    let mut f = vec![0; graph.n];
    let mut t = 0;

    for i in 0..(graph.n) {
        if d[i] == 0 {
            dfs(&graph, &mut d, &mut f, &mut t, i);
        }
    }

    for i in 0..(graph.n) {
        println!("{} {} {}", i + 1, d[i], f[i]);
    }
}



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

const int INF = INT_MAX / 2;

int main(){
    int N, M; cin >> N >> M;
    vector<int> h(N);
    for (int i = 0; i < N; i++) cin >> h[i];
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int cnt = 0;
/*
    queue<int> pos;
    vector<int> d(N, INF);
    for (int i = 0; i < N; i++)
    {
        if(d[i]!=INF) continue;
        cnt++;
        pos.push(i);
        d[i]=0;
        while (!pos.empty())
        {
            int from = pos.front();
            pos.pop();
            for(int to : G[from]){
                if(d[to]!=INF) continue;
                d[to] = d[from] + 1;
                pos.push(to);
            }
        }
    }
*/

    for (int from = 0; from < N; from++)
    {
        bool flag = true;
        for(int to: G[from]){
            if(h[from]<=h[to]){
                flag = false;
                break;
            }
        }
        if(flag){
            cnt++;
        } 
    }
    cout << cnt << endl;
    
}

Measured memory_bytes: 8736
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))

c = [0] * 3

for i in p:
    if i <= a:
        c[0] += 1
    elif i <= b:
        c[1] += 1
    else:
        c[2] += 1

print(min(c))


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

static const int N = 5;
static const int di[4] = {0, -1, 0, 1};
static const int dj[4] = {1, 0, -1, 0};

int G[N][N], T[N][N], F[N][N];
int P[N];
int maxs = 0;

void update(){
  for ( int i = 0; i < N; i++ )
    for ( int j = 0; j < N; j++ ) T[i][j] = G[i][j];
  
  int bs = 1;
  int score = 0;
  bool updated = false;
  while(true){
    updated = false;
    for ( int i = 0; i < N; i++ )
      for ( int j = 0; j < N; j++ ) F[i][j] = 0;
    for ( int i = 0; i < N; i++ ){
      for ( int j = 0; j < N-2; j++ ) {
	if ( T[i][j] == 0 ) continue;
	if ( T[i][j] == T[i][j+1] && T[i][j+1] == T[i][j+2]) {
	  F[i][j] = F[i][j+1] = F[i][j+2] = 1;
	  updated = true;
	}
      }
    }
    for ( int i = 0; i < N-2; i++ ){
      for ( int j = 0; j < N; j++ ) {
	if ( T[i][j] == 0 ) continue;
	if ( T[i][j] == T[i+1][j] && T[i+1][j] == T[i+2][j]) {
	  F[i][j] = F[i+1][j] = F[i+2][j] = 1;
	  updated = true;
	}
      }
    }
    
    for ( int i = 0; i < N; i++ ){
      for ( int j = 0; j < N; j++ ) {
	if ( F[i][j] == 1 ) {
	  score += bs*P[T[i][j]-1];
	  T[i][j] = 0;
	}
      }
    }
    
    for ( int j = 0; j < N; j++ ){
      for ( int i = N-1; i >= 1; i-- ){
	if ( T[i][j] > 0 ) continue;
	int p = i-1;
	while( p > 0 && T[p][j] == 0 ) p--;
	T[i][j] = T[p][j];
	T[p][j] = 0;
	if ( p == 0 ) break;
      }
    }
    
    bs++;
    if ( !updated ) break;
  }
  
  maxs = max(maxs, score);
}

void dfs(int ci, int cj, int n){
  update();
  if ( n == 0 ) return;
  
  for ( int r = 0; r < 4; r++ ){
    int ni = ci + di[r];
    int nj = cj + dj[r];
    if ( ni < 0 || nj < 0 || ni >= N || nj >= N ) continue;
    swap(G[ci][cj], G[ni][nj]);
    dfs(ni, nj, n-1);
    swap(G[ci][cj], G[ni][nj]);
  }
}

main(){
  while(true){
    int n; cin >> n;
    if ( n == -1 ) break;
    for ( int i = 0; i < N; i++ )
      for ( int j = 0; j < N; j++ )
	cin >> G[i][j];
    for ( int i = 0; i < N; i++ )
      cin >> P[i];
    maxs = 0;
    for ( int i = 0; i < N; i++ )
      for ( int j = 0; j < N; j++ )
	dfs(i, j, n);
    cout << maxs << endl;
  }
}

Measured memory_bytes: 1160
#include <stdio.h>
 
void W(int line[],int temp[]){
    line[0]=temp[2];
    line[3]=temp[0];
    line[5]=temp[3];
    line[2]=temp[5];
}
void S(int line[],int temp[]){
    line[1]=temp[0];
    line[5]=temp[1];
    line[4]=temp[5];
    line[0]=temp[4];
}
void E(int line[],int temp[]){
    line[2]=temp[0];
    line[5]=temp[2];
    line[3]=temp[5];
    line[0]=temp[3];
}
void N(int line[],int temp[]){
    line[1]=temp[5];
    line[0]=temp[1];
    line[4]=temp[0];
    line[5]=temp[4];
}
int main(void){
    int line[6],i,t,temp[6];
    char ope[101];
    for(i=0;i<6;i++)
        scanf("%d",&line[i]);
    scanf("%s",ope);
    t=0;
    while(ope[t]){
        for(i=0;i<6;i++)
            temp[i]=line[i];
        if(ope[t]=='W')
            W(line,temp);
        else if(ope[t]=='S')
            S(line,temp);
        else if(ope[t]=='E')
            E(line,temp);
        else
            N(line,temp);
        t++;
    }
    printf("%d\n",line[0]);
    return 0;
}


Measured memory_bytes: 2088
// May this submission get accepted
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll n = inp1;
    ll m = inp1;

    ll t = (n-m)*100 + m * 1900;

    ll pow2m = 1;
    REP(i, m) pow2m *= 2;
    cout << t * pow2m << endl;
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
lint d[205][205]={0};
lint n,m,r;
vector<lint> vr;
lint res=INF;
int main(){
    cin>>n>>m>>r;
    rep(i,n){
        rep(j,n){
            if(i!=j){
                d[i][j]=INF;
            }
        }
    }
    vr.resize(r);
    rep(i,r) {
        cin>>vr[i];
        vr[i]--;
    }   
    rep(i,m){  
        lint a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        d[a][b]=c;
        d[b][a]=c;
    }     
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
             for(int j=0;j<n;j++){
                if(d[i][k]==INF || d[k][j]==INF)continue;
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }  
        }
    }
    sort(vr.begin(),vr.end());
    do{
        lint sum=0;
        for(int i=0;i<r-1;i++){
            sum+=d[vr[i]][vr[i+1]];
        }
        res=min(res,sum);
    }while (next_permutation(vr.begin(), vr.end()));
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a, k, b;
int main()
{
    cin >> k >> a >> b;
    for(int i = a; i <= b; i++){
        if(i%k==0){
            cout << "OK" << endl; return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
const int N=2e5+5;
int n,k,x[N],y[N];
ll tree[N],ans;
inline int lowbit(int x){return x&(-x);}
void update(int x){for(;x<=n;x+=lowbit(x))tree[x]++;}
int ask(int x){int res=0;for(;x;x-=lowbit(x))res+=tree[x];return res;}
signed main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>x[i],x[i]-=k;
	for(int i=1;i<=n;i++)x[i]+=x[i-1],y[i]=x[i],ans+=(x[i]>=0);
	sort(y+1,y+n+1);
	for(int i=1;i<=n;i++)x[i]=lower_bound(y+1,y+n+1,x[i])-y;
	for(int i=1;i<=n;i++)ans+=ask(x[i]),update(x[i]);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
const int N=11,M=1e3+5;
int b[N][M],c[N][M];
int n,m,k,x,ms,l,r,mid,ans;

inline bool jay(int p,int mid)
{
	memset(c,0,sizeof(c));
	int tot=1;
	for (register int j=1; j<=m; ++j) c[tot][j]=b[1][j]; 
	
	
	
	for (register int i=2; i<=n; ++i)
	{
		if (p&(1<<(i-1))) tot++;
		for (register int j=1; j<=m; ++j) c[tot][j]+=b[i][j];
	}
	
/*	if (mid==2)
	{
		puts("");
		for (register int i=1; i<=tot; ++i)
		{
			for (register int j=1; j<=m; ++j) printf("%d ",c[i][j]); puts(""); 
		}
	}*/
	
	int res=mid-tot+1;
	if (res<0) return false;
	//if (mid==2) printf("res=%d\n",res);
	
	int l=0;
	for (register int r=1; r<=m; ++r)
	for (register int i=1; i<=tot; ++i)
	{
		if (c[i][r]-c[i][r-1]>k) return false;
		if (c[i][r]-c[i][l]>k) res--,l=r-1;
		if (res<0) return false;
	}
	return true;
}

int main(){
	scanf("%d%d%d",&n,&m,&k);
	for (register int i=1; i<=n; ++i)
	for (register int j=1; j<=m; ++j) 
	{
		scanf("%1d",&x);
		b[i][j]=b[i][j-1]+x;
	}
/*	for (register int i=1; i<=n; ++i)
	{
		for (register int j=1; j<=m; ++j) printf("%d ",b[i][j]);
		puts("");
	}*/
			
	int ms=1<<n;
	l=0; r=n+m-2;
	while (l<=r)
	{
		bool f=false;
		mid=l+r>>1;
		for (register int p=0; p<ms; ++p) if (jay(p,mid)) {f=true; break;}
		if (f) ans=mid,r=mid-1; else l=mid+1;
	}
	printf("%d\n",ans);
return 0;	
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int h = sc.NextInt();
        int w = sc.NextInt();
        bool[,] m = new bool[w, h];
        for (int i = 0; i < h; i++)
        {
            string s = sc.NextString();
            for (int j = 0; j < w; j++)
            {
                m[j, i] = s[j] == '#';
            }
        }
        int[,] d = new int[w, h];
        int MAX = 1 << 30;
        var q = new Queue<Tuple<int, int>>();
        for (int i = 0; i < w; i++)
            for (int j = 0; j < h; j++)
            {
                d[i, j] = MAX;
                if (!m[i, j]) continue;
                d[i, j] = 0;
                q.Enqueue(Tuple.Create(i, j));
            }

        int[] vx = new int[] { 0, 1, 0, -1 };
        int[] vy = new int[] { 1, 0, -1, 0 };
        bool[,] visit = new bool[w, h];
        while (q.Count > 0)
        {
            var n = q.Dequeue();
            if (visit[n.Item1, n.Item2]) continue;
            visit[n.Item1, n.Item2] = true;
            for (int i = 0; i < 4; i++)
            {
                int x = n.Item1 + vx[i];
                int y = n.Item2 + vy[i];
                if (x < 0 || y < 0 || x >= w || y >= h) continue;
                d[x, y] = Math.Min(d[n.Item1, n.Item2] + 1, d[x, y]);
                q.Enqueue(Tuple.Create(x, y));
            }
        }

        int max = 0;
        for (int i = 0; i < w; i++)
            for (int j = 0; j < h; j++)
            {
                if (d[i, j] > max) max = d[i, j];
            }
        Console.WriteLine(max);
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 154820
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
#define mod 1000000007
using namespace std;

void solve()
{
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
    ll n;
    cin>>n;
    ll a[n];
    for (ll i = 0; i < n; i++)
    {
        /* code */
        cin>>a[i];
    }
    vector<ll> dp(n, 0);
    dp[0] = 1000;
    for(ll i=1; i<n; i++)
    {
        dp[i] = dp[i-1];
        for(ll j=0; j<i; j++)
        {
            ll stocks_bought = dp[j]/a[j];
            ll profit = stocks_bought*a[i] - stocks_bought*a[j];
            dp[i] = max(dp[i], dp[j] + profit);
        }
    } 
    cout<<dp[n-1]<<'\n';
}

Measured memory_bytes: 3524
#include <iostream>
using namespace std;
int a;

int main(){
    bool flag = false;
    cin >> a;
    for (int i = 1; i <= 9; i ++){
        for (int j = 1; j <= 9; j ++){
            if(i*j == a) flag = true;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
using ll = long long;
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;


using mint = modint998244353;
using Vm = vector<mint>;

istream &operator>>(istream &is, mint &a) { int v; cin >> v; a = v; return is; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.val(); }
// template <int m>
// ostream &operator<<(ostream &os, const static_modint<m, nullptr> &a) { return os << a.val(); }


int main() {
  int n, m; cin >> n >> m;
  Vm a(n), b(m);
  // cin >> a >> b;
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  auto c = convolution(a, b);
  cout << c << '\n';
  // rep(i, n+m-1) cout << c[i] << ' ';
  cout << '\n';
}

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

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

int main(){
  string s;
  cin>>s;
  int l = s.size();
  if(l%2==0)l = l/2-1;
  else l = l/2;
  for(int i = l; l >=1; i--){
    int counter = i;
    for(int j = 0; j < i; j++){
      if(s.at(j)==s.at(j+i))counter--;
      else break;
    }
    if(counter==0){
      cout<<i*2<<endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import heapq
from sys import stdin
input = stdin.readline

#入力
# s = input()[0:-1]
# n = int(input())
m,d = map(int, input().split())
# a = list(map(int,input().split()))
# a = [int(input()) for i in range()]


# ab=[]
# for i in range():
#     a,b = map(int, input().split())
#     ab.append([a,b])


     
def main():
    ans = 0
    for i in range(1,m+1):
        for j in range(20,d+1):
            d10 = j//10
            d1 = j%10
            if d10 ==1 or d1 ==1:
                continue
            if d10*d1 == i:
                ans+=1
    print(ans)
    
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.*;
 
class Main {
 
    public static void main (String args[])
    {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int k=in.nextInt();
        in.nextLine();
        int[]N=new int[n];
        int d=in.nextInt();
        while(d>0)
        {
            int ii=in.nextInt();
            
            N[ii-1]=1;
            d--;
            if(d==0&&in.hasNextInt())
            d=in.nextInt();
        }
        int count=0;
        for(int i=0;i<n;i++)
        {
            if(N[i]==0) count++;
        }
        System.out.println(count);
        
        
    }
}

Measured memory_bytes: 46216
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x*-1, a))
heapq.heapify(a)
for i in range(m):
    tar = heapq.heappop(a)
    ins = ((tar*-1) // 2)*-1
    heapq.heappush(a, ins)
a = list(map(lambda x: x*-1, a))
print(sum(a))


Measured memory_bytes: 14180
#include <bits/stdc++.h>
#include <string.h>
//#include <queue>
using namespace std;
#define ll long long
#define ld long double

vector<int> ST;


void update(int id,int l, int r, int i, int v)
{
    if (i<l|| i>r) return;
    if (l==r)
    {
        ST[id]=v;
        return;
    }
    int mid =(l+r) /2;
    update(id*2, l, mid, i, v);
    update(id*2+1, mid+1, r, i, v);

    ST[id]=min(ST[id*2],ST[id*2+1]);
}

int get(int id, int l, int r, int u, int v)
{
    if (v<l || u>r) return(2000000000);
    if (u<=l && r<=v) return(ST[id]);
    int mid = (l+r)/2;
    int res = min(get (id*2, l, mid, u, v),
                   get (id*2+1, mid+1, r, u, v));
    return(res);
}

int main()
{
    int n;
    cin >> n;
    int a,b;
    cin >> a >> b;
    int dem=0;
    for(int i=2;i<n;i++)
    {
        int c;
        cin >> c;
        if (a<b && b<c) dem++; else
        if (a>b && b>c) dem++;
        a=b;
        b=c;
    }
    cout << dem ;
    return(0);
}


Measured memory_bytes: 256
from collections import deque
import sys
n = int(sys.stdin.readline())
#lines = sys.stdin.readlines()
lines = [input() for i in range(n)]

deq = deque()
for i in range(n):
    o = lines[i].split()
    if o[0] == 'insert':
        deq.appendleft(o[1])
    elif o[0] == 'delete':
        try:
            deq.remove(o[1])
        except:
            continue
    elif o[0] == 'deleteFirst':
        deq.popleft()
    elif o[0] == 'deleteLast':
        deq.pop()

print(' '.join(deq))


Measured memory_bytes: 212320
#include <iostream>
#include <algorithm>

using namespace std;
#define ll long long

int main() {
    string a, b;
    cin >> a;
    b = a;
    reverse(a.begin(), a.end());
    if(a == b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const LL inf = 1e16;
const int maxn = 1e3+3;
int n,w[maxn],c[maxn],v[maxn], sorted[maxn];

bool cmp(const int i, const int j)
{ return w[i]+c[i] < w[j]+c[j]; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> n) {
        int maxw = 0;
        FOR(i,0,n) {
            cin >> w[i] >> c[i] >> v[i];
            maxw = max(maxw,max(w[i],c[i])); sorted[i] = i;
        }
        maxw *= 2;
        sort(sorted,sorted+n,cmp);
        vector<LL> dp(maxw+1,-inf);
        dp[0] = 0;
        FOR(i,0,n) {
            const int j = sorted[i];
            FORR(k,maxw-w[j],-1) if (c[j] >= k) 
                dp[k+w[j]] = max(dp[k+w[j]], dp[k]+v[j]);
        }
        LL ans = 0;
        FOR(i,0,maxw+1)
            ans = max(ans,dp[i]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 512
# frozen_string_literal: true

def factor(n)
  return [1] if n == 1

  `factor #{n}|sed -r 's/[0-9]+://g'|tr ' ' '\n'|sort -n`.split.map(&:to_i)
end

# Example: factors(100) => {2=>2, 5=>2}
def factors_and_num(n)
  factors = factor(n)
  ret = Hash.new(0)
  factors.each do |i|
    ret[i] += 1
  end
  ret
end

def uniq_factor(n)
  `factor #{n}|sed -r 's/[0-9]+://g'|tr ' ' '\n'|sort -n|uniq`.split.map(&:to_i)
end

s = gets.chomp
t = gets.chomp

n = s.length
m = t.length

if n < m
  puts 'UNRESTORABLE'
  exit
end

last = -1
(0..(n - m)).each do |i|
  last = i if t =~ /#{s[i, m].gsub(/\?/, '.')}/
end

if last < 0
  puts 'UNRESTORABLE'
else
  ans = s.gsub(/\?/, 'a')
  ans[last, m] = t
  puts ans
end


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

#define MXN 100005
int N;
pii P[MXN];
ll lsy[MXN];
vector<int> G[MXN];
vector<int> ys[MXN];
bool vis1[MXN], vis2[MXN];
set<int> visy;
ll ycnt;
ll ans;

void dfs1(int u)
{
    vis1[u]=true;
    for( int y : ys[u] )
    {
        if( visy.find(y)==visy.end() )
        {
            ycnt++;
            visy.insert(y);
        }
    }
    for( int v : G[u] )if(!vis1[v])dfs1(v);
}

void dfs2(int u)
{
    vis2[u]=true;
    ans+=(ycnt-ys[u].size());
    for( int v : G[u] )if(!vis2[v])dfs2(v);
}

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

    cin>>N;
    FOR(i,1,N)
    {
        cin>>P[i].f>>P[i].s;
    }
    sort( P+1, P+1+N );
    FOR(i,1,N)
    {
        int x = P[i].f, y = P[i].s;
        if( lsy[y] )
        {
            G[ lsy[y] ].pb(x);
            G[x].pb( lsy[y] );
        }
        ys[x].pb(y);
        lsy[y]=x;
    }
    FOR(i,1,1e5)
    {
        if( !vis1[i] )
        {
            ycnt=0;
            visy.clear();
            dfs1( i );
            dfs2( i );
        }
    }
    cout<<ans<<'\n';

    return 0;
}


Measured memory_bytes: 13696
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        for(;;){
            String s=scan.next();
            if(s.equals("-")){
                break;
            }
            int m=scan.nextInt();

            for(int i=0;i<m;i++){
                int n=scan.nextInt();
                s=s.substring(n)+s.substring(0,n);
            }
            System.out.println(s);
        }
    }
}



Measured memory_bytes: 26576
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
changeit = []
for i in range(0, M):
	changeit.append(list(map(int, input().split())))
changeit.sort(key = lambda v: v[1], reverse = True)
sum = 0
index = 0
flag = False
for i in range(0, M):
	for j in range(0, changeit[i][0]):
		if index == N:
			flag = True
			break
		if changeit[i][1] < A[index]:
			flag = True
			break
		sum += changeit[i][1]
		index += 1
	if flag:
		break
for i in range(index, N):
	sum += A[i]
print(sum)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vi P(N), Q(N);
    rep(i,N) cin>>P[i];
    rep(i,N) cin>>Q[i];
    vi p(N);
    rep(i,N) p[i]=i+1;
    int idx=0,a,b;
    do{
        if (p==P) a = idx;
        if (p==Q) b = idx;
        idx++;
    }while(next_permutation(all(p)));
    cout<<abs(a-b)<<endl;
    return 0;
}


Measured memory_bytes: 3656
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str

import collections
import heapq


class Dijkstra:
    def __init__(self):
        self.e = collections.defaultdict(list)

    def add(self, u, v, d):
        self.e[u].append([v, d])
        self.e[v].append([u, d])

    def delete(self, u, v):
        self.e[u] = [_ for _ in self.e[u] if _[0] != v]
        self.e[v] = [_ for _ in self.e[v] if _[0] != u]

    def search(self, s):
        """
        :param s: 始点
        :return: 始点から各点までの最短経路
        """
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return d

    def prev_search(self, s):
        """
        #0-indexedでなくてもよいことに注意
        #:param s: 始点
        #:return: 始点から各点までの最短経路と最短経路を求めるのに必要なprev
        """
        d = collections.defaultdict(lambda: float('inf'))
        prev = collections.defaultdict(lambda: None)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    prev[uv] = u
                    heapq.heappush(q, (vd, uv))
        return d, prev

def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    G = Dijkstra()
    for a, b in zip(A, B):
        G.add(a, b, 1)
    ans = G.prev_search(1)[1]
    if None in ans:
        print('No')
    else:
        print('Yes')
        for i in range(2, N+1):
            print(ans[i])
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()


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

int main() {
    int n;
    cin >> n;
    vector<int> count(n+1);
    for (int x = 1; x*x < n; x++) {
        for (int y = 1; y*y < n; y++) {
            for (int z = 1; z*z < n; z++) {
                int sum = x*x + y*y + z*z + x*y + y*z + z*x;
                if (n < sum) break;
                count.at(sum)++;
            }
        } 
    }
    for (int i = 1; i <= n; ++i) {
        cout << count.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 3508
import Control.Monad
import qualified Data.IntMap as IM

type Map = IM.IntMap Int

get :: Int -> Map -> Int
get key m = case IM.lookup key m of
  Just x  -> x
  Nothing -> 0

set :: Int -> Int -> Map -> Map
set = IM.insert

solve :: [[Int]] -> Map -> Map
solve [] m = m
solve ([a, b]:rs) m = solve rs $ set a (ca + 1) $ set b (cb + 1) m
  where ca = get a m
        cb = get b m

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  rows <- replicateM m $ map read . words <$> getLine
  let im = solve rows IM.empty
  mapM_ print $ (`get` im) <$> [1..n]

Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  if (n > m / 2) {
    ans += m / 2;
  } else { // n <= m / 2;
    ans += n;
    m -= 2 * n;
    ans += m / 4;
  }
  P(ans);
  return 0;
}

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

using namespace std;
typedef pair<int,int> P;

int main() {
    int i,j,a,n,temp;
    int t=0;
    int flag=0;
    cin>>n;
    vector<string> s(n);
    int q[n];
    int maxsp=0;

    string aaa;
    for(i=0; i<n; ++i){
        cin>>s[i]>>q[i];
    }
    string maxs=s[0];
    for(i=0; i<n; ++i){
        for(j=0; j<n; ++j){
            if(maxs>s[j]){
                maxs=s[j];
                maxsp=j;
            }
            else if(maxs==s[j]){
                if(q[maxsp]<q[j]){maxs=s[j];maxsp=j;}
            }
        }
        cout<<maxsp+1<<endl;
        s[maxsp]="zzzzzzzzzzz";
        maxsp=0;
        maxs="zzzzzzzzzz";

    }

    return 0;
}


Measured memory_bytes: 256