akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  solve();
  return 0;
}

void solve() {
  int a, b, c;
  std::cin >> a >> b >> c;
  if (c >= a && c <= b) {
    cout(yes);
  } else {
    cout(no);
  }
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

//dp[i][j] : 
//先頭i文字として考えられるのものうち,
//13で割った余りがjであるもの.
ll dp[MAX_N][13];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n;
	cin >> n;

	ll ans = 1;
	for (int i = 1; i <= n; i++) {
		ans *= i;
		ans %= mod;
	}

	out(ans);

	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout
#include <algorithm> // sort
#include <vector> // vector
#include <cstdio> // printf
#include <cmath> // M_PI
#include <numeric> // accumulate
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)

int		main(void)
{
	int h, w;
	cin >> h >> w;
	while (h || w) {
		rep(i, h) {
			rep(k, w) {
				if (i == 0 || i == h - 1 ||\
						k == 0 || k == w - 1)
					cout << '#';
				else
					cout << '.';
			}
			cout << endl;
		}
		cout << endl;
		cin >> h >> w;
	}
	return (0);
}



Measured memory_bytes: 3072
#include <iostream>
using namespace std;
int main(void){
    int n,a,max = -10000,min = 100000;
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> a;
        if(max < a){
            max = a;
        }
        if(min > a){
            min = a;
        }
    }
    cout << max-min << endl;
    return 0;
}

Measured memory_bytes: 256
r,c = map(int,input().split())

ss = []
for i in range(r):
    ss_value = list(map(int,input().split()))
    ss_value.append(sum(ss_value))
    ss.append (ss_value)

ss_row = []
for j in range(c+1):
    ss_rows_value = [k[j] for k in ss]
    ss_row.append(sum(ss_rows_value))
    
ss.append(ss_row)

for l in range(r+1):
    print (*ss[l])


Measured memory_bytes: 6232
#include<stdio.h>

