akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N int

func main() {
	sc.Split(bufio.ScanWords)

	N = nextInt()
	m := make(map[int]int, N)
	for i := 0; i < N; i++ {
		a := nextInt()
		//mapにkeyが存在するか判定
		if _, ok := m[a]; ok {
			if m[a] == 1 {
				m[a] = 0
			} else {
				m[a] = 1
			}
		} else {
			m[a] = 1
		}
	}

	ans := 0
	for _, v := range m {
		if v == 1 {
			ans++
		}
	}

	fmt.Println(ans)
}


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

using namespace std;

string a,b;

int main()
{
    int n;
    cin >> n;
    cin >> a >> b;
    int maxi=0;
    int i,j;
    for(i=0;i<a.size();i++)
    {
        if(a[i]==b[0])
        {
            for(j=0;;j++)
            {
                if(i+j>=a.size())
                {
                    maxi=max(maxi,j);
                    break;
                }
                if(a[i+j]!=b[j])
                    break;
            }
        }
    }
    cout << a.size()+b.size()-maxi << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
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;
  cin >> n;
  string s[n];
  ll time[n];
  for(ll i = 0; i < n; i++) cin >> s[i] >> time[i];
  string x;
  cin >> x;

  bool ok = false;
  ll ans = 0;
  for(ll i = 0; i < n; i++){
    if(ok) ans += time[i];
    if(s[i] == x) ok = true;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n;
  cin >>n;
  vector<ll>a(n);
  rep(i,n) cin >> a[i];
  bool ok=true;
  rep(i,n-1){
    if(a[i]<a[i+1])a[i+1]--;
    if(a[i]>a[i+1])ok=false;
  }
  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 1024
s = input()
t = input()

ls = []
cnts = []
lt = []
cntt = []
m = len(s)
for i in range(m):
    if s[i] not in ls:
        ls.append(s[i])
        cnts.append(i)
    else:
        cnts.append(s.index(s[i]))
for i in range(m):
    if t[i] not in lt:
        lt.append(t[i])
        cntt.append(i)
    else:
        cntt.append(t.index(t[i]))

#print(cnts,cntt)

flag = 0

if cntt == cnts:
    flag = 1
if flag == 0:
    print("No")
else:
    print("Yes")

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

using namespace std;
#define lli long long int
#define ff first
#define ss second
#define lld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef pair<int, int> pii;
typedef pair<long long int,long long int> pll;
const int nax=1000*1007;
#define INF 2e18
lli pow(lli x, lli y) { lli res = 1;while (y > 0) { if (y & 1) res = (res * x);  y = y >> 1; x = (x * x); } return res; } 


int main()
{
	IOS;
    int n;
    cin>>n;
    int co=0,mco=0;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        if(x==y)
            co++;
        else
        {
            mco = max(mco,co);
            co=0;
        }
        
    }
    mco =max(mco,co);
    if(mco>=3)
        cout<<"Yes"<<endl;
    else
    {
        cout<<"No"<<endl;
    }
    
}

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

int main() {
	int a[3];
  	cin >> a[0] >> a[1] >> a[2];
  	sort(a, a + 3);
  	if(a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0) {
      cout << 0 << endl;
      exit(0);
    }
  	cout << 1LL * a[0] * a[1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll rec(ll idx,ll out,ll val)
{
	if(idx==s.size())return out*(val==0);
	return rec(idx+1,out,val*10+s[idx]-'0')+
		   rec(idx+1,out+val*10+s[idx]-'0',0);
}
signed main()
{
	cin>>s;
	cout<<rec(0,0,0)<<endl;
	return 0;
}



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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && A != C)
    cout << "Yes" << endl;
  else if (A == C && A != B)
    cout << "Yes" << endl;
  else if (B == C && B != A)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int H, W, K;
  cin >> H >> W >> K;
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  --x1, --y1, --x2, --y2;
  vector<string> G(H);
  rep(i, H) { cin >> G[i]; }

  priority_queue<tuple<int, int, int, int, int>,
                 vector<tuple<int, int, int, int, int>>,
                 greater<tuple<int, int, int, int, int>>>
      que;
  que.emplace(0, x1, y1, -1, 0);
  vector<vector<vector<int64_t>>> visit(
      H, vector<vector<int64_t>>(W, vector<int64_t>(4, INT64_MAX)));
  visit[x1][y1][0] = 0;
  visit[x1][y1][1] = 0;
  visit[x1][y1][2] = 0;
  visit[x1][y1][3] = 0;
  vector<pair<int, int>> dirs = {{+1, 0}, {-1, 0}, {0, +1}, {0, -1}};
  while (!que.empty()) {
    int step, x, y, dir, seq;
    tie(step, x, y, dir, seq) = que.top();
    que.pop();
    if (x == x2 && y == y2) {
      cout << step << endl;
      return 0;
    }
    if (visit[x][y][dir] < (step * 1e7 + seq)) continue;

    for (int d = 0; d < 4; ++d) {
      int nx = x + dirs[d].first;
      int ny = y + dirs[d].second;
      int nstep = step;
      int nseq = seq + 1;
      if (nx < 0 || ny < 0 || H <= nx || W <= ny) continue;
      if (G[nx][ny] == '@') continue;
      if (dir != d) {
        ++nstep;
        nseq = 1;
      } else {
        if (seq >= K) {
          ++nstep;
          nseq = 1;
        }
      }
      if (visit[nx][ny][d] <= (nstep * 1e7 + nseq)) continue;
      visit[nx][ny][d] = nstep * 1e7 + nseq;
      que.emplace(nstep, nx, ny, d, nseq);
    }
  }
  cout << -1 << endl;
  return 0;
}


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

int main(){
	double n,i,tmp;
	double ans=100000;
	cin>>n;
	while(n--){
		ans *= 1.05;
		ans = ceil(ans/1000.0)*1000.0;

	}
	printf("%.f\n", ans);
	return 0;
}

Measured memory_bytes: 1236
#   ?????????????????°???????????????????¨??????????????????°??????
while 1:
    #   ?¨??????\???????????°???????????????
    input_num = list(input())
    #   ???????????????"0"??\?????§??????
    if int(input_num[0]) == 0:
        break
    #   print(input_num)
    #   ??????????¨?????????????????????°
    digit_total = 0
    for i in range(0, len(input_num)):
        digit_total += int(input_num[i])
    print("{0}".format(digit_total))

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

#define REP(var,start,end) for(int var=start; var<end; var++)

int main(void) {
	int H, W;
	cin >> H >> W;
	
	string line[55];
	
	line[0] = "..........""..........""..........""..........""..........""....";
	line[H+1] = "..........""..........""..........""..........""..........""....";
	
	REP(gyo, 1, H+1) {
		string inp;
		cin >> inp;
		
		line[gyo] = "." + inp + ".";
	}
	
	int zengo[8][2] = {{-1,-1}, {-1,0}, {-1,1}, {0,-1}, {0,1}, {1,-1}, {1,0}, {1,1}};
	
	REP(gyo, 1, H+1) {
		REP(yoko, 1, W+1) {
			if ( line[gyo][yoko] == '#' ) {
				cout << '#';
			} else {
				int baku = 0;
				REP(i, 0, 8) {
					if ( line[gyo + zengo[i][0]][yoko + zengo[i][1]] == '#' ) {
						baku++;
					}
				}
				cout << baku;
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <ctime>
#include <string>
#include <cstring>
#include <random>
#define mp make_pair
#define pb push_back
#define NAME ""
#define y1 y1_423
#define list lista

using namespace std;

typedef long long ll;
typedef long double ld;

random_device gen;
mt19937 rnd(gen());

const int nmax = 2000 * 1000;
const int inf = 2000 * 1000 * 1000;
const ll infl = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
const int mod = 1000 * 1000 * 1000 + 7;
const ld pi = acos(-1.0);
    
int n, x, y, a[nmax];

int main() {
    //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    //freopen(NAME".in", "r", stdin);freopen(NAME".out", "w", stdout);
    cin >> n >> x >> y;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (n == 1) {
        cout << abs(a[0] - y) << endl;
        return 0;
    }
    cout << max(abs(a[n - 2] - a[n - 1]), abs(a[n - 1] - y)) << endl;
    return 0;
}



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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
const ll mod = 1000000007;
const ll INF = 10010010010010010;

int main() {
    int n; cin >> n;
    int a[n]; rep(i,n) cin >> a[i];
    int b[n]; rep(i,n) cin >> b[i];
    int c[n-1]; rep(i,n-1) cin >> c[i];
    int ans = b[a[0]-1];
    rep(i,n-1) {
        ans += b[a[i+1]-1];
        if (a[i]+1 == a[i+1]) {
            ans += c[a[i]-1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
signed main(void) {
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB")
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val A = Array(3) { sc.next() }.distinct().count()
        if (A == 2) {
            pw.println("Yes")
        } else {
            pw.println("No")
        }
    }
}


Measured memory_bytes: 35780
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<59;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n, s;
	cin>>n>>s;
	for(ll b = 2; b*b<=n; b++){
		ll r = 0, m = n;
		while(m){
			r += m%b;
			m /= b;
		}
		if(r==s){
			cout<<b<<endl;
			return 0;
		}
	}
	ll res = INF;
	if(s==n) res = n+1;
	if(s==1) res = max(n, 2LL);
	for(ll i = 1; i<=s; i++){
		ll b = (n-s+i)/i;
		if(b<=sqrt(n)) break;
		if(n/b+n%b!=s) continue;
		res = min(res, b);
	}
	if(res==INF) res = -1;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	string a,b,e;
    int c,d;
    cin>>a>>b>>c>>d>>e;
    if(a==e)c--;
    else d--;
    cout<<c<<" "<<d<<endl;
}


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

using namespace std;
#define pb push_back

typedef long long ll;



int n, k;
const int maxn = 1e4+5;
const int maxk = 100+5;
const ll MOD = 1e9+7;
ll dp[maxn][2][maxk]; //0: a[i] < s[i], 1: a[i] == s[i]

inline void add(ll& a, ll b){ a+=b; a%=MOD;};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  string s;
  cin >> s >> k;
  n = s.size();

  memset(dp, 0ll, sizeof(dp));
  for(int d = 0; d < int(s[0]-'0'); d++) dp[0][0][d%k] += 1ll;
  dp[0][1][int(s[0]-'0')%k] = 1ll;
  for(int i = 1; i < n; i++)
  {
    for(int ki = 0; ki < k; ki++)
    {
      //any a[i], before < , case 0
      for(int d = 0; d < 10; d++) add(dp[i][0][(ki+d)%k], dp[i-1][0][ki]);
      //a[i] < s[i], before = maximum, case 0
      for(int d = 0; d < int(s[i]-'0'); d++) add(dp[i][0][(ki+d)%k], dp[i-1][1][ki]);
      //a[i-1], before = maximum, case 1
      dp[i][1][(ki+int(s[i]-'0'))%k] = dp[i-1][1][ki];
    }
  }
  ll ans = (dp[n-1][0][0]+dp[n-1][1][0]-1ll+MOD)%MOD;//-1, 00000000
  cout <<  ans << endl;

  return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a,i,temp,j,c=0;
    cin>>a;
    ll b[a];
    for(i=0;i<a;i++)
    {
        cin>>b[i];
    }
    for(i=0;i<a;i++)
    {
        for(j=a-1;j>i;j--)
        {
            if(b[j]<b[j-1])
            {
                c++;
                temp = b[j];
                b[j]=b[j-1];
                b[j-1]=temp;
            }
        }
    }
    for(i=0;i<a;i++)
    {
        if(i==a-1)
            cout<<b[i]<<endl;
        else
        cout<<b[i]<<" ";
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3092
n, m = gets.split.map(&:to_i)
ss = m.times.map { gets.split.map(&:to_i)[1..-1] }
ps = gets.split.map(&:to_i)

ans = 0

(1 << n).times do |bit|
  valid = true

  m.times do |i|
    count = ss[i].count { |s| bit & (1 << (s - 1)) != 0 }
    next if count % 2 == ps[i]

    valid = false
    break
  end

  ans += 1 if valid
end

puts ans

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
map<string,int> M;
vector<string> NG[41];
string A[41];
int n,B[41],ans;
ull g[41];
int Sum[41];
 
void dfs(int pos,int sum,ull U){
  ans=max(ans,sum);
  if(pos==n)return;
  if(ans>=sum+Sum[pos]) return;
   
  dfs(pos+1,sum,U);
  if((U&(1LL<<pos))==0)dfs(pos+1,sum+B[pos],U|g[pos]);
   
}
 
int main(){
  while(cin>>n,n){
    M.clear();
     
    for(int i=0,C;i<n;i++){
      cin>>A[i]>>B[i]>>C;
      Sum[i]=B[i];
      M[A[i]]=i;
      NG[i].resize(C);
      for(int j=0;j<C;j++)cin>>NG[i][j];
    }
     
    for(int i=n-2;i>=0;i--) Sum[i]+=Sum[i+1];
     
    for(int i=0;i<n;i++){
      g[i]=1LL<<i;
      for(int j=0;j<(int)NG[i].size();j++)g[i]|=1LL<<M[NG[i][j]];
    }
    ans=0;
    dfs(1,B[0],g[0]);
    cout<<ans<<endl;
  }
  return 0;
}

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

char a[100010],b[100010];
string a1,b1;

int main()
{
	cin>>a;
	int len=strlen(a);
	for(int i=0;i<len;i++) b[i]=a[len-i-1];
	for(int i=0;i<len;i++)
	{
		if(b[i]=='b') b[i]='d';
		else if(b[i]=='d') b[i]='b';
		else if(b[i]=='q') b[i]='p';
		else b[i]='q';
	}
	a1=a;b1=b;
	if(a1==b1) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 640
#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, m;
  cin >> n >> m;
  vector<P> xy(m);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    xy.at(i) = make_pair(x, y);
  }
  vector<int> cnt(n, 1);
  vector<bool> possible(n, false);
  possible.at(0) = true;
  rep(i, m) {
    int x = xy.at(i).first;
    int y = xy.at(i).second;
    cnt.at(x)--;
    cnt.at(y)++;
    if (possible.at(x)) {
      possible.at(y) = true;
    }
    if (cnt.at(x) == 0) {
      possible.at(x) = false;
    }
  }
  int res = 0;
  rep(i, n) {
    if (possible.at(i) > 0) {
      res++;
    }
  }
  cout << res << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  long long sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    sum += a.at(i);
  }
  
  vector<int> ans(n);
  for(int i = 1; i < n; i++){
    if(i % 2) sum -= a.at(i) * 2;
  }
  ans.at(0) = sum;
  for(int i = 1; i < n; i++){
    ans.at(i) = a.at(i-1) * 2 - ans.at(i-1);
  }
  
  for(int i = 0; i < n; i++) cout << ans.at(i) << " ";
  cout << endl;
}

Measured memory_bytes: 3920
#include <iostream>

using namespace std;
using ll = long long int;

//拡張ユークリッドの互除法
//ax + by = cとなるようなc=gcd(a,b)をxをペアにして返す
//firstがx,secondがc
template <typename number>
pair<number, number> extended_euclid(number a, number b)
{
    number r0, r1, a0, a1, b0, b1;
    r0 = a; r1 = b;
    a0 = 1; a1 = 0;
    b0 = 0; b1 = 1;
    while (r1>0) {
        number q1 = r0 / r1;
        number r2 = r0 % r1;
        number a2 = a0 - q1 * a1;
        number b2 = b0 - q1 * b1;
        r0 = r1 ; r1 = r2;
        a0 = a1 ; a1 = a2;
        b0 = b1 ; b1 = b2;
    }
    number c = r0;
    a = a0; //x
    b = b0; //y
    return  {a, c};
}

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    //cの倍数の数を数える
    ll dif = b - a + 1;
    if(a % c != 0){
        dif -= c - (a % c);
        if(dif < 0) dif = 0;
    }
    ll countc = dif / c;
    if(dif % c != 0) countc++;
    dif = b - a + 1;
    //dの倍数の数を数える
    if(a % d != 0)
    {
        dif -= d- (a % d);
        if(dif < 0) dif = 0;
    }
    ll countd = dif / d;
    if(dif % d != 0) countd++;
    //cとdの最小公倍数の倍数の数を数える
    ll lcm = c * d / extended_euclid(c, d).second;
    dif = b - a + 1;
    if(a % lcm != 0)
    {
        dif -= lcm - (a % lcm);
        if(dif < 0) dif = 0;
    }
    ll countcd = dif / lcm;
    if(dif % lcm != 0) countcd++;
    ll result = b - a + 1 - countc - countd + countcd;
    cout << result << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>

using namespace std;

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

int main()
{
  string S;
  cin >> S;
  int N = S.size();
  int ans = 0;
  vector<int> remainder(N);
  remainder[0] = S[N - 1] - '0';
  int n = 10;
  for (int i = 1; i < N; i++)
  {
    remainder[i] = ((S[N - i - 1] - '0') * n + remainder[i - 1]) % 2019;
    n = n * 10 % 2019;
  }
  vector<int> vec(2019);
  for (int i = 0; i < N; i++)
  {
    vec[remainder[i]]++;
  }
  ans += vec[0];
  for (int i = 0; i < 2019; i++)
  {
    ans += vec[i] * (vec[i] - 1) / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4340
/*
How to lambda
  ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound
  1 2 2 2 3 3 
    ^lb   ^ub */
#include <bits/stdc++.h>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define assign_if_greater(V, T) V=max(V,T)
using namespace std;
typedef long long ll;
typedef long double ld;
int N;
int main() {
  cout << fixed << setprecision(15);
  cin >> N;
  ld ans=0;
  REP(i,N) {
    ld x;string u;
    cin >> x >> u;
    if (u=="JPY") {
      ans+=x;
    }else {
      ans+=x*(ld)380000;
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
 
int main(){
    int N,M;
    cin >> N >> M;
    vector<pair<int,int>> P(M);
    int a,b;
    rep(i,M){
        cin >> a >> b;
        P[i] = make_pair(b,a);
    }
    sort(P.begin(),P.end());
    int x=0;
    int c=0;
    rep(i,M){
        if(x < P[i].second){
            x = P[i].first - 1;
            c++;
        }
    }
    cout << c << endl;

    return 0;
}

Measured memory_bytes: 1152
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line: Vec<usize> = read_as_vec();
    let (h, w) = (line[0], line[1]);

    let mut grid: Vec<Vec<char>> = Vec::new();

    for _ in 0..h{
        grid.push(read_as_string().chars().collect::<Vec<char>>());
    }

    //let mut width_range_map: Vec<Vec<usize>> = vec![vec![0;w];h];
    let mut width_range_map: Vec<usize> = vec![0;h*w];
    for i in 0..h{
        let mut left = 0;
        for j in 0..w{
            if grid[i][j] == '#'{
                for k in left..j{
                    //width_range_map[i][k] = j - left;
                    width_range_map[i*w+k] = j - left;
                }
                left = j+1;
            }
        }
        for k in left..w{
            //width_range_map[i][k] = w - left;
            width_range_map[i*w+k] = w - left;
        }
    }

    let mut height_range_map: Vec<usize> = vec![0;h*w];
    for j in 0..w{
        let mut upper = 0;
        for i in 0..h{
            if grid[i][j] == '#'{
                for k in upper..i{
                    //height_range_map[k][j] = i - upper;
                    height_range_map[k*w+j] = i - upper;
                }
                upper = i+1;
            }
        }
        for k in upper..h{
            //height_range_map[k][j] = h - upper;
            height_range_map[k*w+j] = h - upper;
        }
    }

    /*
    let ans =
        width_range_map.into_iter().flatten()
        .zip(height_range_map.into_iter().flatten()).map(|(x, y)| {
            if x > 0 && y > 0{ x+y -1}
            else{ 0 }
        }).max().unwrap();
     */

    let ans =
        width_range_map.into_iter()
        .zip(height_range_map.into_iter()).map(|(x, y)| {
            if x > 0 && y > 0{ x+y -1}
            else{ 0 }
        }).max().unwrap();    

    println!("{}", ans);
    
}


Measured memory_bytes: 86268
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	ll K, A, B;
	cin >> K >> A >> B;
	double rate = (B - A) / 2;
	ll nowBis = 1;
	if(rate > 1.0){
		if(nowBis < A){
			if(A - nowBis >= K){
				cout << K + 1 << endl;
				return 0;
			}
			nowBis = A;
			if((K - A + 1) % 2 == 0){
				nowBis += (B - A) * (K - A + 1) / 2;
				cout << nowBis << endl;
				return 0;
			}
			nowBis += (B - A) * (K - A) / 2;
			nowBis ++;
			cout << nowBis << endl;
			return 0;
		}
		if(nowBis >= A){
			if((K - A + 1) % 2 == 0){
				nowBis += (B - A) * (K - A + 1) / 2;
				cout << nowBis << endl;
				return 0;
			}
			nowBis += (B - A) * (K - A) / 2;
			nowBis ++;
			cout << nowBis << endl;
			return 0;
		}
	}
	else{
		cout << K + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  string s[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string t;cin>>t;
  rep(i,7){
    if(s[i]==t){
      cout<<6-i+1;return 0;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
#include<list>

#define ll long long
#define N 150005
#define pb push_back
#define Sca(a) scanf("%d",&a)
#define Scs(a) scanf("%s",&a)
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define Scal(a) scanf("%ld",&a)
#define Scall(a) scanf("%lld",&a)
#define Pri(a) printf("%d",a)
#define Prs(a) printf("%s",a)
#define Pril(a) printf("%ld",a)
#define Prill(a) printf("%lld",a)
#define FAST_IO ios::sync_with_stdio(false)
using namespace std;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
const double pi = 3.141592653;
using namespace std;

template<class T>
void tomax(T &a, T b) {
    a = max(a, b);
}

template<class T>
void tomin(T &a, T b) {
    a = min(a, b);
}

vector<ll> datas[N];
ll ans[N];
void bfs() {
    queue<int> q;
    q.push(1);
    ans[1] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (auto v:datas[u]) {
            if (0==ans[v]) {
                q.push(v);
                ans[v] = u;
            }
        }
    }
}

int main() {
    int n,m;
    scanf("%d%d", &n, &m);
    for (int i=0; i<m; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        datas[u].pb(v);
        datas[v].pb(u);
    }
    bfs();
    for (int i=2; i<=n; i++) {
        if (0==ans[i]) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    for (int i=2; i<=n; i++) {
        printf("%d\n", ans[i]);
    }
}

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

using namespace std;
const long mod = 1000000007;
typedef long long lint;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(N) for(int i = 0; i < (int)(N); i++)
#define all(x) (x).begin(),(x).end()
#define length(x) ((int)(x).size())
#define prln(s) cout<<s<<endl;

#define str(s) string s;cin>>s;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;

lint n;
lint W;
vector<lint>v;
vector<lint>w;

int main() {
  cin>>n>>W;

  lint dp[n+100][W+100];
  repi(n){
    int2(wi,vi);
    w.push_back((lint)wi);
    v.push_back((lint)vi);
  }
  for (lint i=n-1; i >=0; --i) {
    for (lint j=0; j <=W; ++j) {
      if(j<w[i]){
        dp[i][j]=dp[i+1][j];
      }
      else{
        dp[i][j]=max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
      }
    }
  }
  prln(dp[0][W]);
  
}

Measured memory_bytes: 79616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Graph vector<vector<ll>>
constexpr ll INF=(1ll<<60);
constexpr ll mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

int main(){
    ll r;cin>>r;
    cout<<3*r*r<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <inttypes.h>

#define KAZU 2019

int main(void) {
	uint32_t L, R;
	uint32_t i, j;
	int cnt, cnt2;
	int answer = KAZU - 1;
	if (scanf("%" SCNu32 "%" SCNu32, &L, &R) != 2) return 1;
	for (cnt = 0, i = L; i <= R && cnt < KAZU; i++, cnt++) {
		for (cnt2 = 0, j = i + 1; j <= R && cnt2 < KAZU; j++, cnt2++) {
			int nyan = (int)(((uint64_t)i * j) % KAZU);
			if (nyan < answer) answer = nyan;
		}
	}
	printf("%d\n", answer);
	return 0;
}


Measured memory_bytes: 128
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

fn main() {
    let (n, m) = read!(usize, usize);
    let mut edges = vec![vec![]; n + 1];

    for _ in 0..m {
        let (a, b) = read!(usize, usize);
        edges[a].push(b);
        edges[b].push(a);
    }

    let mut visited = vec![-1; n + 1];
    visited[0] = 0;
    visited[1] = 0;

    let mut open = VecDeque::new();
    open.push_front(1);
    while let Some(o) = open.pop_back() {
        for dist in &edges[o] {
            if visited[*dist] == -1 {
                visited[*dist] = o as isize;
                open.push_front(*dist);
            }
        }
    }

    if visited.iter().filter(|&&e| e == -1).count() != 0 {
        println!("No");
    } else {
        println!("Yes");
        for i in 2..n+1 {
            println!("{}", visited[i]);
        }
    }
}


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

const ll MOD = 1e9 + 7;

ll dp[100005][13];

int main(){
  string s;
  cin >> s;
  int N = s.size();

  dp[0][0] = 1;
  for(int i = 0; i < N; i++){
    if(s[i] == '?'){
      for(int j = 0; j < 13; j++){
        for(int k = 0; k <= 9; k++){
          dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
          dp[i + 1][(j * 10 + k) % 13] %= MOD;
        }
      }
    } else {
      int num = s[i] - '0';
      for(int j = 0; j < 13; j++){
        dp[i + 1][(j * 10 + num) % 13] += dp[i][j];
        dp[i + 1][(j * 10 + num) % 13] %= MOD;
      }
    }
  }

  /*for(int i = 0; i <= N; i++){
    for(int j = 0; j < 13; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/

  cout << dp[N][5] % MOD << endl;
  return 0;
}

Measured memory_bytes: 10624
#include <stdio.h>

int main(){
    int a,b,c,d;

	scanf("%d", &a);
	scanf("%d", &b);
	c = a + b ;
	d = c - 24 ;
	
	if(c<24){
		printf("%d",c);	
	}
	else{
		c>=24;
		printf("%d", d);
	}
	
	
	return 0 ;
	
}

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

using namespace std;

const int N = 100010;
const int INF = 1e9 + 7;

int a[N], mn[N], mx[N];
int n, T;

int main() {
	scanf("%d %d", &n, &T);
	mn[0] = INF;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		mn[i] = min(a[i], mn[i - 1]);
	}
	mx[n + 1] = 0;
	for (int i = n; i; i--) {
		mx[i] = max(mx[i + 1], a[i]);
	}
	int ans = 0;
	for (int i = 2; i <= n; i++) {
		ans = max(ans, mx[i] - mn[i - 1]);
	}
	int pre = INF;
	int tot = 0;
	for (int i = 1; i <= n; i++) {
		if (mx[i] - pre == ans) {
			int j = i;
			while (j < n && a[j] != pre + ans) ++j;
			++tot;
			i = j;
			pre = INF;
		} else pre = min(pre, a[i]);
	}
	cout << tot << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

int main() {
  int N, M, L; cin >> N >> M >> L;
  const int INFTY = 1e9+7;
  Graph edge(N, vi(N, INFTY));
  rep(i,N) edge[i][i] = 0;
  rep(i,M) {
    int a, b, c; cin >> a >> b >> c; --a; --b;
    edge[a][b] = edge[b][a] = c;
  }

  rep(k,N) {
    rep(i,N) {
      rep(j,N) {
        edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
      }
    }
  }

  Graph move(N);
  rep(i,N) {
    rep(j,N) {
      if (i != j && edge[i][j] <= L) move[i].push_back(j);
    }
  }

  Graph query(N, vi(N, -1));
  rep(i,N) {
    queue<int> q;
    q.push(i);
    query[i][i] = 0;

    while (!q.empty()) {
      auto v = q.front(); q.pop();

      for (auto nv : move[v]) {
        if (query[i][nv] != -1) continue;
        query[i][nv] = query[i][v] + 1;
        q.push(nv);
      }
    }
  }

  int Q; cin >> Q;
  rep(i,Q) {
    int s, t; cin >> s >> t; --s; --t;
    if (query[s][t] == -1) cout << -1 << endl;
    else cout << query[s][t] - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#coding:UTF-8
import sys

def func(x, y, z):
	print("{0} {1} {2}".format(z, y, x))
	sys.exit()

def main():
	N, Y = map(int, input().split())
	cash = Y
	x, y, z = 0, 0, 0
	while cash >= 10000:
		cash -= 10000
		z += 1;

	while cash >= 5000:
		cash -= 5000
		y += 1

	while cash >= 1000:
		cash -= 1000
		x += 1
	#この時点で枚数最小

	if x+y+z > N:
		func(-1, -1, -1)

	while True:
		if x+y+z == N:
			func(x, y, z)
		else:
			prev = x+y+z
			if prev+4 <= N:
				if y > 0:
					x += 5
					y -= 1
					if x+y+z == N:
						func(x, y, z)
				elif z > 0:
					y += 2
					z -= 1
				else:
					func(-1, -1, -1)
			else:
				if z > 0:
					y += 2
					z -= 1
					if x+y+z == N:
						func(x, y, z)
				else:
					func(-1, -1, -1)

if __name__ == "__main__":
	main()


Measured memory_bytes: 3064
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
As = list(map(int, input().split()))

mx = None
ans = 0
for a in As:
    if mx is None:
        mx = a
    else:
        if a >= mx:
            mx = a
        else:
            ans += mx - a
print(ans)

            



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

#define int long long

int32_t main(){
	int n ;
	cin >> n ;
	string s , t ;
	cin >> s >> t ;
	string ans = "" ;
	for(int i = 0 ; i < n ; i++) ans += s[i] , ans += t[i] ;
	cout << ans ;
	return 0 ;
}



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


using namespace std;
static int perms;

void print(pair<int,int> p)
{
	cout<<"("<<p.first<<","<<p.second<<")";
}
double calculate(vector<pair<int,int>> &points, int n)
{
	double ans = 0.0;
	for(int i = 1; i<n; i++)
	{
		int x = points[i].first - points[i-1].first;
		int y = points[i].second - points[i-1].second;
		ans += sqrt(x*x+y*y);
	}
	return ans;
}

void permute(vector<pair<int,int>> &points, int index, int n, double &res)
{
	if(index>=n)
	{
		perms+=1;
		double ans = calculate(points,n);
		res += ans;
		return;
	}
	else
	{
		for(int i = index; i<n; i++)
		{
			swap(points[index],points[i]);
			permute(points, index+1, n, res);
			swap(points[index],points[i]);
		}
	}

}	

int main()
{
	int n; cin>>n;
	vector<pair<int,int>>points(n);

	for(int i = 0; i<n; i++)
			cin>>points[i].first>>points[i].second;

	double res = 0.0;
	permute(points,0,n, res);
	cout<<setprecision(8)<<res/perms;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

bool go(vector<vector<int> > &g, int u, vector<int> &mt, vector<bool> &vs){
	int n = g.size();
	if(u<0) return true;
	for(int v = 0; v < n; v++){
		if(!g[u][v] || vs[v] || mt[v]!=-1) continue;
		vs[v] = true;
		mt[v] = u;
		return true;
	}
	for(int v = 0; v < n; v++){
		if(!g[u][v] || vs[v]) continue;
		vs[v] = true;
		if(go(g, mt[v], mt, vs)){
			mt[v] = u;
			return true;
		}
	}
	return false;
}
int bm(vector<vector<int> > &g){
	int n = g.size();
	vector<int> mt(n, -1);
	int res = 0;
	for(int i = 0; i < n; i++){
		vector<bool> vs(n);
		if(go(g, i, mt, vs)) res++;
	}
	return res;
}

bool isPrime3(ll x){
	if(x<=2) return false;
	for(ll i = 2; i*i<=x; i++) if(x%i==0) return false;
	return true;
}

int main(){
	int n;
	cin>>n;
	vector<ll> a;
	rep(i, n){
		ll x;
		cin>>x;
		if(a.empty() || a.back()!=x){
			a.push_back(x);
			a.push_back(0);
		}
		a.back() = x+1;
	}
	ll m = a.size();
	vector<vector<int> > g(m, vector<int>(m));
	rep(i, m){
		rep(j, i){
			if(isPrime3(abs(a[i]-a[j]))){
				if(a[i]%2) g[i][j] = 1;
				else g[j][i] = 1;
			}
		}
	}
	ll t = bm(g);
	ll odd = 0;
	rep(i, m) if(a[i]%2) odd++;
	ll s = (odd-t)%2;
	ll res = t + s*3 + (m/2-s-t)*2;
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1e9+10;
const int maxn=2e5+10;
const int maxm=20;
const int mod=1e9+7;
const double pi=acos(-1.0);
ll n,m;
ll func(ll x)
{
    ll ans=1;
    for(ll i=x;i>=1;i--)
        ans=(ans*i)%mod;
    return ans;
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%lld %lld",&n,&m))
    {
        ll ans;
        if(abs(n-m)==1)
            ans=(func(n)*func(m))%mod;
        else if(abs(n-m)==0)
            ans=(func(n)*func(m)*2)%mod;
        else
            ans=0;
        printf("%lld\n",ans);
    }
    return 0;
}


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

const long long mod = 1e9 + 7;

int main() {
  long long n, k;
  cin >> n >> k;

  long long ans = 0;
  for ( long long i = k; i <= n+1; i++ ) {
    long long mn = ( (i-1) * i / 2 ) % mod;
    long long mx = ( ((n-i+1)+n) * i / 2 ) % mod;
    ans += mx - mn + 1;
    ans %= mod;
  }
  ans = ( ans < 0 ) ? ans+mod : ans;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3584
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxm=500007;
char s[maxm];
int n;
int dp[maxm];//到i位置的最大操作数 
int l[maxm];//在左边离i最近的0的位置 
int main()
{
 scanf("%d",&n);
 scanf("%s",s+1);
 for(int i=1;i<=n;i++)
 {
  if(s[i]=='1') l[i]=l[i-1];
  else l[i]=i;	
 }
 for(int i=1;i<=n;i++)
 {
   dp[i]=dp[i-1];
   if(s[i]=='1')
   {
     if(s[i-1]=='0'&&s[i-2]=='1')
     {
       dp[i]=max(dp[i],dp[l[i-2]]+i-l[i-2]-2);//100|11111101的贡献为他们的长度-2,
       dp[i]=max(dp[i],dp[l[i-2]+1]+i-l[i-2]-1-2);//11111101|11111101
     }
     else if(l[i]>1&&s[l[i]-1]=='1')
	 {
	  dp[i]=max(dp[i],dp[l[i]-2]+i-l[i]+2-2);//101111111
     }
   }
 }
 printf("%d\n",dp[n]);
 return 0;	
}

Measured memory_bytes: 4608
#include <iostream>
using namespace std;
typedef long long ll;

ll min(ll a, ll b) {
  return (a < b) ? a : b;
}

int main(void) {
  ll N; cin >> N;
  ll A[N+1], B[N];
  ll cnt = 0;

  for (int i=0; i < N+1; i++) {
    cin >> A[i];
  }

  for (int i=0; i < N; i++) {
    cin >> B[i];
  }

  for (int i=0; i < N; i++) {
    ll defeat = min(A[i], B[i]);
    cnt += defeat;
    B[i] -= defeat;
    defeat = min(A[i+1], B[i]);
    cnt += defeat;
    A[i+1] -= defeat;
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @author radhakm
 * https://atcoder.jp/contests/dp/tasks/dp_a
 */
public class Main {
    static int[] h;
    static int n;
    static Integer[] dp;
    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    }

    static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }

        int minCost = Math.abs(h[idx] - h[idx+1]) + frogJump(idx+1);
        if(idx+2<n) {
            int cost = Math.abs(h[idx] - h[idx+2]) + frogJump(idx+2);
            minCost = Math.min(minCost,cost);
        }
        dp[idx] = minCost;
        return minCost;
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

Measured memory_bytes: 53052