akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

int main() {
	int n = ri(), m1 = ri(), m2 = ri();
	int a[n], b[n], c[n];
	for (int i = 0; i < n; i++) a[i] = ri(), b[i] = ri(), c[i] = ri();
	int dp[401][401];
	for (int i = 0; i <= 400; i++)
		for (int j = 0; j <= 400; j++) dp[i][j] = 1000000000;
	dp[0][0] = 0;
	for (int i = 0; i < n; i++)
		for (int j = 400; j >= 0; j--)
			for (int k = 400; k >= 0; k--)
				if (j + a[i] <= 400 && k + b[i] <= 400)
					dp[j + a[i]][k + b[i]] = std::min(dp[j + a[i]][k + b[i]], dp[j][k] + c[i]);
	int res = 1000000000;
	for (int i = 1; ; i++) {
		if (i * std::max(m1, m2) > 400) break;
		res = std::min(res, dp[i * m1][i * m2]);
	}
	std::cout << (res == 1000000000 ? -1 : res) << std::endl;
	
	return 0;
}


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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mod 1000000007
#define INF 1e9+5
#define endl "\n"
#define all(a) (a).begin(),(a).end()
#define lp(i,a,b) for(i=a;i<b;++i)
#define lpr(i,a,b) for(i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;

int main(){

  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif*/

  fast;
  int i,j,tc,ip,n;

  tc=1;
  while(tc--){
    cin>>i>>j;
    if(j>=i)  cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
  }
  return 0; 
} 


Measured memory_bytes: 3652
# https://ikatakos.com/pot/programming_algorithm/data_structure/binary_indexed_tree

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

class RangeUpdate:
    def __init__(self, n):
        self.p = Bit(n + 1)
        self.q = Bit(n + 1)

    def add(self, s, t, x):
        t += 1
        self.p.add(s, -x * s)
        self.p.add(t, x * t)
        self.q.add(s, x)
        self.q.add(t, -x)

    def sum(self, s, t):
        t += 1
        return (self.p.sum(t) + self.q.sum(t) * t - \
               self.p.sum(s) - self.q.sum(s) * s) % mod


mod = 998244353

N, K, *LR = map(int, open(0).read().split())

LR = list(zip(*[iter(LR)] * 2))

dp = RangeUpdate(N)
dp.add(1, 1, 1)
for i in range(1, N + 1):
    for l, r in LR:
        dp.add(i + l, i + r, dp.sum(i, i))

print(dp.sum(N, N))

Measured memory_bytes: 113828
#/usr/bin/env python3
 
s = list(input())
Q = int(input())
 
reverse = False
leading = []
trailing = []
 
for q in range(Q):
    query = input().split()
 
    if len(query) == 1:
        reverse = not reverse
    else:
        direction = int(query[1])
        if (direction == 1 and not reverse) or (direction == 2 and reverse):
            leading.append(query[2])
        else:
            trailing.append(query[2])
 
if reverse:
    print(''.join((leading[::-1] + s + trailing)[::-1]))
else:
    print(''.join(leading[::-1] + s + trailing))

Measured memory_bytes: 80504
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
	unsigned int key;
	struct node *next;
	struct node *prev;
};

typedef struct node *NodePointer;

NodePointer nil;


NodePointer listSearch(int key){
	NodePointer cur = nil->next;
	while(cur != nil && cur->key != key){
		cur = cur->next;
	}
	return cur;
}


void init(){
	nil = malloc(sizeof(struct node));
	nil->next = nil;
	nil->prev = nil;
}


