akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll p = 1e9+7;

string s;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> s;
	if (s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << "-1\n";
		return 0;
	}

	if (s.length() < 26) {
		char y;
		for (char i = 'a'; i <= 'z'; ++i) {
			bool z = 0;
			for (int j = 0; j < s.length(); ++j)
				if (s[j] == i)
					z = 1;
			if (!z) {
				y = i;
				break;
			}
		}

		s += y;
		cout << s << endl;
		return 0;
	}

	int ind = -1;
	for (int i = 0; i < 26; ++i) {
		bool z = 0;
		for (int j = i; j < 25; ++j)
			if (s[j] < s[j+1])
				z = 1;
		if (z == 0) {
			ind = i;
			break;
		}
	}

	ind--;
	string ans = "";
	for (int i = 0; i < ind; ++i)
		ans += s[i];
	char mini = 'z';
	for (int i = ind+1; i < 26; ++i)
		if (s[i] > s[ind])
			mini = min(s[i], mini);
	ans += mini;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
int n,maxp,ans=0,p;
int main(){
  cin >> n;
  for (size_t i = 0; i < n; i++) {
    cin >> p;
    ans += p;
    maxp = max(p,maxp);
  }
  cout << (ans-maxp)+(maxp/2) << endl; 
}


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

int monster[100001];

int main(){
    int N; cin >> N;
    rep(i, N+1){
        int m; cin >> m;
        monster[i] = m;
    }

    ll ans = 0;

    rep(i, N){
        int b; cin >> b;
        if (monster[i] > b){
            ans += b;
            continue;
        }
        else {
            ans += monster[i];
            b -= monster[i];
            ans += monster[i+1]-max(0, monster[i+1]-b);
            monster[i+1] = max(0, monster[i+1]-b);
        }

    }

    cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e11;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];

  int mn = min(n, k);
  ll ans = -1LL * INF;
  for (int i = 0; i <= mn; ++i) {
    for (int j = 0; i + j <= mn; ++j) {
      ll val = 0;
      int cnt = k - i - j;
      vector<ll> a;
      rep(l, i) a.push_back(v[l]);
      rep(l, j) a.push_back(v[n - 1 - l]);
      for (auto al : a) val += al;
      sort(a.begin(), a.end());
      for (int l = 0; l < cnt && l < a.size() && a[l] < 0; ++l) val -= a[l];
      ans = max(ans, val);
    }
  }

  cout << ans << endl;
  return 0;
}


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

string s;
bool f;

int main(){
	cin >> s;
	f = false;
	for (int i = 0; i < 3; ++i){
		if (s[i] == s[i+1]) f = true;
	}
	cout << (f ? "Bad" : "Good");
}

Measured memory_bytes: 256
#include<iostream>	// 入出力
#include<stdio.h>	// printf()が使える 小数は%fで
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか

using namespace std;

using ll = long long;


int main()
{

	int N, M;

	cin >> N;

	map<int, int> mp;

	for (int i = 0; i < N; ++i)
	{

		int D; cin >> D;

		auto itr = mp.find(D);

		if (itr != mp.end())
		{
			mp[D]++;
		}
		else
		{
			mp[D] = 1;
		}

	}

	cin >> M;

	for (int i = 0; i < M; ++i)
	{

		int T; cin >> T;

		auto itr = mp.find(T);

		if (itr != mp.end())
		{
			if (mp[T] == 0)
			{
				cout << "NO" << endl; return 0;
			}

			mp[T]--;
		}
		else
		{
			cout << "NO" << endl; return 0;
		}
		
	}


	cout << "YES" << endl;

	return 0;

}

Measured memory_bytes: 9600
#include<cstdio>
#include<cstring>
const int N=15;
int a[N],b[N];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)	scanf("%d",&a[i]);
	
	int ans=1;
	for(int i=1;i<=n;i++)	ans*=3;
	int sum=1;
	for(int i=1;i<=n;i++)	if(! ( a[i]&1 ) )	sum*=2;
	printf("%d\n",ans-sum);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[5];
  for(int i=0;i<5;i++){
    cin>>a[i];
    if(a[i]<40) a[i]=40;
  }
  int x=0;
  for(int i=0;i<5;i++){
    x+=a[i];
  }
  cout<<x/5<<endl;
  return 0;
}



Measured memory_bytes: 3104
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------