int main(){
	int n, a, b, month = 13, i, h = 0;
	while(scanf("%d", &n) != 0){
		if(n == 0) break;
		for(i = 1; i <= 12; i++){
			scanf("%d %d", &a, &b);
			h += a - b;
			if(h >= n && i < month) month = i;
		}
		if(month == 13) printf("NA\n");
		else printf("%d\n", month);
		h = 0;
		month = 13;
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long 
#define INF 1e9
#define LINF 1e18
 
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;
 
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

    string s;
    cin >> s;
    int latte = 0, malta = 0;
    for(int i = 0; i < s.size(); ++i) {
        if((s[i] == '0' && i % 2) || (s[i] == '1' && i % 2 == 0)) ++latte; 
        if((s[i] == '0' && i % 2 == 0) || (s[i] == '1' && i % 2)) ++malta; 
    }
    cout << min(latte, malta) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second
#define mk make_pair
int main(){
	string s;
	cin>>s;
	r(i,s.size()-8)cout<<s[i];
	cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long int ll;
static const int MOD = 1000000007;

ll mod_pow(ll n, ll x){
	if(n == 0) return 1;
	ll ret = mod_pow(n / 2, x * x % MOD) % MOD;
	if(n % 2) return ret * x % MOD;
	return ret;
}

ll comb(int n, int k){
	if(k < 0 || k > n) return 0;
	vector<ll> memo(n + 1);
	memo[0] = 1; memo[1] = 1;
	for(int i = 2; i <= n; i++){
		memo[i] = memo[i - 1] * (ll)i;
		memo[i] %= MOD;
	}
	return ((memo[n] * mod_pow(MOD - 2, memo[k])) % MOD) * mod_pow(MOD - 2, memo[n - k]) % MOD;
}

int main(){
	int N, K;
	cin >> N >> K;
	for(int i = 1; i <= K; i++){
		if(N == K && i == 1){
			cout << 1 << endl;
			continue;
		}
		ll res = ((2 * comb(N - K - 1, i - 1)) % MOD) * comb(K - 1, i - 1);
		res %= MOD;
		res += (comb(N - K - 1, i) * comb(K - 1, i - 1)) % MOD;
		res %= MOD;
		res += (comb(N - K - 1, i - 2) * comb(K - 1, i - 1)) % MOD;
		res %= MOD;
		cout << res << endl;
	}
	return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;
using PP = pair<int, pair<int, int> >;

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

const int INF = 1e9;
const int INFLL = 1e18;
const int MOD = 1e9 + 7;

const int MAX_V = 1001;

struct Edge{
    int from, to, cost;
};

int d[MAX_V];

signed main(){
    int V, E, r; cin >> V >> E >> r;
    vector<Edge> e( E );
    REP( i, E ){
        cin >> e[i].from >> e[i].to >> e[i].cost;
    }

    fill( d, d + MAX_V, INF );
    d[r] = 0;

    bool negative = false;
    REP( i, V ){
        REP( j, E ){
            if( d[e[j].from] != INF && chmin( d[e[j].to], d[e[j].from] + e[j].cost ) ){
                if( i == V - 1 ) negative = true;
            }
        }
    }

    if( negative ) cout << "NEGATIVE CYCLE" << endl;
    else{
        REP( i, V ){
            if( d[i] != INF ) cout << d[i] << endl;
            else cout << "INF" << endl;
        }
    }
}



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

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)
#define scin(a) scanf("%d",&a);
#define scdo(a) scanf("%lf",&a);
#define scch(a) scanf("%s",a);
#define anin(a) printf("%d\n",a);
#define ando(a) printf("%lf\n",a);
#define anch(a) printf("%s\n",a);

int main(void){
	int b(0);
	char a[100];
	scch(a)
	a[strlen(a)] = '\0';
	rep(i,0,100){
		if(a[i] ==  '\0') break;
		if(i % 2 == 0){
			if(a[i] == 'R' || a[i] == 'U' || a[i] == 'D'){
			} else {
				b = 1;
			} 
		} 
		if(i % 2 == 1) {
			if(a[i] == 'L' || a[i] == 'U' || a[i] == 'D'){
			} else {
				b = 1;
			}
		}	
	}
	if(b == 0) printf("Yes\n"); else printf("No\n");
	return 0;
}

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

class HandV {
private:
	int h, w, k;
	int black = 0;
	int ans = 0;

	vector<string> board;
	vector<int> hBlack;
	vector<bool> hDrawn;

public:
	HandV(int _h, int _w, int _k) {
		h = _h;
		w = _w;
		k = _k;

		board = vector<string>(h);
		hBlack = vector<int>(h, 0);
		hDrawn = vector<bool>(h, false);
	}

	void setBoard() {
		for (int i = 0; i < h; i++) {
			cin >> board.at(i);
			for (auto e : board.at(i)) {
				if (e == '#') {
					black++;
					hBlack.at(i)++;
				}
			}
		}
		if (black == k) ans++;
	}

	void drawH(int _h) {
		if (black - hBlack.at(_h) < k || _h >= h) return;
		else if (black - hBlack.at(_h) == k) ans++;

		black -= hBlack.at(_h);
		hDrawn.at(_h) = true;
		for (int i = _h + 1; i < h; i++) {
			drawH(i);
		}

		for (int i = 0; i < w; i++) {
			drawW(i);
		}

		hDrawn.at(_h) = false;
		black += hBlack.at(_h);
	}

	void drawW(int _w) {

		int wBlack = 0;

		for (int i = 0; i < h; i++) {
			if (hDrawn.at(i) == false && board.at(i).at(_w) == '#') {
				wBlack++;
			}
		}

		if (black - wBlack < k) return;
		else if (black - wBlack == k) ans++;

		black -= wBlack;

		for (int i = _w + 1; i < w; i++) {
			drawW(i);
		}

		black += wBlack;
	}

	void solve() {
		setBoard();

		for (int i = 0; i < h; i++) {
			drawH(i);
		}

		for (int i = 0; i < w; i++) {
			drawW(i);
		}

		cout << ans << endl;
	}
};


int main() {
	int h, w, k;
	cin >> h >> w >> k;

	HandV hv(h, w, k);
	hv.solve();
}

Measured memory_bytes: 3612
#include<stdio.h>
int N,B[100010]={0};
void bset(int n){for(N=1;N<n;N+=2);}
void badd(int i,int n){for(;i<=N;i+=i&-i)B[i]+=n;}
int  bsum(int i){
  int s=0;
  for(;i;i-=i&-i)s+=B[i];
  return s;
}		   
int main(){
  int n,m,a,b,c;
  scanf("%d %d",&N,&m);
  //bset(n);
  while(m--){
    scanf("%d %d %d",&a,&b,&c);
    a?printf("%d\n",bsum(c)-bsum(b-1)):badd(b,c);
  }    
  return 0;
}

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

int P[100010],R[100010];

int findS(int x){
	if(P[x] != x) P[x] = findS(P[x]);
	return P[x];
}

void mergeS(int x,int y){
	x = findS(x);
	y = findS(y);
	if(x == y) return;
	if(R[x] > R[y]) P[y] = x;
	else P[x] = y;
	if(R[x] == R[y]) R[y] += 1;
}

int main(){
	int N,M;cin>>N>>M;
	for(int i=0;i<N;i++) P[i] = i;
	vector<int> nos(N);
	for(int i=0;i<N;i++) cin>>nos[i];
	int total = 0;
	for(int i=0;i<M;i++){
		int x,y;cin>>x>>y;
		x--;y--;
		mergeS(x,y);
	}
	
	map<int,vector<int>> m;
	for(int i=0;i<N;i++) m[findS(i)].push_back(i);
	for(auto p: m){
		set<int> snos;
		for(auto x:p.second) snos.insert(nos[x]);
		for(auto x:p.second) if(snos.count(x+1) == 1) total += 1;
	}
	cout<<total<<endl;
	return 0;
}

Measured memory_bytes: 12288
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
int main() {
		string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size()/2;i++){
		if(s[i]!=s[s.size()-1-i]){
			ans++;
		}
	}
	cout<<ans<<endl;
 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    long long int n,d,p,q,c=0,a=2;
    double x;
    cin>>n>>d;
    while(n--)
    {
        cin>>p>>q;
        x= sqrt(pow(p,a)+pow(q,a));
        if(x<=d)
        {
            c++;

        }
        else
        {
            c=c;
        }

    }
    cout<<c<<endl;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,dp[2][3][3];
	string s;
	cin >> s;
	n = s.length();
	for(int i = 0;i < 3;i++){
		for(int j = 0;j < 3;j++) dp[0][i][j] = dp[1][i][j] = 0;
	}
	dp[0][0][0] = 1;
	for(int i = 0;i < n;i++){
		int now = i % 2,nxt = !now;
		if(s[i] != '1'){
			for(int j = 0;j < 3;j++){
				for(int k = 0;k < 3;k++){
					(dp[nxt][j][((k == 2) ? 1 : k + 1)] += dp[now][j][k]) %= MOD;
				}
			}
		}
		if(s[i] != '0'){
			for(int j = 0;j < 3;j++){
				for(int k = 0;k < 3;k++){
					if(k) (dp[nxt][j][k - 1] += dp[now][j][k]) %= MOD;
					else (dp[nxt][min(2ll,j + 1)][k] += dp[now][j][k]) %= MOD;
				}
			}
		}
		for(int j = 0;j < 3;j++){
			for(int k = 0;k < 3;k++){
				dp[now][j][k] = 0;
				//cout << dp[nxt][j][k] << " ";
			}
		//	cout << endl;
		}
		//cout << endl;
	}
	cout << (dp[1][1][0] + dp[1][2][1] + dp[1][2][0] + dp[1][2][2]) % MOD << endl;
	return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

vector<ll> all_divisor(ll X){
  vector<ll> ret;
  for(ll i=1;i*i<=X;++i){
    if(X%i==0){
      ret.push_back(i);
      ret.push_back(X/i);
    }
  }
  sort(ret.begin(),ret.end());
  return move(ret);
}
void solve(long long N, long long K, std::vector<long long> A){
  ll sum=accumulate(A.begin(),A.end(),0LL);
  auto divisor=all_divisor(sum);
  ll ans=1;
  for (auto &&d : divisor)
  {
    auto cpy=A;
    ll cK=K;
    REP(N)cpy[i]%=d;
    ll ssum=accumulate(cpy.begin(),cpy.end(),0LL);
    sort(cpy.begin(),cpy.end());
    ll l=upper_bound(cpy.begin(),cpy.end(),0LL)-cpy.begin(),r=cpy.size()-1;
    while(cK>0&&l<r){
      if(cpy[l]>d-cpy[r]){
        cK-=(d-cpy[r]);
        cpy[l]-=(d-cpy[r]);
        cpy[r]=d;
        --r;
      }else if(cpy[l]==d-cpy[r]){
        cK-=(cpy[l]);
        cpy[r]+=cpy[l];
        cpy[l]=0;
        ++l;--r;
      }else{
        cK-=cpy[l];
        cpy[r]+=cpy[l];
        cpy[l]=0;
        ++l;
      }
    }
    if(cK<0||l<r){
      continue;
    }else{
      ans=d;
    }
  }
  cout<<ans<<endl;
}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String a[])
	{
		Scanner sc= new Scanner(System.in);

		boolean tmp = true, tmp2 = true;

		if (sc.next().equals("D"))
		{
			tmp = false;
			//System.out.println(tmp);
		}

		if (sc.next().equals("D"))
		{
			tmp2 = false;
			//System.out.println(tmp2);
		}

		sc.close();

		if (!tmp)
		{
			tmp2 = !tmp2;
		}

		if (tmp2)
		{
			System.out.println("H");
		}
		else
		{
			System.out.println("D");
		}
	}
}


Measured memory_bytes: 21716
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.ReadLine();
        }

        public void Solve(ConsoleInput cin)
        {
            long a = cin.ReadLong;
            long b = cin.ReadLong;
            long c = cin.ReadLong;

            bool can = false;
            for (int i = 1; i < b; i++)
                if ((a * i) % b == c) can = true;

            Console.WriteLine(can ? "YES" : "NO");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long num) { var ret = new string[num]; for (long i = 0; i < num; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long num) { var ret = new int[num]; for (long i = 0; i < num; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long num) { var ret = new long[num]; for (long i = 0; i < num; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

int main(){
    int N,L;
    cin>>N>>L;
    vector<string> data(N);
    for(int i=0;i<N;i++){
        cin>>data[i];
    }
    sort(data.begin(),data.end());
   

    string s="";

    for(int i=0;i<N;i++){
        s+=data[i];
    }

    cout<<s<<endl;
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define lint long long
#define FOR(i,a,b) for(lint i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;

lint ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
 
int power(int n,int k){
	int a =1;
	REP(i,k) a*=n;
	return a;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	int n, m; cin>>n>>m;
	vector<P > a(m);
	REP(i,m) cin>>a[i].first>>a[i].second;
	sort(all(a));
	bool flag = true;
	vector<int> d(n,0);
	REP(i,m-1){
		if(flag==false) break;
		if(a[i].first==a[i+1].first&&a[i].second!=a[i+1].second) flag = false;
	}
	REP(i,m){
		d[a[i].first-1] = a[i].second;
		if(a[i].first==1&&a[i].second==0&&n!=1) flag = false;
	}
	int ans=0;
	if(flag){
		REP(i,n){
			ans+= d[i]*power(10,n-i-1);
		}	
		if(n!=1&&d[0]==0) ans+= power(10,n-1);
	}
	if(!flag) ans = -1;
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=2e5+50;

/*
int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
*/

ll n,x,a[N],ans=1e18,q[N],h,t;

ll solve(int k){
	h=t=0; 
	ll res=0;
	lop(i,0,n+n){
		while(h!=t&&i-q[h]>k)++h;
		while(h!=t&&a[i]<a[q[t-1]])--t;
		q[t++]=i;
		if(i>=n)res+=a[q[h]];
	}
	return res;
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	read(n),read(x);
	lop(i,0,n)read(a[i]);
	lop(i,n,n+n)a[i]=a[i-n];
	lop(k,0,n)ans=min(ans,solve(k)+x*k);
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

int main()
{

	//cin.tie(0); ios_base::sync_with_stdio(false);
	int dr[]={0,1,0,-1,1,1,-1,-1,0};
	int h,w;
	cin >>h >>w;
	vector<string> s(h);
	rep(i,h) cin >>s[i];
	
	rep(i,h) rep(j,w){
		if(s[i][j]=='#') continue;
		int sm =0;
		rep(p,8){
			int ny=i+dr[p], nx=j+dr[p+1];
			if(ny<0 || ny>=h || nx<0 || nx>=w) continue;
			if(s[ny][nx]=='#') sm++;
		}
		s[i][j] = sm +'0';
	}
	for(auto x: s) cout<<x <<"\n";
	return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

//AtCoder Beginner Contest 160
// C - Traveling Salesman around Lake
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = Integer.parseInt(sc.next());
		int N = Integer.parseInt(sc.next());
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = Integer.parseInt(sc.next());
		}
		sc.close();

		int ans = Math.min(K, Math.abs((A[N - 1]) - A[0]));
		for (int i = 1; i < N; i++) {
			ans = Math.min(ans, Math.abs((K + A[i - 1]) - A[i]));
		}

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


Measured memory_bytes: 50608
#include<stdio.h>

int main(void){
	
	char a= '#';
	int i,j;
	int H,W;
	
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0 && W==0){
			break;
		}
		else{
			for( i =0; i<H; i++){
				for( j=0; j<W; j++){
					printf("%c",a);
				}
				printf("\n");
				j=0;
			}
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2104
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
use std::cmp::max;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    println!("{}",max(a*b,max(a+b,a-b)))
}


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

int main() {
    char b;
    cin >> b;
    if(b == 'A') cout << 'T' << endl;
    if(b == 'T') cout << 'A' << endl;
    if(b == 'C') cout << 'G' << endl;
    if(b == 'G') cout << 'C' << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d %d", $N, $M, $Q);
$a = $b = $c = $d = [];
$ans = [0];
for ($i = 0; $i < $Q; $i++) {
    fscanf(STDIN, "%d %d %d %d", $a[$i], $b[$i], $c[$i], $d[$i]);
}
$pat = pow(2, $N + $M - 1);
for ($i = 0; $i < $pat; $i++) {
    $arr = str_split(str_pad(base_convert($i, 10, 2), $N + $M - 1, "0", STR_PAD_LEFT));
    if (array_sum($arr) !== $N) continue;
    $cur = 1;
    $tmp = [];
    for ($j = 0; $j < $N + $M - 1; $j++) {
        if ($arr[$j] === "1") {
            $tmp[] = $cur;
        } else {
            $cur++;
        }
    }
    $score = 0;
    for ($j = 0; $j < $Q; $j++) {
        if ($tmp[$b[$j] - 1] - $tmp[$a[$j] - 1] === $c[$j]) {
            $score += $d[$j];
        }
    }
    $ans[] = $score;
}
printf("%d", max($ans));


Measured memory_bytes: 20824
#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;

vector<bool> seen(200010, false);
vector<ll> ans(200010);
vector<ll> P(200010);
vvll graph;

void dfs(int v) {
    ans[v] += P[v];
    seen[v] = true;
    for (auto nv : graph[v]) {
        if (seen[nv]) continue;
        ans[nv] += ans[v];
        dfs(nv);
    }
}

int main()
{    
    ll n, q; cin >> n >> q;
    graph.resize(n);
    rep(i, n - 1) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    rep(i, q) {
        ll p, x; cin >> p >> x; p--;
        P[p] += x;
    }
    dfs(0);
    rep(i, n) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 25856
from operator import itemgetter


n, m = map(int, input().split())
info = [list(map(int, input().split())) + [i] for i in range(m)]

info = sorted(info, key=itemgetter(1))
ans = [0] * m

cnt_ind = [1] * (n + 1)
for i in range(m):
    p, y, ind = info[i]
    cnt = cnt_ind[p]
    cnt_ind[p] += 1
    ans[ind] = ("0000000"+str(p))[-6:] + ("0000000"+str(cnt))[-6:]
for i in ans:
    print(i)

Measured memory_bytes: 85080
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ",debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os,pair<T,S>a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}

//char inv(char c){
//    return c^32;
//}
//string inv(string &a){
//    auto res = a;
//    for(auto &x:res) x^=32;
//    reverse(res.begin(),res.end());
//    return res;
//}
//string product(const string &a,const string &b){
//    auto res = a;
//    for(auto x:b){
//        if(res.size() and inv(x) == res.back())res.erase(res.begin()+res.size()-1);
//        else res.push_back(x);
//    }
//    return res;
//    
//}

vector<int> id(const int n){
    vector<int> res(n);
    rep(i,n)res[i] = i;
    return res;
}
vector<int> inv(const vector<int> &a){
    vector<int> res(a.size());
    rep(i,a.size()){
        res[a[i]] = i;
    }
    return res;
}
vector<int> product(const vector<int> &a, const vector<int> &b){
    vector<int> res(a.size());
    rep(i,a.size()){
        res[i] = a[b[i]];
    }
    return res;
}
vector<int> power(const vector<int> &a, ll p){
    if(p == 0)return id((int)a.size());
    auto res = a;
    auto temp = a;
    p--;
    for(int i = 0; i < 60; i++){
        if(p >> i & 1){
            res = product(res, temp);
        }
        temp = product(temp, temp);
    }
    return res;
}
int main(){
    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int>p(n),q(n);
    rep(i,n)cin >> p[i],p[i]--;
    rep(i,n)cin >> q[i],q[i]--;
    auto g = product(q,product(inv(p),product(inv(q),p)));
    g = power(g,(k-1)/6);
    auto a = product(g,product(p,inv(g)));
    auto b = product(g,product(q,inv(g)));
    int now = 1 + (k-1)/6*6;
    while(now != k){
        auto c = product(b,inv(a));
        a = b;
        b = c;
        now++;
    }
    rep(i,n)cout << a[i] + 1 << " \n"[i==n-1];
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = 998244353;
const ll INF = 1LL << 61;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N;
    bool same = true;
    ll mini = INF, sum = 0;
    rep(i,N){
        cin>>A>>B;
        if(A != B) same = false;
        sum += A;
        if(A > B){
            mini = min(B,mini);
        }
    }
    cout<<(same ? 0 : sum - mini)<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  long long x;
  cin >> x;
  long long num;
  num = x/11*2;
  if(0<x%11 && x%11<7){
    num += 1;
  }else if(6<x%11){
    num += 2;
  }
  cout << num << endl;
}

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

int main(){
  int n,a;
  cin>>n;
  if(n%2==0){
    a=n/2;
  }else{
    a=n/2+1;
  }
  double ans=(a*0.1)/(n*0.1);
  cout<<ans<<endl;
}

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

using namespace std;

#define PI acos(-1)

double toRad(double ang){
    return (ang*PI/180);
}

int main(){
    char c;
    double a,b,x = 0,y = 0,rd = 0;
    while(cin >> a >> c >> b){
	if(a == 0 && b == 0) break;
	x += a*sin(toRad(rd));
	y += a*cos(toRad(rd));
	rd += b;
    }
    cout << (int)x << endl << (int)y << endl;
    
    return 0;
}

Measured memory_bytes: 1228
#include <stdio.h>
#define M 100000
int parent (int );
int left (int );
int right (int );
int main ()
{
  int h,i,a[M+1],t=0;

  scanf("%d",&h);
  for(i=1; i<=h;i++)
    {
      scanf("%d",&a[i]);
    }
  for(i=1;i<=h;i++)
    {
      printf("node %d: key = %d, ",i,a[i]);
      t=parent(i);
      if(t>=1)printf("parent key = %d, ",a[t]);
      t=left(i);
      if(t<=h) printf("left key = %d, ",a[t]);
      t=right(i);
      if(t<=h) printf("right key = %d, ",a[t]);
     printf("\n");
    }

  return 0;
}
int parent (int x){
  return x/2;
}
int left(int x){
  
  return 2*x;
}
int right (int x){
  return 2*x+1;
}
  



Measured memory_bytes: 2112
#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 <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    ll N, K;
    cin >> N >> K;
    vector<ll> v(N);
    REP(i, N) cin >> v[i];
    sort(v.begin(), v.end());
    ll s = 0;
    REP(i, N-K) s += v[i];
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 1792
import scala.io.StdIn.readLine

object Main extends App {
  val Array(a, b, c) = readLine().split(" ").map(_.toInt)
  val radian = Math.toRadians(c)
  val area = a * b * Math.sin(radian) * 0.5
  val height = 2 * area / a
//  val otherLen = Math.sqrt((a * a) + (b * b) - (2 * a * b * Math.cos(radian)))
  val bottomLen = c match {
    case x if c < 90 => a - Math.sqrt((b * b) - (height * height))
    case _ => a + Math.sqrt((b * b) - (height * height))
  }
  var otherLen = Math.sqrt((bottomLen * bottomLen) + (height * height))
  val circumference = otherLen + a + b;

  println(area)
  println(circumference)
  println(height)
}



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

int main(){
    string s;
    cin >> s;
    if(s == "SUN") cout << 7 << endl;
    if(s == "MON") cout << 6 << endl;
    if(s == "TUE") cout << 5 << endl;
    if(s == "WED") cout << 4 << endl;
    if(s == "THU") cout << 3 << endl;
    if(s == "FRI") cout << 2 << endl;
    if(s == "SAT") cout << 1 << endl;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
#define fst                       \
    ios_base::sync_with_stdio(0); \
    ios::sync_with_stdio(0);      \
    cin.tie(0);                   \
    cout.tie(0);
#define PI acos(-1.0)
#define rd freopen("ip.txt", "r", stdin)
#define wr freopen("op.txt", "w", stdout)
#define wis(x) cout << #x << " is " << x << endl;
#define mem(array, int) memset(array, int, sizeof(array))
#define ll long long int
#define nl cout << endl;
#define mx 10000009
#define MOD 1000000007
using namespace std;



int main()
{
    
    
    string s;

    cin>>s;

    int l = s.size();
    int n = l-2;
    
    cout<<s[0]<<n<<s[l-1]<<endl;
    

    return 0;
       
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

word = gets.chomp
loop_number = gets.to_i
loop_number.times  do 
    line = gets.split
    case line[0]
    when "replace" then
        word[line[1].to_i..line[2].to_i] = line[3]
    when "reverse" then
        word[line[1].to_i..line[2].to_i] = word[line[1].to_i..line[2].to_i].reverse
    when "print"
        puts word[line[1].to_i..line[2].to_i]
    end
end


Measured memory_bytes: 6944
#include<iostream>
#define N_MAX 200
int P[N_MAX];
int main(){
    int N, X;
    std::cin >> X >> N;
    for(int i=0; i<N; i++){
        int tmp;
        std::cin >> tmp;
        P[tmp] = 1;
    }
    for(int i=0;i<=100; i++){
        if(P[X-i] == 0){
            printf("%d\n", X-i);
            break;
        }else if(P[X+i] == 0){
            printf("%d\n", X+i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    string S;
  string ans = "yes";
  cin >> S;
  for(int i=0;i<S.size()-1;i++){
    for(int j=i+1;j<S.size();j++){
      if(S[i] == S[j]) ans = "no";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
typedef struct { int to, cost_y, cost_s; } edge;

int main() {
    int n, m, s, t; cin >> n >> m >> s >> t;
    s--; t--;
    vector<vector<edge> > adj(n);
    for (int i = 0; i < m; i++) {
        int from, to, yen, sn; cin >> from >> to >> yen >> sn;
        adj[from-1].push_back((edge){ to-1, yen, sn });
        adj[to-1].push_back((edge){ from-1, yen, sn });
    }
    long long dy[n], ds[n];
    fill(dy, dy+n, 1LL<<60);
    fill(ds, ds+n, 1LL<<60);
    dy[s] = 0;
    priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > q;
    q.push(make_pair(0, s));
    while (!q.empty()) {
        auto p = q.top(); q.pop();
        if (dy[p.second] < p.first) continue;
        for (edge e : adj[p.second]) {
            if (dy[e.to] > p.first + e.cost_y) {
                dy[e.to] = p.first + e.cost_y;
                q.push(make_pair(p.first + e.cost_y, e.to));
            }
        }
    }
    ds[t] = 0;
    q.push(make_pair(0, t));
    while (!q.empty()) {
        auto p = q.top(); q.pop();
        if (ds[p.second] < p.first) continue;
        for (edge e : adj[p.second]) {
            if (ds[e.to] > p.first + e.cost_s) {
                ds[e.to] = p.first + e.cost_s;
                q.push(make_pair(p.first + e.cost_s, e.to));
            }
        }
    }
    long long d[n];
    for (int i = n-1; i >= 0; i--) {
        if (i < n-1) d[i] = min(d[i+1], dy[i] + ds[i]);
        else d[i] = dy[i] + ds[i];
    }
    for (int i = 0; i < n; i++)
        // cerr << dy[i] << ' ' << ds[i] << endl,
        cout << 1000000000000000LL - d[i] << endl;
}


Measured memory_bytes: 11252
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int n, m; string S0[5000], S1[5000], S2[5000], T0[5000], T1[5000], T2[5000];
bool solve(string p1, string p2) {
	for (int i = 0; i < p1.size(); i++) {
		if (p1[i] != '?' && p1[i] != p2[i])return false;
	}
	return true;
}
int main() {
	while (true) {
		cin >> n >> m; vector<int>vec; if (n == 0 && m == 0)break;
		for (int i = 0; i < n; i++)cin >> S0[i] >> S1[i] >> S2[i];
		for (int i = 0; i < m; i++) {
			cin >> T1[i] >> T2[i] >> T0[i];
			for (int j = n - 1; j >= 0; j--) {
				bool P = solve(S1[j], T1[i]);
				if (P == true && solve(S2[j], T2[i]) == false)P = false;
				if (P == true && S0[j] == "deny")break;
				if (P == true && S0[j] == "permit") { vec.push_back(i); break; }
			}
		}
		cout << vec.size() << endl;
		for (int i = 0; i < vec.size(); i++)cout << T1[vec[i]] << ' ' << T2[vec[i]] << ' ' << T0[vec[i]] << endl;
	}
	return 0;
}

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

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

int f(vector<vector<bool>> a) {
    int H = a.size();
    int W = a[0].size();
    int ans = 0;
    rep(y, H) rep(x, W) {
        for (int d = 1; y + d < H && x - d >= 0 && x + d < W; d++) {
            if (a[y][x] && a[y + d][x - d] && a[y + d][x + d])
                ans++;
        }
    }
    vector<vector<int>> sum(H + 1, vector<int>(W + 1));
    rep(y, H) rep(x, W) sum[y + 1][x + 1] = sum[y][x] + a[y][x];
    rep(y1, H) rep(x1, W) {
        for (int d = 2; y1 + d < H && x1 + d < W; d++) {
            int y2 = y1 + d;
            int x2 = x1 + d;
            if (!a[y1][x1]) continue;
            if (!a[y2][x2]) continue;
            int y3 = y1 + d + 1;
            int x3 = x1 - d + 1;
            int y4 = y2 + d - 1;
            int x4 = x2 - d - 1;
            if (x3 < 0) {
                y3 -= x3;
                x3 = 0;
            }
            if (y4 > H - 1) {
                x4 -= y4 - (H - 1);
                y4 = H - 1;
            }
            if (0 <= y3 && y3 < H && 0 <= x4 && x4 < W)
                ans += sum[y4 + 1][x4 + 1] - sum[y3][x3];
        }
    }
    return ans;
}

vector<vector<bool>> rotate(vector<vector<bool>> a) {
    int H = a.size();
    int W = a[0].size();
    vector<vector<bool>> b(W, vector<bool>(H));
    rep(y, H) rep(x, W) b[x][H - 1 - y] = a[y][x];
    return b;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<bool>> a(H, vector<bool>(W));
    rep(y, H) {
        string s; cin >> s;
        rep(x, W) a[y][x] = (s[x] == '#');
    }
    int ans = 0;
    rep(t, 4) {
        ans += f(a);
        a = rotate(a);
    }
    cout << ans << endl;
}


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

int main(){
    int N,M;
    int mod = 1000000007;
    cin >> N >> M;
    int a;
    int b[N] = {};
    for (int i = 0;i < M;i++){
        cin >> a;
        b[a - 1] = 1;
    }
    long long c[N] = {};
    if (b[0] == 1) c[0] = 0;
    else c[0] = 1;
    if (b[1] == 1) c[1] = 0;
    else c[1] = c[0] + 1;
    for (int i = 2;i < N;i++){
        if (b[i] == 1) c[i] = 0;
        else c[i] = (c[i - 1] + c[i - 2]) % mod;
    }
    cout << c[N - 1] << endl;
}

Measured memory_bytes: 1408
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a.sort(reverse=True)
    t = 0
    for i in range(1, n * 2, 2):
        t += a[i]
    print(t)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 79088
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i,H)cin >> a[i];
  vector<vector<ll>> dp(H,vector<ll>(W,0));
  dp[0][0] = 1;

  for(int i = 1;i < H;i++){
    if(a.at(i).at(0)=='#')dp[i][0] = 0;
    else dp[i][0] = dp[i-1][0];
    dp[i][0] %= MOD;
  }
  for(int i = 1;i < W;i++){
    if(a.at(0).at(i)=='#')dp[0][i] = 0;
    else dp[0][i] = dp[0][i-1];
    dp[0][i] %= MOD;
  }

  for(int i = 1;i < H;i++){
    for(int j = 1;j < W;j++){
      if(a.at(i).at(j)=='#')dp[i][j] = 0;
      else dp[i][j] = dp[i-1][j] + dp[i][j-1];
      dp[i][j] %= MOD;
    }
  }

  cout << dp[H-1][W-1] << endl;

}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define int long long  
#define INF 1145141919810893
signed main(){
    int N,K;
    int D[10];
    int c=0;
    int keta[5];
    cin >> N >> K;
    REP(i,K){cin >> D[i];}
    REP(i,1000000){
        if(i<N)continue;
        c=0;
        keta[4]=i/10000;
        keta[3]=(i/1000)%10;
        keta[2]=(i/100)%10;
        keta[1]=(i/10)%10;
        keta[0]=i%10;
        //REP(j,(int)log10(i)+1){cout << keta[j] << " ";}cout << endl;
        REP(j,K){
            REP(k,(int)log10(i)+1){
                if(keta[k]==D[j]){
                    c=1;
                }
            }
        }
        if(c==0){
            cout << i << endl;
            return 0;
        }
    }
    
	return 0;
}


Measured memory_bytes: 512
def main(argv)
  (a, b) = gets.chomp.split(' ').map(&:to_i)
  
  s = a + b
  
  if (s % 2) == 0 then
    puts (s / 2).to_s
  else
    puts 'IMPOSSIBLE'
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
N=int(input())
 
ans=0
odd=[]
for i in range(1,N+1):
  if i%2!=0:
    odd.append(i)
    
if N  <104:
  pass
else:
  for i in range(105,N+1):
    if i%2!=0:
      tmp=0
      for j in odd:
        if i%j==0:
          tmp+=1
      if tmp==8:
        ans+=1 
print(ans)

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define lf long double
#define F first
#define S second
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <pair <ll,ll> >vii;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vi a(n+1);
    for(ll i=0;i<=n;i++)
        cin>>a[i];
    vi b(n);
    for(ll i=0;i<n;i++)
        cin>>b[i];
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        ll total=a[i]+a[i+1];
        ll capacity=b[i];
        if(b[i]>=total)
        {
            a[i]=0;
            a[i+1]=0;
            ans+=total;
        }
        else if(b[i]>=a[i])
        {
            ans+=b[i];
            ll left=b[i]-a[i];
            a[i]=0;
            a[i+1]-=left;
        }
        else
        {
            ans+=b[i];
            a[i]-=b[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

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

		int a,b,c;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();

		int cnt=0;

		if(a==b) {
			cnt++;
		}
		if(a==c) {
			cnt++;
		}
		if(b==c) {
			cnt++;
		}

		//System.out.println(cnt);
		if(cnt == 1) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();

	}

}

Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {

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

		int min = 0;
		int cur = 0;
		for (int i = 0; i < X.length(); i++) {
			switch (X.charAt(i)) {
			case 'S':
				cur++;
				break;
			case 'T':
				cur--;
				min = Math.min(min, cur);
				break;

			default:
				break;
			}
		}

		System.out.println(-min * 2);
	}
}


Measured memory_bytes: 14424
//
// Created on 2020/06/21.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int n;
    cin>>n;
    ll sum = 0;
    map<ll,ll>mp;
    for (int i = 0; i < n; ++i) {
        ll a;
        cin>>a;
        mp[a] ++;
        sum += a;
    }
    int q;
    cin>>q;
    for (int j = 0; j < q; ++j) {
        ll b,c;
        cin>>b>>c;
        ll cnt = mp[b];
        mp[b] = 0;
        sum -= cnt * b;
        mp[c] += cnt;
        sum += cnt * c;
        cout<<sum<<endl;
    }

    return 0;
}


Measured memory_bytes: 9440
END { load __FILE__ unless $stdin.eof? }

n = gets.to_i
m = 100

h = Hash.new(0)

(1..m).each do |x|
  (1..m).each do |y|
    (1..m).each do |z|
      w = x + y + z
      q = x * x + y * y + z * z + w * w
      h[q >> 1] += 1
    end
  end
end

(1..n).each do |i|
  puts h[i]
end


Measured memory_bytes: 16696
fun main(args: Array<String>) {
    var s= readLine()!!
    var l=s.length
    var lm=(l+1)/2
    var ll=(lm+1)/2
    var ls=Array(ll){' '}.toMutableList()
    var f=true
    for(i in 0 until ll){
        ls[i]=s[i]
        if(ls[i]!=s[l-1-i]){
            f=false
        }
        if(ls[i]!=s[lm-2-i]){
            f=false
        }
        if(ls[i]!=s[lm+i]){
            f=false
        }
    }
    if(f){
        println("Yes")
    }else{
        println("No")
    }

}

Measured memory_bytes: 35848
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int K;
  cin >> K;
  int N = s.size();
  set<string> S;
  for (int i = 0; i < N; i++){
    for (int j = 1; j <= min(K, N - i); j++){
      S.insert(s.substr(i, j));
    }
  }
  auto itr = S.begin();
  for (int i = 0; i < K - 1; i++){
    itr++;
  }
  cout << *itr << endl;  
}

Measured memory_bytes: 1664
#include <iostream>
#include <stack>
#include <deque>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdio>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fi first
#define se second
#define sz(a) a.size()
#define pb push_back
#define fo(i,k,n) for(size_t i=k; (int)i<n; ++i)
#define all(v) sort(v.begin(), v.end())
#define pii <pair<int, int> >
#define it ::iterator
#define forit(it, st) for(it = st.begin(); it!=st.end(); it++)
const int inf = 1e9;

int n, cnt, ss;
string x,cur;
bool ok;
char ch;
stack<char> st;

int main(){

    //    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    
    
    while(cin>>ch){
        if(ch == 'S')
            ss++;
        else{
            if(ss)
                ss--;
            else
                cnt++;
        }
    }
    
    cout<<cnt+ss;
   
    return 0;
}



Measured memory_bytes: 256