akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
from heapq import heapify, heappush, heappop
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy

sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]



def main(H, W, c_h, c_w, d_h, d_w):

    que = deque([(c_h, c_w)])
    INF = 1e9
    dist = [[INF]*W for _ in range(H)]
    dist[c_h][c_w] = 0
    while que:
        # print(que)
        tmp = que.popleft()
        h, w = tmp
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if board[new_h][new_w] == '#':
                continue
            if dist[new_h][new_w] <= d:
                continue
            dist[new_h][new_w] = d
            que.appendleft((new_h, new_w))
        # 魔法
        for m_dy in range(-2, 3):
            for m_dx in range(-2, 3):
                new_h = h + m_dy
                new_w = w + m_dx
                if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                    continue
                if board[new_h][new_w] == '#':
                    continue
                if dist[new_h][new_w] <= d + 1:
                    continue
                dist[new_h][new_w] = d + 1
                que.append((new_h, new_w))

    ans = dist[d_h][d_w]
    if ans == INF:
        print(-1)
    else:
        print(ans)


H, W = zz()
c_h, c_w = zz()
d_h, d_w = zz()
board = []
c_h -= 1
c_w -= 1
d_h -= 1
d_w -= 1
for i in range(H):
    tmp = S()
    board.append(tmp)
main(H, W, c_h, c_w, d_h, d_w)


Measured memory_bytes: 105836
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
#define pr(x) cout << x << endl;
using namespace std;

//const int mod = 998244353;
const int mod=1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// 出力は.xで！！！！

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll mpow(ll a, ll b){
  ll ans=1;
  rep(i,b){
    ans*=a;
    ans%=mod;
  }
  return ans;
}

int main(){
  int n; cin >> n;
  vector<ll> s(n),xm(n);
  rep(i,n){
    ll x,y; cin >> x >> y;
    s[i]=x+y; xm[i]=x-y;
  }

  sort(all(s));
  sort(all(xm));
  cout << max(s[n-1]-s[0],-xm[0]+xm[n-1]);
return 0;
}
/*
3 4
1 9

2 -5

2 5 -3
8 3 5


8 4 4
7 9 -2
*/



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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

bool solve(int n, int a, int b) {
	int alice = a;
	int borys = b;

	bool state = a < b;
	for (int i = 0;; i++) {
		if (i % 2 == 0) {
			alice += alice < borys ? 1 : -1;
		} else {
			borys += alice < borys ? -1 : 1;
		}

		if (alice == borys) {
			return i & 1;
		}
	}
}

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

	int n, a, b;
	cin >> n >> a >> b;

	cout << (solve(n, a, b) ? "Alice" : "Borys") << endl;
	return 0;
}


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

void solve(){

}
typedef pair<string,int> PSI;

int main(){
  string s;
  map<string, int> cnt;
  PSI mostcnt("",0), mostlen("",0);
  while(cin >> s){
    cnt[s]++;
    if(mostcnt.second < cnt[s]){
      mostcnt = PSI(s, cnt[s]);
    }
    if(mostlen.second < (int)s.size()){
      mostlen = PSI(s, s.size());
    }
  }
  cout << mostcnt.first << " " << mostlen.first << endl;
  
  return 0;
}

Measured memory_bytes: 1192
def powerset(n, lessequal):
    retval = []
    power = n
    while power <= lessequal:
        retval += [power]
        power *= n
    return retval


def main():
    N = int(input())
    dp = [0] * (N + 1)
    for i in range(1, N + 1):
        withdraw = [1] + powerset(6, i) + powerset(9, i)
        dp[i] = min([dp[i - x] for x in withdraw]) + 1
    print(dp[N])


if __name__ == "__main__":
    main()


Measured memory_bytes: 3828
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);


    int h, w;
    cin >> h >> w;
    vector<string> M(h);
    for (int i = 0; i < h; ++i) {
        cin >> M[i];
    }

    bool res = true;

    vector<int> X{-1, 1, 0, 0};
    vector<int> Y{0, 0, -1, 1};
    for (int i = 0; i < h && res; ++i) {
        for (int j = 0; j < w; ++j) {
            if (M[i][j] == '#') {
                int cnt = 0;
                for (int k = 0; k < 4; ++k) {
                    int x = i + X[k], y = j + Y[k];
                    if (x >= 0 && x < h && y >= 0 && y < w) {
                        if (M[x][y] == '#') {
                            ++cnt;
                        }
                    }
                }
                if (cnt == 0) {
                    res = false;
                    break;
                }
            }
        }
    }
    if (res) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
