akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep01(i, n) for(int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for(int i = 1; i < (n); i++)
#define rep11(i, n) for(int i = 1; i < (n) + 1; i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
typedef struct { int x; int y; } Pos;
using namespace std;

int H, W;
int Cw, Ch;
int Dw, Dh;
int cost = 0;
bool reach = false;
vector<vector<char>> S;
vector<vector<bool>> R;
vector<vector<int>> C;
queue<Pos> innerQ;
queue<Pos> jumpQ;
int main()
{
    cin >> H >> W;
    cin >> Ch >> Cw;
    cin >> Dh >> Dw;
    S = vector<vector<char>>(W + 1, vector<char>(H + 1));
    R = vector<vector<bool>>(W + 1, vector<bool>(H + 1));
    C = vector<vector<int>>(W + 1, vector<int>(H + 1, INT_MAX));
    rep11(y, H) rep11(x, W) cin >> S[x][y];
    innerQ.push(Pos{ Cw, Ch });
    jumpQ.push(Pos{ Cw, Ch });
    R[Cw][Ch] = true;
    C[Cw][Ch] = cost;
    while (0 < innerQ.size()) {
        //内部探索
        while (0 < innerQ.size()) {
            const int dx[] = { 1,-1,0,0 }, dy[] = { 0,0,1,-1 };
            Pos ref = innerQ.front();
            innerQ.pop();
            rep(i, 4) {
                Pos chk = Pos{ ref.x + dx[i], ref.y + dy[i] };
                if (chk.x <= 0 || chk.x > W || chk.y <= 0 || chk.y > H) continue;
                if (S[chk.x][chk.y] == '#') continue;
                if (R[chk.x][chk.y]) continue;
                if (C[chk.x][chk.y] <= cost) continue;
                R[chk.x][chk.y] = true;
                C[chk.x][chk.y] = cost;
                innerQ.push(Pos{ chk.x, chk.y });
                jumpQ.push(Pos{ chk.x, chk.y });
            }
        }
        //ジャンプ探索
        int jump = jumpQ.size();
        rep(i, jump){
            Pos ref = jumpQ.front();
            jumpQ.pop();
            for (int dy = -2; dy < 3; dy++) {
                for (int dx = -2; dx < 3; dx++) {
                    if (ref.x + dx <= 0 || ref.x + dx > W || ref.y + dy <= 0 || ref.y + dy > H) continue;
                    if (!R[ref.x + dx][ref.y + dy] && (S[ref.x + dx][ref.y + dy] == '.')) {
                        R[ref.x + dx][ref.y + dy] = true;
                        C[ref.x + dx][ref.y + dy] = cost + 1;
                        innerQ.push(Pos{ ref.x + dx, ref.y + dy });
                        jumpQ.push(Pos{ ref.x + dx, ref.y + dy });
                    }
                }
            }
        }
        if (R[Dw][Dh]) {
            reach = true;
            break;
        }
        cost++;
    }
    if (reach)
        cout << C[Dw][Dh] << endl;
    else
        cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 8744
#include<stdio.h>

int sankaku(int x){return (x*(x+1))/2;}

int main(void){
	int i,x;
	scanf("%d",&x);
	for(i = 1;i <= 100000;i++){
		if(x <= sankaku(i)){printf("%d\n",i);return 0;}
	}
	return 0;
}


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

typedef long long ll;
typedef pair<int, pair<int, int>> piii;
//loop
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//STL
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

const int INF = 1e9;

#define deg_to_rad(deg) ((deg)*M_PI / 180.0)

// const int MOD = 998244353;

void Main()
{
    int N, A;
    cin >> N >> A;

    cout << N * N - A << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<map>
#include <iomanip>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define Yes(a) if(a)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;

int main() {
	int a, b,c;
	cin >> a >> b>>c;
	int ans = 0;
	if (a == b)ans++;
	if (a == c)ans++;
	if (b == c)ans++;
	Yes(ans == 1);

	return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")

#include<bits/stdc++.h>

#define pb push_back
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define f(i, a ,b) for(int i = (int)a; i <=(int)(b);i++)
#define endl "\n"
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;

using namespace std;

const int N = 1e5+5,MOD = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void IOS()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
   	cout.precision(10);
   	cout << fixed;
}
int a[N],dp[N];
	
int32_t main()
{
	IOS();
	int n,k;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}				
	fill(dp,dp+n,2e9);
	dp[0] = 0,dp[1] = abs(a[1]-a[0]);
	for(int i = 2; i < n; i++)
	{
		for(int j = 1; j <= min(k,i); j++)
		{
			dp[i] = min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
		}
	}
	cout << dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
// AOJ 2151: Brave Princess Revisited
// 2017.11.11 bal4u@uu

#include <stdio.h>
#include <string.h>

typedef struct { int t, n, m; } QUE;
QUE que[20001]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		QUE t = que[i]; que[i] = que[min]; que[min] = t;
		min_heapify(min);
	}
}

int deq(int *n, int *m)
{
	if (qsize == 0) return 0;
	*n = que[0].n, *m = que[0].m;
	que[0] = que[--qsize];
	min_heapify(0);
	return 1;
}

void enq(int t, int n, int m)
{
	int i, min;

	i = qsize++;
	que[i].t = t, que[i].n = n, que[i].m = m;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		QUE tt = que[i]; que[i] = que[min]; que[min] = tt;
		i = min;
	}
}

