akhauriyash/Code-Regression huggingface dataset:
L,N = list(map(int,input().split()))
X=[]
Y=[]
SX=[0]
SY=[0]
sx=0
sy=0
for i in range(N):
   x=int(input())
   X.append(x)
   sx+=x
   SX.append(sx)
   Y.append(L-x)
   sy+=L-x
   SY.append(sy)   

max_score=0   
for i in range(N):
    if i>N-i-1:
        max_score=max(2*(SX[i]-SX[2*i-N])+2*(SY[N]-SY[i+1])+Y[i],max_score)
    elif i<N-i-1:
        max_score=max(2*(SX[i]-SX[0])+2*(SY[2*i+2]-SY[i+1])+X[i],max_score)

        
    ind = min(i,N-i-1)
    max_score=max(2*(SX[i]-SX[i-ind])+2*(SY[i+ind+1]-SY[i+1])+X[i],max_score)
    max_score=max(2*(SX[i]-SX[i-ind])+2*(SY[i+ind+1]-SY[i+1])+Y[i],max_score)


print(max_score)

Measured memory_bytes: 38544
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
int n,K;
ll dp[55][55][5005];
int main()
{
    scanf("%d%d",&n,&K);
    if(K&1){printf("0\n");return 0;}
    dp[0][0][0] = 1;
    for(int i=0;i<n;i++)
        for(int j=0;j<=i;j++)
        for(int k=0;k<=n*n;k++)
    {
        dp[i+1][j][k+j]=(dp[i+1][j][k+j]+dp[i][j][k]*(2*j+1))%mod;
        if(j>0)
            dp[i+1][j-1][k+j-1]=(dp[i+1][j-1][k+j-1]+dp[i][j][k]*j*j)%mod;
        dp[i+1][j+1][k+j+1]=(dp[i+1][j+1][k+j+1]+dp[i][j][k])%mod;
    }
    printf("%lld\n",dp[n][0][K/2]);
}


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

int d[100][100];
int main(){
	int n;
	while(cin >> n && n){
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < n ; j++)
				cin >> d[i][j];
		int cnt[100][100] = {0};

		for(int i = 0 ; i < n ; i++){
			int hey = *min_element(d[i],d[i]+n);
			for(int j = 0 ; j < n ; j++) if(d[i][j] == hey) cnt[i][j]++;
		}
		for(int i = 0 ; i < n ; i++){
			int k = 0;
			for(int j = 0 ; j < n ; j++) if( d[j][i] > d[k][i]) k = j;
			int f = 0;
			for(int j = 0 ; j < n ; j++) if(d[k][i] == d[j][i]) cnt[j][i]++;
		}
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < n ; j++)
				if(cnt[i][j] == 2){ cout << d[i][j] << endl;goto exit;}
		cout << 0 << endl;
		exit:;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0};
const int INF = 1e9+101;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(ll i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 998244353
typedef long long ll;
typedef pair<ll,ll> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}

int main() {
    int N;
    cin >> N;
    vi a(N);
    rep(i,N) {
        cin >> a[i];
    }
    sort(all(a));
    int bef = a[0];
    int nxt = INF;
    while(true){
        //printf("%d %d\n",bef, nxt);
        rep(i,N){
            if(a[i]%bef == 0){
                a[i] = bef;
                nxt = min(nxt, bef);
            }
            else{
                a[i] = a[i]%bef;
                nxt = min(a[i], nxt);
            }
        }
        if(nxt == bef){
            break;
        }
        bef = nxt;
        nxt = INF;
    }
    cout << nxt << endl;
    return 0;
}

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

