akhauriyash/Code-Regression huggingface dataset:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1_k,co1_v = zip(*Counter(vo1).most_common())
ce2_k,ce2_v = zip(*Counter(ve2).most_common())

ans =0

if vo1 ==ve2:
    if len(ce2_k) <=2:
        ans =sum(ce2_v)
    else:
        ans =sum(ce2_v) +sum(co1_v[2:])   
elif len(co1_v) ==len(ce2_v) ==1:
    ans =0
elif co1_k[0] ==ce2_k[0]:
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    elif len(co1_v) ==len(ce2_v) ==2:
        ans1 =co1_v[1] +ce2_v[0]
        ans2 =co1_v[0] +ce2_v[1]
        ans =min(ans1,ans2)
    elif len(co1_v) ==2:
        ans1 =co1_v[1] +ce2_v[0] +sum(ce2_v[2:])
        ans2 =co1_v[0] +sum(ce2_v[1:])
        ans =min(ans1,ans2)
    elif len(ce2_v) ==2:
        ans1 =ce2_v[1] +co1_v[0] +sum(co1_v[2:])
        ans2 =ce2_v[0] +sum(co1_v[1:])
        ans =min(ans1,ans2)
    else:
        ans1 =sum(co1_v[1:]) +ce2_v[0] +sum(ce2_v[2:] )
        ans2 =sum(ce2_v[1:]) +co1_v[0] +sum(co1_v[2:] )
        ans =min(ans1,ans2)
else: 
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    else:
        ans =sum(co1_v[1:]) +sum(ce2_v[1:])  
   
print(ans)

Measured memory_bytes: 25772
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N, K; cin >> N >> K;
    vector<int> H;
    rep (i, 0, N) {
        int h; cin >> h;
        H.push_back(h);
    }

    vector<int> dp(110000, INF);
    dp[0] = 0;
    for (int now = 0; now < N; ++now) {
        for (int next = now+1; next <= now+K; ++next) {
            dp[next] = min(dp[next], abs(H[now] - H[next])+dp[now]);
        }
    }

    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1144
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
#include <map>
#include <set>
using namespace std;

const int mod = 1e9+7;

void add_self(int& a, int b){
	a += b;
	if(a >= mod)
		a -= mod;
	return;
}

int main(void){
	int n;
	cin >> n;
	vector<vector<int> > can(n, vector<int>(n));
	for(int i = 0;i < n;i++)
		for(int j = 0;j < n;j++)
			cin >> can[i][j];
	vector<int> dp(1 << n);
	dp[0] = 1;
	for(int mask = 0;mask < (1 << n)-1;mask++){ // 1- means women matched
			int m = __builtin_popcount(mask);
			for(int w = 0;w < n;w++){
					if(can[m][w] == 1 && !(mask & (1 << w))){
							int new_mask = mask^(1 << w);
							add_self(dp[new_mask], dp[mask]);
					}
			}
	}
	cout << dp[(1<<n)-1] << endl;
}


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

#define INF (INT32_MAX/2)
#define MAX 100

int N, M;
typedef pair<int, int> P;
vector<P> vp[MAX];

int m[MAX][MAX];