typedef struct { int len, to[101], d[101], e[101]; } TBL;
TBL tbl[101];
int node[101][101]; int size;

int search(int start, int goal, int l)
{
	int s, m, i, k, e, p, ans;
	TBL *tp;

	qsize = 0;
	memset(node, 0x55, sizeof(node));
	node[start][l] = 0; enq(0, start, l);
	ans = 0x7ffffff;
	while(deq(&s, &m)) {
		p = node[s][m];
		if (s == goal) {
			if (p < ans) ans = p;
			continue;
		}

		for (tp = tbl + s, i = 0; i < tp->len; i++) {
			e = tp->to[i];

			k = p + tp->e[i];
			if (k < node[e][m]) node[e][m] = k, enq(node[e][m], e, m);

			k = m - tp->d[i];
			if (tp->d[i] <= m && p < node[e][k]) node[e][k] = p, enq(node[e][k], e, k);
		}
	}
	return ans;
}

int main()
{
	int n, m, l, a, b, d, e, i;

	while (scanf("%d%d%d", &n, &m, &l) && n > 0) {
		memset(tbl, 0, sizeof(tbl));
		while (m--) {
			scanf("%d%d%d%d", &a, &b, &d, &e);
			a--, b--;
			i = tbl[a].len, tbl[a].to[i] = b, tbl[a].d[i] = d, tbl[a].e[i] = e, tbl[a].len++;
			i = tbl[b].len, tbl[b].to[i] = a, tbl[b].d[i] = d, tbl[b].e[i] = e, tbl[b].len++;
		}
		size = n;
		printf("%d\n", search(0, n-1, l));
	}
	return 0;
}

Measured memory_bytes: 2108
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int a[8007];
bool dp[8007][16007];
int main()
{
	string s;
	cin>>s;
	int fx,fy,i,j;
	cin>>fx>>fy;
	int m=0,k=0;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='T')
		{
			k++;
			a[k]=m;
			m=0;
		}
		else 
			m++;
	}
	k++;
	a[k]=m;
	dp[1][a[1]+8000]=1;
	for(i=3;i<=k;i+=2)
		for(j=0;j<=16000;j++)
		{
			if(j+a[i]<=16000)
				dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
				dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	dp[0][8000]=1;
	for(i=2;i<=k;i+=2)
		for(j=0;j<=16000;j++)
		{
			if(j+a[i]<=16000)
				dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
				dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	int ans;
	if(k%2==0){ 
		ans=dp[k][fy+8000]&&dp[k-1][fx+8000];
	}
	else{
		ans=dp[k][fx+8000]&&dp[k-1][fy+8000];
	}	
	cout<<(ans==0?"No":"Yes");
	return 0;
}

Measured memory_bytes: 125184
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 105;
ll dp0[MAX_N][4],dp1[MAX_N][4];

int main()
{
	string N;
	cin >> N;
	int L = N.size();
	int K;
	cin >> K;
	dp0[1][1] = N[0] - '0' - 1;
	rep(i,MAX_N)
	{
		dp0[i][0] = 1;
	}
	dp1[1][1] = 1;
	for(int i = 2; i <= L; ++i)
	{
		for (int j = 1; j <= 3; ++j)
		{
			dp0[i][j] = dp0[i-1][j-1]*9 + dp0[i-1][j] + dp1[i-1][j-1]*max(0,N[i-1]-'0'-1);
			if (N[i-1] != '0') dp0[i][j] += dp1[i-1][j];
			if (N[i-1] == '0') dp1[i][j] = dp1[i-1][j];
			else dp1[i][j] = dp1[i-1][j-1];
		}
	}

	/*
	for (int i = 1; i <= L; ++i)
	{
		for (int j = 0; j <= K; ++j)
		{
			cout << dp0[i][j] << " ";
		}
		cout << endl;
	}

	for (int i = 1; i <= L; ++i)
	{
		for (int j = 0; j <= K; ++j)
		{
			cout << dp1[i][j] << " ";
		}
		cout << endl;
	}
	*/
	cout << dp0[L][K] + dp1[L][K] << endl;
	return 0;
}

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

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

    for(int i = a; i <= b; i++){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;

}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;

string temp = "ABC";

long long solve(int pos, int which, int&n, string& s, 
	vector<vector<long long>>& dp) {

	if(pos >= n) {
		return which == 2 ? 1 : 0;
	}
	if(dp[pos][which] != -1)
		return dp[pos][which];

	long long ways = solve(pos + 1, which, n, s, dp);

	if(which < 3 && temp[which] == s[pos]) {
		ways += solve(pos + 1, which + 1, n, s, dp);
	}
	return dp[pos][which] = ways;
}

void getAC() {	
	ios_base :: sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	// vector<vector<long long>> dp(n, vector<long long>(3, -1));
	// long long ans = solve(0, 0, n, s, dp);
	// cout << ans << '\n';
	int ans = 0;
	for(int i = 0; i < n - 2; ++i) {
		if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			ans++;
		}
	}
	cout << ans << '\n';
}
 