void printList(){
	NodePointer cur = nil->next;
	int isf = 1;
	while(1){
		if(cur == nil) break;
		if(isf == 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
		isf = 0;
	}
	printf("\n");
}


void deleteNode(NodePointer t){
	if(t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}


void deleteFirst(){
	NodePointer t = nil->next;
	if(t==nil) return;
	deleteNode(t);
}


void deleteLast(){
	deleteNode(nil ->prev);
}


void delete(int key){
	deleteNode(listSearch(key));
}


void insert(int key){
	NodePointer x;
	x = malloc(sizeof(struct node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}


int main(){
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for(i=0; i<n; i++){
		scanf("%s%d", com, &key);
		if(com[0] == 'i') {insert(key); np++; size++;}
		else if(com[0] == 'd')
		{
			if(strlen(com) > 6)
			{
				if(com[6] == 'F') deleteFirst();
				else if(com[6] == 'L') deleteLast();
			}
			else
			{
				delete(key); nd++;
			}
			size--;
		}
	}
	
	printList();
	return 0;
}


Measured memory_bytes: 32984
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll R=2e5+69, INF=2e9+6969;

int ile[R],rep[R],n,m;

int Find(int a)
{
	if(rep[a] != a) rep[a] = Find(rep[a]);
	return rep[a];
}
void Union(int a, int b)
{
	a = Find(a);
	b = Find(b);
	if(ile[a] < ile[b]) swap(a,b);
	ile[a] += ile[b];
	rep[b] = a;
}

int main()
{
	scanf("%d%d", &n, &m);
	for(int i=1;i<=n;++i) 
	{
		rep[i] = i;
		ile[i] = 1;
	}
	for(int i=0;i<m;++i)
	{
		int a,b;
		scanf("%d%d", &a, &b);
		if(Find(a)!=Find(b)) Union(a,b);
	}
	set <int> s;
	for(int i=1;i<=n;++i) s.insert(Find(i));
	printf("%d\n", (int)s.size()-1);
	return 0;
}


Measured memory_bytes: 8332
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
        int a,b,k;

        scanf("%d%d",&a,&b);
        k=(a+b)/2;
        if(abs(a-k)==abs(b-k)) printf("%d\n",k);
        else printf("IMPOSSIBLE\n");

        return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

#define N 200100
#define uint unsigned int

//head

int n;
uint a[N], b[N], c[N];
uint ans;

inline const uint minus_u(const uint a, const uint b) {return a>b?a-b:0;}

int main() {
	scanf("%d", &n);
	rep(i, n) scanf("%u", a+i);
	rep(i, n) scanf("%u", b+i);
	rep(i, 29) {
		uint X = (1U<<(i+1)) - 1, T = 1U<<i;
		rep(i, n) c[i] = b[i] & X;
		sort(c, c+n);
		rep(j, n) {
			uint now = a[j] & X;
			uint *itr = lower_bound(c, c+n, minus_u(T, now)), *utr = lower_bound(c, c+n, minus_u(2*T, now));
			ans ^= ((uint)(utr-itr)&1U)<<i;
			itr = lower_bound(c, c+n, minus_u(3*T, now));
			ans ^= ((uint)(c+n-itr)&1U)<<i;
		}
	}
	printf("%u\n", ans);
}

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

const ll INF = 1LL << 60;

ll N, M, K;

// 隣接の数
// ブロックの数
map<ll, ll> ab, cd;

class UnionFind {
public:
  //親の番号を格納する。親だった場合は-(その集合のサイズ)
  vector<int> Parent;

  //作るときはParentの値を全て-1にする
  //こうすると全てバラバラになる
  UnionFind(int N) {
    Parent = vector<int>(N, -1);
  }

  //Aがどのグループに属しているか調べる
  int root(int A) {
    if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }

  //自分のいるグループの頂点数を調べる
  int size(int A) {
    return -Parent[root(A)];//親をとってきたい]
  }

  //AとBをくっ付ける
  bool connect(int A, int B) {
    //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
    A = root(A);
    B = root(B);
    if (A == B) {
      //すでにくっついてるからくっ付けない
      return false;
    }

    //大きい方(A)に小さいほう(B)をくっ付けたい
    //大小が逆だったらひっくり返しちゃう。
    if (size(A) < size(B)) swap(A, B);

    //Aのサイズを更新する
    Parent[A] += Parent[B];
    //Bの親をAに変更する
    Parent[B] = A;

    return true;
  }
};

int main() {
    cin >> N >> M >> K;

    UnionFind uf = UnionFind(N);

    // 連結
    rep(i, M) {
        ll A, B;
        cin >> A >> B;
        A--; B--;

        uf.connect(A, B);
        ab[A]++;
        ab[B]++;
    }

    rep(i, K) {
        ll C, D;
        cin >> C >> D;
        C--; D--;

        // 連結だったら足す
        if (uf.root(C) == uf.root(D)) {
            cd[C]++;
            cd[D]++;
        }
    }

    // cout << ab[0] << " " << cd[0] << endl;
    rep(i, N) {
        ll ans = uf.size(i);
        ans -= 1;
        ans -= ab[i];
        ans -= cd[i];

        cout << ans << " ";
    }
    cout << endl;
}

Measured memory_bytes: 16064
n,m,v,p = map(int,input().split())
A = list(map(int,input().split()))

A.sort(reverse = True)

ans = p-1

d = 0

for i in range(p-1,n):
    if A[p-1] > A[i] + m:break
    may = (p-1 + n-i-1)*m
    may +=(A[i]+m)*(i - p+1) - d
    ans += (may + m>= m*v)
    d += A[i]

print(ans)


Measured memory_bytes: 14484
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

int N;
long long W, weight[110], value[110];
long long dp[110][100010] = {0};

int main()
{
    cin >> N >> W;
    for (int i = 0; i < N; i++)
    {
        cin >> weight[i] >> value[i];
    }

    for (int i = 0; i < N; i++)
    {
        for (int sum_w = 0; sum_w <= W; sum_w++)
        {
            if (sum_w - weight[i] >= 0)
            {
                chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            chmax(dp[i + 1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
# https://atcoder.jp/contests/abc043/tasks/arc059_a
# C - いっしょ / Be Together
import statistics
N = int(input().split()[0])
a_list = list(map(int, input().split()))

# たかだか200なので、全探索で間に合う
min_cost = float('inf')

for x in range(-100, 101):
    cost = 0
    for a in a_list:
        cost += (a - x) ** 2
    if cost < min_cost:
        min_cost = cost

print(min_cost)


Measured memory_bytes: 5148
s=input()
t=input()
num=len(s)-len(t)
res=[]
for n1 in range(0,num+1):
    count=0
    for n2 in range(0,len(t)):
        if(t[n2]!=s[n1+n2]):
            count+=1
    res.append(count)
print(min(res))

Measured memory_bytes: 9116
program prob4
    integer::i,N
    character(len=200)::S,T
    character,allocatable::ans(:)
    read(*,*) N
    read(*,*) S, T
    allocate(ans(2*N))

    do i = 1,N
        ans(2*i-1) = S(i:i)
        ans(2*i) = T(i:i)
    end do

    write(*,*) ans

	deallocate(ans)
    stop
end program

Measured memory_bytes: 2852
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    int n,a,b;
    while(cin>>a>>b>>n){
        int ans=0;
        a%=b;
        rep(i,n){
             a*=10;
            ans+=a/b;
            a%=b;
        }
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 2988
#include <stdio.h>
#include <math.h>
int main(){
  double cr=0,x=0,y=0;
  int l,r;
  while(scanf("%d,%d",&l,&r)!=EOF){
    x+=l*sin(cr*M_PI/180.0);
    y+=l*cos(cr*M_PI/180.0);
    cr+=r;
  }
  printf("%d\n%d\n",(int)x,(int)y);
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
int n,a[51],cnt;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for (int i=1;i<=n;++i)
	{
		cin>>a[i];
		if (a[i]!=i) ++cnt;
	}
	if (cnt==0 || cnt==2) cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
	string s; cin>>s;
	bool t[26]; memset(t,true,sizeof(t));
	rep(i,s.size()) t[s[i]-'a']=false;
	rep(i,26){
		if(t[i]){
			char ans='a'+i;
			cout<<ans<<endl;
			return 0;
		}
	}
	cout<<"None"<<endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF 1e9+7
#define LLINF 1e18
// #define int ll
using namespace std;
const int MOD = 1e9 +7;


struct WeightedUnionFind{
    vector<int> par;
    vector<int> rank;
    vector<int> diff_weight;

    WeightedUnionFind(int n){
        init(n);
    }
    void init(int n){
        par.resize(n);
        rank.resize(n);
        diff_weight.resize(n);
        rep(i,n){
            par[i]=i;
            rank[i]=0;
            diff_weight[i]=0;
        }
    }

    int find(int x){
        if(par[x]==x){
            return x;
        }
        else{
            int r=find(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] =r;
        }
    }
    int weight(int x) {
        find(x);
        return diff_weight[x];
    }

    bool same(int x,int y){
        return find(x) ==find(y);
    }
    

    bool unite(int x, int y, int w) {
        w += weight(x); w -= weight(y);
        x = find(x); y = find(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    int diff(int x, int y) {
        return weight(y) - weight(x);
    }

    
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    WeightedUnionFind uf(n);
    rep(i,m){
        int l,r,d;
        cin>>l>>r>>d;
        r--;l--;
        if(uf.same(l,r)){
            int diff=uf.diff(l,r);
            if(diff !=d){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else uf.unite(l,r,d);
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 1408
/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-05-30 20:09:32
 * @LastEditTime: 2020-05-30 20:19:02
 * @FilePath: \VSC\C++\Public\Nomura2020 B.cpp
 */ 
#include<bits/stdc++.h>
using namespace std;

string s;

signed main(){
    char ch;
    while((ch=getchar())!=10){
        if(ch=='?') putchar('D');
        else putchar(ch);
    }

    puts("");
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

    if(n % 2 == 0){
        cout << n/2.0 / n << endl;
    }else {
        cout << (n/2+ 1) / double(n) << endl;
    }
    
}

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
	int N; int b[100];
	cin >> N;
	REP(i, N-1) cin >> b[i];
	REP(i, N){
		if(i == N-1) ans += b[N-2];
		else if(i > 0) ans += min(b[i-1], b[i]);
		else if( i == 0) ans += b[0];
		
	}
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>


/*  小さい順に並び替えてnumber[0]から代入していく

	int i, j, tmp;
	int number[100];
	int total;
	scanf("%d", &total);
	for (i = 0; i < total; ++i) scanf("%d", &number[i]);
	for (i = 0; i < total; ++i) {
		for (j = i + 1; j < total; ++j) {
			if (number[i] > number[j]) {
				tmp = number[i];
				number[i] = number[j];
				number[j] = tmp;
			}
		}
	}

*/

/*

    int i, N;

	int a[100];

	for (i = 0; i < N; i++) scanf("%d", &a[i]);

*/


int main()
{
	int i, N;

	char a[5];

	scanf("%s", &a);

	for (i = 0; i< 4; i++) {
		if (a[i] == 'A' && a[i + 1] == 'C') {
			printf("Yes");
			return 0;
		}
	}

	printf("No");


	

	
}






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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(std::string s, long long K){
  ll i = 0;
  for(; i+1<s.size(); i++) {
    if(s[i]=='a')
      continue;
    else{
      ll x = 'z'-s[i]+1;
      if(K>=x) {
	K-=x;
	s[i] = 'a';
      }
    }
  }
  if(K>0) {
    K = K % 26;
    if('z'-s[i] < K) {
      K-='z'-s[i]+1;
      s[i] = 'a'+K;
    } else {
      s[i] = s[i]+K;
    }
  }
  std::cout << s << std::endl;
}

int main(){
    std::string s;
    std::cin >> s;
    long long K;
    scanf("%lld",&K);
    solve(s, K);
    return 0;
}


Measured memory_bytes: 512
using System;
class Program
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    long W = long.Parse(input[0]);
    long H = long.Parse(input[1]);
    long x = long.Parse(input[2]);
    long y = long.Parse(input[3]);
    
    double area = (double)W / 2 * (double)H;
    string multi = "0";
    if (W == x*2 && H == y*2)
      multi = "1";
    
    Console.WriteLine(area.ToString() + " " + multi);
  }
}

Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second





int main() {
	ll n, ans = 0;
	string s, l, r,rr;
	map<pair<string, string>, ll>mp;
	cin >> n >> s;
	l = s.substr(0, n);
	r = s.substr(n, n);
	for (int i = n - 1;i >= 0;i--) rr += r[i];
	//cout << l << ' ' << r << ' ' << rr << endl;
	for (int i = 1;i <= (1 << n);i++) {
		string a, b;
		for (int j = 0;j < n;j++) {
			if (i&(1 << j))a += l[j];
			else b += l[j];
		}
		mp[sP(a, b)]++;
	}
	for (int i = 1;i <= (1 << n);i++) {
		string a, b;
		for (int j = 0;j < n;j++) {
			if (i&(1 << j))a += rr[j];
			else b += rr[j];
		}
		if (mp[sP(a, b)])ans += mp[sP(a, b)];
	}
	cout << ans << endl;
	return 0;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int dp[110][10100] = {0};

int main() {

    int n; cin >> n;

    vector<int> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }

    dp[0][0] = 1;

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= 10100; ++j) {
            if (dp[i][j] == 1) {
                dp[i+1][j + s[i]] = 1;
                dp[i+1][j] = 1;
            }
        }
    }

    for (int i = 10000; i > 0; --i) {
        if (i % 10 != 0 && dp[n][i] == 1) {
            cout << i << endl;
            return 0;
        }
    }

    cout << 0 << endl;
}

Measured memory_bytes: 3072
stack = []
until (years = $<.gets.split.map(&:to_i)) == [0, 0]
  is_uruu = ->(year) {
    (year % 4).zero? and ((year % 100).nonzero? or (year % 400).zero?)
  }
  result = (years.first..years.last).map {|i| is_uruu.(i) ? i : nil}.compact
  result << "NA" if result.empty?
  stack << result.join("\n") 
end
print stack.join("\n\n") + "\n"


Measured memory_bytes: 6996
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
const long long MOD = 1e9 + 7;
using namespace std;

//main
int main(){
  int N;
  string S;
  cin >> N >> S;
  if (N%2 == 0){
    string a = S.substr(0,N/2);
    if(a+a == S) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int solve(int n,vvi &d){
    vi dp(n);
    rep(i,n)dp[i]=1ll<<i;
    REP(day,1,30){
        rep(i,n){
            rep(j,n){
                int c=0;
                rep(k,d[day].size()){
                    if(d[day][k]==i)c++;
                    if(d[day][k]==j)c++;
                }
                if(c!=2)continue;
                dp[i]=dp[j]=(dp[i]|dp[j]);
                if(dp[i]==((1ll<<n)-1)){
                    return day;
                }
            }
        }
    }
    return -1;
}

void run(){
    int n;
    cin>>n;
    if(!n)return;
    vvi d(31);
    rep(i,n){
        int f;
        cin>>f;
        rep(j,f){
            int x;
            cin>>x;
            d[x].pb(i);
        }
    }
    cout<<solve(n,d)<<endl;
    run();
}


Measured memory_bytes: 6224
/*
貪欲
後ろから見る
DP
順位表をチェック
二分探索
不変なもの・偶奇に注目

*/
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<tuple>
#include<set>
using namespace std;
#define INF 1LL<<60
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
//typedef pair< pair<int,int>,pair<int,int> > p;
//#define int ll int main->signed main
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());

int main(){
    int N;
    cin>>N;
    for(int i=0;i<=50000;i++){
        if(i*1.08>=N && i*1.08<N+1){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
}


Measured memory_bytes: 888
import math

a, b = map(int, input().split())
 
if math.ceil(a*100/8) <= math.ceil(b*100/10):
    if math.floor(b*100/10) < math.floor((a+1)*100/8):
        print(math.ceil(b*100/10))
    else:
        print(-1)
else:
    if math.floor(a*100/8) < math.floor((b+1)*100/10):
        print(math.ceil(a*100/8))
    else:
        print(-1)

Measured memory_bytes: 9208
# -*- coding: utf-8 -*-
def my_count(a, b, n):
    ret = 0
    if a == b and a <= n:
        ret = ret + 1
    if a * 10 + b <= n:
        ret = ret + 1
    keta = len(str(n))
    if keta > 3:
        ret = ret + (int('1'*(keta-2)) - 1)
    if keta >= 3:
        candidate = a * (10 ** (keta-1)) + b
        if n - candidate >= 0:
            num = ((n - candidate) // 10) + 1
            if num >= (10 ** (keta-2)):
                ret = ret + (10 ** (keta-2))
            else:
                ret = ret + num
    return ret


n = int(input())

ret = 0

for i in range(1, 10):
    for j in range(1, 10):
        ret = ret + my_count(i, j, n) * my_count(j, i, n)

print(ret)


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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a,b;
    rep(i,n){
        int num;
        cin>>num;
        if(num>0) a.push_back(num);
        else if(num<0) b.push_back(-num);
        else k -= 1;
    }
    reverse(b.begin(),b.end());

    long long dist=1e18;
    int aNum = min(k,(int)a.size());
    int bNum = k - aNum;
    while(bNum <= min(k,(int)b.size())){
        int aD=0,bD=0;
        if(aNum!=0) aD=a[aNum-1];
        if(bNum!=0) bD=b[bNum-1];
        dist = min((long long)2*aD+bD,dist);
        dist = min((long long)2*bD+aD,dist);
        aNum--;
        bNum++;
    }

    cout<<dist<<endl;
}

Measured memory_bytes: 1020
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  return n+1 >> 1;
}

Measured memory_bytes: 11468
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    let a: isize = read!();
    let b: isize = read!();
    let c: isize = read!();
    let d: isize = read!();
    println!("{} {} {} {}",c-d+b,d+c-a,a-d+b,b-a+c)
}

Measured memory_bytes: 2160
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n, h, w;
    cin >> n >> h >> w;
    int ans = 0;
    rep(i, n)
    {
        int a, b;
        cin >> a >> b;
        if (a >= h && b >= w)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val s = Array(N) { readLine()!! }

    val a = s.indices.filter { s[it].last() == 'A' }
    val b = s.indices.filter { s[it].first() == 'B' }
    val ab = s.indices.filter { s[it].first() == 'B' && s[it].last() == 'A' }

    var r = s.map {
        var t = 0
        for (i in 0 .. it.length - 2) {
            if (it.substring(i, i + 2) == "AB") {
                t++
            }
        }
        t
    }.sum()

    if (ab.isNotEmpty() && ab.size == a.size && ab.size == b.size) {
        r += ab.size - 1
    } else {
        r += Math.min(a.size, b.size)
    }

    println(r)
}


Measured memory_bytes: 44280
package main

import "fmt"

const debug = true

func main() {
	var A, B, C, D int
	fmt.Scan(&A, &B, &C, &D)

	if abs(A-C) <= D {
		fmt.Println("Yes")
		return
	}

	if A < B && B < C {
		if B-A <= D && C-B <= D {
			fmt.Println("Yes")
			return
		}
	}

	if A >= B && B >= C {
		if A-B <= D && B-C <= D {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
	return

}

func abs(a int) int {
	if a < 0 {
		a = -a
	}
	return a
}


Measured memory_bytes: 512
#include<stdio.h>
    #include<stdlib.h>
    
    
    int min(int a,int b){
    	if(a<b){
    		return a;
		}else{
			return b;
		}
	}
	
	int main(){
		
      int n,m,i,j,h[100010],d[100010]={};
      
      	scanf("%d %d",&n,&m);
      	
      	for(i=0;i<n;i++)scanf("%d",&h[i]);
      		for(i=1;i<n;i++){
				d[i]=1e9;
		}
      		
			  
			for(i=0;i<n;i++){
        		for(j=0;j<m && i+j+1<n;j++){
        			d[i+j+1]=min(d[i+j+1],d[i]+abs(h[i]-h[i+j+1]));	
				}
        		
      }
      
      printf("%d\n",d[n-1]);
      return 0;
      
    }

Measured memory_bytes: 896
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

//#define fi1 ifstream cin("input.txt")
//#define of1 ofstream cout("output.txt")
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

ll lcm(ll a,ll b)
{
    return (a*b)/(__gcd(a,b));
}

ll func(ll a,ll b,ll c)
{
	if(a<=0)
		return 0;
	ll xx=lcm(b,c);
	ll tot=(a/b)+(a/c)-(a/xx);
	return (a-tot);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<func(b,c,d)-func(a-1,c,d);
    return 0;
}

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

int n;;
int A[101][101];
int d[101];

void bfs(int r) {
	queue<int> Q;
	Q.push(r);
	d[r] = 0;
	while (!Q.empty()) {
		int t = Q.front();
		Q.pop();
		for (int i = 1; i <= n; i++) {
			if (A[t][i] && d[i] == -1) {
				d[i] = d[t] + 1;
				Q.push(i);
			}
		}
	}
}

int main() {
	int u, v, l;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		d[i] = -1;
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			A[i][j] = 0;
		}
	}

	for (int i = 1; i <= n; i++) {
		cin >> u >> l;
		for (int j = 0; j < l; j++) {
			cin >> v;
			A[u][v] = 1;
		}
	}

	bfs(1);

	for (int i = 1; i <= n; i++) {
		cout << i << ' ' << d[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>
#include <stdio.h>
#include <sstream>
#define int_inf 1000000000 //1e9
#define ll_inf  1000000000000000000 //1e18
using namespace std;
template <typename T> std::string to_string(const T& t){
	std::ostringstream os; os<<t; return os.str();
}




int main(){
	long long q, h, s, d;
	cin >> q >> h >> s >> d;
	long long n;
	cin >> n;
	long long ans=0;
	
	if(q*8<=h*4 && q*8<=s*2 && q*8<=d) ans+=(n/2)*q*8;
	else if(h*4<=q*8 && h*4<=s*2 && h*4<=d) ans+=(n/2)*h*4;
	else if(s*2<=q*8 && s*2<=h*4 && s*2<=d) ans+=(n/2)*s*2;
	else if(d<=q*8 && d<=h*4 && d<=s*2) ans+=(n/2)*d;
	
	n-=(n/2)*2;
	
	if(q*8<=h*4 && q*8<=s*2) ans+=n*q*4;
	else if(h*4<=q*8 && h*4<=s*2) ans+=n*h*2;
	else if(s*2<=q*8 && s*2<=h*4) ans+=n*s;
	
	cout << ans << endl;
	return 0;
}




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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()

void Main() {
    // todo
    float n; cin >> n;
    float a = (int)(n / 1.08);
    float b = (int)(n / 1.08 + 1);
    if ((int)(a * 1.08) == (int)(n)) {
        cout << (int)(a) << endl;
    } else if ((int)(b * 1.08) == (int)(n)) {
        cout << (int)(b) << endl;
    } else {
        cout << ":(" << endl;
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long[][] dp = new long[S.length()+1][13];
        final int MOD = (int)Math.pow(10, 9) + 7;
        dp[0][0] = 1;
        
        for(int i = 0; i < S.length() ; i++){
            if (S.charAt(i) == '?'){
                for(int j = 0; j < 13; j++){
                    for(int k = 0; k < 10; k++){
                        dp[i+1][(j*10 + k) % 13] += dp[i][j] % MOD;
                    }
                }
            } else {
                for(int j = 0; j < 13; j++){
                    dp[i+1][(j *10 + Character.getNumericValue(S.charAt(i))) % 13] += dp[i][j] % MOD;
                }
            }
        }
        
        System.out.println(dp[S.length()][5] % MOD);
    }
}


Measured memory_bytes: 36524
while(True):
    try:
        N = int(input())
        m = 0
        for i in range(10):
            for j in range(10):
                for k in range(10):
                    for l in range(10):
                        if i+j+k+l == N:
                            m += 1
        print(m)
    except:
        break


Measured memory_bytes: 5588
import java.util.Scanner;

public class Main
{
    public static void main( String[] args )
    {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        if((A == B || B == C || A == C) && A*3 != A + B + C){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        scanner.close();
    }
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int                 long long
#define FF(i,a,b)           for(int i=a;i<b;i++)
#define BF(i,a,b)           for(int i=a;i>=b;i--)
#define vi                  vector<int>
#define MAP                 map<int,int>
#define pb                  push_back
#define MP                  make_pair
#define F                   first
#define S                   second
#define pi                  pair<int,int>
#define all(v)              v.begin(),v.end()
#define PIE                 3.1415926535897932384626433832795
#define FastIO              ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
//#define ordered_set         tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
/*

    order_of_key (k) : Number of items strictly smaller than k .
    find_by_order(k) : K-th element in a set (counting from zero).

*/
/**************************************************************************************/
                       /*Global Variables*/
const int mod = 1e9+7;
const int N = 2e5+10;
const int inf = 3e18;

/**************************************************************************************/
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
int Power(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1)res*=a;
        a*=a;
        b>>=1;
    }
    return res;
}
signed main()
{
    FastIO;
    int T=1;
    //cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        int dp[n][3];
        cin>>dp[0][0]>>dp[0][1]>>dp[0][2];
        for(int i=1;i<n;i++)
        {
            int x,y,z;
            cin>>x>>y>>z;
            dp[i][0]=x+max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=y+max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=z+max(dp[i-1][1],dp[i-1][0]);
        }
        int ans = max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
        cout<<ans<<"\n";
    }

}
/*
|| Do what you can with all you have,wherever you are. ||

|| Knowing is not enough, we must apply. Wishing is not enough, we must do. ||

|| A goal is a dream with deadline. ||

|| Whether you think you can or you think you can't, you're right. ||

|| A year from now you may wish you had started today ||
*/



Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<ll,ll>
#define vint vector<ll>
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
ll read(){
	ll g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const ll mod=998244353;
const ll N=100005;
const ll M=205;
const ll maxn=100000;
ll fac[N],inv[N],n,m,wn[N];
vint h,g,f[M],na,nb;
ll ksm(ll x,ll y){
	ll re=1;
	while(y){
		if(y&1)re=re*x%mod;
		x=x*x%mod;y>>=1;
	}return re;
}
void ntt(vint &a,ll n,ll opt){
	for(ll i=0;i<n;i++){
		ll j,k,m;
		for(k=i,m=1,j=0;m<n;m<<=1,j=(j<<1)|(k&1),k>>=1);
		if(i>j)swap(a[i],a[j]);
	}ll t0,t1;wn[0]=1;
	for(ll m=1;m<n;m<<=1){
		t0=ksm(3,mod-1+opt*(mod-1)/(m<<1));
		for(ll i=1;i<m;i++)wn[i]=wn[i-1]*t0%mod;
		for(ll st=0;st<n;st+=(m<<1))for(ll i=st;i<st+m;i++){
			t0=a[i],t1=a[i+m]*wn[i-st]%mod;
			a[i]=(t0+t1)%mod,a[i+m]=(t0-t1+mod)%mod;
		}
	}if(opt==1)return;
	ll inv=ksm(n,mod-2);
	for(ll i=0;i<n;i++)a[i]=a[i]*inv%mod;
}
void merge(vint&a,vint&b){
	ll n=a.size(),m=b.size(),L=n+m-1;
	ll len;for(len=1;len<L;len<<=1);
	na.clear(),na.resize(len);for(ll i=0;i<n;i++)na[i]=a[i];
	nb.clear(),nb.resize(len);for(ll i=0;i<m;i++)nb[i]=b[i];
	ntt(na,len,1),ntt(nb,len,1);
	for(ll i=0;i<len;i++)na[i]=na[i]*nb[i]%mod;
	ntt(na,len,-1);
	a.resize(L);for(ll i=0;i<L;i++)a[i]=na[i];
}
ll C(ll n,ll m){
	if(n<m)return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
signed main(){
	n=read(),m=read();
	fac[0]=1;for(ll i=1;i<=maxn;i++)fac[i]=fac[i-1]*i%mod;
	inv[1]=1;for(ll i=2;i<=maxn;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	inv[0]=1;for(ll i=1;i<=maxn;i++)inv[i]=inv[i]*inv[i-1]%mod;
	f[m].resize(n+1);for(int i=0;i<=n;i++)f[m][i]=C(n,i);
	for(ll i=m-1;i>=0;i--){
		h.resize(n+1);for(ll j=0;j<=n;j++)h[j]=inv[n-j+2];h[n]=0;
		g.resize(n+1);for(ll j=0;j<=n;j++)g[j]=f[i+1][j]*fac[j+2]%mod;
		merge(h,g);f[i].resize(n+1);
		for(ll j=0;j<=n;j++)f[i][j]=(h[n+j]*inv[j]%mod+f[i+1][j]*(C(j+1,2)+1)%mod)%mod;
	}return cout<<f[0][0],signed();
}
/*
3 2
*/

Measured memory_bytes: 17860
def main():
    length, num = map(int, input().split())
    a = list(map(int, input().split()))
    max_dis = 0
    first_h = a[0]
    prev_h = a[0]
    for h in a[1:]:
        dis = h - prev_h
        max_dis = max(max_dis, dis)
        prev_h = h

    dis = (length - prev_h) + first_h
    max_dis = max(max_dis, dis)
    print(length - max_dis)


if __name__ == "__main__":
    main()

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
const int MOD=1000000007;
const int INF=LLONG_MAX/2;

signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
//    if(n%3!=0){cout<<"No"<<endl; return 0;}
    Vi a(n),b;
    int count=0;
    map<int,int> ma;
    REP(i,0,n){
        cin>>a[i];
        ma[a[i]]++;
        if(a[i]==0) count++;
    }
    if(count==n){cout<<"Yes"<<endl; return 0;}
    if(n%3!=0){cout<<"No"<<endl; return 0;}
    if(ma.size()==3){
        for(auto x : ma){
            if(x.second!=n/3) {cout<<"No"<<endl; return 0;}
            else b.pb(x.first);
        }
        if((b[0]^b[1])==b[2]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }else if(ma.size()==2){
        for(auto x : ma){
            if(x.first==0 && x.second==n/3) continue;
            if(x.second==n/3*2) continue;
            cout<<"No"<<endl;
            return 0;
        }
        cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 5760
n = int(input())

h = list(map(int,input().split()))

flag = False
length = len(h)

if length == 1:
	flag = True

for i in reversed(range(1,length)):
	if h[i] < h[i-1]:
		h[i-1] = h[i-1] - 1
		if h[i] != h[i-1]:
			break

	if i == 1:
		flag = True

if flag:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 15020
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
  double x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  printf("%.6f\n", sqrt(pow(x2-x1, 2) + pow(y2-y1, 2)));
  return 0;
}



Measured memory_bytes: 3280
import sys

input = sys.stdin.readline


def main():
    N, C = [int(x) for x in input().split()]
    STC = [[int(x) for x in input().split()] for _ in range(N)]

    S = [[] for _ in range(10 ** 5 + 1)]
    T = [[] for _ in range(10 ** 5 + 1)]

    for s, t, c in STC:
        S[s].append(c)
        T[t].append(c)

    used = set()
    ans = 0
    for i in range(10 ** 5 + 1):
        sused = set()
        tused = set()

        for s in S[i]:
            sused.add(s)
        for t in T[i]:
            tused.add(t)

        ans = max(ans, len(used) + len(sused - tused))
        used = used - tused | sused

    print(ans)








if __name__ == '__main__':
    main()


Measured memory_bytes: 44728
#include <iostream>

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;
	if ( (A>=1) && (B>=1) && (A<=100) && (B<=100))
	{
		if( ((A%3)==0) || ((B%3)==0) || (((A+B)%3)==0) )
			cout <<"Possible"<<endl;
		else cout <<"Impossible"<<endl;
	}
	system("pause");
	return(0);
}

Measured memory_bytes: 504
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
const ll E=1e17+7;
#define F first
#define S second
#define MK make_pair


vector<int> a(110000);


int main(){
    ll n,h;
    ll mx=0;
    vector<ll> k;
    cin>>n>>h;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        mx=max(mx,a);
        k.push_back(b);
    }
    sort(k.begin(),k.end());
    reverse(k.begin(),k.end());
    ll count=0;
    for(int i=0;i<n;i++){
        if(k[i]>mx){h-=k[i]; count++;}
        else{break;}
        if(h<=0){break;}
    }
    if(h>0){
        if(h%mx!=0){count++;}
        count+=h/mx;
    }
    cout<<count<<endl;
    
    
    return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
int minimum_cost(int a[] , int n , int k){
    int dp[n+1];
    dp[0] = 0;
    dp[1] = 0;
     for(int i=2 ; i<=n ; i++){
        dp[i] = INT_MAX;
      for(int j=i-1 ; j>=1 && (i-j)<=k ; j--){
              int ans1 = abs(a[i] - a[j]) + dp[j];
              dp[i] = min(dp[i] , ans1);
      }
     }
     return dp[n];
}
int main() {
    int n , k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1 ; i<=n ; i++){
        cin>>a[i];
    }
    cout<<minimum_cost(a , n , k);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int x[110];
int n,ans,tmp;
int main()
{
	ans=pow(2,31)-1;
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&x[i]);
	for(int p=1;p<=100;++p){
		tmp=0;
		for(int i=1;i<=n;++i) tmp+=(x[i]-p)*(x[i]-p);
		ans=min(ans,tmp);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;

string s;

int main(){
	int n, a, b;
	cin >> n >> a >> b >> s;
	int pass = 0, fpass = 0;
	for(int i=0; i<n; i++){
		if(s[i] == 'c') puts("No");
		if(s[i] == 'a'){
			if(pass < a + b){
				puts("Yes");
				pass++;
			}
			else puts("No");
		}
		if(s[i] == 'b'){
			if(fpass < b && pass < a + b){
				puts("Yes");
				fpass++;
				pass++;
			}
			else puts("No");
		}
	}
}


Measured memory_bytes: 896
N=int(input())
a_input_list=input().split(' ')
a_num_list=[]
for a in a_input_list:
  a_num_list.append(int(a))

a_num_list.sort()
a_num_list.reverse()

bob=0
allice=0

counter=0
for a in a_num_list:
  if counter%2==0:
    allice+=a
  else:
    bob+=a
  counter+=1

print(allice-bob)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s ;
  cin >> s ;
  int ans = 700;
  if( s.at(0) == 'o') ans += 100;
  if( s.at(1) == 'o') ans += 100;
  if( s.at(2) == 'o') ans += 100;
  cout << ans << endl;
}

Measured memory_bytes: 384