akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
ll x[MAX_N] = {}, y[MAX_N] = {};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    ll ans = (ll)(n-2)*(n-2);
    srep(i,2,n){
        x[i] = n;
        y[i] = n;
    }
    int xx = n;
    int yy = n;
    rep(_,q){
        int t, z;
        cin >> t >> z;
        if(t == 1){
            if(z < xx){
                ans -= yy - 2;
                srep(i,z,xx) x[i] = yy;
                xx = z;
            }else{
                ans -= x[z] - 2;
            }
        }else{
            if(z < yy){
                ans -= xx - 2;
                srep(i,z,yy) y[i] = xx;
                yy = z;
            }else{
                ans -= y[z] - 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 6772
N, M = map(int, input().split())
AC = [0 for i in range(N)]
WA = [0 for i in range(N)]
for i in range(M):
    p, v = input().split()
    p = int(p) - 1
    if v == "WA" and AC[p] == 0:
        WA[p] += 1
    elif v == "AC":
        AC[p] = 1

C = sum(AC)
F = 0
for i in range(N):
    if AC[i]: F += WA[i]
print(C, F)

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

int main() {
  int n, a, b, s = 0;
  cin >> n >> a >> b;
  for(int i = 1; i <= n; i++) {
    int t = i, d = 0;
    while(t) {
      d += t % 10;
      t /= 10;
    }
    if(a <= d && d <= b)
      s += i;
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int n;
string s[3];
int a[100][26];
int main()
{
	cin >>n;
	for (int i=0;i<3;i++)
	{
		cin >>s[i];
		for (int j=0;j<n;j++) a[j][s[i][j]-'a']++;
	}
	for (int i=0;i<n;i++) sort(a[i],a[i]+26);
	int res=0;
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<25;j++)
		{
			res+=a[i][j];
		}
	}
	cout <<res;
	return 0;
}

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


class Dice:
    """
    0:top, 1:south, 2:east, 3:west, 4:north, 5:bottom
    """

    def __init__(self, surfaces):
        self.surface = surfaces

    def roll(self, direction: str):
        if direction == "E":
            self.surface = [self.surface[3], self.surface[1], self.surface[0],
                            self.surface[5], self.surface[4], self.surface[2]]

        elif direction == "N":
            self.surface = [self.surface[1], self.surface[5], self.surface[2],
                            self.surface[3], self.surface[0], self.surface[4]]

        elif direction == "S":
            self.surface = [self.surface[4], self.surface[0], self.surface[2],
                            self.surface[3], self.surface[5], self.surface[1]]

        elif direction == "W":
            self.surface = [self.surface[2], self.surface[1], self.surface[5],
                            self.surface[0], self.surface[4], self.surface[3]]

        return

    def get_top(self):
        return self.surface[0]


def main():
    surface = [int(i) for i in input().strip().split()]
    spins = input().strip()
    dice = Dice(surface)
    for d in spins:
        dice.roll(d)
    print(dice.get_top())


if __name__ == "__main__":
    main()


Measured memory_bytes: 5628
L = input()
N = len(L)
MOD = 10**9 + 7

smaller = [0] * N
not_smaller = [0] * N

smaller[0] = 1
not_smaller[0] = 2

for i in range(1, N):
    if L[i] == "1":
        smaller[i] = 3 * smaller[i - 1] + not_smaller[i - 1]
        not_smaller[i] = 2 * not_smaller[i - 1]
    elif L[i] == "0":
        smaller[i] = 3 * smaller[i - 1]
        not_smaller[i] = not_smaller[i - 1]

    smaller[i] %= MOD
    not_smaller[i] %= MOD

ans = (smaller[-1] + not_smaller[-1]) % MOD
print(ans)


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

typedef long long ll;
ll M = 1e9 + 7;
ll n, z, s = 1, num;
string a;
int main()
{
	ll i;
	cin >> n;
	cin >> a;
	if (a[0] == 'W') {
		cout << 0 << endl;
		return 0;
	}
	z = 1;
	for (i = 1; i < a.size(); i++) {
		if (a[i] == 'B') num = 1;
		else num = 0;
		if (z % 2 == num) {
			if (z == 0) {
				cout << 0 << endl;
				return 0;
			}
			s = (s * z) % M;
			z--;
		} else z++;
	}
	if (z != 0) {
		cout << 0 << endl;
		return 0;
	}
	for (i = 1; i <= n; i++) s = (s * i) % M;
    cout << s << endl;
    return 0;
}


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

#define int long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (long long)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 500005



int32_t main(){
sp;
    int n;
    cin>>n;
    int ans=n*(n-1);
    ans>>=1;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 2e18;
const ll fact_table = 1200008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define endl "\n"
#ifdef ENJAPMA
    #undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
// const ll mod = 998244353ll;
const ll mod = 1000000007ll;
  
ll mypow(ll number1,ll number2, ll mod){
    if(number2 == 0){
        return 1ll;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

bool multicase = false;

ll n,m,num,a,b,c,d,e,h,q;
ll w, k, l, r;
ll x[500005], y[500005], z[500005];
ll dp[100005];
string s;


ll mygcd(ll a, ll b){
    if(a > b)swap(a, b);
    if(a == 0 || a == b){
        return b;
    }
    return mygcd(b % a, a);
}

void solve(){
    cin >> n >> k;
    for(ll i=1;i<=k;i++){
        ll num = k / i;
        dp[i] = mypow(num, n, mod);
    }
    for(ll i=k;i>=1;i--){
        for(ll j=2;j*i<=k;j++){
           dp[i] += mod - dp[i*j];
           dp[i] %= mod;
        }
    }
    ll ans = 0;
    for(ll i=1;i<=k;i++){
        ans += (dp[i] * i) % mod;
        ans %= mod;
    }
    p(ans);
    return;
}


int main(){
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;

    if(multicase){
        cin >> q;
    }else{
        q = 1;
    }
    while(q--){
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    
    // solve();
    return 0;

}
















Measured memory_bytes: 4440
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define N 3010
int main() {
  string s, t;
  cin >> s >> t;

  vector<vector<int>> dp(N, vector<int> (N));
  string res;

  rep(i,s.size()){
    rep(j,t.size()){
      dp.at(i+1).at(j+1) = max(dp.at(i+1).at(j),dp.at(i).at(j+1));
      if(s.at(i) == t.at(j)){
        dp.at(i+1).at(j+1) = max(dp.at(i+1).at(j+1) , dp.at(i).at(j) + 1);
      }
    }
  }

  int i = s.size();
  int j = t.size();
  while(i > 0 && j > 0){
    if(dp.at(i).at(j) == dp.at(i-1).at(j)){
      i--;
    }
    else if(dp.at(i).at(j) == dp.at(i).at(j-1)){
      j--;
    }
    else{
      i--;
      j--;
      res += s.at(i);
    }
  }
  reverse(res.begin(), res.end());
  
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 35712
#include <cstdio>
#include <queue>
#include <algorithm>

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

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;
typedef vector<int> V;

const ll inf = 1e11;

int n, m, k, s;
int e, f;
int c[100000];
V g[100000];
int d[100000];
ll h[100000];

void bfs(){
	fill_n(d, n, -1);
	queue<int> q;
	rep(i, k){
		d[c[i]] = 0;
		q.push(c[i]);
	}
	while(!q.empty()){
		int v = q.front();
		q.pop();
		for(int i: g[v]){
			if(d[i] == -1){
				d[i] = d[v] + 1;
				q.push(i);
			}
		}
	}
}

void dijkstra(){
	fill_n(h, n, inf);
	priority_queue<P, vector<P>, greater<P>> q;
	h[0] = 0;
	q.push(P(0, 0));
	while(!q.empty()){
		P v = q.top();
		q.pop();
		if(v.first > h[v.second]){
			continue;
		}
		for(int i: g[v.second]){
			if(d[i] == 0){
				continue;
			}
			int c = i == n - 1 ? 0 : d[i] <= s ? f : e;
			if(h[i] > h[v.second] + c){
				h[i] = h[v.second] + c;
				q.push(P(h[i], i));
			}
		}
	}
}

int main(){
	scanf("%d%d%d%d%d%d", &n, &m, &k, &s, &e, &f);
	rep(i, k){
		scanf("%d", &c[i]);
		--c[i];
	}
	rep(i, m){
		int a, b;
		scanf("%d%d", &a, &b);
		--a;
		--b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	bfs();
	dijkstra();

	printf("%lld\n", h[n - 1]);
	return 0;
}

Measured memory_bytes: 10704
import scala.math._
object Main extends App {
  val in = new java.util.Scanner(System.in)

  val Array(x, y, _, _, _) = in.nextLine.split(" ").map(_.toInt)
  val As, Bs, Cs = in.nextLine.split(" ").map(_.toLong)
  println((As.sorted.takeRight(x) ++ Bs.sorted.takeRight(y) ++ Cs).sorted.takeRight(x + y).sum)
}

Measured memory_bytes: 95132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, n) for(int i=1; i<=n; ++i)
#define all(obj) (obj).begin(), (obj).end()
/*using P = pair<int, int>;*/
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;

int main(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if(a >= k) cout << k << endl;
    else if(a + b >= k) cout << a << endl;
    else cout << a + b - k + a << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<sstream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;

typedef pair<int,string>P;

bool func(const P &a ,const P &b){
   if(a.first == b.first)return a.second < b.second; 
   return a.first > b.first;
   
}


void solve(int n){
   string tmp;
   map<string,int>m;
   
   for(int i = 0 ; i < n ; i++){
      getline(cin,tmp);
      stringstream s(tmp);
      while(s >> tmp){
         m[tmp]++;
      }
   }

   char c;
   cin >> c;
   getline(cin,tmp);
   
   vector<P>v;

   map<string,int>::iterator it;
   
   for(it = m.begin() ; it != m.end() ; ++it){
      if(it->first[0] == c)v.push_back(P(it->second,it->first));
   }
   
   sort(v.begin(),v.end(),func);

   if(v.size() == 0){
      cout << "NA" << endl;
      return;
   }
   
   for(int i = 0 ; i < v.size() && i < 5 ; i++){
      if(i != 0)cout << ' ';
      cout << v[i].second;
   }
   cout << endl;
}

int main(){
   string tmp;
   int n;
   while(1){
      cin >> n;
      if(!n)break;
      getline(cin,tmp);
      solve(n);
   }
   
}

Measured memory_bytes: 956
n = int(input())
ans = 'YES'
if n%2 == 1:
    ans = 'NO'
cnt = 0
for _ in range(n):
    s = input()
    if s == 'A':
        cnt += 1
    elif cnt == 0:
        ans='NO'
    else:
        cnt -= 1
if cnt != 0:
    ans = 'NO'
print(ans)



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

int main(){
    int n;
    long long int h;
    cin >> n >> h;

    vector<long long int> a(n), b(n);
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());

    int count = 0;
    for(int i=0; i<n; i++){
        if(b[i] <= a[n-1]) break;
        h -= b[i];
        count += 1;
        if(h <= 0) break;
    }
    if(h > 0) count += (h + a[n-1] - 1) / a[n-1];

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

#define MAX 200000

int max(int a,int b) { return a>b ? a: b;}
int min(int a,int b) { return a<b ? a: b;}

int main(void) {
    int R[MAX], i, n;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&R[i]);
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i=1; i<n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    printf("%d\n",maxv);

    return 0;
}


Measured memory_bytes: 2640
n, k = map(int, input().split())
h = list(map(int, input().split()))

INF = 10 ** 10
dp = [INF] * 100100

dp[0] = 0
for i in range(n):
    j = 1
    while j <= k and i + j < n:
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
        j += 1

print(dp[n - 1])

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

int main(){
    string s;
  cin >> s;
  int n=(int)s.size()+1;
  vector <unsigned long long> t;
  vector <unsigned long long> l;
  int tmp=1;
  
  rep(i,n-2){
    if(s.at(i)==s.at(i+1)){
      tmp++;
    }else{
      
      t.push_back(tmp);
      tmp=1;
      //cout << t.at((int)t.size()-1) << endl;
      if(s.at(i)=='<' && s.at(i+1)=='>'){
        l.push_back((int)t.size());
        //cout << l.at((int)l.size()-1) << endl;
      }
    }
  }
  
  t.push_back(tmp);
  //cout << t.at((int)t.size()-1) << endl;
  
  unsigned long long ans = 0;
  
  rep(i,(int)t.size()){
    ans+=(t.at(i)*(t.at(i)+1)/2);
    //cout << ans << endl;
  }
  
  
  rep(i,(int)l.size()){
    //cout << t.at(l.at(i)-1) << endl;
    //cout << t.at(l.at(i)) << endl;
    ans-=min(t.at(l.at(i)-1),t.at(l.at(i)));
  }
  
  cout << ans << endl;
 
}



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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var str = IO.GetIntList();
            var N = str[0];
            var D = str[1];

            var X = new int[N][];
            for(int i = 0; i < N; i++)
            {
                X[i] = IO.GetIntList().ToArray() ;
            }

            var ans = 0;
            for(int i = 0; i < N-1; i++)
            {
                for(int j = i+1; j < N; j++)
                {
                    int sum = 0;
                    for(int k = 0; k < D; k++)
                    {
                        sum += (int)Math.Pow(X[i][k] - X[j][k], 2);
                    }
                    var sqrt = Math.Sqrt(sum);
                    ans = sqrt - Math.Ceiling(sqrt) == 0 ? ans + 1 : ans;
                }
            }



            Console.Write(ans);
        }
    }


    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

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

int main()
{
	int i,d;
	while (scanf("%d",&d)!=EOF){
		int sum=0;
		for (i=d;i<=600-d;i+=d){
			sum+=i*i*d;
		}
		printf("%d\n",sum);
	}
	return 0;
}

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

using namespace std;

int main(){

   string s, t;
   int ans = 0;

   cin >> s >> t;

   for(int i = 0; i < s.length(); i++){
      if(s[i] != t[i]){
         ans++;
      }
   }

   cout << ans << endl;

   return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c, std::vector<long long> d){
    REP(i, N) {
        LL min_idx = -1;
        LL min_cost = INFL;

        REP(j, M) {
            LL cost = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (cost < min_cost) {
                min_idx = j+1;
                min_cost = cost;
            }
        }

        cout << min_idx << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    std::vector<long long> c(M);
    std::vector<long long> d(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&c[i]);
        scanf("%lld",&d[i]);
    }
    solve(N, M, std::move(a), std::move(b), std::move(c), std::move(d));
    return 0;
}


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

using namespace std;
#define ll long long
#define ld long double
#define mp make_pair

void print(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cout<<a[i]<<' ';
    cout<<endl;
}

void get(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cin>>a[i];
}

const ll p = 998244353;

int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    s = s%p;
    if (s<0) s+=p; 
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}


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

    int n;
    cin>>n;
    vector<vector<ll>> a(n, vector<ll>(3));
    for (int i = 0; i<n; i++) cin>>a[i][0]>>a[i][1]>>a[i][2];
    vector<vector<ll>> dp(n, vector<ll>(3));
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for (int i = 1; i<n; i++)
    {
        for (int j = 0; j<3; j++)
        {
            dp[i][j] = 0;
            for (int c = 0; c<3; c++) if (c!=j) dp[i][j] = max(dp[i][j], dp[i-1][c] + a[i][j]);
        }
    }
    
    ll res = 0;
    for (int i = 0; i<3; i++) res = max(res, dp[n-1][i]);
    cout<<res;
    
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
template<class T>bool is_prime(T IN){
    if(IN<=1)return false;
    for(long long i=2;i*i<=IN;i++){
        if(IN%i==0){
            return false;
        }
    }
    return true;
}
vector<pair<long long,long long>> primefact(long long x){vector<pair<long long,long long>> ret;for(long long i=1;i*i<=x;i++){if(x%i==0){vector<long long> alt={i,x/i};if(alt[0]==alt[1])alt[1]=1;for(long long j=0;j<alt.size();j++){if(is_prime(alt[j])){pair<long long,long long> t=make_pair(alt[j],0);while(x%alt[j]==0){x/=alt[j];t.second++;}ret.push_back(t); }}}}return ret;}
vll yakusuu(ll x){
    vll ret;
    for(ll i=1;i*i<=x;i++){
        if(x%i==0){
            ll a=x/i; ll b=i;
            if(a!=b){
                ret.push_back(a);
                ret.push_back(b);
            }
            else{
                ret.push_back(a);
            }
        }
    }
    return ret;
}
int main( ){
    ll n;
    cin>>n;
    ll res=0;
    auto pf=yakusuu(n-1);
    unordered_map<ll,int> cnt;
    for(auto v:pf){
        if(v==1)continue;
        cnt[v]++;
        res++;
    }

    vll v=yakusuu(n);
    for(auto p:v){
        if(p==1)continue;
        if(cnt.count(p))continue;
        ll dived=n;
        ll rem=0;
         while(dived%p==0){
            dived/=p;
        }
        if(dived%p==1)res++;
    }
    cout<<res<<endl;
    return 0;
}




Measured memory_bytes: 384
#include <iostream>

int disit_number(int num)
{
	if (num / 10 == 0) {
		return 1;
	}
	return disit_number(num / 10) + 1;
}

int main()
{
	int a, b;
	while (std::cin >> a >> b) {
		std::cout << disit_number(a + b) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 0
import numpy as np
from numba import njit,i8

@njit(i8[:](i8[:]),cache = True)
def calc(A):
    B = np.zeros_like(A)
    for i in range(len(A)):
        B[max(0,i - A[i])] += 1
        if i + A[i] + 1 < len(A):
            B[i + A[i] + 1] -= 1
    B = np.cumsum(B)
    return B

@njit(i8[:](i8,i8,i8[:]),cache = True)
def solve(N,K,A):
  for i in range(K):
    A = calc(A)
    if len(set(A)) == 1 and A[0] == N:
      break
  return A
  
import sys
readline=sys.stdin.readline
  
N,K = map(int,readline().split())
A = np.array(list(map(int,readline().split())))

ans = solve(N,K,A)
print(*ans)


Measured memory_bytes: 130852
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lli long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000

using namespace std;
typedef vector<lli>   vll;
typedef vector<int>   vi;
typedef set<lli>      sll;
typedef set<int>      si;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

lli i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
//
void solve()
{
	lli a,b; cin>>a>>b;
	if(a>=13) cout<<b;
	else if(a<=5) cout<<0;
	else cout<<b/2;
	cout<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstdio>
#define all(x) (x).begin(), (x).end()
using namespace std;

vector<char> split(string s) {
    vector<char> result;
    istringstream iss(s);
    string tmp;
    while (getline(iss, tmp, ' ')) {
        result.push_back(tmp[0]);
    }
    return result;
}

int main(void) {
    string S;
    int Q;
    cin>>S>>Q;
    vector<char> sv;
    for (int i = 0; i < S.size(); i++) {
        sv.push_back(S[i]);
    }
    cin.ignore();
    bool rev = false;
    for (int i = 1; i <= Q; i++) {
        string q;
        getline(cin, q);
        vector<char> vc = split(q);
        if (vc.size() == 1) {
            // reverseはコストが高いので最後の出力の時だけ実施する
            rev = !rev;
        } else {
            if (vc.at(1) == '1') {
                if (!rev) {
                    vector<char>::iterator it = sv.begin();
                    sv.insert(it, vc.at(2));
                } else {
                    sv.push_back(vc.at(2));
                }
            }
            else {
                if (!rev) {
                    sv.push_back(vc.at(2));
                } else {
                    vector<char>::iterator it = sv.begin();
                    sv.insert(it, vc.at(2));                    
                }  
            }
        }
    }
    if (!rev) {
        for (int i = 0; i < sv.size(); i++) printf("%c", sv.at(i));
    } else {
        for (int i = sv.size() - 1; i >= 0; i--) printf("%c", sv.at(i));
    }
    cout << endl;
    return 0;
}

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

int main(){
  int A,B,C,x;
  cin >> A >> B >> C >> x;
  
  int res;
  for(int a = 0; a <= A; a++){
    for(int b = 0; b <= B; b++){
      for(int c = 0; c <= C; c++){
        int total = 500 * a + 100 * b + 50 * c;
        if(total == x) res++;
      }
    }
  }
  
  cout << res << endl;
  
}

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


int main() {
  int n;
  cin >> n;
  int count = 0;
  for(int i = 1; i <= n; i += 2){
    int flag = 0;
    for(int j = i; j > 0; --j){
      if(i%j==0) ++flag;
    }
    if(flag==8) ++count;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
# include <stdio.h>
# include <string.h>
# include <queue>
# include <algorithm>
using namespace std ;

typedef struct Node
{
	int x ;
	int y ;
}NODE ;


int w, h, m ;
NODE N, NN, NNN ;
queue <NODE> que ;
int flag[1010][1010] ;
char route[1010][1010] ;
int direction[4][2] = {0, 1, 0, -1, 1, 0, -1, 0} ;

bool bounds(NODE p)
{
	if(p.x < 0 || p.y < 0 || p.x >= w || p.y >= h)
		return false ;
	return true ;
}

void bfs(char c)
{
	memset(flag, 0, sizeof(flag)) ;
	flag[N.x][N.y] = 1 ;
	que.push(N) ;
	while(!que.empty())
	{
		NN = que.front() ;
		que.pop() ;
		for(int i = 0; i < 4; i ++)
		{
			NNN.x = NN.x + direction[i][0] ;
			NNN.y = NN.y + direction[i][1] ;
			if(bounds(NNN) && route[NNN.x][NNN.y] != 'X' && flag[NNN.x][NNN.y] == 0)
			{ 
				flag[NNN.x][NNN.y] = flag[NN.x][NN.y] + 1 ;
				que.push(NNN) ;
				if(route[NNN.x][NNN.y] == c)
					N = NNN ;
			}
			
		}
	}
}
int main ()
{
	while(scanf("%d%d%d%*c", &w, &h, &m) != EOF)
	{
		for(int i = 0; i < w; i ++)
			gets(route[i]) ;
		for(int i = 0; i < w; i ++)
		{
			for(int j = 0; j < h; j ++)
			{
				if(route[i][j] == 'S')
				{
					N.x = i ;
					N.y = j ;
				}
			}
		}
		int sum = 0 ;
		for(int i = 1; i <= m; i ++)
		{
			bfs(i + '0') ;
			sum += flag[N.x][N.y] - 1 ;	
		}
		printf("%d\n", sum) ;
	}

	return 0 ;
}

Measured memory_bytes: 6032
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val arr = mutableListOf<Int>()
  for (i in 0 until  n)
    arr.add(readLine()!!.toInt())
  var max1 = -1
  var max1Idx = -1
  for (i in 0 until n) {
    val v = arr[i]
    if (max1 < v) {
      max1 = v
      max1Idx = i
    }
  }
  var max2 = -1
  for (i in 0 until n) {
    if (i == max1Idx)
      continue
    val v = arr[i]
    if (max2 < v) {
      max2 = v
    }
  }
  val pw = PrintWriter(System.out)
  for (i in 0 until n) {
    if (i == max1Idx)
      pw.println(max2)
    else
      pw.println(max1)
  }
  pw.flush()
}

fun debug(vararg objs: Any) {
  System.err.println(Arrays.deepToString((objs)))
}

Measured memory_bytes: 49044
//**************************
    //*** writer  :  Alan Hu **
    //************************
    #include<iostream>
    #include<vector>
    #include<string>
    #include<set>
    #include<map>
    #include<algorithm>
    #include<queue>
    #include<list>
    #include<stack>
    #include<cstdio>
    #include<fstream>
    #include<numeric>
    #include<functional>
    #include<utility>
    #include<memory>
    #include<cstring>
    #include<cmath>
     
    using namespace std;
         
    #define CLEAN(a,b) memset(a,b,sizeof(a))
    #define mkp make_pair
    #define pb push_back
    #define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
         
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef vector<int> vi;
     
    const int maxn=1e5+10;
     
    int n,m,tp,cnt[maxn];
    bool vis[maxn];
     
    vi v[maxn];
     
    void dfs(int x)
    {
        rept(i,0,v[x].size())
        {
            int to=v[x][i];
            if (vis[to]) continue;
            vis[to]=true;
    		cnt[++tp]=to;
            dfs(to);
    		return;
        }
    }
     
    int main()
    {
        cin>>n>>m;
        while (m--)
        {
            int x,y;
    		cin>>x>>y;
            v[x].pb(y);
    		v[y].pb(x);
        }
        tp=1;
        cnt[1]=1;
    	vis[1]=true;
    	dfs(1);
        reverse(cnt+1,cnt+tp+1);
    	dfs(1);
    	cout<<tp<<endl;
        rept(i,1,tp) cout<<cnt[i]<<" "; 
    	cout<<cnt[tp]<<endl;
        return 0;
    }

Measured memory_bytes: 6784
#include<stdio.h>

int main(){
  int n,a,b;
  int sum=0;
  int reg=0;
  scanf("%d %d %d",&n,&a,&b);
  int num;

  for(int i=1;i<=n;i++){
    num=i;
    for(int k=10000;k>0;k=k/10){
      if(num>=k){
        reg=reg+(num/k);
	num=num-(k*(num/k));
      }
    }
    if((reg>=a)&&(reg<=b)) sum=sum+i;
    reg=0;
  }

  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
N , Q = [int(i) for i in input().split()]

name = []
time = []

for i in range(N):
    n, q = ([i for i in input().split()])
    name.append(n)
    time.append(q)

count = 0
name2 = []
time2 = []

while len(name)>0:
    st = name.pop(0)
    p = int(time.pop(0))
    
    if p > Q:
        name.append(st)
        time.append(p-Q)
        count += Q
    else:
        count += p
        name2.append(st)
        time2.append(count)

for i in range(N):
    print(name2[i], time2[i])

    


Measured memory_bytes: 11108
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::cout << std::fixed << std::setprecision(10) << static_cast<double>((N + 1) / 2) / N << std::endl;
  return 0;
}

Measured memory_bytes: 256
from sys import stdin
N,A,B = [int(x) for x in stdin.readline().rstrip().split()]
if A > B or ((N == 1) and (A != B)):
  print(0)
else:
  min_ = A * (N - 1) + B
  max_ = B * (N - 1) + A
  print(max_ - min_ + 1)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define fastio 	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define unmap  	unordered_map<int,int>
#define	unset	unordered_set<int>
#define maxpq  	priority_queue<int>
#define minpq  	priority_queue<int, vector<int>, greater<int>>
#define sort(v)  sort(v.begin(),v.end());
#define sortd(v) sort(v.begin(),v.end(),greater<int>());
#define pb 		push_back
#define ll 		long long
#define ff 		first
#define ss 		second//typedef second ss;
#define foton(i,n) for(int i=0;i<n;i++)
#define	faton(i,a,n)	for(int i=a;i<=n;i++)
#define mod 	1000000007
#define endl "\n"
using namespace std;

void solve(){
	int n,m;cin>>n>>m;
	ll k;cin>>k;
	vector<ll> asum(n+1,0),bsum(m+1,0);
	for(int i=0;i<n;i++){
        int t;cin>>t;
        asum[i+1] = t+asum[i];
	}
	for(int i=0;i<m;i++){
        int t;cin>>t;
        bsum[i+1] = t+bsum[i];
	}
	int ans = 0;
	for(int i=0;i<=n;i++){
        ll t = k-asum[i];
        if(t <0 ) break;
        int j = upper_bound(bsum.begin(),bsum.end(),t)-bsum.begin()-1;
        ans = max(ans,i+j);
	}
	cout<<ans<<endl;
}

int main(){
	fastio;
	solve();
	return 0;
}



Measured memory_bytes: 6348
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
//ノート　isupperで大文字の判定　islowerで小文字の判定
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int n,m;
    std::cin >> n>>m;
    std::vector<int> a(n+1,0);
    rep(i,m){
        int q,w;
        std::cin >> q>>w;
        q--;w--;
        if(w<q)swap(q,w);
        a[q]++;a[w]--;
    }
    bool han=1;
    rep(i,n)if(a[i]%2)han=0;
    if(han)std::cout << "YES" << std::endl;
    else std::cout << "NO"<< std::endl;
}

Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut aseq = vec![0 as i64; n];
    for i in 0..n {
        aseq[i] = read();
    }
    let mut sum = 0;
    let mut sums = HashMap::<i64, usize>::new();
    for i in 0..n {
        sum += aseq[i];
        *sums.entry(sum).or_insert(0) += 1;
    }
    let mut ans = 0;
    for (v, cnt) in sums.iter() {
        let v = *v;
        let cnt = *cnt;
        if v == 0 {
            ans += cnt * (cnt + 1) / 2;
        } else {
            ans += cnt * (cnt - 1) / 2;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 17176
#include <cstdio>
#include <iostream>
#include <algorithm> 
#include <vector>
using namespace std;

int main()
{
	int a[105];
	int m,n;
	while(cin>>m>>n)
	{
		int i;
		for(i=0;i<m;i++)
		cin>>a[i];
		sort(a,a+m,greater<int>());
		int sum=0;
		for(i=0;i<n;i++)
		sum+=a[i];
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
const ll maxn = 1e5+100,mod = 1e9+7,INF = 1ll<<62;
int mark[maxn];
int main(){
	ll n,a,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		mark[a]++;
	}
	for(int i=1;i<=maxn-10;i++){
		ll temp=mark[i]+mark[i-1]+mark[i+1];
		ans=max(ans,temp);
	}
	cout<<ans;
}


Measured memory_bytes: 640
#include <stdio.h>
#define MAX_in 2000
int n,A[MAX_in];

int Solve(int i,int m){
  int res;
  if(m==0)return 1;
  if(i>=n)return 0;
  res=Solve(i+1,m)||Solve(i+1,m-A[i]);
  return res;
}

int main(){
  int q,m,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(Solve(0,m)==1)printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

ll numct[210000];
ll k[210000];
ll cnb[210000];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	int q;
	cin>>s>>q;

	bool dire = true;
	for(int i=0; i<q; i++){
		int t,f;string ss;
		cin>>t;

		if(t ==1){
			if(dire){
				dire = false;
			}else {
				dire =true;
			}
		}else if(dire){
			cin>>f>>ss;
			if(f ==1){
				s.insert(0,ss);
			}else {
				s +=ss;
			}
		}else {
			cin>>f>>ss;
			if(f ==1){
				s +=ss;
			}else {
				s.insert(0,ss);
			}
		}

/*		cout<<s<<endl;*/
	}

	if(!dire){
		reverse(s.begin(),s.end());
	}

	cout<<s<<endl;
}


Measured memory_bytes: 912
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N = ir()
memo = [{} for _ in range(N+1)]

def ok(last4):
    if last4.find('AGC') != -1:
        return False
    for i in range(3):
        s = list(last4)
        s[i], s[i+1] = s[i+1], s[i]
        if ''.join(s).find('AGC') != -1:
            return False
    return True

def dfs(i, last3):
    if i == N:
        return 1
    if last3 in memo[i]:
        return memo[i][last3]
    ret = 0
    for la in 'AGCT':
        if ok(last3+la):
            ret += dfs(i+1, last3[1:]+la)
    ret %= MOD
    memo[i][last3] = ret
    return ret

answer = dfs(0, 'TTT')
print(answer % MOD)


Measured memory_bytes: 3828
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N, K = [int(i) for i in input().strip().split()]
    prices = sorted([int(i) for i in input().strip().split()])

    return sum(prices[:K])


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 9232
from itertools import permutations

N, *PQ = map(int, open(0).read().split())
P, Q = tuple(PQ[:N]), tuple(PQ[N:])

A = tuple(permutations(range(1, N + 1)))
a = A.index(P)
b = A.index(Q)

print(abs(a - b))

Measured memory_bytes: 7992
// Pair

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int main() {
    int k;
    cin >> k;

    int even, odd;
    if (k % 2 == 0) {
        even = k / 2;
        odd = k / 2;
    } else {
        even = (k - 1) / 2;
        odd = (k - 1) / 2 + 1;
    }

    cout << even * odd << endl;

    return 0;
}


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

public class Main {
 
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		double ans = 0;
		ArrayList<Double> numList = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			numList.add(sc.nextDouble());
		}
		ArrayList<Double> expectList = new ArrayList<>();
		expectList.add((1 + numList.get(0)) / 2);
		for(int i = 1; i < n; i++) {
			expectList.add(((1 + numList.get(i)) / 2) + expectList.get(i - 1));
		}

		ans = expectList.get(k - 1);
		for(int i = 0; i < n - k; i++) {
			double temp = expectList.get(i + k) - expectList.get(i);
			if(ans < temp) {
				ans = temp;
			}
		}

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

}

Measured memory_bytes: 73352
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h = 0, w = 0, k = 0, res = 0;
	cin >> h >> w >> k;
	vector<vector<char> > s(h, vector<char>(w));
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
			cin >> s[i][j];
	for (int i = 0; i < (1 << h); ++i)
		for (int j = 0; j < (1 << w); ++j)
		{
			int ct = 0;
			for (int x = 0; x < h; ++x)
				for (int y = 0; y < w; ++y)
				{
					if (s[x][y] == '#' && ((i >> x) & 1) == 0 && ((j >> y) & 1) == 0)
						++ct;
				}
			if (ct == k)
				++res;
		}
	cout << res << endl;
}

Measured memory_bytes: 3608
#include <cstdio>

using namespace std;

bool is_prime(int n) {
    if (n < 2) return false;
    for (int i=2; i*i<=n; ++i)
        if (n%i == 0)
            return false;

    return true;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    int res=0;
    for (size_t i=0; i<n; ++i) {
        int a;
        scanf("%d", &a);

        if (is_prime(a))
            ++res;
    }

    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 2700
import numpy as np
def forbidden_list():
    X, N = map(int,input().split())
    p = list(map(int, input().split()))
    lis = np.array([1 for i in range(102)])
    lis[p] = 0
    index = X
    ma = 102 - X
    for i in range(max(X,ma)):
        if index - i >= 0 and lis[index-i]:
            print(index-i)
            break
        elif index + i <= 101 and lis[index + i]:
            print(index + i)
            break
    
forbidden_list()

Measured memory_bytes: 27124
package main

import (
	"bufio"
	"fmt"
	"os"
)

const Mod = int(1e9) + 7

func main() {
	S = ReadString()

	baser = make([]int, len(S))
	b := 1
	for i := 0; i < len(S); i++ {
		baser[i] = b
		b *= 10
		b %= 13
	}

	memo = make([][]*int, len(S))
	for i := 0; i < len(S); i++ {
		memo[i] = make([]*int, 13)
	}
	fmt.Println(recur(0, 0))
}

var S string
var baser []int
var memo [][]*int

func recur(i int, r int) int {
	if i == len(S) {
		if r == 5 {
			return 1
		}
		return 0
	}
	if memo[i][r] != nil {
		return *memo[i][r]
	}
	ans := 0
	if S[i] == '?' {
		for x := 0; x <= 9; x++ {
			ans += recur(i+1, (r*10+x)%13)
			ans %= Mod
		}
	} else {
		x := int(S[i] - '0')
		ans += recur(i+1, (r*10+x)%13)
		ans %= Mod
	}
	memo[i][r] = &ans
	return ans
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 34712
import sys
from collections import defaultdict
class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.rank = [0]*n
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  def unit(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    elif self.rank[x]<self.rank[y]:
      self.par[x] = y
    elif self.rank[y]<self.rank[x]:
      self.par[y] = x
    else:
      self.par[y] = x
      self.rank[x] += 1
  def same(self, x, y):
    return self.find(x)==self.find(y)
  
N,M,*L = map(int, open(0).read().split())
A = L[:N]
U = UnionFind(N)
dic = defaultdict(list)
used = [False]*N
ans = 0
for x,y in zip(*[iter(L[N:])]*2):
  U.unit(x,y)
for i in range(N):
  dic[U.find(i)].append((A[i],i))
if len(dic.keys())==1:
  print(0)
  sys.exit()
for k in dic.keys():
  dic[k].sort()
  ans += dic[k][0][0]
  used[dic[k][0][1]] = True
B = sorted((c,i) for i,c in enumerate(A))
cnt = len(dic.keys())-2
for i in range(N):
  if cnt==0:
    break
  if used[B[i][1]]:
    continue
  ans += B[i][0]
  cnt -= 1
if cnt > 0:
  print('Impossible')
else:
  print(ans)

Measured memory_bytes: 51284
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		Arrays.sort(h);
		
		int ans = 1000000000;
		for(int i = 0; i <= n-k; i++) {
			ans = Math.min(ans, h[i+k-1]-h[i]);
		}
		System.out.println(ans);
	}
}


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

typedef long long ll;
ll MOD = 1e9+7;

ll dp[100001];
ll h[100000];
int main()
{
	int n;
	int k;
	int ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>h[i];
	fill(dp,dp+100001,1e14-1);
	dp[0]=0;
	dp[1]=0;
	dp[2]=abs(h[1]-h[0]);
	for(int i=3;i<n+1;i++)
	{
		ll tmp=1e14-1;
		for(int j=1;j<k+1;j++)
		{
			if(i-j==0)
				break;
			
			tmp=min(tmp,dp[i-j]+abs(h[i-1]-h[i-j-1]));	
		}
		dp[i]=tmp;
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long inf = 100000000000000;
typedef pair<int, int> P;
int main() {
	int n;
	cin >> n;
	int i;
	vector<int> a(n),b(n);
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (i = 0; i < n; i++) {
		cin >> b[i];
	}
	vector<int> P(n);
	for (i = 0; i < n; i++) {
		P[i] = i + 1;
	}
	int F;
	int S;
	int count = 0;
	do {
		count++;
		if (P == a) F = count;
		if (P == b) S = count;
	} while (next_permutation(P.begin(),P.end()));
	cout << abs(F - S);
	return(0);
}

Measured memory_bytes: 256
def gcd(a,b):
  x = max([a,b])
  y = min([a,b])
  while y:
    x, y = y, x % y
  return x

# x * y = lcm(x, y) // gcd(x, y)より
def lcm(x, y):
  return x * y // gcd(x, y)
A,B = map(int, input().split())

print(lcm(A,B))

Measured memory_bytes: 3060
#-*-coding:utf-8-*-

def main():
    find_word=input()
    text=[]
    counter=0
    while True:
        text=input()
        if text =="END_OF_TEXT":
            break
        text=text.lower()
        for string in text.split():
            if string==find_word:
                counter+=1
    print(counter)

if __name__=="__main__":
    main()


Measured memory_bytes: 5560