int main() {	
	getAC();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

long long a, b, g;

long long gcd(long long a, long long b)
{
	if(a%b == 0)  return b;
	else  return gcd(b, a%b);
}

int main()
{
	while(scanf("%lld %lld", &a, &b) != EOF){
		g = gcd(a, b);
		printf("%lld %lld\n", g, a*b/g);
	} 
	return 0;
}

Measured memory_bytes: 3128
/* ===================================*/
/* Author :   MD FAHAD                */
/* Email  :   fahad.mohad99@gmail.com */
/* Institute: HSTU                    */
/* ===================================*/

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / gcd(a,b)))

#define READ_IN freopen("Input.txt","r",stdin)
#define READ_OUT freopen("Output.txt","w",stdout)

typedef long long int           ll;
typedef unsigned long long int  llu;

int main(void)
{
    string s;

    cin >> s;

    ll maxa = 200005,mina = 0;

    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='A'){
            if(i<maxa)
                maxa = i;
        }
        else if(s[i]=='Z')
        {
            if(i>mina)
                mina =i;
        }
    }

    cout << mina - maxa +1 << "\n";



    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
pair<long,int> query[100000];
void Calc(){
	int N = rei();
	int M = rei();
	priority_queue<long,vector<long>,greater<long>> pq;
	for(int i=0;i<N;i++){
		int a = rei();
		pq.push(a);
	}
	for(int i=0;i<M;i++){
		int b = rei();
		long c = rei();
		query[i] = {c,b};
	}
	sort(query,query+M);
	for(int i=M-1;i>=0;i--){
		int b = query[i].second;
		long c = query[i].first;
		int b0 = 0;
		while(!pq.empty() && pq.top() < c && b0 < b){
			pq.pop();
			b0++;
		}
		for(int j=0;j<b0;j++){
			pq.push(c);
		}
	}
	long ans = 0;
	while(!pq.empty()){
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
typedef long long				ll;
typedef pair<int,int >			pii;
#define V						vector
#define SYNC					ios_base::sync_with_stdio(0);cin.tie(0);
#define rep(i,b)				for(int i=0;i<b;i++)
#define repn(i,n)				for(int i=1;i<=n;i++)
#define ALL(x)					(x).begin(),(x).end()
#define fi						first
#define se						second
#define pb						push_back
#define dzx						cerr<<"here";
const ll MOD=1e9+7,INF=9e18;
const int inf=2e9;
/* Equinox */
ll ans[2];
int main(){SYNC
	int n,p;
	ans[0]=1;
	ans[1]=0;
	int f[2]={0,0};
	cin>>n>>p;
	rep(i,n){
		ll a;
		cin>>a;
		a=a&1;
		ll tans[2]={ans[0],ans[1]};
		ans[0^a]+=tans[0];
		ans[1^a]+=tans[1];
	}
	cout<<ans[p];
	return 0;
}

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

void push(int);
int pop();

int num[1000];
int n=0;

int main(){

 
  int i,x,y,ans;
  char c[100];

  for(i=0 ; i<100 ; i++){
    num[i]=0;
  }


  while(scanf("%s",c)!=EOF){
    //if(c=='\n') break;
    //if(c==' ') continue;
    
   
    if(c[0]=='+'){
      x=pop();
      y=pop();
      push(x+y);
    }
      
      else if(c[0]=='-'){
	x=pop();
	y=pop();
	push(y-x);
      }
      else if(c[0]=='*'){
	x=pop();
	y=pop();
	push(x*y);
      }
      else push(atoi(c));
  }
  
  ans=pop();
  printf("%d\n",ans);


  return 0;
}

void push(int x){
  n++;
  num[n]=x;
}

int pop(){
  n--;
  return num[n+1];
}

Measured memory_bytes: 548
#include<bits/stdc++.h>
using namespace std;
const int maxx = 100000;
int A[maxx];
int n,T;
int Ans=1<<30;
int main(){
	cin>>n;cin>>T;
	for(int i=1;i<=n;i++){
		int a,b;
		cin>>a>>b;
		if(b<=T)Ans=min(Ans,a);
	}
	if(Ans==(1<<30))puts("TLE");
	else 
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int max = sc.nextInt();
        
        int keta = String.valueOf(max).length();
        
        Set<Integer> set = new TreeSet<Integer>();
        set.add(7);
        set.add(5);
        set.add(3);
        
        for (int i = 0; i < keta - 1; i++) {
            Set<Integer> set2 = new HashSet<Integer>();
            for (Integer number : set) {
                String str = String.valueOf(number);
                set2.add(Integer.parseInt(str + "7"));
                set2.add(Integer.parseInt(str + "5"));
                set2.add(Integer.parseInt(str + "3"));
            }
            for (Integer number : set2) {
                set.add(number);
            }
        }
        
        int count = 0;
        for (Integer number : set) {
            if (number > max) break;
            
            String str = String.valueOf(number);
            if (str.contains("7") && str.contains("5") && str.contains("3")) count++;
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 37204
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
using namespace std;
ifstream f ("test.in"); ofstream g ("test.out");
int n,dp[100005],v[100005];
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>v[i];
    dp[1]=0;
    dp[2]=abs(v[1]-v[2]);
    for(int i=3;i<=n;i++)
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,m,k,a[100000],i;
int main(){
  cin>>n;
  for(i=0;i<n;i++){
    cin>>a[i];
    m=max(m,a[i]);
  }
  for(i=0;i<n;i++)if(a[i]!=m&&min(k,m-k)<=min(a[i],m-a[i]))k=a[i];
  cout<<m<<" "<<k;
}


Measured memory_bytes: 640
// ------------------------------------
// Date:2018/ 3/ 9
// Problem:ABC 062 Grouping a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

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

  int x, y;
  cin >> x >> y;
  int a[7] = {1, 3, 5, 7, 8, 10, 12};
  int b[4] = {4, 6, 9, 11};

  bool ok1 = false;
  bool ok2 = false;
  REP(i, 7) {
    if (a[i] == x) ok1 = true;
    if (a[i] == y) ok2 = true;
  }
  if (ok1 ^ ok2) {
    cout << "No" << endl;
    return 0;
  }
  if (ok1 && ok2) {
    cout << "Yes" << endl;
    return 0;
  }

  REP(i, 4) {
    if (b[i] == x) ok1 = true;
    if (b[i] == y) ok2 = true;
  }
  if (ok1 ^ ok2) {
    cout << "No" << endl;
    return 0;
  }
  if (ok1 && ok2) {
    cout << "Yes" << endl;
    return 0;
  }

  if (x == 2 && y == 2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long 
#define Mod 1000000007
using namespace std;
LL dp[60];
int n;
char s1[60],s2[60];
int main(){
	cin>>n;
	cin>>s1>>s2;
	int now=0;
	if(s1[0]==s2[0]){
		now=0;
		dp[now]=3;
	}
	else{
		now=1;
		dp[now]=6;
	}
	int step;
	for(int i=now;i<n;i+=step){
		if(s1[i]==s2[i]){
			if(s1[i+1]==s2[i+1]){
				dp[i+1]=(dp[i]*2)%Mod;
				step=1;
			}
			else{
				dp[i+2]=(dp[i]*2)%Mod;
				step=2;
			}
		}
		else{
			if(s1[i+1]==s2[i+1]){
				dp[i+1]=(dp[i])%Mod;
				step=1;
			}
			else{
				dp[i+2]=(dp[i]*3)%Mod;
				step=2;
			}
		}
	}
	cout<<dp[n-1]%Mod;
	return 0;
}

Measured memory_bytes: 256
// 12-22.rs --- 12/22
// author: Seong Yong-ju <sei40kr@gmail.com>

// tanakah's input macro
// cf https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: chars
    };

    let ans = n.into_iter().filter(|&c| c == '2').count();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int MN = 100012;
const int inf = INT_MAX;
int n,k,a[MN],dp[MN];
int main (void) {
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) {
        int j = max(0,i-k);
        dp[i] = inf;
        for (; j < i; j++) {
            dp[i] = min(dp[i], dp[j]+abs(a[i]-a[j]));
        }
    }
    cout << dp[n-1] << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define PI 3.141592653589793238
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in2.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T = 1;
	//cin >> T;
	FOR1(tp, T)
	{
		//cout << "Case #" << tp << ": ";
		int n, k; cin >> n >> k;
		int ans = 0;

		for(int i = k; i <= n+1; i++){
			int lo, hi;
			lo = i*(i-1)/2;
			int t = n-i;
			hi = n*(n+1)/2 - t*(t+1)/2;
			ans = ( ans + hi-lo+1 ) % MOD;
		}

		cout << ans;
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 3652
n = gets.chomp.to_i
input = gets.chomp.split(' ').map(&:to_i)
ans = 0
input.each_cons(3) do |a, b, c|
  array = Array.new
  pushed = array.push(a, b, c)
  sorted = pushed.sort
  ans += 1 if pushed[1] == sorted[1]
end
puts ans


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#define MAX 1000000
using namespace std;

struct pp{
    int t;
    string s;
};

class queue{
public:
    int head;
    int tail;
    vector<pp> v;
    queue();
    void enqueue(pp x);
    pp dequeue();
    bool isEmpty();
};

queue::queue(){
    head = 0;
    tail = 0;
    v.resize(MAX);
}

void queue::enqueue(pp x){
    v[tail].t = x.t;
    v[tail].s = x.s;
    tail++;
}

pp queue::dequeue(){
    head++;
    return v[head-1];
}

bool queue::isEmpty(){
    return head == tail;
}


int main(){
    int n;cin >> n;
    int q;cin >> q;
    queue q1;
    for(int i=0;i<n;i++){
        pp p;
        cin >> p.s >> p.t;
        // cout << p.s << endl;
        q1.enqueue(p);
    }

    int passtime = 0;
    vector<pp> v;
    while(!q1.isEmpty()){
        pp ptmp = q1.dequeue();
        // cout << ptmp.s << endl;
        if(ptmp.t > q){
            passtime +=q;
            ptmp.t -= q;
            q1.enqueue(ptmp);
        }
        else{
            passtime += ptmp.t;
            ptmp.t = passtime;
            v.push_back(ptmp);
        }
    }
    for(int i=0;i<v.size();i++){
        cout << v[i].s << " " << v[i].t << endl;
    }
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

int N, K, Q;
vector<int> correct;

int main()
{
    cin >> N >> K >> Q;
    correct.resize(N, 0);

    for (int i = 0; i < Q; i++)
    {
        int a;
        cin >> a;
        a--;
        correct[a]++;
    }

    for (int i = 0; i < N; i++)
    {
        if (K - Q + correct[i] > 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

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

        if (K % 2 == 0) {
            System.out.println("-1");
            return;
        }

        long[] array = new long[1000001];
        array[0] = 7 % K;

        for (int i = 1; i <= K; i++) {
            array[i] = (10 * array[i - 1] + 7) % K;
        }

        for (int i = 0; i <= K; i++) {
            if (array[i] == 0) {
                System.out.println(i + 1);
                return;
            }
        }

        System.out.println("-1");

    }
}


Measured memory_bytes: 43248
(setq *m* 10000000000)

(defun calc (l)
  (+ (abs (- (nth 1 l) (nth 0 l))) (abs (- (nth 2 l) (nth 1 l)))))

(defun perm (now next)
  (if (equal now nil)
    (when (< (calc next) *m*) (setq *m* (calc next)))
    (dotimes (i (length now))
        (perm (append (subseq now 0 i) (nthcdr (+ i 1) now)) (append next (list (nth i now))))
        )
    )
)

(perm (list (read) (read) (read)) '())
(print *m*)

Measured memory_bytes: 13280
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var S = lines[0];
    S = S.replace("2017", "2018");
    console.log(S);
});

Measured memory_bytes: 7500
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, k, ans = 0;
    string s;
    cin >> n >> k >> s;
    int cnt = 0;
    for(int i = 1; i < s.size(); i++){
        if(s[i - 1] != s[i]){
            cnt++;
        }
    }
    cnt = max(0, cnt - 2 * k);
    ans = n - 1 - cnt;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

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

		String[] patterns = { "S", "H", "C", "D" };
		int cards[][] = new int[4][13];

		//入力されたカードを配列に2次元配列に格納する
		for (int i = 0; i < a; i++) {
			String str = sc.next();
			int num = sc.nextInt();
			cards[convert(str)][num-1] = num;
		}

		//不足してるカードを出力する
		for (int i = 0; i < patterns.length; i++) {
			for (int j = 0; j < 13; j++ ) {
				if(cards[i][j] == 0)
					System.out.println(patterns[i] + " " + (j+1));
			}
		}
	}
	
	public static int convert(String str){
		int value = 0;
		if(str.equals("S")) value = 0;
		else if(str.equals("H")) value = 1;
		else if(str.equals("C")) value = 2;
		else if(str.equals("D")) value = 3;
		return value;
	}
}

Measured memory_bytes: 18064
import numpy as np
N = int(input())
time = np.array([int(input()) for _ in range(5)])
place = np.zeros(6)
place[0] = N
end = 0
cnt = 0
'''
while place[5] != N:

    cnt += 1
    for i in range(4,-1,-1):
        now = place[i + 1]
        work = min(place[i] , time[i])
        place[i + 1] += work
        place[i] -= work
    #print(place)
'''
ans = 0
min_val = min(time)
print(int(np.ceil(N / min_val) + 4))

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

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

    int x, y;
    cin >> x >> y;

    int group[12] = {0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};

    if(group[x-1] == group[y-1]) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
from collections import Counter

h,w,m=map(int,input().split())
hw=[list(map(int,input().split())) for _ in range(m)]

hlst=[x for x,_ in hw]
wlst=[x for _,x in hw]

hcnt=Counter(hlst)
wcnt=Counter(wlst)

_,hmax=hcnt.most_common(1)[0]
_,wmax=wcnt.most_common(1)[0]

hcand=set()
wcand=set()

for k,v in hcnt.items():
    if v==hmax:
        hcand.add(k)

for k,v in wcnt.items():
    if v==wmax:
        wcand.add(k)

ng=set()

for hh,ww in hw:
    if hh in hcand and ww in wcand:
        ng.add((hh,ww))

if len(hcand)*len(wcand)>len(ng):
    print(hmax+wmax)
else:
    print(hmax+wmax-1)

Measured memory_bytes: 214804
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(x,y) for(lli i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
int main(){
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    vector <lli> lun;
    rep(1,10){
    	lun.pb(i);
	}
	lli j=0;
	lli k=1;
	while(lun.size()<100000){
		//cout<<j<<" "<<lun.size()<<"\n";
		lli i;
		for(i=j;(lun[i]/k)>0 && (lun[i]/k)<10;i++){
			//cout<<lun[i]<<" ";
			lli r=lun[i]%10;
			if(r-1>=0)
			lun.pb(lun[i]*10+r-1);
			lun.pb(lun[i]*10+r);
			if((r+1)<10)
			lun.pb(lun[i]*10+r+1);
		}
		j=i;
		k*=10;
	}
	//rep(0,100)
	//cout<<lun[i]<<" ";
	lli x;
	cin>>x;
	cout<<lun[x-1];
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<long long>A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    long long ans = 0, high = A.at(0);
    for (int i = 1; i < N; i++)
    {
        if (A.at(i) > high)
        {
            high = A.at(i);
        }
        else 
        {
            ans += high - A.at(i);
        }
    }
    cout << ans;
}

Measured memory_bytes: 4772
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
#include <complex>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
static const int tx[] = {-1,+0,-1};
static const int ty[] = {-1,-1,+0};
 
static const double EPS = 1e-10;

int dp[2001][2001];
int prev[2001][2001];

int main(){
  string str;
  memset(dp,0,sizeof(dp));
  memset(prev,-1,sizeof(prev));
  while(cin >> str){
    string r_str = str;
    reverse(r_str.begin(),r_str.end());
    for(int y = 0; y < str.size(); y++){
      for(int x = 0; x < r_str.size(); x++){
        if(str[y] == r_str[x]){
          dp[y+1][x+1] = dp[y][x] + 1;
          prev[y+1][x+1] = 0;
        }
        else if(dp[y][x+1] < dp[y+1][x]){
          dp[y+1][x+1] = dp[y+1][x];
          prev[y+1][x+1] = 2;
        }
        else {
          dp[y+1][x+1] = dp[y][x+1];
          prev[y+1][x+1] = 1;
        }
      }
    }

    string res = "";
    queue<P> que;
    que.push(P(str.size(),r_str.size()));
    while(!que.empty()){
      P p = que.front();
      que.pop();
      int y = p.first;
      int x = p.second;
      int dir = prev[y][x];
      if(dir == 0){
        res.push_back(str[y-1]);
      }
      int dx = x + tx[dir];
      int dy = y + ty[dir];
      if(prev[dy][dx] == -1) break;
      P next(dy,dx);
      que.push(next);
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 32500
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    ll a[100005];
    ll s = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        s += a[i];
    }
    if(s % (n * (n + 1) / 2)){
        cout << "NO" << endl;
        return 0;
    }
    ll l = s / (n * (n + 1) / 2);
    ll k = 0;
    for(int i = 0; i < n; i++){
        ll d = a[i] - a[(i + 1) % n] + l;
        if(d < 0 || d % n != 0){
            cout << "NO" << endl;
            return 0;
        }
        k += d / n;
    }
    if(k == l) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 4392
import sys
N,M = map(int,input().split())
P = []
for i in range (N):
    P.append(-1)

A=[] #appendのために宣言が必要
while True:
    try:
        A.append(list(map(int,input().split())))

    except:
        break;



for s in range(M):
    if P[A[s][0]-1]== -1 or P[A[s][0]-1] ==A[s][1]:
        P[A[s][0]-1] = A[s][1]
    else:
        print(-1)
        sys.exit()
if P[0] == -1 and N != 1:
    P[0] = 1
elif P[0] == -1 and N == 1:
    P[0] = 0
elif P[0] == 0 and N != 1:
    print(-1)
    sys.exit()
elif P[0] == 0 and N == 1:
    print(0)
    sys.exit()
for j in range(1,N):
    if P[j] == -1:
        P[j] = 0 
print("".join(map(str,P)))
    




Measured memory_bytes: 3064
/*
ID: victorn2
LANG: C++
TASK: fact4
*/

// 178

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define trie bakayerou_konayarou
#define pb push_back
#define INF 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, ll> pii;
typedef pair<int, pair<int, int>> ppi;
typedef vector<vector<int>> mat;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const ll mod = 1e9+7;
const ll MOD = 9901;
const ll LINF = 0x3f3f3f3f3f3f3f;
const int MAXN = 10000005;
#define fin cin
#define fout cout

int menor[MAXN];

void crivo() {
	for(int i = 2; i < MAXN; i++)
		if(!menor[i])
			for(int j = i; j < MAXN; j += i) 
				if(!menor[j]) 
					menor[j] = i;
			
}

int32_t main() {
	FAST;
	crivo();
	int n;
	cin >> n;
	ll ans = 1;
	for(int i = 2; i <= n; i++) {
		int aux = i;
		ll queb = 1;
		while(aux > 1) {
			int p = menor[aux], tot = 0;
			while(aux % p == 0) {
				tot++;
				aux /= p;
			}
			queb *= (tot+1);
		}
		ans += i*queb;
	}
	cout << ans << endl;
}

Measured memory_bytes: 42712
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    ll m = (n + 1) % 2;
    map<ll, ll> mp;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        ll num; num = a[i];
        if (num % 2 != m) {
            cout << 0 << endl;
            return 0;
        }
        mp[num]++;
    }

    bool isok = true;
    ll prev = -1;
    pair<ll, ll> fe = *mp.begin();
    if (!((fe.first == 0 && n % 2 == 1 && fe.second == 1) || (fe.first == 1 && n % 2 == 0 && fe.second == 2))) {
        cout << 0 << endl;
        return 0;
    }
    for (auto elem : mp) {
        if (elem.first == 0 || elem.second == 1) {
            prev = elem.first;
            continue;
        }
        if (elem.second != 2) {
            cout << 0 << endl;
            return 0;
        }
        if (elem.first - prev != 2) {
            cout << 0 << endl;
            return 0;
        }
        prev = elem.first;
    }

    ll ans = 1;
    for (size_t i = 1; i <= n / 2; i++)
    {
        ans = (ans * 2) % (ll)(1e9+7);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  int c = stoi(a+b);
  bool ans = false;
  for(int i = 0;i <= 400;i++){
    if(c == i*i){ans = true;break;}
  }
  if(ans == true){
    cout << "Yes" << endl;
  }
  else{cout << "No" << endl;}
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  string s;
  cin >> s;
  int n = s.size();
  ll ans = 0;
  vector<int> pow10(n);
  pow10[0] = 1;
  for (int i = 1; i < n; ++i) {
    pow10[i] = (pow10[i - 1] * 10) % 2019;
  }
  map<int, int> mp;
  mp[0] = 1;
  int cur = 0;
  for (int i = n - 1; i >= 0; --i) {
    cur = ((pow10[n - 1 - i] * (s[i] - '0')) % 2019 + cur) % 2019;
    ans += mp[cur];
    mp[cur]++;
  }
  cout << ans << endl;
  return 0;
}

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

long long divUp(long long A, long long B){
    if(A%B == 0){
        return A/B;
    }else{
        return A/B + 1;
    }
}


void solve(long long H, long long W){
    if(H == 1 || W == 1){
        cout << 1 << endl;
        return;
    }
    ll res = 0;
    if(H%2 == 0 && W%2 == 0){
        res = (H)*(W/2);
    }else if(H%2 == 0 && W%2 == 1){
        res = (H)*(W/2) + (H/2);
    }else if(H%2==1 && W%2 == 0){
        res = (W)*(H/2) + (W/2);
    }else{
        res = H*(W/2) + divUp(H, 2);
    }
    // auto res = divUp(H, 2)*divUp(W, 2);
    cout << res << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    solve(H, W);
    return 0;
}


Measured memory_bytes: 256
/* Simplicity and Goodness */
 
#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;
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;

void solve()
{
    int N; int M;
    cin >> N >> M;

    int sum = 0;

    rep(i, 0, M) {
        int val;
        scn(val);
        sum += val;
    } 

    int here = N - sum;

    if(here < 0)
        here = -1;

    prin(here);
}

int main()
{
    int t = 1;
    // scn(t);

    while(t --) {
        solve();
    }
    return 0;
}

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

int main(void){

  int a, *num;
  int i=0;
  long Max=-1000000, min=1000000, sum=0;

  scanf("%d", &a);

  num = (int *)malloc(a * sizeof(int));

  while(i<a){
    scanf("%d", &num[i]);
    sum += num[i];
    if(Max <= num[i])
      Max = num[i];
    if(min >= num[i])
      min = num[i];
    i++;
  }

  printf("%ld %ld %ld\n", min, Max, sum);
  free(num);
  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repin(Array,n) for(int i=0;i<n;i++){cin>>Array[i];}
using namespace std;

using ll = long long;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;

int main() {

	string s;
	cin >> s;

	int li[26] = { 0 };

	rep(i, s.size())
		li[s[i] - 'a']++;

	rep(i, 26) {
		if (li[i] == 0) {
			cout << char('a' + i) << endl;
			return 0;
		}
	}
	cout << "None" << endl;

	return 0;
}

Measured memory_bytes: 512
//?????????????????????????????§?????????

#include<iostream>
using namespace std;

//Euclid
int gcd(int x, int y){
	if (x < y) swap(x,y);
//	int q = x /y;
	int r = x%y;
	while (r!=0) {
	x = y;
	y = r;
//	q = x/y;
	r = x%y;
	}
	return y;
}

int main(){
	int x,y;
	cin >> x >> y;
	cout << gcd(x,y) << endl;
	return 0;
}
	

Measured memory_bytes: 3052
#include<iostream>
#include<string>
#include<array>
#include<algorithm>
using namespace std;

int main() {
	long long int a, b;
	cin >> a >> b;
	if (a<b) {
		
			cout << 0 << endl;
		
	}
	else {
		cout<< 10<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
int n, a[1<<18], a2[1<<18], t;
int main(){
	scanf("%d", &n);
	rep(i,1<<n) scanf("%d", a+i);
	rep(i,n) rep(j,1<<n) if(j>>i&1){
		if(a[j] > a[j^(1<<i)]) a2[j] = max(a2[j], a[j^(1<<i)]);
		else{
			a2[j] = max(a[j], a2[j^(1<<i)]);
			a[j] = a[j^(1<<i)];
		}
	}
	rep(i,1<<n) if(i) printf("%d\n",t = max(t,a[i]+a2[i]));
}

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

int main() {
  long long int N,ans;
    cin>>N;
	vector<long long int> A(N+1);
	vector<long long int> B(N);
	rep(i,N+1) cin>>A[i];
	rep(i,N) cin>>B[i];
	ans=0;
	for(int i=0;i<N;i++){
	  int now=B[i];
		if (A[i]<B[i]){
		  now-=A[i];
			ans+=A[i];
			if (A[i+1]>=now){
				A[i+1]-=now;
				ans+=now;
			}
			else{
                ans+=A[i+1];
				A[i+1]=0;
			}
		}
		else{
		  ans+=B[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4776
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	for (int n = 0; n < N; ++n) {
		cin >> A[n];
	}
	vector<int>copyA = A;
	sort(copyA.begin(), copyA.end(), std::greater<int>());//降順ソート
	int top = copyA[0];
	int next = copyA[1];
	for (int n = 0; n < N; ++n) {
		if (top == A[n]) {
			cout << next <<endl;
		}
		else {
			cout << top << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 4776
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

#define int long long

const int N = 3005;

int32_t main() {
  int n, t;
  cin >> n >> t;
  int dp[3 * N] = {};
  vector < pair <int, int> > vec;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    vec.push_back({x, y});
  }
  sort(vec.begin(), vec.end());
  for (int j = 0; j < n; j++) {
    for (int i = 3 * N - 1; i >= 0; i--) {
      if (i - vec[j].first >= 0 && i - vec[j].first < t) {
        dp[i] = max(dp[i], dp[i - vec[j].first] + vec[j].second);
      }
    }
  }
  cout << *max_element(dp, dp + 3 * N) << endl;
  return 0;
}


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

int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  double vx1, vy1, vx2, vy2, vxp, vyp;
  double s, t;
  while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
    vx1 = x2-x1;
    vy1 = y2-y1;
    vx2 = x3-x1;
    vy2 = y3-y1;
    vxp = xp-x1;
    vyp = yp-y1;
    s = (vyp*vx2 - vxp*vy2) / (vy1*vx2-vx1*vy2);
    if (vx2) {
      t = (vxp-vx1*s) / vx2;
    } else {
      t = (vyp-vy1*s) / vy2;
    }

    if (s>0.0 && t>0.0 && s+t<1.0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1220
import collections

N, M = map(int, input().split())
x = []
for n in range(N):
  l = list(set(list(map(int, input().split()))[1:]))
  #print(l)
  x.extend(l)
  
c = collections.Counter(x)

ans = 0
for k in c.keys():
  if c[k] == N:
    ans += 1
print(ans)

Measured memory_bytes: 38420
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,x,count;
  cin >> N >> K;
  
  for(int i=0;i<N;i++){
    cin >> x;
    if(x*2<(K-x)*2){
      count += x*2;
    }
    else{
      count += (K-x)*2;
    }
  }

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

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

namespace ConsoleApp15
{
    class Class406
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var A = new int[N];
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
            }

            int num = 0;
            long ans = 0;
            if (A[0] != 0) { Console.WriteLine(-1);return; }
            for (int i = 1; i < N; i++)
            {
                if (A[i] <= num)
                {
                    ans += A[i];
                    num = A[i];
                }
                else if (A[i]== num + 1)
                {
                    ans += 1;
                    num = A[i];
                }
                else
                {
                    Console.WriteLine(-1);
                    return;
                }
            }

            Console.WriteLine(ans);
        }
        
    }
}


Measured memory_bytes: 35764
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	mod int = 1e9 + 7
)

func main() {
	N := getInt()
	K := getInt()

	num := 0
	for ; ; {
		N /= K
		num++
		if N == 0 {
			break
		}
	}
	fmt.Println(num)
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 640