int main() {
	for( int i = 0; i < MAX; i++ ) {
		for( int j = 0; j < MAX; j++ ) {
			m[i][j] = INF;
		}
	}

	cin >> N >> M;
	for( int i = 0; i < M; i++ ) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		P p( b, c );
		vp[a].push_back( p );
		m[a][b] = c;
		m[b][a] = c;
	}

	for( int k = 0; k < N; k++ ) {
		for( int i = 0; i < N; i++ ) {
			for( int j = 0; j < N; j++ ) {
				m[i][j] = min( m[i][j], m[i][k] + m[k][j] );
			}
		}
	}
	int ans = 0;
	for( int i = 0; i < MAX; i++ ) {
		vector<P> pv = vp[i];
		for( int j = 0; j < vp[i].size(); j++ ) {
			if( pv[j].second > m[i][pv[j].first] ) {
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

#define INF 210000000
#define int long long

int gcd(int a, int b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

signed main() {
		int n;
		cin >> n;
		vector<int> a;
		for(int i=0;i<n;i++){
				int tmp;
				cin >> tmp;
				a.push_back(tmp);
		}
		auto max = max_element(a.begin(),a.end());
		cout << accumulate(a.begin(),a.end(),0) - *max / 2;
}



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int dp[3010][3010];

int main(void){
	string s,t;
	cin >> s >> t;
	const int n = s.size();
	const int m = t.size();

	rep(i,n)rep(j,m){
		if(s[i] == t[j]){
			chmax(dp[i + 1][j + 1], dp[i][j] + 1);
		} else {
			chmax(dp[i + 1][j + 1], max(dp[i + 1][j], dp[i][j + 1]));
		}
	}
	
	int ci = n, cj = m;
	string ans = "";
	while(1){
		if(ci == 0 or cj == 0) break;

		if(s[ci-1] == t[cj - 1] and dp[ci - 1][cj -1] + 1 == dp[ci][cj]){
			ans += s[ci - 1];
			ci--,cj--;
		} else if(dp[ci - 1][cj] == dp[ci][cj]){
			ci--;
		} else if(dp[ci][cj - 1] == dp[ci][cj]){
			cj--;
		}
	}

	reverse(begin(ans),end(ans));
	cout << ans << endl;

	return 0;
}

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

int  main()
{
	int  n,i,s=0,f;
	cin>>n;
	int  a[n+1];
	
	for(i=1; i<=n; i++)
	   cin>>a[i];
	   
	do{
		f=0;
		for(i=1; i<=n; i++)
		{
			if(a[i]%2==0)
			{
				a[i]=a[i]/2;
			}
			else
			{
				f=1;
				break;
			}
		}
		
		if(f==0)
		   s++;
	}while(f==0);
	
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

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

    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    cout << min((N + A - 1) / A * B, (N + C - 1) / C * D) << endl;
}


Measured memory_bytes: 3204
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

string s, mew = "mew";
int sp = 0;

bool cat(){
  int m = 0;
  for(;sp < s.size();){
    if(s[sp] == mew[m]){
      m++; sp++;
      if(m == 3)return true;
    }else{
      if(m == 0)return false;
      if(!cat())return false;
    }
  }
  return false;
}

bool solve(){
  if(s.size() == 0)return true;
  bool fl = cat();
  return fl && sp == s.size();
}

signed main(void){
  int i, j, k;
  for(int testcase = 0;testcase < 1234567;testcase++){
    cin >> s;
    puts((solve()) ? "Cat" : "Rabbit");


/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,check=0,ans=0,num=0;
    cin >> n;
	std::vector<int> a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
    //for (int i = 0; i < n; i ++ )cout << a[i] << endl;
	std::sort(a.begin(), a.end() );
    //for (int i = 0; i < n; i ++ )cout << a[i] << endl;
    a.push_back(0);
	//for (int i = 0; i < n; i ++ )cout << a[i];
	for (int i = 0; i < n; i++) {
		num = a[i];
		if (num != a[i + 1]) {
			check++;
			if (num > check) ans += check;
            else if (num < check)ans += check - num;
			check = 0;
		}
		else check++;
	}
	cout << ans << endl;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    for(int i = 0; i < 26; ++i){
        for(int j = 0; j < 15; ++j){
            if(4*i+7*j == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
import math

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


def solve(p, n):
  ans = 0
  l = list(range(1, n+1))
  for i in range(n):
    num = p[i]
    order = l.index(num) + 1
    l.remove(num)
    rest = len(l)

    ans += math.factorial(rest) * order

  return ans

print(abs(solve(p, n) - solve(q, n)))



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)

const long long  int INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
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; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n"

void Main()
{
	ll result=0;

	VI A(3);
	REP(i,3){cin>>A[i];}
	SORT(A);
	ll d=A[0]+A[1];
	ll e=A[2];
	if(d==e) COUT("Yes");
	else COUT("No");
	return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>//stayCalmNeverSettle
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define szof(x) ((int)x.size())
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pii; 
int const INF = (int)1e9+1e3;
ll const INFL = (ll)1e18+1e6;

const int N = 1e5+5;
 
int main(){
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    forn(i,n) cin >> a[i];
    for(int i=k-1;i<n-1;i++){
    	if(a[i+1]>a[i-(k-1)]){
    		cout << "Yes" << endl;
    	}
    	else{
    		cout << "No" << endl;
    	}
    }
}

Measured memory_bytes: 4836
#include <iostream>
#include <cctype>
using namespace std;

int main(){
	int Case[26]={0};
	char c , lc;
	while (cin>>c){
		if(isalpha(c)){
			if(c<='Z'){
				Case[c-'Z'+25]++;
			} else {
				Case[c-'z'+25]++;
			}
		}
	}
	for(int i=0 , lc='a' ; i<26 ; i++ , lc++){
			cout << (char)lc << " : " << Case[i] << endl;
		}
	return 0;
}

Measured memory_bytes: 1140
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific

using namespace std;

int main(void) {
    const size_t nums = 101;
    size_t hello[nums];
    for(size_t i = 0; i < nums; ++i)
        hello[i] = 0;
    size_t a, b, c;
    cin >> a >> b >> c;
    ++hello[a];
    ++hello[b];
    ++hello[c];
    size_t count = 0;
    for(size_t i = 0; i < nums; ++i)
        if(hello[i]) ++count;
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	//ios::sync_with_stdio(false);
	ll N,A,B;
	string s;
	while(cin>>N>>A>>B) {
		ll ans = max(0LL, B*(N-1)+A-(A*(N-1)+B)+1);
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c\n",c)
int main(void){
  double w,h,x,y;
  scanf("%lf %lf %lf %lf",&w,&h,&x,&y);
  printf("%lf ",w*h/2.0);
  PRN((x*2==w)&&(y*2==h));
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
   int a, b;
   char op;
   
   while(1){
       scanf("%d %c %d",&a, &op, &b);
       if(op == '+'){printf("%d\n", a + b);
 }else if(op == '-'){
printf("%d\n", a - b);
       }else if (op == '*'){
 printf("%d\n", a * b);
       } else if (op == '/'){
printf("%d\n", a / b);
       } else {
break;
       }
   }
}


Measured memory_bytes: 2100
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N;
  cin >> N;

  vector<int> x(N), y(N);
  REP(i, N) cin >> x[i] >> y[i];

  int A = 1, B = 1;
  REP(i, N){
    int n = max((A+x[i]-1)/x[i], (B+y[i]-1)/y[i]);
    A = n*x[i]; B = n*y[i];
  }

  cout << A+B << endl;

  return 0;
}

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

int main() {
  int x , y ;
  cin >> x >> y ;
  
  vector<int> a = {0,1,3,1,2,1,2,1,1,2,1,2,1} ;
  if(a[x]==a[y]) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  



Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(0,min(b,d) - max(a,c)) << endl;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll k,q;cin>>k>>q;
  V<ll> d(k);
  rep(i,0,k){
    cin>>d[i];
  }

  while(q--){
    ll n,x,m;cin>>n>>x>>m;  
    ll last=x,sum=0;
    rep(i,0,k){
      sum+=d[i]%m;
    }
    
    last+=sum*((n-1)/k);
    rep(i,0,(n-1)%k){
      if(n%k==1)break;
      last+=d[i]%m;
    }
    
    ll same=0;
    rep(i,0,k){
      if(d[i]%m==0){
        same+=(n-1)/k;
        if(n%k!=1 && i<(n-1)%k)same++;
      }
    }
    //cerr<<same<<ENDL;
    cout<<n-1-(last/m - (x/m))-same<<ENDL;
  }
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MOD = 1000 * 1000 * 1000 + 7;

typedef vector<VI> matr;

matr get(int n)
{
	return matr(n, VI(n, 0));
}

matr mul(matr a, matr b)
{
	int n = SZ(a);
	matr res = get(n);
	FOR (i, 0, n)
	{
		FOR (j, 0, n)
		{
			FOR (k, 0, n)
			{
				res[i][j] = (res[i][j] + a[i][k] * (LL)b[k][j]) % MOD;
			}
		}
	}

	return res;
}

matr bpow(matr a, LL b)
{
	matr res = get(SZ(a));
	FOR (i, 0, SZ(a))
	{
		res[i][i] = 1;
	}

	while(b)
	{
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b /= 2;
	}
	return res;
}

const int MAX = 1010;

string S[MAX];

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

	int h, w;
	LL n;
	cin>>h>>w>>n;

	int k = 0;
	int hh = 0;
	int v = 0;

	int a = 0;
	int b = 0;

	FOR (i, 0, h)
	{
		cin>>S[i];
	}

	FOR (i, 0, h)
	{
		FOR (j, 0, w)
		{
			if (S[i][j] == '#') k++;
			if (j + 1 < w && S[i][j] == '#' && S[i][j+1] == '#') hh++;
			if (i + 1 < h && S[i][j] == '#' && S[i+1][j] == '#') v++;
		}
	}

	FOR (i, 0, h)
	{
		if (S[i][0] == '#' && S[i][w-1] == '#') a++;
	}

	FOR (j, 0, w)
	{
		if (S[0][j] == '#' && S[h-1][j] == '#') b++;
	}

	if (a > 0 && b > 0)
	{
		cout<<1<<endl;
		return 0;
	}

	if (a == 0 && b == 0)
	{
		matr a = get(1);
		a[0][0] = k;
		a = bpow(a, n - 1);
		cout<<a[0][0]<<endl;
		return 0;
	}

	if (a == 0)
	{
		swap(a, b);
		swap(hh, v);
	}

	matr A = get(2);
	A[0][0] = k;
	A[1][0] = hh;
	A[1][1] = a;

	A = bpow(A, n-1);
	int res = A[0][0] - A[1][0];
	if (res < 0) res += MOD;
	res %= MOD;
	cout<<res<<endl;



}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    int n, w; cin>>n>>w;
    vector<int> wei(n), val(n);
    for(int i=0; i<n; i++) cin>>wei[i]>>val[i];

    vector<vector<ll>> dp(n+10, vector<ll>(w+10, 0));
    for(int i=0; i<n; i++){
        for(int j=0; j<=w; j++){
            if(j-wei[i]>=0) dp[i+1][j]=max(dp[i][j], dp[i][j-wei[i]]+val[i]);
            else dp[i+1][j]=dp[i][j];
        }
    }
    cout << dp[n][w] << endl;
}

Measured memory_bytes: 87296
#include<stdio.h>
int main()
{
    int W,a,b,c,d,e,f;
    scanf("%d %d %d",&W,&a,&b);
         c=a+W;
         d=0;
       if(c>=b&&a<=b||(b+W)>=a&&(a+W)>=(b+W))
        printf("%d\n",d);
       if(b>c)
       {
           e=b-c;
           printf("%d",e);
       }
       if((b+W)<a)
       {
           f=a-(b+W);
           printf("%d",f);
       }

    return 0;
}

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

bool isPrime(int n){
	if(n<=1)return false;
	for(int i=2;i*i<=n;i++)
		if(n%i==0)return false;
	return true;
}

signed main() {
  int q;
  cin >> q;

  vector<int> is2017n(100001);
  for (int i = 0; i < 100001; i++) {
    bool is2017 = isPrime(i) && isPrime((i+1)/2);
    if(is2017){
      is2017n[i] = 1;
    }else{
      is2017n[i] = 0;
    }
  }
  vector<int> is2017s(100002);
  is2017s[0] = 0;
  for (int i = 1; i < 100002; i++) {
    is2017s[i] = is2017s[i-1] + is2017n[i];
  }

  for (int i = 0; i < 20; i++) {
   // cerr << is2017s[i] << " ";
  }
  //cerr << endl;
  


  for (int query = 0; query < q; query++) {
    int l,r;
    cin >> l >> r;
    cout << is2017s[r] - is2017s[l-1] << endl;
  }

  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b;
    cin >> a  >> b;
    if(a>b){
        cout << "safe" << endl;
    }else{
        cout << "unsafe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
fun main(args: Array<String>): Unit {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    val a = sc.asSequence().take(n).map { it.toInt() }.toMutableList()

    var r = 0
    for (i in 0 until n) {
        while (true) {
            val p = a[i]
            if (p == 0) {
                break
            }
            r++
            (i until n).takeWhile { a[it] >= p }.forEach { a[it]-- }
       }
    }
    println(r)
}

Measured memory_bytes: 31456
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

struct UnionFind{
	vector<int> par,rank;
	UnionFind(int N){
		par.assign(N,0);
		rank.assign(N,0);
		rep(i,N) par[i]=i;
	}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]) par[x]=y;
		else{
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
};

int N,M,K;
vector<int> c;
using P = pair<int,int>;
using PP = pair<int,P>;

int main(){
	cin>>N>>M>>K;
	c.resize(N);
	int I = K;
	rep(i,N){
		cin>>c[i];
		c[i]--;
		if(c[i]==-1){
			c[i] = I++;
		}
	}
	vector<PP> es;
	UnionFind UF(I);
	rep(i,M){
		int x,y,w;
		cin>>x>>y>>w;
		x--,y--;
		x = c[x];
		y = c[y];
		es.pb(PP(w,P(x,y)));
	}
	sort(all(es));
	long long ans = 0;
	int cnt = 0;
	for(auto e:es){
		if(cnt==K-1) break;
		int w = e.fs;
		int x = e.sc.fs, y = e.sc.sc;
		if(UF.same(x,y)) continue;
		UF.unite(x,y);
		ans += w;
		cnt++;
	}
	if(cnt!=K-1){
		puts("-1");
	}else{
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3832
I=lambda:map(int,input().split())
N=0xfffff
n,q=I()
c=list(I())
Q=[]
for i in range(q):l,r=I();Q.append(l<<40|r<<20|i)
Q.sort()
A=[[]for i in range(N)]
for i,x in enumerate(c):A[x].append(i)
B=[0]*N
def P(i,x):
	i+=1
	while i<=n:B[i]+=x;i+=i&-i
def G(i):
	s=0
	while i:s+=B[i];i-=i&-i
	return s
for i in A:
	if i:P(i[0],1);i.reverse()
t=0
o=[0]*q
for x in Q:
	l=x>>40
	r=x>>20&N
	i=x&N
	while t+1<l:
		b=A[c[t]]
		P(b[-1],-1)
		b.pop()
		if b:P(b[-1],1)
		t+=1
	o[i]=G(r)-G(l-1)
for i in o:print(i)

Measured memory_bytes: 248716
N = int(input())
A = [int(input()) for i in range(N)]
ans = [0]*N
count = 0
ans_tmp2 = 0
ans_tmp = 0

for i in range(0,N):
    if ans_tmp < A[i]:
        ans_tmp = A[i]

for i in range(0,N):
    if ans_tmp == A[i]:
        count += 1
    if ans_tmp2 < A[i] and ans_tmp > A[i]:
        ans_tmp2 = A[i]

if count > 1:
    for j in range(0,N):
        ans[j] = ans_tmp

else:
    for j in range(0,N):
        if A[j] != ans_tmp:
            ans[j] = ans_tmp
        else:
            ans[j] = ans_tmp2

for i in range(0,N):
    print(ans[i])


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

s = list()
for i in range(n):
    s.append(input())

print("AC x {}".format(s.count("AC")))
print("WA x {}".format(s.count("WA")))
print("TLE x {}".format(s.count("TLE")))
print("RE x {}".format(s.count("RE")))


Measured memory_bytes: 16268
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int cnt=0;
for(int i=0;i<s.size();i++){
  if(i%2==0){
  if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
  //  cout<<"a"<<endl;
cnt++;
  }
}
else{
  if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
cnt++;

//cout<<"b"<<endl;
  }
}
}
if(cnt==s.size()) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    l=list(map(int,input().split('/')))
    if l[0]<2019 or l[1]<=4:
        print('Heisei')
    else:
        print('TBD')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long N, std::vector<long long> A){
    vll orig(N, 0);
    REP(i, N){
        orig[i] = i - A[i];
    }
    REP(i, N){
        if(orig[i]<0 || orig[i] > i){
            cout<<-1<<endl; return;
        }
        if(i > 0){
            if(orig[i] < orig[i-1]){
                cout<<-1<<endl; return;
            }
        }
    }

    ll res = 0;
    for(ll i=N-1; i >=0 ; i--){
        if(i == N-1) res += i - orig[i];
        else if(orig[i] - orig[i+1]){
            res += i - orig[i];
        }
    }
    cout<<res<<endl;
}

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


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int INT;
typedef unsigned long long LONG;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define FW freopen("data2.txt", "w", stdout);
//快速读入输出，只适用于整数，使用时流同步打开，C语言不准关流
// getchar()<<cin(关流)<<scanf()<<cin
template <class T>
inline bool Read(T& ret)
{
    char c;
    int sgn;
    if (static_cast<void>(c = getchar()), c == EOF)
        return 0;
    while (c != '-' && (c < '0' || c > '9'))
        c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
        ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}
//输出只能用于整数
template <class T>
inline void Write(T x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        Write(x / 10);
    putchar(x % 10 + '0');
}

long long sum[N * 2];
int a[N * 2];
void slove(int quetion_num)
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
        sum[i] %= mod;
    }
    long long ans = 0;
    for (int i = 1; i < n; ++i) {
        long long cur = sum[n] - sum[i];
        if (cur < 0)
            cur += mod;
        ans = ans % mod + (a[i] * cur) % mod;
    }
    cout << ans % mod << endl;
}
int main()
{
    int num = 1;
    //cin >> num;
    for (int i = 1; i <= num; ++i) {
        slove(i);
    }
    // system("pause");
    return 0;
}

Measured memory_bytes: 5960
#include<bits/stdc++.h>
using namespace std;
int main()
{   
    int a[7]={1,3,5,7,8,10,12},b[1]={2},c[4]={4,6,9,11};
    int x,y;
    int flag1=0,flag2=0;
    cin>>x>>y;

    if(x==2 || y==2)
    {
        printf("No");
        return 0;
    }
    for(int i=0;i<7;i++)
    {
        if(a[i]==x)
        {
            flag1=1;
        }

        if(a[i]==y)
        {
            flag2=1;
        }
    }

    if(flag1==flag2)
    {
        printf("Yes");
        return 0;
    }

flag1=0;flag2=0;
     for(int i=0;i<4;i++)
    {
        if(c[i]==x)
        {
            flag1=1;
        }

        if(c[i]==y)
        {
            flag2=1;
        }
    }

    if(flag1==flag2)
    {
        printf("Yes");
        return 0;
    }



    printf("No");

    return 0;






}

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

const int N = 1000 + 5;

int h, w, A, B, num[N], a[N][N];

int main()
{
	scanf("%d%d%d%d", &h, &w, &A, &B);
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
			if ((i <= B && j <= A) || (i >= B + 1 && j >= A + 1))
				printf("1");
			else printf("0");
		printf("\n");
	}
    return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
long long int ans=0;
long long sort(long long d[],int NumberArrays,int up){
  int tmp;
  for (int i = 0; i < NumberArrays-1; i++) {
    if (up && d[i]<d[i+1]) {
      d[i]=tmp;
      d[i]=d[i+1];
      d[i+1]=tmp;
    }else if (d[i]>d[i+1]) {
      d[i]=tmp;
      d[i]=d[i+1];
      d[i+1]=tmp;
    }
  }
}
//最大公約数
long long int getgcd(long long n, long long m)
{
  int r;
  if (n > m) {
    long long t = m;
    m = n;
    n = t;
  }
  while ((r = m % n) != 0) {
    m = n;
    n = r;
  }
return n;
}

//nの階乗を計算
long long factorial(long long n){
    long long int answer = 1;
while(n > 1){
  answer *= n;
  n--;
}
    return answer;
}

//組み合わせの数nCrを計算
long long calcNumOfCombination(long long  n, long long r){
    return factorial(n) / (factorial(r) * factorial(n-r));
}


int main(int argc, char* argv[]){
	long long a = 0,b=0;
	scanf("%lld %lld",&a,&b);
  long long c[b];
  for (long long i = 0; i < b; i++) {
    scanf("%lld",&c[i]);
    ans+=c[i];
  }
  if (ans>a) {
    printf("-1");
    return 0;
  }
  printf("%lld\n",a-ans);
  return 0;
}


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cin >> n;
	long long int arr[n+1], dp[n+5][n+5];
	for(int i=1;i<=n;i++){
		cin >> arr[i];
	}
	for(int i=n;i>=0;i--){
		for(int j=0;j<=n;j++){
			if(i==0 || j==0){
				dp[i][j]=0;
			}
			else if(i==j){
				dp[i][j]=arr[i];
			}
			else{
				dp[i][j]=max(arr[i]-dp[i+1][j], arr[j]-dp[i][j-1]);
			}
		}
	}
	cout << dp[1][n] << '\n';
}

Measured memory_bytes: 70784
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  n <- (read::String -> Integer) <$> getLine
  print . head $ calc (n - 1) [1, 2]

calc::Integer -> [Integer] -> [Integer]
calc n (x:y:rest)
  | n == 0 = x:y:rest
  | otherwise = calc (n - 1) ((x + y):x:y:rest)


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7, mod = 1e9 + 7;
typedef long long ll;
ll qkpow(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll dp[2005];
int main() {
    ll n; cin >> n;
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 3; i - j >= 0; j++) {
            dp[i] = (dp[i] + dp[i - j]) % mod;
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 3640
N = int(input())
B = list(map(int, input().split()))

res = []

while len(B) > 0:
    p = -1
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            p = j
            break
    if p == -1:
        print(-1)
        exit()
    else:
        res.append(p)
        B.pop(p - 1)

for r in res[::-1]:
    print(r)


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<pii> a;
  pii now = pii(0, s[0] - '0');
  rep (i, n) {
    if (now.second == s[i] - '0') {
      now.first++;
    }
    else {
      a.push_back(now);
      now = pii(1, s[i] - '0');
    }
  }
  a.push_back(now);
  int l = 0, r = 0;
  int m = a.size();
  int nokori = k;
  ll sum = 0;
  while (r < m) {
    if (a[r].second) sum += a[r].first;
    else {
      if (nokori == 0) break;
      sum += a[r].first;
      nokori--;
    }
    r++;
  }

  ll ans = sum;
  while (r < m) {
    if (a[l].second) {
      sum -= a[l].first;
      l++;
    }
    else {
      sum -= a[l].first;
      l++;
      nokori++;
      while (r < m) {
        if (a[r].second) {
          sum += a[r].first;
          chmax(ans, sum);
        }
        else {
          if (nokori == 0) break;
          sum += a[r].first;
          chmax(ans, sum);
          nokori--;
        }
        r++;
      }        
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1528
# Here your code !
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
n,t = inp
a = inp
smax = 0
min = 999999999
ans = 0
a.each do |d|
  min = d if d < min
  sa =  d - min
  if(sa > smax)
    smax = sa
    ans = 1
  elsif(sa == smax)
    ans += 1
  end
end
p ans


Measured memory_bytes: 9492
#include<bits/stdc++.h>
using namespace std;
#define N 100010
typedef long long ll;
int cnt=0;
struct node
{
    int to;
}p[2*N];
int nxt[2*N],head[N],d[N];
vector<int>d4;
void add(int u,int v)
{
    cnt++;
    p[cnt].to=v;
    nxt[cnt]=head[u];
    head[u]=cnt;
}
int dfs(int x,int fa,int st,int ed)
{
    if(x==st)return 0;
    if(x==ed)return 1;
    for(int i=head[x];i;i=nxt[i])
    {
        if(p[i].to==fa )continue;
        return dfs(p[i].to,x,st,ed);
    }
    return 0;
}
int main()
{
    int n,m,x,y;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        add(x,y),add(y,x);
        d[x]++,d[y]++;
    }
    int flag=0;
    for(int i=1;i<=n;i++)
    {
        if(d[i]&1){printf("No\n");return 0;}
        if(d[i]>=6)flag=1;
        if(d[i]==4)d4.push_back(i);
    }
    if(flag || d4.size()>=3)
        {printf("Yes\n");return 0;}
    if(d4.size()<2)
    { printf("No\n");return 0;}

    int num=0,st=d4[0],ed=d4[1];
    for(int i=head[st];i;i=nxt[i])
        if(dfs(p[i].to,st,st,ed))
                num++;
    if(num==2)
        printf("Yes\n");
    else
        printf("No\n");
}



Measured memory_bytes: 2560
def getval():
    n = int(input())
    h = [list(map(int,input().split())) for i in range(n)]
    return n,h

def main(n,h):
    dp = [[h[0][0],h[0][1],h[0][2]]]
    for i in range(1,n):
        cur = h[i]
        prev = dp[-1]
        temp = []
        temp.append(max(prev[1],prev[2])+cur[0])
        temp.append(max(prev[0],prev[2])+cur[1])
        temp.append(max(prev[0],prev[1])+cur[2])
        dp.append(temp)
    print(max(dp[-1]))
    
if __name__=="__main__":
    n,h = getval()
    main(n,h)

Measured memory_bytes: 97056
import math
K = int(input())
num_list = []

for t in range(K):
  a = t + 1
  for s in range(K):
    b = s + 1
    koyaku = math.gcd(a,b)
    for u in range(K):
      c = u + 1
      num_list.append(math.gcd(koyaku,c))
      
print(sum(num_list))

Measured memory_bytes: 71340
#B
n = int(input())
p = list(map(int, input().split()))
count=0
for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i + 1] < p[i] < p[i - 1]:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    string str; cin >> str;
    reverse(str.begin(), str.end());
    if(str[0] == '2' || str[0] == '4' || str[0] == '5' || str[0] == '7' || str[0] == '9')
        cout << "hon\n";
    else if(str[0] == '0' || str[0] == '1' || str[0] == '6' || str[0] == '8')
        cout << "pon\n";
    else
        cout << "bon\n";
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
int main(void){
    int sum=0;
    char a[100];
    scanf("%s",a);
    int len=strlen(a);
    int i = 0;
    while(2*(i+1)<=len){
        if(a[i]!=a[len-1-i]){
            sum ++;
            
        }
        i ++;
    }   
    printf("%d",sum);
}


Measured memory_bytes: 128
#include<cstdio>

int main(void){
int H,W,i,j;
do {
scanf("%d%d",&H,&W);
if(H!=0||W!=0){
for(j=1;j<=W;j++){printf("#");}printf("\n");//1retume
for(i=2;i<=H-1;i++){
printf("#");
for(j=2;j<=W-1;j++){printf(".");}
printf("#\n");}//2karaH-1retume
for(j=1;j<=W;j++){printf("#");}printf("\n");
printf("\n");}
}while(H!=0||W!=0);
return 0;
}

Measured memory_bytes: 2576
while (n=gets.to_i)!=0
  mat=Array.new(n+1){Array.new(n+1,0)}
  ans=Array.new(n+1){Array.new(n+1)}
  n.times.with_index do |id|
    mat[id]=gets.split.map(&:to_i)
    mat[id][n]=mat[id].inject(:+)
    (n+1).times.with_index do |id2|
      mat[n][id2]+=mat[id][id2]
    end
  end
  mat.each.with_index do |item,id|
    item.each.with_index do |ss,id2|
      ans[id][id2]=format("%5d",ss)
    end
  end
  ans.each do |line|
    puts line.join
  end
end

Measured memory_bytes: 8844