q, h, s, d = (int(x) for x in input().split())
n = int(input())
l1 = min(4*q, 2*h, s)
l2 = min(8*q, 4*h, 2*s, d)
if n%2 == 0:
  print((n//2) * l2)
else:
  print((n//2) * l2 + l1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)

using namespace std;
int N;
vector<int> G[100005];

int dfs(int v, int p){
  int res = 0;
  for(int u : G[v]){
    if(u == p) continue;
    res ^= dfs(u, v) + 1;
  }
  return res;
}

int main(){
  cin >> N;
  REP(i,N-1){
    int x, y;
    cin >> x >> y;
    x--;y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  cout << (dfs(0, -1) ? "Alice" : "Bob") << endl;
  return 0;
}


Measured memory_bytes: 10368
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, v;
	cin >> n >> v;
	vi x(n), y(n);
	REP(i, n)cin >> x[i] >> y[i];
	ll  ans = 4*INF*INF;
	REP(i, n) {
		REP(j, n) {
			REP(k, n) {
				REP(l, n) {
					ll sx = min(x[i], x[j]), tx = max(x[i], x[j]), sy = min(y[k], y[l]), ty = max(y[k], y[l]);
					int cnt = 0;
					REP(f, n) {
						if (x[f] >= sx&&x[f] <= tx&&y[f] >= sy&&y[f] <= ty)cnt++;
					}
					if (cnt >= v)ans = min(ans, (tx - sx)*(ty - sy));
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <set>
#include <deque>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 100000;

/*
10
5
4  1 2 3 4
4  1 5 6 7
4  2 5 8 9
4  3 6 8 10
4  4 7 9 10


6
4
3  1 2 3
3  1 4 5
3  2 4 6
3  3 5 6
*/

int n;
int ans[505][505];

int main()
{
	while(scanf("%d", &n) != EOF)
	{
		int tmp = (int)sqrt(2.0 * n);
		if(tmp * (tmp + 1) != 2 * n) printf("No\n");
		else {
			printf("Yes\n");
			printf("%d\n", tmp + 1);
			int sta = 1;
			for(int col = 1; col <= tmp; col++) {
				for(int j = col; j <= tmp; j++) {
					ans[col][j] = sta + (j - col);

					ans[j + 1][col] = sta + (j - col);
				}
				sta += (tmp - col + 1);
			}
			for(int i = 1; i <= tmp + 1; i++) {
				printf("%d", tmp);
				for(int j = 1; j <= tmp; j++) printf(" %d", ans[i][j]);
				printf("\n");
			}
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;

char sn[2] = {' ', '\n'};

int main()
{	
    int n, x = 0, k = 0;
    string s;
    scanf("%d", &n);
    cin >> s;
    for(int i=0; i < (int)s.size();i++) {
        if(s.at(i) == 'I') k++;
        else k--;
        x = max(x,k);
    }
    printf("%d\n",x);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int m,x[16],y[16],dp[1<<16];
bool s[1<<16][16][16],f[1<<16];
int hei(int a,int b,int c,int d){return a*d-b*c;}

int main(){
  cin>>m;
  for(int i=0;i<m;i++)cin>>x[i]>>y[i];
  s[0][0][1]=1;
  for(int i=0;i<1<<m;i++){
    for(int a=0;a<m;a++)
      for(int b=a+1;b<m;b++)
	if(s[i][a][b])
	  for(int c=0;c<m;c++)
	    if(!(i&1<<c))
	      for(int d=c+1;d<m;d++)
		if(!(i&1<<d))
		  if(!i||hei(x[a]-x[b],y[a]-y[b],x[c]-x[d],y[c]-y[d])==0)
		    s[i|1<<c|1<<d][c][d]=1;
    for(int j=0;j<m;j++)
      for(int k=j+1;k<m;k++)if(s[i][j][k])f[i]=1;
  }
  memset(dp,-1,sizeof(dp));
  dp[0]=0;
  int ans=0;
  for(int i=0;i<1<<m;i++)
    if(dp[i]!=-1)
      for(int j=0;j<1<<m;j++){
	if(!(i&j)&&f[j]){
	  int a=__builtin_popcount(j)/2;
	  ans=max(ans,dp[i|j]=max(dp[i|j],dp[i]+a*(a-1)/2));
	}
      }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4696
#include <iostream>
#include <cstdio>
#include <numeric>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int N, x; cin >> N >> x;
    vector<int> ns;
    for(int i = 1; i <= 2*N-1; i++){ns.push_back(i);}

    if(x == 1 || x == 2*N-1) cout<< "No" << endl;
    else{
        cout << "Yes" << endl;

        if(x <= ns[N-1]){
            swap(ns[x], ns[N]);
            swap(ns[x-1], ns[N-1]);
            swap(ns[x-2], ns[N-2]);
        }else{
            swap(ns[x-2], ns[N-2]);
            swap(ns[x-1], ns[N-1]);
            swap(ns[x], ns[N]);
        }

        for(int i = 0; i < 2*N-1; i++) cout << ns[i] << endl;

    }

    return 0;
}

Measured memory_bytes: 2420
import java.util.*;

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

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        double value[] = new double[n];

        for (int i=0; i<n; i++) value[i] = sc.nextDouble();

        Arrays.sort(value);

        for (int i=0; i<n-1; i++){
            if (value[i]==0) continue;
            value[i+1] = (double)(value[i]+value[i+1])/2;
            Arrays.sort(value);
        }
        System.out.println(value[n-1]);

    }
}

Measured memory_bytes: 23252
//#include <bits/stdc++.h>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <sstream>
#include <complex>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
#define ll long long
#define ull unsigned long long

const int MAXN = 100005;
const int INF = 0x3f3f3f3f;
const ll INFLL = 9223372036854775807;
const int MOD = 1e9 + 7;
const double PI=2.0*asin(1.0);

int r, g, b;

int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);

	while(cin>>r>>g>>b){
		if((r*100+g*10+b)%4) puts("NO");
		else puts("YES");
	}

	return 0;
}


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

int main(void) {
  int n;
  cin >> n;
  vector<int> ds(n);
  for (int &d : ds) cin >> d;

  sort(ds.begin(), ds.end());
  int result = ds[n / 2] - ds[n / 2 - 1];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int a[100010];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,C,K,ans=0;
    cin>>n>>C>>K;
    for(int i=1;i<=n;i++) a[i]=gi();
    sort(a+1,a+1+n);
    for(int i=1,j=0,t=0;i<=n;i++)
	if(j<a[i]||!t) t=C-1,j=a[i]+K,++ans;
	else --t;
    cout<<ans;
    return 0;
}

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

int main(){
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll r=0, g=0, b=0;
  for (ll i=0; i<n; i++) {
    if (s[i] == 'R') r++;
    else if (s[i] == 'G') g++;
    else b++;
  }
  ll ans = r * g * b;

  for (ll m=1; m<n; m++) {
    for (ll i = 0; (i+m+m)<n; i++) {
      char x, y, z;
      x = s[i];
      y = s[i+m];
      z = s[i+m+m];
      if (x != y && y != z && z != x) ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}
	ArrayList<ArrayList<Integer>> g = new ArrayList<ArrayList<Integer>>();
	boolean used[];
	int n;
	int ans;
	public void run() {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long m=sc.nextLong();
		long ans = 0;
		long a = Math.min(n, m/2);
		ans += a;
		m -= 2*a;
		ans += m/4;
		System.out.println(ans);
		sc.close();
	}


}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(Math.min(n * a, b));

		sc.close();
	}

}




Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 998244353;

signed main() {
  int n;
  cin>>n;
  int d[n];
  for(int i=0;i<n;i++)cin>>d[i];
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)if(i!=j)ans+=d[i]*d[j];
  }
  cout<<ans/2;
  



  return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

const int INF = 1001001001;

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

int main()
{
    int n;
    cin >> n;
    vector<ll> su(n), cum(n + 1, 0);
    rep(i, n) cin >> su[i];
    rep(i, n) cum[i + 1] += su[i] + cum[i];

    map<ll, ll> mp;
    rep(i, n + 1)
    {
        mp[cum[i]]++;
    }

    ll ans = 0;
    for (auto itr : mp)
    {
        ll n = itr.second;
        ans += n * (n - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15872
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a > b) {
            System.out.println(a - 1);
        }else {
            System.out.println(a);
        }
    }
}


Measured memory_bytes: 35408
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;

int main()
{
	int i,n,flag=1,a[1005];
	char b[1005];
	scanf("%s",b);
	n=strlen(b);
	for(i=0;i<n;i++)
	{
		a[i+1]=b[i]-'0';
	}
	for(i=1;i<=n/2;i++)
	{
		if(a[i]!=a[n-i+1])
		{
			flag=0;
			break;
		}
	}
	if(flag==1) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll b(n-1);
    rep(i, n-1){
        cin >> b[i];
    }
    vll a(n, 0);
    a[0] = b[0];
    a[n-1] = b[n-2];
    repr(i, 1, n-1){
        a[i] = min(b[i-1], b[i]);
    }
    cout << accumulate(ALL(a), 0ll) << endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c,x,y = map(int, input().split())
c*=2
ans = min (a*x+b*y,c*max(x,y))
if x<y:
    ans = min(c*x+(y-x)*b,ans)
else:
    ans = min(c*y+(x-y)*a,ans)
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;



int main(){
    int n;
    cin >> n;
    if((n & -n) == n){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
//    cout << n << endl;
    int k = n;
    while(k % 4 != 3)k--;
    for(int i = 1;i < k;i++){
        cout << i << " " << i + 1 << endl;
        cout << i + n << " " << i + n + 1 << endl;
    }
    cout << k << " "<< 1 + n << endl;
    if(n % 4 == 3)return 0;
    if(n % 4 == 0){
        int r = 1;
        while(r * 2 <= n)r *= 2;
        int l = n - r;
        cout << n << " " << l + 3 <<endl; 
        cout << n + n << " " << r + 2 <<endl;
        return 0;
    }
    k++;
    cout << k+1 << " " << k << endl;
    cout << k << " " << 1 << endl;
    cout << 1 << " " << k+1+n << endl;
    cout << k+1+n << " " << k+n << endl;
    if(n % 4 == 1)return 0;
    cout << n << " " << 2 << endl;
    cout << n + n << " " << k+1+n << endl;
    return 0;
}

Measured memory_bytes: 2816
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }
    val map = mutableMapOf<Int, Long>()
    println(a.mapIndexed { idx, v ->
        val cnt = if (map.contains(v - idx)) map[v - idx] else 0L
        map[-v - idx] = if (map.containsKey(-v - idx)) map[-v - idx]!!.plus(1L) else 1
        cnt
    }.reduce { acc, v -> acc!! + v!! })
}

Measured memory_bytes: 80944
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main() {
    
    
    int n;
    cin>>n;
    ll ans=0;
    ll bn=0;
    int arr[n];
    for(int i=0;i<n;i++) {
        
        cin>>arr[i];
        ans+=arr[i];
    }
    for(int i=0;i<n;i++) {
        
      //  cin>>arr[i];
        bn+=arr[i]*(ans-arr[i]);
    }
    cout<<bn/2<<endl;
    
    
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	final int INF = Integer.MAX_VALUE / 2;
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[][] g = new int[n][n];
		
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				g[i][j] = INF;
		for (int i = 0; i < n; i++)
				g[i][i] = 0;

		for (int i = 0; i < n; i++) {
			int u = scan.nextInt();
			int k = scan.nextInt();
			for (int j = 0; j < k; j++) {
				int v = scan.nextInt();
				int c = scan.nextInt();
				g[u][v] = c;
			}
		}
		
		for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
			g[i][j] = Math.min(g[i][j], g[i][k] + g[k][j]);
		}

		for (int i = 0; i < n; i++) {
			System.out.println(i + " " + g[0][i]);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 39792
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

long N;
vector<long> A;
vector<long> B;
void solve();

int main() {
  cin >> N;
  A.resize(N + 1);
  for (int i = 0; i < N + 1; i++) {
    cin >> A[i];
  }
  B.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  solve();
}

void solve() {
  // 後ろから決まる漸化式
  long counter = 0;
  long last_index_of_B = (B.size() - 1);
  for (long i = last_index_of_B; i > -1; i--) {
    // マイナスにならないように最大限減らす
    long h1 = (A[i + 1] <= B[i]) ? A[i + 1] : B[i];
    A[i + 1] -= h1;
    B[i] -= h1;
    counter += h1;

    long h2 = (A[i] <= B[i]) ? A[i] : B[i];
    A[i] -= h2;
    B[i] -= h2;
    counter += h2;
  }
  cout << counter << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b, c; cin >> a >> b >> c;
    if (a+b+c >= 22) cout << "bust";
    else cout << "win";
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <stack>

#include <vector>

using namespace std;

typedef long long ll;

vector<set<ll> > mp;
vector<int> seen;

int main() {
    ll N,M;
    cin>>N>>M;
    
   
    mp.resize(N);
    seen.resize(N);
    
    int a,b;
    
    
    for(int i=0;i<M;++i){
        cin>>a>>b;
        --a;--b;
        mp[a].insert(b);
        mp[b].insert(a);

    }
    
    int count=1;
    
    
    
    
    for(int i=0;i<N;++i){
        stack<ll> st;
        ll x=i;
        if(seen[x]!=0)continue;
        st.push(x);
        seen[x]=count;
        
        while(!st.empty()){
            ll y=st.top();
            st.pop();
            for(set<ll>::iterator itr=mp[y].begin();itr!=mp[y].end();++itr){
                if(seen[*itr]!=0) continue;
                st.push(*itr);
                seen[*itr]=seen[x];
            }
        }
        ++count;
    }
    
    vector<ll> table(count+1,0);
    
    for(ll i=0;i!=N;++i){
        ++table[seen[i]];
    }
  
    ll ans=0;
    for(int i=1;i<=count;++i){
        ans=max(ans,table[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 32260
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	int n; scanf("%d", &n);
	vector<ll> a(n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	ll res = -1;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			ll sc = a[i] * a[j];
			string s = to_string(sc);
			bool flag = true;
			for (int k = 0; k + 1 < s.size(); k++) {
				if (s[k] + 1 != s[k + 1]) {
					flag = false;
					break;
				}
			}
			if (flag) chmax(res, sc);
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3368
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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

__attribute__ ((constructor))
void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> dis(n, vector<int>(n, inf));
    vector<int> to[n];
    map<pair<int, int>, int> mii;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        mii[{a, b}] = c;
        mii[{b, a}] = c;
        dis[b][a] = c;
        dis[a][b] = c;
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                chmin(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }
    int cnt = 0;
    for(auto u : mii){
        if(dis[u.first.first][u.first.second] < u.second)
            cnt++;
    }
    cout << cnt/2 << endl;
    return 0;
}

Measured memory_bytes: 3764
import sys
from bisect import bisect_left


read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, K, *V = map(int, read().split())

    ans = 0
    for k in range(min(N, K) + 1):
        for left in range(k + 1):
            right = k - left
            tmp = V[:left] + (V[-right:] if right else [])
            tmp.sort()

            idx = bisect_left(tmp, 0)
            if idx > K - k:
                idx = K - k

            this_ans = sum(tmp[idx:])
            if ans < this_ans:
                ans = this_ans

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>

using namespace std;

bool check(int m, int i, int A[], int n) {

	if (m == 0) {
		return true;
	}

	if (i >= n) {
		return false;
	}

	return check(m, i + 1, A, n) || check(m - A[i], i + 1, A, n);
}

int main() {

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

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

	for (int i = 0; i < q; ++i) {
		if (check(Q[i], 0, A, n)) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3152
import java.util.Scanner; 
public class Main { 
	public static void main(String... args) { 
		Scanner sc = new Scanner(System.in); 
		while(true) { 
			
			int m = sc.nextInt(); 
			int f = sc.nextInt(); 
			int r = sc.nextInt(); 
			
			if(m == -1 && f == -1 && r == -1) break; 
			
			if(m == -1 || f == -1) { 
				System.out.println('F'); 
				continue; 
			} 
			if(m + f >= 80) { 
				System.out.println('A'); 
				continue; 
			} 
			if(m + f >= 65) { 
				System.out.println('B'); 
				continue; 
			} 
			if(m + f >= 50) { 
				System.out.println('C'); 
				continue; 
			} 
			if(m + f >= 30) { 
				if(r >= 50) System.out.println('C'); 
				else System.out.println('D'); 
				continue; 
			}
			
			System.out.println('F'); 
		} 
	} 
}



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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr long double EPSL = numeric_limits<long double>::epsilon();
static constexpr const char* YES = "Yes";
static constexpr const char* NO = "No";

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  ll a, b, c;
  cin >> a >> b >> c;

  ll t = c - a - b;
  if ((c - a - b) > 0 && 4 * a * b < t * t) {
    put(YES);
    return 0;
  }

  put(NO);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


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

cnt = 0
last = 0
row = 0
for i in range(N):
    #print(i, last, A[i])
    if(last == A[i]):
        row += 1
    elif(row > 0):
        cnt += int((row+1)/2)
        row = 0
    last = A[i]
    #print(row, cnt)
cnt += int((row+1)/2)
print(cnt)
    

Measured memory_bytes: 38384
#!/usr/bin/perl
#abc083_a.pl
#Wed Jan 10 20:22:50 2018
#

use warnings;
use strict;

my $temp = <STDIN>;
chomp $temp;

my @temps = split(" ",$temp);

my $a = $temps[0];
my $b = $temps[1];
my $c = $temps[2];
my $d = $temps[3];

if ($a+$b > $c+$d){
	print "Left\n";
}elsif ($a+$b == $c+$d){
	print "Balanced\n";
}else{
	print "Right\n";
}


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

#define CIN2(a,b) long long a,b;cin >> a >> b; 
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int dfs(int,int,int,int);

int N,A,B,C;
int L[8] = {};
int main(){
    cin >> N >> A >> B >> C;
    //rep(i,N)
    for(int i = 0; i < N; i++)
    {
        cin >> L[i];
    }

    cout << dfs(0,0,0,0) << endl;
    //round-robin
    //再帰,DP,bit全探索
    
}
//n進法の作成

int dfs(int depth,int a,int b,int c){
    if(depth-N){
        int score_a = dfs(depth+1,a+L[depth],b,c)+(a?10:0);
        int score_b = dfs(depth+1,a,b+L[depth],c)+(b?10:0);
        int score_c = dfs(depth+1,a,b,c+L[depth])+(c?10:0);
        int score_z = dfs(depth+1,a,b,c);
        return min({score_a,score_b,score_c,score_z});
    }else{
        if(a*b*c){
            return abs(a-A) +abs(b-B) +abs(c-C);            
        }else{
            return 1e9;
        }
    }
}




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

int overlap(int a, int b, int al, int bl);

int main() {
  int a[4], b[4];
  int i;
  for (i = 0; i < 4; i++) {
    cin >> a[i];
  }
  for (i = 0; i < 4; i++) {
    cin >> b[i];
  }
  // cout << overlap(a[0], b[0], a[2], b[2]) << ' ' << overlap(a[1], b[1], a[3], b[3]) << endl << endl;
  cout << (a[2] * a[3] + b[2] * b[3]) - (overlap(a[0], b[0], a[2], b[2]) * overlap(a[1], b[1], a[3], b[3]) * 2) << endl;
  return 0;
}

int overlap(int a, int b, int ap, int bp) {
  int al = a, ar = a + ap;
  int bl = b, br = b + bp;
  if (al > bl) {
    swap(al, bl);
    swap(ar, br);
  }

  // cout << al << ar << bl << br << endl;
  if (bl < ar) {
    if (br < ar) {
      // cout << "br-bl";
      return br - bl;
    } else {
      // cout << "ar-bl";
      return ar - bl;
    }
  }
  return 0;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const LL INF = 1e18;
const LL MOD = 1e9 + 7;

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

void END(){cout << 1 << endl; exit(0);}

int fact(int n)
{
  if (n <= 1) return 1;
  return n * fact(n-1);
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VI p(n), q(n);
  INPUT(p); INPUT(q);
  VI v(n);
  iota(ALL(v), 1);
  VVI per(fact(n), VI(n));
  int idx = 0;
  do
  {
    VI t(n);
    REP(i, n) t[i] = v[i];
    per[idx] = t;
    idx++;
  } while(next_permutation(ALL(v)));
  int a, b;
  REP(i, fact(n))
  {
    if (p == per[i])
    {
      a = i+1;
      break;
    }
  }
  REP(i, fact(n))
  {
    if (q == per[i])
    {
      b = i+1;
      break;
    }
  }
  cout << abs(a-b) << endl;

  return 0;
}


Measured memory_bytes: 3072
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(int n, int K) {
        const long long MOD = 1000000007;
        
        int N = n * (n + 1);
        vector<vector<long long>> dp(n, vector<long long>(N + N + 1, 0));
        dp[0][N] = 1;
        auto ndp = dp;
        for (int i = 1; i <= n; ++i) {
            for (auto& V : ndp) {
                fill(V.begin(), V.end(), 0);
            }
            for (int j = 0; j < i; ++j) {
                for (int k = 0; k <= N * 2; ++k) {
                    if (j > 0) {
                        int nj = j - 1;
                        int nk = k + i + i;
                      
                        if (nk <= 2 * N) {
                            (ndp[nj][nk] += dp[j][k] * j % MOD * j % MOD) %= MOD;
                        }

                        nj = j;
                        nk = k;
       
                        (ndp[nj][nk] += dp[j][k] * 2 * j % MOD) %= MOD;
                    }

             
                    (ndp[j][k] += dp[j][k]) %= MOD;

                    {
                       
                        int nj = j + 1;
                        int nk = k - 2 * i;
                        if (nj < n && nk >= 0) {
                            (ndp[nj][nk] += dp[j][k]) %= MOD;
                        }
                    }                    
                }
            }
            swap(ndp, dp);
        }

        return dp[0][N + K];
    }

    int test (int n, int k) {
        vector<int> P(n, 0);
        iota(P.begin(), P.end(), 1);

        int res = 0;
        do {
            int sum = 0;
            for (int i = 0; i < n; ++i) {
                sum += abs(P[i] - i - 1);
            }
            if (sum == k) {
                ++res;
                for (int i = 0; i < n; ++i) {
                    cout << (i + 1) << ":" << P[i] << " ";
                }
                cout << endl;
            }
        } while (next_permutation(P.begin(), P.end()));
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    int k;
    cin >> k;
    Solution sol;
    cout << sol.solve(n, k) << "\n";

    return 0;
}

Measured memory_bytes: 4224
#include <cstdio>
#define MOD 1000000007
typedef long long ll;
int cnt[25][100005], dp[100005];
int main()
{
	// freopen("AGC016-F.in", "r", stdin);
	int n, m, ans = 1;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		cnt[--u][1 << --v]++;
		(ans += ans) %= MOD;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 1 << n; j++)
			cnt[i][j] = cnt[i][j & -j] + cnt[i][j ^ (j & -j)];
	}
	for (int i = 0; i < 1 << n; i++)
	{
		if ((i & 3) && (i & 3) != 3)
			continue;
		dp[i] = 1;
		for (int j = i - 1 & i; j; j = j - 1 & i)
		{
			if ((j & 3) && (j & 3) != 3)
				continue;
			int x = i ^ j, val = dp[x];
			for (int k = 0; k < n; k++)
			{
				if (x & (1 << k))
					val = (ll)val * ((1 << cnt[k][j]) - 1) % MOD;
				else if (j & (1 << k))
					val = (ll)val * (1 << cnt[k][x]) % MOD;
			}
			(dp[i] += val) %= MOD;
		}
	}
	printf("%d\n", (ans - dp[(1 << n) - 1] + MOD) % MOD);
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 1000000000000000000
#define int long long int
#define mod 1000000007
#define mod2 1000000000000037

int F[200001];

int Mul(int a, int b){
    return ((a % mod) * (b % mod)) % mod;
}

int fact(void){
    F[0] = 1;
    F[1] = 1;
    for( int i = 2; i < 200000; i++){
        F[i] = Mul(i ,F[i-1]);
    }
}
int square(int x){
    return (x * x) % mod;
}

int power(int x, int y){
    if( y == 0) return 1;
    else if( y == 1) return x % mod;
    else if( y % 2 == 0) return square(power(x, y/2)) % mod;
    else return square(power(x, y/2)) * x % mod;
}

int Div(int a, int b){
    return Mul(a, power(b, mod-2));
}

int C(int n, int r){
    if( n < r) return 0;
    int ret;
    ret = Div(F[n],Mul(F[n-r],F[r]));
    return ret;
}

signed main(void)
{
    fact();
    string A;
    int count[26] = {0};
    cin >> A;
    for( int j = 0; j < 26; j++){
        for( int i = 0; i < A.length(); i++){
            if(A[i] == 'a' + j) count[j]++;
        }
    }
    int ans = 0;
    for( int j = 0; j < 26; j++){
        ans -= count[j]*(count[j]-1)/2;
    }
    int tmp = A.length() * (A.length()-1);
    ans = ans + tmp/2;
    cout << ans + 1;
    return 0;
}

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

int main () {
  int N ;
  cin >> N ;
  
  int line[N] ;
  for(int i = 0 ; i < N ; i++ ) cin >> line[i] ;
  
  int ans = 0 ;
  
  bool can = true ;
  
  while(can) {
    for(int i = 0 ; i < N ; i++ ){
      if(line[i] % 2 == 0 ) {
        line[i] = line[i]/2 ;
      } else {
        can = false ;
        break ;
      }
    }
    if(!can) break ;
    ans ++ ;
  }
  cout << ans << endl ;
  
}


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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"
#define MOD 1000000000+7

#define forit(v) for(auto it = v.begin(); it != v.end(); ++it)

using namespace std;

int f(int n, int x) {
  if (n == -1) return 0;
  else return n / x + 1;
}

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

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  string o; cin >> o;
  string e; cin >> e;

  for (int i = 0; i < o.length() + e.length(); ++i) {
    if (i % 2 == 0) { // i + 1 -> odd
      cout << o[(i + 1) / 2];
    } else { // i + 1 -> even
      cout << e[(i + 1) / 2 - 1];
    }
  }
  cout << endl;
  
    
  // cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<int> a;
    for (int i = 0; i < n; ++i) {
        if(s[i] == 'o') a.emplace_back(i);
    }
    int m = a.size();
    vector<int> dp(m);
    int val = 1, cur = 0;
    map<int, int> x, y;
    for (int i = 0; i < m; ++i) {

        while(a[cur] < a[i]-c) val = max(val, dp[cur++]+1);
        dp[i] = val;
        if(dp[i] > k) return 0;
        if(!x.count(dp[i])) x[dp[i]] = i;
    }
    vector<int> dp2(m);
    val = 1, cur = m-1;
    for (int i = m-1; i >= 0; --i) {
        while(a[cur] > a[i]+c) val =  max(val, dp2[cur--]+1);
        dp2[i] = val;
        if(!y.count(dp2[i])) y[dp2[i]] = i;
    }
    for (int i = 0; i < m; ++i) {
        if(x[dp[i]] == y[dp2[i]] && x[dp[i]] == i) cout << a[i]+1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 22776
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<chrono>
#include<typeinfo>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds; 
#define lli long long int
#define fr(i,a,b) for(lli i=a;i<b;i++)
#define bfr(i,a,b) for(lli i=a;i>=b;i--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
#define tc int t;cin>>t;while(t--)
#define mod 1000000007LL
#define mod2 998244353LL
#define all(vec) vec.begin(),vec.end()  
#define ld long double
#define pb push_back
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 

lli power(lli x,lli y)
{
     lli res=1;
     while(y>0)
     {
        if(y&1)res = ((res%mod)*(x%mod))%mod;
        y>>=1;
        x= ((x%mod)*(x%mod))%mod;
     }
     return res;
}

int main()
{
    
         

    fio

    lli n;
    cin>>n;
    lli cnt=0;

    fr(i,1,n)
    fr(j,1,n)
    if(i*j<n)cnt++;else break;

    cout<<cnt;

    


  
     

    


     

     


    
      




 

return 0;}

Measured memory_bytes: 3648
let N=Int(readLine()!)!
let s=readLine()!.characters.map{$0}
let t=readLine()!.characters.map{$0}
var ans=N*2
for i in 0..<N {
  if s[i..<N] == t[0..<N-i] {
    ans=i+N
    break
  }
}
print(ans)

Measured memory_bytes: 4208
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;


int main(){
    int N,K;
    string S;
    cin >> N >> S >> K;
    for(int i=0; i<N; i++){
        if(S[i]!=S[K-1]){
            cout<<"*";
        }else{
            cout<<S[i];
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256