//n
int main() {
    int matrix[3][3];
    map<int,pair<int,int>>map;
    for(int i = 0;i < 3;i++){
        for(int j = 0;j < 3;j++){
            cin >> matrix[i][j];
            map[matrix[i][j]] = pair<int,int>(i,j);
        }
    }
    int t;
    cin >> t;
    while (t--){
        int i;
        cin >> i;
        if(map.count(i) != 0){
            auto p = map[i];
            matrix[p.first][p.second] = -1;
        }
    }
    bool find = false;
    for(int i = 0;i < 3;i++){
        if(matrix[i][0] == -1 && matrix[i][1] == -1 && matrix[i][2] == -1)
            find = true;
        if(matrix[0][i] == -1 && matrix[1][i] == -1 && matrix[2][i] == -1)
            find = true;
    }
    if(matrix[0][0] == -1 && matrix[1][1] == -1 && matrix[2][2] == -1)
        find = true;
    if(matrix[0][2] == -1 && matrix[1][1] == -1 && matrix[2][0] == -1)
        find = true;
    if(find)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

n = int(input())
a = list(map(int, input().split()))
cnt = [0, 0, 0]
for ai in a:
    cnt[ai-1] += 1
p, q, r = cnt[0], cnt[1], cnt[2]

dp = [[[0.0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]

for k in range(r + 1):
    for j in range(r + q + 1):
        for i in range(n + 1):
            if not (0 < i + j + k <= n):
                continue
            tmp = 0.0
            if i > 0:
                tmp += dp[i - 1][j][k] * i
            if j > 0:
                tmp += dp[i + 1][j - 1][k] * j
            if k > 0:
                tmp += dp[i][j + 1][k - 1] * k
            tmp += n
            dp[i][j][k] = tmp / (i + j + k)

print(dp[p][q][r])


Measured memory_bytes: 254088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    while(true) {
      String tmp = br.readLine();
      if (tmp == null || tmp.isEmpty()) {
        break;
      }
      List<Long> list = Arrays.asList(tmp.split(" ")).stream().map(i -> Long.parseLong(i)).sorted().collect(Collectors.toList());
      long koyakusu = getKoyakusu(list.get(0), list.get(1));
      long kobaisu = getKobaisu(list.get(0), list.get(1));
      System.out.printf("%d %d\n", koyakusu, kobaisu);
    }
  }

  // ??¬?´???°?????????
  private static long getKoyakusu(long a, long b) {
    long candidate = a;
    while (b % a != 0) {
      candidate = b % a;
      b = a;
      a = candidate;
    }
    return candidate;
  }

  // ??¬?????°?????????
  private static long getKobaisu(long a, long b) {
    return (a * b) / getKoyakusu(a, b);
  }
}

Measured memory_bytes: 31232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    int x = 0;
    int tmp = n, t, p = 1;
    while(tmp) x++, t = tmp % 10, tmp /= 10, p *= 10;
    p /= 10;
    int ans = 0;
    for(int i = 1; i < x; i++) {
        if(i == 1) ans += 9;
        if(i == 3) ans += 900;  //100~999
        if(i == 5) ans += 90000;
    }
    if(x & 1) {
        ans += n - p + 1;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
x,k,d = map(int,input().split())
flg = 1
if x < 0:
    x = -1*x
    flg = -1

if x//d <= k:
    if (k - (x//d))%2 == 0:
        print(abs((x%d*flg)))
    else:
        print(abs((x%d-d)*flg))
else:
    print(abs((x-d*k)*flg))

Measured memory_bytes: 9196
#include<iostream>
#include<vector>
#include<algorithm>
#define int long long
using namespace std;
const int N=2e5+2;
int head[N],color[N];
vector<pair<int,pair<int,int> > > lis;
int findd(int x){
	if(head[x]<0){
		return x;
	}
	int y=findd(head[x]);
	head[x]=y;
	return y;
}
void unionn(int x,int y){
	x=findd(x);
	y=findd(y);
	head[x]+=head[y];
	head[y]=x;
}
bool samee(int x,int y){
	return findd(x)==findd(y);
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,m,j,k,l,sum=0,num,hihi=0;
	cin>>n>>m>>num;
	for(i=1;i<=n;i++){
		cin>>color[i];
		if(!color[i]){
			color[i]=i+num;
		}
	}
	for(i=1;i<=n+num;i++){
		head[i]=-1;
	}
	for(i=1;i<=m;i++){
		cin>>j>>k>>l;
		lis.push_back({l,{color[j],color[k]}});
	}
	sort(lis.begin(),lis.end());
	for(i=0;i<lis.size();i++){
		if(hihi==num-1){
			break;
		}
		if(!samee(lis[i].second.first,lis[i].second.second)){
			sum+=lis[i].first;
			unionn(lis[i].second.first,lis[i].second.second);
			hihi++;
		}
	}
	if(hihi<num-1){
		cout<<-1;
		return 0;
	}
	cout<<sum;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    string st;
    cin >> st;

    bool fl = true;
    rep(i, st.size()) {
        if (st[0] != st[i]) fl = false;
    }
    if (fl) {
        std::cout << 0 << std::endl;
        return 0;
    }
    vi cnt(n+1, 0);
    rep(i, st.size()) {
        cnt[i+1] = (int)(st[i] == '#');
    }
    Rep(i, n+1) {
        cnt[i] += cnt[i-1];
    }

    int ans = cnt[n];
    rep(i, n) {
        ans = min(ans, cnt[i] + ((n-i)-(cnt[n]-cnt[i])));
        //cout << i << " : " << cnt[i] + ((n-i)-(cnt[n]-cnt[i])) << endl;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 2196
N = int(input())
H = [int(x) for x in input().split()]
cnt = [0 for _ in range(N)]

for i in range(1, N):
    if H[i] <= H[i-1]:
        cnt[i] = cnt[i-1] + 1
    else:
        cnt[i] = 0
print(max(cnt))

Measured memory_bytes: 14224
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
// initialize: UnionFind UF(N)

class UnionFind {                                              // OOP style
private:
	vector<int> p, rank, setSize;
	// p = path toward the root of disjoint set; p[i] = i means it is root
	// rank = upper bound of the actual height of the tree; not reliable as accurate measure
	// setSize = size of each disjoint set

	int numSets;
public:
	UnionFind(int N) {
		setSize.assign(N, 1);
		numSets = N;
		rank.assign(N, 0);
		p.assign(N, 0);
		for (int i = 0; i < N; i++) p[i] = i;	// each belongs to its own set
	}

	int findSet(int i) {
		return (p[i] == i) ? i : (p[i] = findSet(p[i]));		// path compression: cut short of the path if possible
	}

	bool isSameSet(int i, int j) {
		return findSet(i) == findSet(j);
	}

	void unionSet(int i, int j) {
		if (!isSameSet(i, j)) {
			numSets--;
			int x = findSet(i), y = findSet(j);
			// rank is used to keep the tree short
			if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
			else {
				p[x] = y; setSize[y] += setSize[x];
				if (rank[x] == rank[y]) rank[y]++;
			}
		}
	}

	int numDisjointSets() {		// # of disjoint sets
		return numSets;
	}

	int sizeOfSet(int i) {		// size of set
		return setSize[findSet(i)];
	}
};


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

	int n, m, i, j, k, x, y, z, ans;
	cin >> n >> m;

	UnionFind uf(n + 1);
	for (i = 0; i < m; i++) {
		cin >> x >> y >> z;
		uf.unionSet(x, y);
	}

	ans = uf.numDisjointSets() - 1;
	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    long maxa=0, maxb;

    long i;
    for(i=0; i<n; i++) {
        long a,b;
        scanf("%ld%ld", &a, &b);
        if(maxa<a) {
            maxa=a; maxb=b;
        }
    }

    printf("%ld\n", maxa+maxb);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

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

  vector<int> a(n);
  rep(i,n) cin >> a.at(i);

  int maxdis = 0;
  int maxdisi;
  rep(i, n){
    int a1 = a.at(i);
    int next=i+1;
    if(i+1>=n) next = 0;
    int a2 = a.at(next);

    int dis;
    if(a2 > a1){
      dis = a2 - a1;
    }else{
      dis = a2 + k-a1;
    }

    if(dis > maxdis){
      maxdis = dis;
      maxdisi = next;
    }
  }

  int a1 = a.at(maxdisi);
  int end = maxdisi - 1;
  if(end<0) end=n-1;
  int a2 = a.at(end);

  int dis;
  if(a2 > a1){
    dis = a2 - a1;
  }else{
    dis = a2 + k-a1;
  }

  cout << dis << endl;
}


Measured memory_bytes: 1024
using System;

namespace AOJ.Volume0
{
    public class MagicSquare
    {
        private class Position
        {
            public int X { get; set; }
            public int Y { get; set; }
        }

        private static int n;
        private static int[,] map;

        public static int Main()
        {
            while (true)
            {
                n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }

                map = new int[n, n];
                // ??????????????????(?¨???????x????????????y)
                int x = -1;
                int y = -1;

                int num = 1;
                while (true)
                {
                    if(x < 0)
                    {
                        // ?????????
                        x = n / 2;
                        y = (n / 2) + 1;
                    }
                    else
                    {
                        var p = new Position() { X = x, Y = y };
                        p = Move(p, true);
                        x = p.X;
                        y = p.Y;
                    }

                    map[y, x] = num;
                    num++;
                    if(num > n * n) { break; }
                }
                // ??????
                for(int i = 0; i < n; i++)
                {
                    string line = "";
                    for(int j = 0; j < n; j++) { line += map[i, j].ToString().PadLeft(4); }
                    Console.WriteLine(line);
                }
            }
            return 0;
        }

        private static Position Move(Position pos, bool first)
        {
            int x = pos.X;
            int y = pos.Y;
            if (first)
            {
                // ???????????????????§????
                x++;
                y++;
            }
            else
            {
                // ????????\????????????????§????
                x--;
                y++;
            }

            // ????????????????????´???????????????
            if (x == n) { x = 0; }
            // ????????????????????´???????????????
            if (x < 0) { x = n - 1; }
            // ????????????????????´????????????
            if (y == n) { y = 0; }
            // ????????????????????´????????????
            if (y < 0) { y = n - 1; }

            // ??¢???????????£???????????´????????´?????¢???
            if (map[y, x] != 0)
            {
                var p = new Position() { X = x, Y = y };
                return Move(p, false);
            }

            var ret = new Position();
            ret.X = x;
            ret.Y = y;
            return ret;
        }
    }
}

Measured memory_bytes: 9156
N = int(input())
count = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for _ in range(N):
    count[input()] += 1

print("AC x " + str(count["AC"]))
print("WA x " + str(count["WA"]))
print("TLE x " + str(count["TLE"]))
print("RE x " + str(count["RE"]))


Measured memory_bytes: 69796
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[21];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	int ans=0;
	for(int i=1;i<N-1;i++){
		vector<int> v;
		for(int j=i-1;j<=i+1;j++){
			v.push_back(A[j]);
		}
		sort(v.begin(),v.end());
		if(v[1]==A[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;

using namespace std;


int main(int argc, char* argv[])
{
    char str[55]={0};
    scanf("%s", str);

    int a[4];
    int i;
    for(i=0; i<4; i++) {
        a[i]=str[i]-'0';
    }
    int tmp0 =a[0]*10+a[1];
    int tmp1 =a[2]*10+a[3];
    if(tmp0>0 && tmp0<13) {
        if(tmp1>0 && tmp1<13) {
            printf("AMBIGUOUS\n");
        }
        else {
            printf("MMYY\n");
        }
    }
    else {
        if(tmp1>0 && tmp1<13) {
            printf("YYMM\n");
        }
        else {
            printf("NA\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int const INF = 10001;

int main() {
    int n, T;
    int c, t;
    int result = INF;

    cin >> n >> T;

    for(int i = 0; i < n; i++) {
        cin >> c >> t;

        if(t <= T) {
            if(c < result) {
                result = c;
            }
        }
    }

    if(result == INF) {
        cout << "TLE" << endl;
    } else {
        cout << result << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=55;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin>>s;
    cout<<(s=="ABC"?"ARC":"ABC")<<'\n';
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> R(N);
  for(int i = 0; i < N; ++i) cin >> R[i];
  vector<int> minVal(N);
  int ans = numeric_limits<int>::min();
  minVal[0] = R[0];
  for(int i = 1; i < N; ++i) {
    ans = max(ans, R[i] - minVal[i - 1]);
    minVal[i] = min(minVal[i - 1], R[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2580
S = input()
T = input()

best_score = 0
for i in range(len(S) - len(T) + 1):
    score = 0
    for j in range(len(T)):
        if S[i + j] == T[j]:
            score += 1
    best_score = max(score, best_score)

print(len(T) - best_score)


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

int main(){
    string s,t;
    cin>>s>>t;

    int ans=0;

    if(s[0]==t[0])ans++;

    if(s[1]==t[1])ans++;

    if(s[2]==t[2])ans++;

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
s1 = int(s[:2])
s2 = int(s[2:])
MMYY = False
YYMM = False
if 0<s1<13:
    MMYY = True
if 0<s2<13:
    YYMM = True
if MMYY and YYMM:
    print('AMBIGUOUS')
elif MMYY:
    print('MMYY')
elif YYMM:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		sc.close();
		int x = 800 * N;
		int y = (N / 15) * 200;
		int answer = x - y;
		System.out.println(answer);
	}
}


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

const int N=1e5;

int h[N+5];

int mem[N];

long long  dp(int i){

if (i==n+1){

    return 1e10;

}
if (i==n){

    return 0;

}
if (mem[i]!=-1){

    return mem[i];

}

long long path1=abs(h[i]-h[i+1])+dp(i+1);

long long path2=abs(h[i]-h[i+2])+dp(i+2);

mem[i]=min(path1,path2);

return mem[i];



}

int main(){

scanf("%d",&n);



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

memset(mem , -1 , sizeof mem);

printf("%lld\n",dp(1));

}



Measured memory_bytes: 4096
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <bits/stdc++.h>

using namespace std;
#define lli long long int
#define rep(i, n) for(in i = 0; i < (int)n; i++)

int main()
{
    int K, A, B;
    scanf("%d", &K);
    scanf("%d %d", &A, &B);

    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            printf("OK\n");
            return 0;
        }
    }


    printf("NG\n");

    return 0;
}

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

int main(void){
    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll> a(n+1,0),b(m+1,0),A(n+1,0),B(m+1,0);
    rep(i,n){
        cin>>a[i];
        A[i]=A[i-1]+a[i];
    }
    rep(i,m){
        cin>>b[i];
        B[i]=B[i-1]+b[i];
    }
    ll ans=0,i,j=m;
    for(i=0;i<=n;i++){
        while(A[i]+B[j]>k && j>0){
            j--;
        }
        if(A[i]+B[j]<=k)ans=max(ans,i+j);
        else break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9576
#include <stdio.h>
#include <math.h>

#define PI 3.141592653589793
int main()
{
    double a,b,x,x1;
    scanf("%lf %lf %lf",&a,&b,&x);

    x1 = x / (a * a);
    if(2.0 * x >= a * a * b)
    {
        printf("%.12lf",atan((b - x1) * 2.0 / a) * 180.0 / PI);
    }
    else
    {
        double x2 = x * 2.0 / (b * a);
        printf("%.12lf",atan(b / x2) * 180.0 / PI);
    }
    
}


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

int main(){
    long int a,b,d,r;
    double f;
    cin >> a;
    cin >> b;

    d = a/b;
    r = a%b;
    f = (double)a/(double)b;

    cout << d << " " << r << " " ;
    printf("%.5lf\n",f);
}


Measured memory_bytes: 3224
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.next().split("");
    int ans = 0;
      
      for(String s : S){
        if(s.equals("1")){
        	ans++;
        }
      }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    
    // a+b = l*K, b = l*K - a
    // b+c = m*K, l*K + n*K - 2*a = m*K
    // c+a = n*K, c = n*K - a
    //
    // (l+n-m)*K = 2*a
    // x*K = 2*a
    // y*K = 2*b
    // z*K = 2*c
    

    int sum1 = N/K;

    int sum2 = 0;
    if (K%2 == 0) {
      sum2 = (N+K/2)/K;
    }
    
    System.out.println((long)sum1*sum1*sum1 + (long)sum2*sum2*sum2);
  }
}

Measured memory_bytes: 23892
n,k = map(int,input().split())
A = list(map(int,input().split()))
dp = [-1]*(k+1) #dp[i]:i個の山の勝敗 -1の時後手の勝ち
for i in range(1,k+1):
    for a in A:
        if a <= i and dp[i-a] == -1:
            dp[i] = 1
            break

#print(dp)

print("First" if dp[k] == 1 else "Second")

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

using ll =long long;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b == 0){
       return(b);
   }else{
       return(gcd(b, a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a * b / gcd(a, b);
}

//文字列→数列
//string S;int A=atoi(S.c_str());
//数列→文字列
//int A;string S=to_string(A);
//数字判定　isdigit(a)
//pair宣言　pair<int,int> p(5,7);
//

int main(){
cout<<fixed<<setprecision(10);
  
string T;
  cin>>T;
  for(int i=0;i<T.size();i++){
    cout<<'x';
  }
  cout<<endl;
  
  
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

void func(string &s){

    if(s.back()=='1'){
        cout<<-1<<endl;
        return;
    }

    lli size = s.size();
    s.pop_back();
    REP(i,0,s.size()){
        if(s[i] != s[s.size()-1-i]){
            cout<<-1<<endl;
            return;
        }
    }
    if(s[0]=='0' || s[s.size()-1] == '0'){
        cout<<-1<<endl;
        return;
    }

    lli left = 0;
    REP(i,0,size-1){
        cout<<left+1<<" "<<i+2<<endl;
        if(s[i]=='1')left = i + 1;
    }
    

}

int main(){
    // cout << fixed << setprecision(5);

    string s;
    cin>>s;
    func(s);
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/
signed main(){
  double a,b,h,m;
  cin>>a>>b>>h>>m;
  if(12*m==60*h+m){
    cout<<abs(a-b)<<endl;
    return 0;
  }
  if(abs(12*m-60*h+m)==360){
    cout<<a+b<<endl;
    return 0;
  }

  double fun=6*m,ji=30*h+m/2;
  double deg=abs(fun-ji);
  
  double pi=acos(-1);

  double rad=deg*pi/180;

  double ans=a*a+b*b-2*a*b*cos(rad);
  ans=sqrt(ans);

  cout<<setprecision(20)<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 4292
#include<iostream>
using namespace std;
 
int main(){
	int a,b,x,y,z;
  	cin >> a >> b;
  	x = a + b;
  	y = a - b;
  	z = a * b;
  	if(y < x && z < x){
    	cout << x << endl;
    }
  	if(x < y && z < y){
    	cout << y << endl;
    }
  	if(x < z && y < z){
    	cout << z << endl;
    }
  	if(x == y && z == y){
    	cout << x << endl;
    }
  	if(x == y && z < y){
    	cout << x << endl;
    }
  	if(x == z && y < x){
    	cout << x << endl;
    }
  	if(y == z && x < y){
    	cout << y << endl;
    }
  	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		ArrayList<Integer> result = new ArrayList<Integer>(); 
		Scanner sc = new Scanner(System.in);
		while(true){
			int point =0;
			int n = sc.nextInt();
			int[] score = new int[n];
			if(n==0){
				break;
			}
			
			for(int i=0;i<n;i++){
			score[i] = sc.nextInt();
			}
			Arrays.sort(score);
			for(int i=1;i<n-1;i++){
				point += score[i];
			}
			result.add(point/(n-2));
		}
		for(int i=0;i<result.size();i++){
			System.out.println(result.get(i));
		}
	}
}

Measured memory_bytes: 29712
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, M, X, Y;
  std::cin >> N >> M >> X >> Y;
  std::vector<int> x(N+1);
  std::vector<int> y(M+1);
  range(i, N) std::cin >> x[i];
  range(i, M) std::cin >> y[i];
  x[N] = X;
  y[M] = Y;
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  if(x[N]<y[0]) std::cout << "No War" << '\n';
  else std::cout << "War" << '\n';
  return 0;
}


Measured memory_bytes: 512
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        mut a: isize,
        mut v: isize,
        mut b: isize,
        mut w: isize,
        t: isize,
    }
    if b < a {
        if b - t * w >= a - t * v {
            println!("YES");
        } else {
            println!("NO");
        }
    } else {
        if b + t * w <= a + t * v {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}


Measured memory_bytes: 2084
N,K=map(int,input().split())
V=list(map(int,input().split()))+[-10**8]
ans=0
for i in range(1,K+1):
    for j in range(1,min(i+1,N+1)):
        W=sorted(V[:j]+V[-min(i,N)-1+j:],reverse=True)[:-1]
        for k in range(0,K-i):
            if W[-1]<0:
                W.pop()
                if W==[]:
                    break
            else:
                break
        if ans<sum(W):
            ans=sum(W)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#define ll long long int
#define rep(i,n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair

using namespace std;

int main(){
    
    ll n,p;
    cin >> n >> p;
    map<ll,ll> m;
    ll i = 2;
    ll tmp = p;
    if(n == 1){
        cout << p << endl;
        return 0;
    }
    while(p != 1){
        if(p % i == 0){
            p /= i;
            m[i]++;
            i = 1;
        }
        if(sqrt(tmp) < i) {
            m[p]++;
            break;
        }
        i++;
    }
    ll ans = 1;
    for(auto x : m){
        if(x.second >= n){
            ans *= pow(x.first, (x.second / n));
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    string S, T;
    cin >> S >> T;
    int count = 0;
    for(int i=0; i<S.length(); i++){
        if(S.at(i) != T.at(i)) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3860
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int int_vector_find(std::vector<int> vec, int num) {
	auto itr = std::find(vec.begin(), vec.end(), num);
	int index = std::distance(vec.begin(), itr);

	if (index != vec.size()) {
		return 1;
	}
	else {
		return 0;
	}
}

int main() {
	int o, n;
	std::cin >> o >> n;

	if (o >= 13) {
		std::cout << n << std::endl;
	}
	else if (o >= 6) {
		std::cout << n / 2 << std::endl;
	}
	else {
		std::cout << 0 << std::endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a;
  cin>>a;
  int b[3];
  for(int i=0;i<3;i++){
    b[i]=a%10;
    a=a/10;
  }
  printf("%s",b[0]==b[2]?"Yes":"No");
  return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>

typedef long long ll;
#define rep(i, n) for(int i=0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define fill(x,y) memset(x,y,sizeof(x))
#define debug1(i) cout << i << '\n'
#define debug2(i,j) cout << i << j << '\n'

using namespace std;

ll a,b,c,d;
ll box[100000];


int main(){
    cin >> a >>b;

    cout << (double)a/b;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool is_p(string s)
{
	string ss=s;
	reverse(s.begin(),s.end());
	if(ss==s)
		return 1;
	else 
		return 0;
}
int main()
{	
	string s,ss="";
	cin>>s;
	if(!is_p(s))
	{
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<(s.size()-1)/2;i++)
		ss+=s[i];
	if(!is_p(ss))
	{
		cout<<"No"<<endl;
		return 0;
	}
	ss="";
	for(int i=(s.size()+3)/2-1;i<s.size();i++)
		ss+=s[i];
	if(!is_p(ss))
	{
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
}






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

DB d,x,n;
int main() {
    cin>>n>>d>>x; DB ans=0;
    for(int i=n;i>=1;i--) {
        DB sum=(d*2*n+n*(2*n-1)*x);
        ans+=sum/2/n;
        DB d2=(d*(2*n-2)+d+2*x+3*d+3*x)/2/n;
        sum=sum-(4*d+4*n*x-2*x)/2/n;
        n-=1;
        DB x2=(sum-2*n*d2)/n/(2*n-1);
        d=d2; x=x2;
    } printf("%.15f\n",(double)ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <string>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

bool table[8][8];
int f(bool check[8],int n,int v){
    bool allcheck=true;
    for(int i=0;i<n;i++){
        if(!check[i]) allcheck=false;
    }
    if(allcheck) return 1;

    int res=0;
    for(int i=0;i<n;i++){
        if(table[v][i]==false) continue;
        if(check[i]) continue;
        check[i]=true;
        res+=f(check,n,i);
        check[i]=false;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    int m,n;
    cin>>n>>m;

    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        table[a-1][b-1]=true;
        table[b-1][a-1]=true;
    }

    bool check[8];
    for(int i=0;i<8;i++){
        check[i]=false;
    }
    check[0]=true;

    cout<<f(check,n,0)<<endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
S = input().rstrip()

ans = 0
for i in range(1000):
    a = ('00' + str(i))[-3:]
    try:
        j = S.index(a[0])
    except ValueError:
        continue
    try:
        k = S.index(a[1], j+1)
    except ValueError:
        continue
    try:
        l = S.index(a[2], k+1)
    except ValueError:
        continue
    ans += 1
print(ans)

Measured memory_bytes: 3060
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

MOD = 10**9+7

# X,Yに変換
n = ni()
s1 = lc()
s2 = lc()

xy = []

cnt = 0
while cnt < n:
    if s1[cnt] == s2[cnt]:
        xy.append("x")
        cnt += 1
    else:
        xy.append("y")
        cnt += 2
        
ans = 0

if xy[0] == "x":
    ans = 3
else:
    ans = 6
   
    
for pr,nx in zip(xy[:-1], xy[1:]):
    if pr == "x" and nx == "x":
        ans = (ans * 2) % MOD
        
    elif pr == "x" and nx == "y":
        ans = (ans * 2) % MOD
        
    elif pr == "y" and nx == "y":
        ans = (ans * 3) % MOD
        
print(ans)

Measured memory_bytes: 3064
N = int(input())

mod = 10 ** 9 + 7

dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(N + 1)]

dp[0][3][3][3] = 1

for i in range(N):
    for j in range(4):
        for k in range(4):
            for m in range(4):
                if dp[i][j][k][m] == 0:
                    continue
                for l in range(4):
                    if l == 2 and j == 1 and k == 0:
                        continue
                    if l == 2 and j == 0 and k == 1:
                        continue
                    if l == 1 and j == 2 and k == 0:
                        continue
                    if l == 2 and j == 1 and m == 0:
                        continue
                    if l == 2 and k == 1 and m == 0:
                        continue
                    dp[i + 1][l][j][k] += dp[i][j][k][m]
                    dp[i + 1][l][j][k] %= mod

ans = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += dp[N][i][j][k]
            ans %= mod
print(ans)


Measured memory_bytes: 3312
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int[] b = new int[a];
        int d = 0;
        int c=0;
        for (int i = 0; i < a; i++) {
            b[i] = sc.nextInt();
            if (i >= 1) {
                if (b[i - 1] - b[i] >= 0) {
                    d++;
                    c=Math.max(c, d);
                } else {
                    d = 0;
                }
            }
        }
        System.out.println(c);
    }
}



Measured memory_bytes: 48324
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  int A[N];
  int dam[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  int sum = 0;
  int direction = -1;
  for(int i=0;i<N;i++){
    direction *= -1;
    sum += direction*A[i];
  }
  dam[0] = sum/2;
  for(int i=1;i<N-1;i++){
    dam[i] = A[i-1] - dam[i-1];
  }
  dam[N-1] = A[N-1] - dam[0];
 
  for(int i=0;i<N;i++){
    cout << dam[i]*2 << ' ';
  }
  cout << endl;
  return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,m;cin>>n>>m;
  vector<int> v(n+1);
  for(int i=0;i<m;i++){
    int a,b;cin>>a>>b;
    v[a]++;
    v[b]++;
  }
  for(int i=1;i<=n;i++){
    cout<<v[i]<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce

def f(*numbers):
    return reduce(math.gcd, numbers)
n=int(input())



def sigma2(frm, to):
    r = 0;
    for i in range(frm, to+1):
        for j in range(frm, to+1):
            for k in range(frm, to+1):
                r+=f(i,j,k)
    return r

print(sigma2(1,n))
# print(sum(sigma2(1,n)+sigma2(1,n)+sigma2(1,n)))


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

int main() {
  string A,B,C;
  cin >> A >> B >>C;
  if (A[A.size()-1] == B[0] && B[B.size()-1] == C[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
 int H, W, N;
 int grid[10005];
 int a[10005];
 int i,j;
 int colors[10005];
 int count=0;
 int temp;

 scanf("%d %d",&H,&W);
 scanf("%d",&N);

 for(i=0;i<N;i++)
 {
  scanf("%d",&a[i]);
  for(j=0;j<a[i];j++) 
  { 
    colors[count]=i+1;
    count++;
  }
 }

 for(j=0;j<H;j++)
 {
  if(j%2 == 0)
  {
   for(i=0;i<W;i++) grid[i+j*W] = colors[i+j*W];
  }else{
   for(i=0;i<W;i++) grid[(j+1)*W-1-i] = colors[i+j*W];
  }
 }

 for(j=0;j<H;j++)
 {
  for(i=0;i<W;i++) printf("%d ",grid[i+j*W]);
  printf("\n");
 }

 return 0;
}


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

using namespace std;

void swap(string& card1, string& card2) {
	string tmp = card1;
	card1 = card2;
	card2 = tmp;
}

int peek_number(string card) {
	return atoi(&card[1]);
}

vector<string> bubble_sort(vector<string> cards) {
	for (int i = 0; i < cards.size(); i++) {
		for (int j = cards.size() - 1; j > i; j--) {
			if (peek_number(cards[j]) < peek_number(cards[j - 1])) swap(cards[j], cards[j - 1]);
		}
	}

	return cards;
}

vector<string> selection_sort(vector<string> cards) {
	for (int i = 0; i < cards.size(); i++) {
		int minj = i;

		for (int j = i; j < cards.size(); j++) {
			if (peek_number(cards[j]) < peek_number(cards[minj])) minj = j;
		}

		swap(cards[i], cards[minj]);
	}

	return cards;
}

bool is_stable(vector<string> stable, vector<string> target) {
	for (int i = 0; i < stable.size(); i++) {
		if (stable[i] != target[i]) return false;
	}

	return true;
}

void print_cards(vector<string> cards) {
	bool first = true;

	for (int i = 0; i < cards.size(); i++) {
		if (!first) cout << " ";
		cout << cards[i];
		first = false;
	}

	cout << endl;
}

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

	vector<string> unsorted(n);
	for (int i = 0; i < n; i++) cin >> unsorted[i];

	vector<string> bubble_sorted    = bubble_sort(unsorted);
	vector<string> selection_sorted = selection_sort(unsorted);

	print_cards(bubble_sorted);
	cout << "Stable" << endl;

	print_cards(selection_sorted);
	cout << (is_stable(bubble_sorted, selection_sorted) ? "Stable" : "Not stable") << endl;

	return 0;
}



Measured memory_bytes: 3228
/*
    Created by 10_months
    Tag:
    Link:
*/

#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
                
using namespace std;

const long long inf = 1e17;
const int INF = 1e9;
const int N = 1234567;
const int M = 123456;

int n, m;
string a[N], b[N];
                         
int main() {
    #ifdef home
        freopen("in", "r", stdin);
        freopen("out", "w", stdout);
    #endif
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    int good = 0;                      
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {    
            int diff = 0;
            for (int l = 0; l < m; l++)
                for (int k = 0; k < m; k++)
                    if (a[i + l][j + k] != b[l][k]) diff++;
        if (diff == 0) good = 1;                        
        }
    puts(good ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 19584
#include<bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
int n,k,m,pl,pr,a[25010],f[25010][410],g[25010][410],ans,fact[25010],ifact[25010];
bool work1(){
	static int cnt[410],ret;
	for(int i=1;i<=k;++i)++cnt[a[i]];
	for(int l=1,r=k;r<=n;++l,++r){
		bool flg=0;
		for(int i=1;i<=k;++i)if(!cnt[i]){flg=1;break;}
		if(!flg){ret=1;break;}
		--cnt[a[l]],++cnt[a[r+1]];
	}
	if(!ret)return 0;
	printf("%d\n",ans);
	return 1;
}
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	n=gi(),k=gi(),m=gi();ans=1ll*(n-m+1)*pow(k,n-m)%mod;if(k>n)puts("0"),exit(0);
	fact[0]=1;for(int i=1;i<=n;++i)fact[i]=1ll*fact[i-1]*i%mod;
	ifact[n]=pow(fact[n],mod-2);for(int i=n;i;--i)ifact[i-1]=1ll*ifact[i]*i%mod;
	for(int i=1;i<=m;++i)a[i]=gi();
	f[0][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=k-1,s=0,sg=0;j;--j){
			inc(s,f[i-1][j]);inc(sg,g[i-1][j]);
			f[i][j]=(s+1ll*(k-j+1)*f[i-1][j-1])%mod;
			g[i][j]=(sg+1ll*(k-j+1)*g[i-1][j-1])%mod;
			if(j>=m)inc(g[i][j],f[i][j]);
		}
	for(int i=1;i<=n;++i)for(int j=k-1;j;--j)inc(f[i][j],f[i][j+1]),inc(g[i][j],g[i][j+1]);
	static bool yes[410];
	pl=1,pr=m;
	while(pl<=m&&!yes[a[pl]])yes[a[pl++]]=1;--pl;
	memset(yes,0,sizeof yes);
	while(pr&&!yes[a[pr]])yes[a[pr--]]=1;++pr;
	if(work1())return 0;//已包含1-k
	if(pr>1){
		for(int l=1,r=m;r<=n;++l,++r)dec(ans,1ll*f[l+pl-1][pl]*f[m-pr+1+n-r][m-pr+1]%mod*pow(1ll*fact[k]*ifact[k-pl]%mod*fact[k]%mod*ifact[k-(m-pr+1)]%mod,mod-2)%mod);
	}else dec(ans,1ll*g[n][1]*ifact[k]%mod*fact[k-m]%mod);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 80640
package main

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

func main() {
	var a, b int
	s := wordScanner(100)
	scanInts(s, &a, &b)

	fmt.Println(max(a+b, max(a*b, a-b)))
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func wordScanner(n int) *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	b := make([]byte, n)
	s.Buffer(b, n)
	return s
}

func scanInts(s *bufio.Scanner, vals ...*int) {
	for i := range vals {
		s.Scan()
		n, _ := strconv.Atoi(s.Text())
		*vals[i] = n
	}
}


Measured memory_bytes: 640
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = sorted(p)

a = 0
b = 0

for i, j in enumerate(itertools.permutations(r)):
    if list(j) == p:
        a = i
    if list(j) == q:
        b = i

print(abs(b-a))

Measured memory_bytes: 3060
#include <iostream>
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

void findit(vector<vector<char>> &arr)
{
         int m=arr.size();
        int n=arr[0].size();
        long long dp[n];
       
        dp[0]=1;
        
        for(int i=1;i<n;i++)
        {
           if(dp[i-1]==1 && arr[0][i]=='.')
           {
               dp[i]=1;
           }
            else
            {
                dp[i]=0;
            }
        }
        
        for(int i=1;i<m;i++)
        {
           for(int j=0;j<n;j++)
           { 
               if(arr[i][j]=='.')
               {
                   long long right= j>0 ? dp[j-1] : 0;
                   long long down=dp[j];
                   dp[j]= ( (right%mod)  + (down)%mod) %mod;
            
               }
               else
               {
                   dp[j]=0;
               }
               
           }
        }
        
        cout<<dp[n-1];
}

int main() 
{

   int m;
   cin>>m;
   int n;
   cin>>n;
   
   vector<vector<char>> v ( m, vector<char>(n) );
   
   for(int i=0;i<m;i++)
   {
       for(int j=0;j<n;j++)
       {
           cin>>v[i][j];
       }
   }
   findit(v);
}


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

int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> X(N);
    for(ll i = 0; i < N; i++){
        cin >> X[i];
    }

    ll ans = 0;
    for(int i = 0; i < N - 1; i++){
        ans += min(A * (X[i + 1] - X[i]), B);
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 1024
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    S = input().rstrip()
    N = len(S)
    ans = float('inf')
    for i in range(N-2):
        num = int(S[i:i+3])
        ans = min(ans, abs(753-num))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3952