int main()
{
	int n;
	cin >> n;
	cout << n * (n + 1) / 2 << 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++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, h[100010];
ll dp[100010];

int main() {
    cin >> n;
    rep(i, n) cin >> h[i];
    rep(i, 100010) dp[i] = LLINF;
    dp[0] = 0;
    rep(i, n) {
        chmin(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
        chmin(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;
const int MOD = 1000000007;

long long factorial(int n)
{
  long long ret = 1;
  for(long long i = 1; i <= n; ++i) {
    ret *= i;
    ret = ret % MOD;
  }
  return ret % MOD;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  
  if (n == m) {
    cout << (factorial(n) % MOD) * (factorial(m) % MOD) % MOD * 2 % MOD << endl;
  } else if (abs(n-m) == 1) {
    cout << (factorial(n) % MOD) * (factorial(m) % MOD) % MOD << endl;
  } else {
    cout << 0 << endl;
  }
  
  return 0;
}

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

int main(){
  string s;cin>>s;
  bool c=0,f=0;
  REP(i,s.size()){
    if(!c){if(s[i]=='C') c=1;}
    else if(s[i]=='F'){f=1;break;}
  }
  cout<<(f?"Yes":"No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  vector<int> v(3);
  rep(snip_i, 3) cin >> v.at(snip_i);
  sort(v.begin(), v.end());
  int ans = v.at(2)-v.at(1);
  v.at(0) += ans;
  // cerr << ans << " " << v.at(0) << " " << v.at(2) << endl;
  if((v.at(2)-v.at(0)) % 2 == 0) ans += (v.at(2) - v.at(0)) / 2;
  else ans += (v.at(2)-v.at(0)+1)/2 + 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL N;
	cin >> N;
	LL p = 0, w = 0, g = 0, y = 0;
	FOR(i, 0, N) {
		char S = IN<char>();
		if (S == 'G')g++;
		else if (S == 'W')w++;
		else if (S == 'P')p++;
		else y++;
	}
	if (y > 0) {
		O("Four");
	}
	else {
		O("Three");
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	for (int t = 0; t < 2; ++t)
	{
		int a[10];
		for (int i = 0; i < 10; ++i)
			scanf("%d", a + i);
		sort(a, a + 10);
		printf("%d%c", accumulate(a + 7, a + 10, 0), t ? '\n' : ' ');
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int dy[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dx[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int A, B;
char s[100][100];

bool check(int i, int j, char c) {
  for (int k = 0; k < 9; k++) {
    int ny = i + dy[k];
    int nx = j + dx[k];
    if (ny >= 0 && ny < 100 && nx >= 0 && nx < 100 && s[ny][nx] == c) return false;
  }
  return true;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> A >> B;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      s[i][j] = (i < 50) ? '#' : '.';
    }
  }
  A--; B--;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      if (A && check(i, j, '.')) {
        s[i][j] = '.';
        A--;
      } else if (B && check(i, j, '#')) {
        s[i][j] = '#';
        B--;
      }
    }
  }
  cout << 100 << " " << 100 << endl;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      cout << s[i][j];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int s,n,m;
int x[2010],t[2010],p[2010];
vector<int> v;
int dp[2010][2010];
int K[2010][2010];
int imos[2010];
int rest[2010][2010];
int minima[2010];
int dist(int a,int b)
{
	return imos[b]-imos[a];
}
int sum_dist(int a,int b)
{
	if(a==b)return 0;
	return rest[b][b-a-1];
}
int F(int j,int i,int k)
{
	if(k>i)return INF;
	return dp[k][j]+sum_dist(k,i);
}
void update(int j)
{
	for(int i=0;i<n;i++)dp[i][j]=F(j-1,i,minima[i]);
	return;
}
void culc(int x,int ib,int ie,int jb,int je)//[ib,ie],[jb,je]
{
	if(ib>ie)return;
	int mid = (ib+ie)/2;
	int val=INF+1,id,v;
	for(int i=jb;i<=je;i++)
	{
		if((v=F(x,mid,i))<val)
		{
			val=v;
			id=i;
		}
	}
	minima[mid]=id;
	culc(x,ib,mid-1,jb,minima[mid]);
	culc(x,mid+1,ie,minima[mid],je);
	return;
}
int main()
{
	scanf("%d %d %d",&s,&n,&m);
	for(int i=0;i<s;i++)scanf("%d",&x[i]);
	for(int i=0;i<n;i++)scanf("%d %d",&t[i],&p[i]);
	for(int i=0;i<n;i++)v.pb(t[i]-x[p[i]-1]);
	sort(all(v));
	for(int i=1;i<n;i++)imos[i]=v[i]-v[i-1];
	for(int i=1;i<n;i++)imos[i]+=imos[i-1];
	for(int i=0;i<n;i++)for(int j=1;j<=i;j++)rest[i][j]=rest[i][j-1]+dist(i-j,i);
	for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)dp[i][j]=INF;
	for(int i=0;i<n;i++)dp[i][1]=rest[i][i];
	for(int j=1;j<m;j++)
	{
		culc(j,0,n-1,0,n-1);
		update(j+1);
	}
	printf("%d\n",dp[n-1][m]);
	return 0;
}

Measured memory_bytes: 33336
#include <stdio.h>
#include <assert.h>
int n,i,j,x,a[10][10],list[200][3],size;
void push(int x,int y,int s){list[size][0]=i;list[size][1]=j;list[size][2]=s;size++;}

int check(int x,int y,int s){
	int d;
	if(s<3 && (x<1 || x>9 || y<1 || y>9)) return 0;
	if(s==3 && (x<2 || x>8 || y<2 || y>8)) return 0;
	d=a[x][y];
	if(a[x-1][y]<d)d=a[x-1][y];
	if(a[x+1][y]<d)d=a[x+1][y];
	if(a[x][y-1]<d)d=a[x][y-1];
	if(a[x][y+1]<d)d=a[x][y+1];
	if(s==1 || d==0)return d;
	if(a[x-1][y-1]<d)d=a[x-1][y-1];
	if(a[x+1][y+1]<d)d=a[x+1][y+1];
	if(a[x+1][y-1]<d)d=a[x+1][y-1];
	if(a[x-1][y+1]<d)d=a[x-1][y+1];
	if(s==2 || d==0)return d;
	if(a[x-2][y]<d)d=a[x-2][y];
	if(a[x+2][y]<d)d=a[x+2][y];
	if(a[x][y-2]<d)d=a[x][y-2];
	if(a[x][y+2]<d)d=a[x][y+2];
	return d;
}

void draw(int x,int y,int s,int d){
	if(size==3 && (x<2 || x>8 || y<2 || y>8)) return;
	a[x][y]+=d;
	a[x-1][y]+=d;
	a[x+1][y]+=d;
	a[x][y-1]+=d;
	a[x][y+1]+=d;
	if(s==1)return;
	a[x-1][y-1]+=d;
	a[x+1][y+1]+=d;
	a[x+1][y-1]+=d;
	a[x-1][y+1]+=d;
	if(s==2)return;
	a[x-2][y]+=d;
	a[x+2][y]+=d;
	a[x][y-2]+=d;
	a[x][y+2]+=d;
}

int search(int nn,int from){
	int i,x,y,s,t;
	for(i=from;i>=0;i--){
		x=list[i][0];y=list[i][1];s=list[i][2];
		//if(a[x][y]==0 && a[x+1][y]>0)return 0;
		if(x<8){
		if(s<3 && a[x+2][y]>0)return 0;
		if(y==1 && a[x+2][y-1]>0)return 0;
		}
		//if(y==1 && s<2 && a[x+1][y-1]>0)return 0;
        //if(y==8 && s<2 && a[x+1][y+1])return 0;
		t=check(x,y,s);
		if(t>0){
			draw(x,y,s,-t);
			for(;t>0;t--){
				//if(s==1 && a[x+1][y+1]>0 && check(x-1,y+1,3)==0){draw(x,y,s,+1);continue;}
				if(nn-t>0){
					if(search(nn-t,i-1)>0){goto answer;}
				}else{
					int p,q;
					for(p=0;p<10;p++)for(q=0;q<10;q++){{if(a[p][q]!=0)goto miss;}}
					goto answer;
					miss:;
				}
				draw(x,y,s,+1);
			}
		}
	}
	return 0;

	answer:
	for(;t>0;t--)printf("%d %d %d\n",y,x,s);
	return 1;
}

int main(void){
	scanf("%d",&n);size=0;
	for(i=0;i<10;i++){for(j=0;j<10;j++){scanf("%d",&a[i][j]);}}
	for(i=1;i<9;i++){
		for(j=1;j<9;j++){
			x=check(i,j,1); if(x==0)continue; push(i,j,1);
			x=check(i,j,2); if(x==0)continue; push(i,j,2);
			x=check(i,j,3); if(x==0)continue; push(i,j,3);
		}
	}
	search(n,size-1);
	return 0;
}

Measured memory_bytes: 600
# encoding: utf-8
import sys
from collections import deque
input = sys.stdin.readline

N = int(input())
b = list(map(int, input().split()))

for i, bi in enumerate(b):
    if i + 1 < bi:
        q = deque([])
        break
else:
    q = deque([(b, [])])
    
while len(q) > 0:
    b_tmp, seq = q.pop()
    if len(b_tmp) == 0: break
    for i, bi in enumerate(b_tmp):
        if i + 1 < bi: break
        elif i + 1 == bi:
            if i == 0: q.append((b_tmp[i + 1:], seq + [i + 1]))
            elif i == len(b_tmp) - 1: q.append((b_tmp[:i], seq + [i + 1]))
            else: q.append((b_tmp[:i] + b_tmp[i + 1:], seq + [i + 1]))
else:
    seq = [-1]

for i in seq[::-1]: print(i)

Measured memory_bytes: 4084
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define MOD int(1e9 + 7)

int main()
{
    long long N, A;
    cin >> N >> A;

    if(N % 500 <= A)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  static Scanner scan = new Scanner(System.in);

  public static void main(String[] args) {
    int n = scan.nextInt();
    int m = scan.nextInt();

    for (int i = 0; i < m; i++) {
      int d = scan.nextInt();
      n -= d;
    }

    System.out.println(n >= 0 ? n : -1);
  }
}

Measured memory_bytes: 39572
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        scan.close();
      
      if(str.equals("SAT")){
        System.out.println("1");
      }else if(str.equals("FRI")){
        System.out.println("2");
      }else if(str.equals("THU")){
        System.out.println("3");
      }else if(str.equals("WED")){
        System.out.println("4");
      }else if(str.equals("TUE")){
        System.out.println("5");
      }else if(str.equals("MON")){
        System.out.println("6");
      }else if(str.equals("SUN")){
        System.out.println("7");
    }
    }
}

Measured memory_bytes: 22228
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    Rep (i, H) cin >> S[i];

    vector<vector<bool>> visited(H, vector<bool>(W, false));
    vector<ll> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
    
    ll ans = 0;
    Rep (i, H) Rep (j, W) {
        if (!visited[i][j]) {
            queue<pair<ll, ll>> q;
            q.push(make_pair(i, j));
            visited[i][j] = true;
            ll black = 0, white = 0;
            if (S[i][j] == '#') black++;
            else white++;
            while (!q.empty()) {
                auto now = q.front(); q.pop();
                ll ny = now.first;
                ll nx = now.second;
                Rep (k, 4) {
                    ll y = ny + dy[k];
                    ll x = nx + dx[k];
                    if (y < 0 || H <= y || x < 0 || W <= x) continue;
                    if (visited[y][x] || S[ny][nx] == S[y][x]) continue;
                    if (S[y][x] == '#') black++;
                    else white++;
                    visited[y][x] = true;
                    q.push(make_pair(y, x));
                }
            }
            ans += black * white;
        }
    }

    cout << ans << endl;

}

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

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl

li n, a, b;

int main () {
    cin >> n >> a >> b;
    cout << min(a*n, b);
}


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

vector<vector<int>> G;

void dfs(vector<bool> &seen,int u,int &res) {
    bool ok = true;
    for(int i = 0;i < seen.size();i++) if(!seen[i] && i != u) ok = false;
    if(ok) {
      res++;
      return;
    }

    seen[u] = true;
    for(auto nu: G[u]) {
      if(!seen[nu]) dfs(seen,nu,res);
    }
    seen[u] = false;
}

int main() {

  int N,M;
  cin >> N >> M;

  G.assign(N,vector<int>());
  vector<bool> seen(N,false);

  for(int i = 0;i < M;i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  int res = 0;
  dfs(seen,0,res);

  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
const int maxn=1e5+10;
const LL inf=1e18;
LL n,k;
LL p[maxn];
LL po(LL x,LL m)
{
    LL ans=1;
    LL tmp=x%mod;
    while(m){
        if(m&1){
            ans=ans*tmp;
            ans%=mod;
        }
        tmp*=tmp;
        tmp%=mod;
        m/=2;
    }
    return ans;
}
LL dp[maxn];
int main()
{
    scanf("%lld%lld",&n,&k);
    dp[k]=1;
    for(LL i=k-1;i>=1;i--){
        dp[i]=po((k/i),n);
        for(LL j=2;j*i<=k;j++){
            dp[i]-=dp[j*i];
        }
        dp[i]=(dp[i]+mod)%mod;
    }
    LL res=0;
    for(LL i=1;i<=k;i++){
        res+=((dp[i]*i)%mod);
        res%=mod;
        //printf("%lld ",dp[i]);
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 4496
# -*- coding: utf-8 -*-
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n, y = map(int,input().split())
for i in range(n + 1): #10000
    for j in range(n + 1): #5000
        k = n - i - j #1000
        if k >= 0 and i * 10000 + j * 5000 + k * 1000 == y:
            print(i, j, k)
            exit()
print(-1, -1, -1)


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

ll dp[25000002];

int main()
{
    int n;
    cin >> n;
    int a[3], b[3];
    for(int i = 0; i < 3; i++) cin >> a[i];
    for(int i = 0; i < 3; i++) cin >> b[i];
    for(int i = 0; i <= n; i++){
        dp[i] = i;
        for(int j = 0; j < 3; j++){
            if(i >= a[j]) dp[i] = max(dp[i], dp[i - a[j]] + b[j]);
        }
    }
    int l = dp[n];
    for(int i = 0; i <= l; i++){
        dp[i] = i;
        for(int j = 0; j < 3; j++){
            if(i >= b[j]) dp[i] = max(dp[i], dp[i - b[j]] + a[j]);
        }
    }
    cout << dp[l] << endl;
}


Measured memory_bytes: 198724
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Prelim/1179?year=2012

#include <bits/stdc++.h>

using namespace std;

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

    for (int i = 0; i < n; ++i) {
        int year, month, day;
        cin >> year >> month >> day;

        int ans = 0;
        // 月末まで
        if (year % 3 == 0 || month % 2 == 1) {
            ans += 20 - day;
        } else {
            ans += 19 - day;
        }

        // 年末まで
        for (int i = month + 1; i <= 10; i++) {
            if (year % 3 == 0 || i % 2 == 1) {
                ans += 20;
            } else {
                ans += 19;
            }
        }

        // 記念日まで
        for (int i = year + 1; i < 1000; i++) {
            if (i % 3 == 0) {
                ans += 200;
            } else {
                ans += 195;
            }
        }

        cout << ans + 1 << endl;
    }
    return 0;
}

/*
 * 「月末まで」「年末まで」「記念日まで」
 *  に分けて数える。
 *
 */


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {

  int x, y, z;
  cin >> x >> y >> z; cout << z << ' ' << x << ' ' << y << '\n';

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,k;
void solve()
{
	for(int i=0;i<=n;++i)
		for(int j=0;j<=m;++j)
		{
			int tmp=i*m+j*n-i*j*2;
			if(tmp==k)	
			{
				puts("Yes");
				return ;
			}
		}
	puts("No");
}

int main()
{
//	freopen("1.txt","r",stdin);
//	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	solve();
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a = 0;
		for(int i = 0; i < N; i++)
			a = a ^ sc.nextInt();
		System.out.println(a == 0 ? "Yes" : "No");

	}

}

Measured memory_bytes: 46244
#include <bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define ls rt << 1
#define rs rt << 1 | 1
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define eps 1e-9
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int main()
{
	LL l, r, mid, no, wei; 
	string res;
	for(no = 0, wei = 100000000000000000LL; ; wei /= 10)
	{
		l = (no ? 0 : 1), r = 9;
		while(l < r)
		{
			mid = (l + r) >> 1;
			cout << "? " << (no * 10 + mid + 1) * wei - 1 << endl << flush;
			cin >> res;
			if(res[0] == 'Y') r = mid;
			else l = mid + 1;
		} 
		no = no * 10 + r;
		cout << "? " << no * wei << endl << flush;
		cin >> res;
		if(res[0] == 'Y')
		{
			if(no == 1)
				for(wei = 1;; wei *= 10)
				{
					cout << "? " << wei + 1 << endl << flush;
					cin >> res;
					if(res[0] == 'Y')
					{
						cout << "! " << wei << endl << flush;
						return 0;
					}
				}
			
			for(wei = 1;; wei *= 10)
			{
				cout << "? " << (no - 1) * wei << endl << flush;
				cin >> res;
				if(res[0] == 'N') break;
			} 
			cout << "! " << no * wei / 10 << endl << flush;
			return 0;
		}
	}
	return 0;
}

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

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

int main() {
    int64_t N, M;
    cin >> N >> M;
    set<int64_t> st;
    for (int64_t i = 0; i < N; i++) {
        int64_t a;
        cin >> a;
        st.insert(a);
    }

    int64_t even_lcm = 1, half_lcm = 1;
    for (int64_t e : st) {
        even_lcm = lcm(even_lcm, e);
        half_lcm = lcm(half_lcm, e / 2);
    }

    cout << M / half_lcm - M / lcm(half_lcm, *st.begin()) << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int  N=100000 +10, M=(ll)1e9+1 ;
const int mod =998244353 ,sz=5 ;

void work(){
  ll n;
  cin >> n;
  string s;
  cin >> s;
  if(n<3200)
    cout << "red\n";
  else
    cout << s; 
}
int main(){
 ios_base::sync_with_stdio(0);
 cin.tie(0);
    ll t;
    // cin >> t;
    t=1;
    while(t--){
            work();
    }
   return 0;

}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
B = [A[0]]
for i in range(1,N):
    B.append(B[-1]+A[i])
ans = 10**18
for i in range(N-1):
    diff = abs(B[i]-(S-B[i]))
    if diff < ans:
        ans = diff
print(ans)

Measured memory_bytes: 87120
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int MAX = 999999999;

int main(){
    vector<int> nums(3);
    cin >> nums[0] >> nums[1] >> nums[2];

    int count = 0;
    while(true){
        sort(all(nums));
        if(nums[0] == nums[1] && nums[1] == nums[2]) break;

        if(((nums[0] == nums[1] || nums[1] == nums[2]) && nums[2]*3 - accumulate(all(nums), 0) == 1) || nums[1] - nums[0] > 1){
            *min_element(all(nums)) += 2;
        }else{
            auto max_itr = max_element(all(nums));
            auto itr = nums.begin();
            while(itr != nums.end()){
                if(itr != max_itr) *itr += 1;
                itr++;
            }
        }

        count ++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 505
using namespace std;
typedef long long ll;
int a[maxn][maxn];
inline int in()
{
    int res=0;
    char c=getchar();
    if (c>='0'&&c<='9') res=c-48;
    while((c=getchar())>='0'&&c<='9') res=res*10+c-48;
    return res;
}
void out(int x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m, q;
    n = in(), m = in(), q = in();
    while (m--){
        int l, r;
        l = in(), r = in();
        ++a[l][r];
    }
    for (int i = n; i >= 1; --i){
        for (int j = 1; j <= n; ++j){
            a[i][j] += a[i + 1][j] + a[i][j - 1] - a[i + 1][j - 1];
        }
    }
    while (q--){
        int l, r;
        l = in(), r = in();
        out(a[l][r]);
        putchar(10);
    }
    return 0;
}


Measured memory_bytes: 1920
#!/usr/bin/env python3

import sys

N = int(input())
A = [int(s) for s in input().split()]

for a in A:
    if a == 0:
        print(0)
        sys.exit(0)

ans = 1
for a in A:
    if (ans > 10**18):
        print(-1)
        sys.exit(0)
    ans *= a

if ans > 10**18:
    print(-1)
else:
    print(ans)




Measured memory_bytes: 21584
using System;

namespace AOJapps
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            string data = Console.ReadLine();
            string[] values = data.Split(' ');

            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(values[i]);
            }

            Console.WriteLine(data);

            for (int i = 1; i < N; i++)
            {
                int v= A[i];
                int j = i - 1;
                while (j>=0 && A[j] > v)
                {
                    A[j + 1] = A[j];
                    j--;
                }
                A[j + 1] = v;
                for (int k = 0; k < N; k++) { values[k] = A[k].ToString(); }
                Console.WriteLine(string.Join(" ", values));
            }
        }
    }
}

Measured memory_bytes: 9200
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a,b;
	cin>>n>>a>>b;
	int p[111]={},c[3]={};
	FOR(i,0,n){
		cin>>p[i];
		if(p[i]<=a){
			c[0]++;
		}else if(p[i]<=b){
			c[1]++;
		}else{
			c[2]++;
		}
	}
	cout<<min({c[0],c[1],c[2]})<<endl;

    return 0;
}


Measured memory_bytes: 256
import math

def prime_factorization(n):
    factors = []
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            while True:
                factors.append(i)
                n //= i
                if n % i != 0: break
    if n > 1:
        factors.append(n)
    return factors

n = int(input())
factors = prime_factorization(n)
print(f'{n}:', *factors)



Measured memory_bytes: 5676
#ABC-109-B
N = int(input())
ans = "Yes"
memo = {}
word = input()
memo[word] = None
last_char = word[-1]

for _ in range(N-1):
    word = input()
    if word in memo:
        ans = "No"
        break
    if word[0] != last_char:
        ans = "No"
        break
    memo[word] = None
    last_char = word[-1]

print(ans)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
 
		try (Scanner sc = new Scanner(System.in)) {
			int left = sc.nextInt();
			int center = sc.nextInt();
			int right = sc.nextInt();
 
			Integer array[] = {left, center, right};
 
			Arrays.sort(array, Comparator.reverseOrder());
 
			int outLeft = array[0];
			int outCenter = array[1];
			int outright = array[2];
 
			String leftAndCenterStr = String.valueOf(outLeft) + String.valueOf(outCenter);
			Integer leftAndCenterNum = Integer.valueOf(leftAndCenterStr);
			int sum = leftAndCenterNum + outright;
 
			System.out.println(sum);
 
		}
		catch (Exception e) {
			// TODO: handle exception
		}
	}
}

Measured memory_bytes: 21844
from itertools import permutations
import numpy as np
from scipy.sparse.csgraph import dijkstra

with open(0) as f:
    N, M, R = map(int, f.readline().split())
    r = list(map(int, f.readline().split()))
    path = [tuple(map(int, line.split())) for line in f.readlines()]

graph = np.full((N,N), np.inf)
for a, b, c in path:
    graph[a-1, b-1] = c
    graph[b-1, a-1] = c

graph = dijkstra(graph, directed=False)
ans = np.inf
permutation = list(permutations(r))
for p in permutation:
    way = 0
    for x,y in zip(p[:len(r)], p[1:]):
        way += graph[x-1, y-1]
    ans = min(ans, way)
print(int(ans))

Measured memory_bytes: 46252
#include<bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define inf             1e18
#define no_of_test(x)        int x; cin>>x; while(x--)
const int mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	no_of_test(x)
	{
       int n;
       cin>>n;
       int cnt=0;
       int r=1;
       while(n>=1)
       {
           n=n/2;
           cnt+=r;
           r=r*2;
       }
       cout<<cnt<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3656
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    P=list(map(float,input().split()))
    dp=[[0]*(n+1) for _ in range(n)]#コインi(0-)までで，j枚が表
    dp[0][0]=1-P[0]
    dp[0][1]=P[0]
    for i in range(1,n):
        for j in range(i+2):
            if j==0:
                dp[i][j]=dp[i-1][j]*(1-P[i])
            else:
                dp[i][j]=dp[i-1][j-1]*P[i]+dp[i-1][j]*(1-P[i])
    print(sum(dp[-1][n//2+1:]))
if __name__=='__main__':
    main()

Measured memory_bytes: 273928
#include<iostream>
#include<cassert>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 500;
const int inf = (1<<20);
int cap[N][N];
int flow[N][N];
bool vis[N];
 
int fordFulkerson(const int n,const int t,int now,int fl){
  if (now == t)return fl;
  if (vis[now])return 0;
  vis[now]=true;
  int tmp=0;
  rep(i,n){
    int &next=i;
    if (cap[now][i] - flow[now][i] > 0){
      tmp=fordFulkerson(n,t,next,min(fl,cap[now][i]-flow[now][i]));
      if (tmp != 0){
	flow[now][next]+=tmp;
	flow[next][now]=-flow[now][next];
	return tmp;
      }
    }
  }
  return 0;
}

int maxFlow(int n,int s,int t){
  int tmp=0,ret=0;
  rep(i,n)vis[i]=false;
  while((tmp = fordFulkerson(n,t,s,inf)) != 0){
    ret+=tmp;
    rep(i,n)vis[i]=false;
  }
  return ret;
}

bool dfs(int n,int now,int t){
  if (now == t)return true;
  if (vis[now])return false;
  vis[now]=true;
  rep(i,n){
    int &next=i;
    //if (cap[next][now]-flow[next][now] > 0){
    if (flow[now][next] < 0){
      if (dfs(n,next,t)){
	flow[now][next]=flow[next][now]=0;
	return true;
      }
    }
  }
  return false;
}

int dfs2(int n,int now,int t){
  if (now == t)return 1;
  if (vis[now])return 0;
  vis[now]=true;
  rep(i,n){
    int &next=i;
    if (cap[now][next]-flow[now][next] > 0){
    //if (flow[now][next] < 0){
      if (dfs2(n,next,t)){
	flow[now][next]+=1;
	flow[next][now]=-flow[now][next];
	return 1;
      }
    }
  }
  return 0;
}


main(){
  int n,e,q;
  while(cin>>n>>e>>q){
    //cout << n <<" " << e <<" " <<q << endl;
    const int s = 0,t=n-1;
    rep(i,n)rep(j,n)cap[i][j]=0,flow[i][j]=0;
    rep(i,e){
      int f,t;
      cin>>f>>t;
      f--;t--;
      cap[f][t]=1;
      cap[t][f]=1;
    }
    int prev=maxFlow(n,s,t);
    rep(i,q){
      int a,from,to,tmp;
      cin>>a>>from>>to;
      from--;to--;
      if (a == 1){//add
	cap[from][to]=cap[to][from]=1;
	tmp = maxFlow(n,s,t);
#ifdef DEBUG1
	cout <<"add:";
#endif
	cout << prev+tmp << endl;
	prev=prev+tmp;
      }else if (flow[from][to] == 0){
#ifdef DEBUG1
	cout <<"noflow:";
#endif
	cap[from][to]=cap[to][from]=0;
	cout << prev << endl;
      }else {//delete
#ifdef DEBUG1
	cout <<"del:";
#endif
	if (flow[from][to] < 0)swap(from,to);
	cap[from][to]=cap[to][from]=0;
	flow[from][to]=flow[to][from]=0;

	//tmp = fordFulkerson(n,to,from,1);
	//tmp=maxFlow(n,from,to);
	//tmp=fordFulkerson(n,to,from,1);
	rep(j,n)vis[j]=false;
	tmp=dfs2(n,from,to);
	if (tmp != 0){
	  cout << prev << endl;
	  prev=prev;//keep
	}else {
	  rep(j,n)vis[j]=false;
	  dfs(n,from,s);
	  //assert(fordFulkerson(n,s,from,1) == 1);
	  rep(j,n)vis[j]=false;
	  dfs(n,t,to);
	  //assert(fordFulkerson(n,to,t,1) == 1);
	  cout << prev-1 << endl;
	  prev=prev-1;
	}
      }
      /*
	rep(ii,n){
	  rep(jj,n){
	    cout << flow[ii][jj] <<" ";
	  }
	  cout << endl;
	}
	rep(i,n){
	  int cnt=0;
	  if (i == 0||i == n-1)continue;
	  rep(j,n)cnt+=flow[i][j];
	  cout <<" " << a << " " <<  i <<": " << cnt << endl;
	  assert(cnt==0);
	}
      */
    }
#ifdef DEBUG
    cout << "end " << endl;
#endif
  }
}

Measured memory_bytes: 2832
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while (cin >> n) {
        int odd = 0;
        REP(i, n) {
            int x;
            cin >> x;
            if (x % 2 == 1) {
                odd = 1;
            }
        }
        cout << (odd ? "first" : "second") << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
ai = [int(i) for i in input().split()]
bi = []
for i in range(len(ai)):
    bi.append(ai[i]-(i+1))
bi = sorted(bi)
b = bi[int(len(bi)/2)]
ans = 0
for i in range(len(ai)):
    ans += abs(ai[i] - (b+i+1))
print(ans)

Measured memory_bytes: 25196
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    vector<int> dp(40);
    dp[0] = 1;
    for(int i=0; i<30; i++){
        dp[i+1] += dp[i];
        dp[i+2] += dp[i];
        dp[i+3] += dp[i];
    }
    
    while(1){
        int n; cin >> n;
        if(n==0) return 0;
        cout << ((dp[n] + 9)/ 10 + 364) / 365 << endl;
    }
    
    
    return 0;
}






Measured memory_bytes: 3056
/*input
2
ip cc
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int main(){
	IOS;
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22) cout<<"bust";
	else cout<<"win";
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int W,H,x,y,r;
    
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    
    if(x<-100||100<x){
        printf("error\n");
        return 0;
    }
    if(y<-100||100<y){
        printf("error\n");
        return 0;
    }
    if(W<=0||100<W){
        printf("error\n");
        return 0;
    }
    if(H<=0||100<H){
        printf("error\n");
        return 0;
    }
    if(r<=0||100<r){
        printf("error\n");
        return 0;
    }
    
    if( (x-r>=0) && (x+r<=W) && (y-r>=0) && (y+r<=H) ){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    
    return 0;
}


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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin (),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)

const double pi = 2*acos(0.0);
//__gcd(n1, n2);
//cout << fixed;
//cout << setprecision(6); //fixes # of dp



int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
	
    int h, n;
    cin >> h >> n;
    int d = 0;
    while(n--){
        int temp;
        cin >> temp;
        d += temp;
    }
    if(d >= h){
        cout << "Yes";
    } else{
        cout << "No";
    }
}








Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io::*;

fn main() {
    let mut buff = String::new();
    stdin().read_line(&mut buff).unwrap();
    let mut itr = buff.split_whitespace();
    let mut x: i32 = itr.next().unwrap().parse().unwrap();


    let res: i32;
    loop {
        let mut i: i32 = (x as f64).sqrt().ceil() as i32;
        while i > 1 {
            if x != i && x % i == 0 {
                break;
            }
            i -= 1;
        }
        if i == 1 {
            res = x;
            break;
        }
        x += 1;
    }


    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    let ans = format!("{}", res);
    writeln!(out, "{}", ans).unwrap();
}

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

int main() {
  int n, h;
  cin >> n >> h;
  vector<int> a(n), b(n);
  rep(i,n) cin >> a[i] >> b[i];
  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end(), greater<int>());
  int res = 0;
  int max_a = a[0];
  int i = 0;
  while (h > 0 && b[i] > max_a && i < n) {
    h -= b[i];
    i++;
    res++;
  }
  if (h > 0) res += (h + max_a - 1) / max_a;
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e10;
using Graph = vector<vector<int>>;

signed main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  vector<int> R(N+1);
  for( int i = 0; i < N; i++ ) cin >> A[i];

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

}

Measured memory_bytes: 6420