akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
char s[105][105];
int a[105];
int b[105];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%s",&s[i]);
        scanf("%d",&a[i]);
    b[i]=i+1;
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(strcmp(s[i],s[j])>0)
            {
                char ss[i][j];
                strcpy(ss[i],s[i]);
                strcpy(s[i],s[j]);
                strcpy(s[j],ss[i]);
                int t=a[i];a[i]=a[j];a[j]=t;
                int k=b[i];b[i]=b[j];b[j]=k;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(strcmp(s[i],s[j])==0&&a[i]<a[j])
            {
                 char ss[i][j];
                strcpy(ss[i],s[i]);
                strcpy(s[i],s[j]);
                strcpy(s[j],ss[i]);
                int t=a[i];a[i]=a[j];a[j]=t;
                int k=b[i];b[i]=b[j];b[j]=k;
            }
        }



    }
    for(int i=0;i<n;i++)
    {
        printf("%d\n",b[i]);
    }
}
//2563415

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

#define fi first
#define se second
#define pb push_back
#define CLR(A, X) memset(A, X, sizeof(A))
#define bitcount(X) __builtin_popcountll(X)
//#pragma comment(linker, "/STACK:102400000, 102400000")
const double eps = 1e-10;
int dcmp(double x) { if(fabs(x) < eps) return 0; return x<0?-1:1; }
typedef long long LL;
typedef pair<int, int> PII;

const int N = 60;
const LL MOD = 1e9+7;

char s[N], s2[N];

int main() {
    int n;
    scanf("%d", &n);
    scanf("%s%s", s, s2);
    LL ans = 1;
    int pre = -1;
    for(int i = 0; i < n; i++) {
        if(i+1<n && s[i]==s[i+1]) {
            if(pre == 1) ans = ans*2%MOD;
            else if(pre == 2) ans = ans*3%MOD;
            else ans = ans*6%MOD;
            pre = 2;
            i++;
        }
        else {
            if(pre == 1) ans = ans*2%MOD;
            else if(pre == 2);
            else ans = ans*3%MOD;
            pre = 1;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int solve(int,int);
int n,A[2000];
 
int main(){
  int q,Mi,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&Mi);
    if(solve(0,Mi)){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }
  }
  return 0;
}


int solve(int i,int m){
  if(m==0){
    return 1;
  }
  if(i>=n){
    return 0;
  }
  int res=solve(i+1 , m) ||solve(i+1 , m-A[i]);
return res;
}

Measured memory_bytes: 580
import java.util.Scanner;
import java.util.LinkedList; 
import java.util.Queue; 

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ts = 0;
		
		Queue<Integer> qN = new LinkedList<>(); 
		Queue<String> qP = new LinkedList<>(); 
		
		String line = sc.nextLine();
		
		String[] lineList = line.split(" ");
		String[] itemsList = new String[Integer.parseInt(lineList[0])*2];
		
		int q = Integer.parseInt(lineList[1]);
		
		String[] items = new String[Integer.parseInt(lineList[0])];
		
		//add everything into queues
		for(int i = 0; i < Integer.parseInt(lineList[0]); i++) {
			items[i] = sc.nextLine();
			itemsList = items[i].split(" ");
			qP.add(itemsList[0]);
			qN.add(Integer.parseInt(itemsList[1]));
		}
		
		while(!qP.isEmpty()){
			if(q - qN.peek() < 0) {
				qN.add(-1*(q-qN.remove()));
				qP.add(qP.remove());
				ts += q;
			}
			else {
				ts += qN.remove();
				System.out.println(qP.remove() + " " + ts);
			}
		}
		
	}
}



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

using std::cin;
using std::cout;
using std::string;

int main()
{
  std::vector<int> vec(5);
  int k;
  for (size_t i = 0; i < 5; ++i)
  {
    cin >> vec[i];
  }
  cin >> k;

  bool result = true;
  for (size_t i = 0; i < vec.size(); ++i)
  {
    for (size_t j = i; j < vec.size(); ++j)
    {
      if (vec[j] - vec[i] > k)
      {
        result = false;
        break;
      }
    }
  }
  if (!result)
  {
    cout << ":("
         << "\n";
  }
  else
  {
    cout << "Yay!"
         << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a;
	int i;
	while(scanf("%d",&a)!=EOF){
	int j=1;
	for(i=a;i > 0 ; i--)
		j = j+i;
	printf("%d\n",j);
	if (a == 0)
		break;
	}
	return 0;
}

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

namespace Contest20191017
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int Counter = 0;

            for(int i =1;i <= N;i++)
            { 
            if(i % 2 != 0)
                {
                    Counter++;
                }

            }
            double a = (double)Counter / N;

            Console.WriteLine(a);
        }
    }
}


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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>
bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

vector<pair<ll,ll>> P;
vvll memo;

ll dfs(int l,int r){
	if(memo[l][r]>=0) return memo[l][r];
	if(r-l<2){
		return 0;
	}
	
	ll V=1LL<<60;
	for(int i=l+1;i<r;i++){
		V = min(V,dfs(l,i)+dfs(i,r)+P[l].first*P[i].first*P[r-1].second);
	}
	memo[l][r] = V;
	return V;
}

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

	int N=in();
	P.resize(N);
	memo.resize(N+1,vll(N+1,-1));
	REP(i,N){
		P[i].first=in();
		P[i].second=in();
	}
	
	out(dfs(0,N));
	return 0;
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
    #define HAR BAR LAGTA HAI APUN HI J BHAGWAAN HAI!!
    #define UTSAV  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define ll long long int
    #define MAX 1e9
    #define MIN -1e9
    #define mod 1000000007
    #define pb push_back
    #define all(x) (x).begin(), (x).end()
    #define debug(x) cerr<<#x<<'='<<(x)<<endl;
    #define output(x) cout << ( x ? "YES" : "NO" ) << '\n' ;
    #define mxn 100005
    using namespace std;
    vector<int> arr[100001];
    int vis[100001];
    int cc;
    void dfs(int i){
        vis[i]=1;
        for(int child : arr[i]){
            if(vis[child]==0) dfs(child);
        }
    }
    int main()
    {
        UTSAV
        ll n,m,a,b;
        cin>>n>>m;
        for(int i=0;i<m;i++){
            cin>>a>>b;
            arr[a].pb(b);
            arr[b].pb(a);
        }
        cc=0;
        for(int i=1;i<=n;i++){
            if(vis[i]==0) dfs(i),cc++;
        }
        cout<<cc-1<<endl;
        return 0;
    }
       

Measured memory_bytes: 10008
// Bismillahirrahmanirrahim
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int n, a, b; cin >> n >> a >> b;
  if(abs(a-b)%2 == 0) {
    cout << (abs(a-b)/2) << endl;
    return 0;
  }
  int mn = min(a, b), mx = max(a, b);
  int m1 = 0, m2 = 0;
  int sn = n - mx;
  m1 = sn + 1 + (n-(mn+sn+1))/2;
  int bs = mn-1;
  m2 = bs + 1 + (mx - (bs+1+1))/2;
  cout << min(m1, m2) << endl;


}


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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if (a == c) {
		cout << b << '\n';
	}
	else if (a == b) {
		cout << c << '\n';
	}
	else {
		cout << a << '\n';
	}
	return 0;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

struct UnionFind {
  UnionFind(int n) : data(n, -1) {}

  int root(int ver) { return data[ver] < 0 ? ver : data[ver] = root(data[ver]); }

  bool unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return false;
    if (data[u] > data[v]) std::swap(u, v);
    data[u] += data[v];
    data[v] = u;
    return true;
  }

  bool same(int u, int v) { return root(u) == root(v); }

  int size(int ver) { return -data[root(ver)]; }

private:
  std::vector<int> data;
};

int main() {
  int n; cin >> n;
  vector<int> x(n), y(n); REP(i, n) cin >> x[i] >> y[i], --x[i], --y[i];
  vector<int> y_idx(n);
  REP(i, n) y_idx[y[i]] = i;
  vector<int> idx(n);
  iota(ALL(idx), 0);
  sort(ALL(idx), [&](int a, int b) { return x[a] < x[b]; });
  UnionFind uf(n);
  set<int> st;
  REP(i, n) {
    if (st.empty() || y[idx[i]] < *st.begin()) {
      st.emplace(y[idx[i]]);
    } else {
      for (auto it = next(st.begin()); it != st.end() && *it < y[idx[i]]; it = st.erase(it)) uf.unite(idx[i], y_idx[*it]);
      uf.unite(idx[i], y_idx[*st.begin()]);
    }
  }
  st.clear();
  for (int i = n - 1; i >= 0; --i) {
    if (st.empty() || *st.rbegin() < y[idx[i]]) {
      st.emplace(y[idx[i]]);
    } else {
      for (auto it = st.lower_bound(y[idx[i]]); it != prev(st.end()); it = st.erase(it)) uf.unite(idx[i], y_idx[*it]);
      uf.unite(idx[i], y_idx[*st.rbegin()]);
    }
  }
  REP(i, n) cout << uf.size(i) << '\n';
  return 0;
}


Measured memory_bytes: 11552
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;

int l[100];

void solve() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    int t;
    cin >> t;
    l[i] += t;
  }
  for(int i = 0; i < n; i++) {
    int t;
    cin >> t;
    l[i] -= t;
  }
  int ret = 0;
  for(int i = 0; i < n; i++) if(l[i] > 0) ret += l[i];
  cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long int LLI;
int main()
{
	int h, w, sum;
	cin >> h >> w;
	char arr[h][w];
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			cin >> arr[i][j];
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			if( arr[i][j] == '.' )
			{
				sum = 0;
				for(int k = i-1; k <= i+1; k++)
					for(int l = j-1; l <= j+1; l++)
					{
						if( k == i and l == j )
							continue;
						if( l >= 0 and l < w and k >= 0 and k < h and arr[k][l] == '#' )
							sum++;
					}
				arr[i][j] = (char)('0'+sum);
			}
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
			cout << arr[i][j];
		cout << "\n";
	}
}

Measured memory_bytes: 3636
my $a = glob<>;
my $b = glob<>;
my $c = glob<>;
my $x = glob<>;

my $cnt = 0;
for my $i ( 0 .. $a ) {
    for my $j ( 0 .. $b ) {
	my $y = $x - 500*$i - 100*$j;
	$y < 0 and last;
	$y / 50 <= $c and $cnt++;
    }
}
print $cnt;

Measured memory_bytes: 768
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m=map(int,input().split())
tree = UnionFind(n+m+1) 
for i in range(n):
  l=list(map(int,input().split()))
  for j in range(1,len(l)):
    tree.unite(i,l[j]+n)
rt=tree.find(0)
# print(tree)
for i in range(1,n):
  # print(rt, tree.find(i))
  if rt!= tree.find(i):
    print("NO");exit()
print("YES")

Measured memory_bytes: 9660
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
struct BIT{
    int n;
    vector<int>bit;
    BIT(int x){
        bit.resize(x,0);
        n=x;
    }
    int sum(int i){
        int res=0;
        while(i>0){
            res+=bit[i];
            i-=i&-i;
        }
        return res;
    }
    void add(int i,int x){
        while(i<n){
            bit[i]+=x;
            i+=i&-i;
        }
    }
};
int n,a[100010];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n)cin>>a[i];
    int l=(n+1)*n/2/2;
    if(n%4==1||n%4==2)l++;
    int ok=0,ng=1000000001;
    while(ng-ok>1){
        int x=(ok+ng)/2;
        vector<int>v(n+1);
        v[0]=0;
        rep(i,n){
            if(a[i]>=x)v[i+1]=1;
            else v[i+1]=-1;
        }
        for(int i=1;i<=n;i++)v[i]+=v[i-1];
        rep(i,n+1)v[i]+=n+1;
        BIT bit(2*n+5);
        bit.add(v[0],1);
        int sum=0;
        for(int i=1;i<=n;i++){
            sum+=bit.sum(v[i]);
            bit.add(v[i],1);
        }
        if(sum>=l)ok=x;
        else ng=x;
    }
    cout<<ok<<endl;
	return 0;
}


Measured memory_bytes: 3424
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int main()
{
    fastio();
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int flag = 0;
    while(a>0 && c>0)
    {
        if(flag==0) c-=b;
        else a-=d;
        flag ^= 1;
    }
    if(a<=0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3664
n = int(input())
a = list(map(int, input().split()))

sum = 0
max = -1000000
min = 1000000
for i in range(n):
    sum = sum + a[i]
    if max < a[i]:
        max = a[i]
    if min > a[i]:
        min = a[i]
        
print(min, max, sum)


Measured memory_bytes: 6588
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    int H, N; cin >> H >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    int sum = accumulate(A.begin(), A.end(), 0);

    if (sum >= H) cout << "Yes" << endl;
    else cout << "No" << endl;

}


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

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<int, int, int> T;
// get<K>(tuple型の変数)

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

const int inf = 1<<29;
int N, M;
vector<int> adj[1010];

vector<int> bfs(int s){
    vector<int> dist(N, inf), pre(N, -1);
    queue<int> q;
    dist[s] = 0;
    q.push(s);

    while(!q.empty()){
        int now = q.front(); q.pop();
        for(int to : adj[now]){
            if(dist[to] == inf){
                dist[to] = dist[now]+1;
                pre[to] = now;
                q.push(to);
            }
        }
    }

    pair<int, int> best(inf, -1);
    rep(i, N){
        if(i == s) continue;
        for(auto j : adj[i]){
            if(j == s){
                chmin(best, make_pair(dist[i], i));
            }
        }
    }
    
    if(best.first == inf){
        vector<int> a(N+1, 0);
        return a;
    }

    vector<int> ans;
    int now = best.second;
    while(now != -1){
        ans.push_back(now);
        now = pre[now];
    }
    return ans;

}

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

    cin >> N >> M;
    rep(i, M){
        int a, b; cin >> a >> b;
        --a; --b;
        adj[a].push_back(b);
    }

    vector<int> ans(N+1);
    rep(i, N){
        auto now = bfs(i);
        if(now.size() < ans.size()) ans = now;
    }

    if(ans.size()==N+1) cout << -1 << endl;
    else{
        cout << ans.size() << endl;
        for(int v : ans) cout << v+1 << endl;
    }

    return 0;
} 

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
const ll MOD = 998244353;
ll dp[3005];
ll dp_[3005];
int N, S;
int A[3000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> S;
    for(int i = 0; i < N; i++) cin >> A[i];
    ll ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= S; j++){
            dp_[j] = dp[j];
        }
        dp_[A[i]] += (i+1);
        for(int j = 0; j+A[i] <= S; j++){
            dp_[j+A[i]] += dp[j];
        }
        for(int j = 0; j <= S; j++){
            dp[j] = dp_[j];
            dp[j] %= MOD;
            // cout << dp[j] << ' ';
        }
        // cout << endl;
        ans += dp_[S];
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
 
// #include <bits/stdc++.h>
// #include <epxt/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef pair<int,int> pii;
// tree <pii,null_tpype,greater<pii>,rb_tree_tag,tree_order_statistics_node_update> tr;
// cin.tie(0);
// std::ios::spync_with_stdio(false);
typedef long long LL;
const int N = 205;
const int M = 205;
// const int V = 207;
// const int E = 60007;
const int INF = 0x3f3f3f3f;
const double inf = 2e9;
const double Pi = acos(-1);
const int MOD = 1e9+7;
const double eps=1e-13;
int n,m;
int s[N];
int main()
{
    while (~scanf("%d",&n))
    {
        int ma = 0;
        int p = 0;
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&s[i]);
            if (abs(s[i])>=ma)
            {
                ma = abs(s[i]);
                p = i;
            }
        }
        printf("%d\n", 2*n-2);
        for (int i=1;i<=n;i++)
            if (i!=p)
                printf("%d %d\n",p,i);
        if (s[p]>0)
            for (int i=1;i<n;i++)
                printf("%d %d\n", i,i+1);
        else
            for (int i=n;i>1;i--)
                printf("%d %d\n", i,i-1);
    }
    return 0;
}


/*

3
-2 5 -1

2
-1 -3

5
0 0 0 0 0

*/

Measured memory_bytes: 256
const main = (input) => {
  const args = input.trim().split("\n");
  const Ai = args[1]
    .trim()
    .split(" ")
    .map((n) => parseInt(n, 10));

  const MAX = 10 ** 6;
  const checkMarks = new Array((MAX + 1) | 0).fill(0);

  const hasChecked = (c) => c !== 0;
  for (const a of Ai) {
    if (hasChecked(checkMarks[a])) {
      checkMarks[a] = 2;
      continue;
    }
    for (const i of checkMarks.keys()) {
      const position = (((i + 1) | 0) * a) | 0;
      if (position > MAX) break;
      checkMarks[position] = (checkMarks[position] + 1) | 0;
    }
  }

  const isNotDivided = (n) => checkMarks[n] === 1;
  const answer = Ai.filter(isNotDivided).length;

  console.log(answer);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 66944
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define int long long
int nemp[1000];
int emp[1000];
vector<int> g[1000];
string type[1000];
int mo = 1e9 + 7;

void dfs(int x)
{
    for (int j = 0; j < g[x].size(); j++) dfs(g[x][j]);
    if (type[x][0] != 'E')
    {
        emp[x] = type[x].back() == '?';
        if (type[x][0] == 'R')
        {
            for (int i = 1; i < (1 << g[x].size()); i++)
            {
                int e = 1;
                int sub = 1;
                for (int j = 0; j < g[x].size(); j++)
                {
                    if (i >> j & 1)
                    {
                        e *= emp[g[x][j]];
                        sub *= emp[g[x][j]] + nemp[g[x][j]];
                        sub %= mo;
                    }
                }
                emp[x] |= e;
                nemp[x] += sub;
                nemp[x] %= mo;
            }
        }
        else
        {
            for (int j = 0; j < g[x].size(); j++)
            {
                emp[x] |= emp[g[x][j]];
                nemp[x] += nemp[g[x][j]];
                nemp[x] %= mo;
            }
        }
    }
    else
    {
        emp[x] = type[x].back() == '?';
        int sub = 1;
        int e = 1;
        for (int j = 0; j < g[x].size(); j++)
        {
            e *= emp[g[x][j]];
            sub *= (emp[g[x][j]] + nemp[g[x][j]]);
        }
        sub %= mo;
        nemp[x] = sub;
    }
}
signed main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)cin >> type[i];
    for (int i = 0; i < n - 1; i++)
    {
        int s, t;cin >> s >> t;
        --s, --t;
        g[s].push_back(t);
    }
    dfs(0);
    cout << ((nemp[0] + emp[0]) % mo + mo) % mo << endl;
}



Measured memory_bytes: 3332
import sys


INF = sys.maxsize

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

dp = [INF] * N

for i in range(1, N):
  dp[i] = min(dp[i - 1], P[i - 1])
  
dp[0] = INF

print(sum(dp[i] >= P[i] for i in range(N)))


Measured memory_bytes: 75472
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int coin;
		
		coin = Math.max(a, b);
		coin += Math.max(coin-1, Math.min(a, b));	
		System.out.print(coin);
	}	
}

Measured memory_bytes: 22736
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[33]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
   int k;
   cin>>k;
   cout<<a[k-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int		main(void)
{
	double sum = 0;
	unsigned int get;
	unsigned int i = 0;

	scanf("%d", &get);
	if (get > 1000000)
		get = 1000000;
	while (++i <= get)
	{
		if (i % 3 == 0 && i >= 3)
			continue;
		if (i % 5 == 0 && i >= 5)
			continue;
		sum = sum + i;
	}
	printf("%.0f\n", sum);
	return (0);
}


Measured memory_bytes: 1740
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/lazysegtree>
#include <atcoder/modint>
using mint = atcoder::modint998244353;

struct S {
    mint n = 1;
    int size = 1;
};

S op(S a, S b) {
    S res;
    res.size = a.size + b.size;
    res.n = a.n * mint(10).pow(b.size) + b.n;
    return res;
}

S e() {
    return S{0, 0};
}

vector<mint> precomp;
S mapping(int a, S b) {
    if (a == 0) return b;
    b.n = mint(a) * precomp[b.size];
    return b;
}

int composition(int a, int b) {
    return a == 0 ? b : a;
}

int id() {
    return 0;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    precomp.resize(n + 1);
    precomp[1] = 1;
    for (int i = 2; i <= n; i++) {
        precomp[i] = precomp[i - 1] * 10 + 1;
    }
    vector<S> a(n);
    atcoder::lazy_segtree<S, op, e, int, mapping, composition, id> st(move(a));
    for (int i = 0; i < m; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        st.apply(l - 1, r, d);
        cout << st.all_prod().n.val() << '\n';
    }
    return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

ll f(ll x){
    if(x <= 0){
        return 0;
    }

    int i = 40;
    for(;i>=0;--i){
        if(x >> i & 1){
            break;
        }
    }

    ll y = 0;

    unless(x & 1){
        y |= 1ll << i;
    }

    for(int j=i-1;j>0;--j){
        if(x >> j & 1){
            unless(x & 1){
                y |= 1ll << j;
            }
        }
    }

    if(((x & 1) + (x >> 1 & 1)) % 2 == 1){
        y |= 1;
    }

    return y;
}

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

    ll A, B;
    std::cin >> A >> B;

    ll res = f(B) ^ f(A - 1);
    std::cout << res << std::endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.Arrays;
import java.util.List;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        int[] copyA = new int[N];
        copyA = (int[])A.clone();
        quick_sort(copyA, 0, N-1);
        int max = copyA[N - 1];
        int max2 = copyA[N - 2];
        for (int i = 0; i < N; i++) {
            if (A[i] == max) {
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
        scan.close();
    }

    static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }
}

Measured memory_bytes: 88448
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main(void){
	int H,W,cnt=0;
	char c;
	cin>>H>>W;
	rep(y,H)rep(x,W)cin>>c, cnt+=c=='#';
	cout<<(cnt==H+W-1 ? "Possible" : "Impossible")<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void){
  int A,H,f;
  
  scanf("%d %d",&H,&A);
  f=H;
  for(int i=0;i<H;i++){
    f=f-A;
    if(f<=0){
      printf("%d\n",i+1);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  ll odd = 0;
  ll even = 0;
  rep(i,0,n){
    ll a;
    cin>>a;
    if(a%2==1)odd++;
    else even++;
  }
  if(odd%2==1){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
  return 0;
}
 

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;
const int INF=1e+09;
int N,X,Y;

int main(){    
    //入力
    cin >> N >> X >> Y;
    vector<int> ans(N+1,0);
    rep2(i,1,N){
        rep2(j,i+1,N+1){
            int dist = min(j-i,abs(X-i)+abs(Y-j)+1);
            ans[dist]++;
        }
    }

    rep2(i,1,N){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int n,p[101],min[101][101];

void matrixChainMultiplication(){
  int i,j,l,k,temp;
  for(i=0;i<=n;i++)
    min[i][i]=0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      min[i][j]=1000000000;
      for(k=i;k<=j-1;k++){
	temp=min[i][k]+min[k+1][j]+p[i-1]*p[k]*p[j];
	if(min[i][j]>temp)min[i][j]=temp;
      }
    }
  }
}

int main(){
  int i,no;
  scanf("%d",&n);
  scanf("%d%d",&p[0],&p[1]);
  for(i=2;i<=n;i++)
    scanf("%d%d",&no,&p[i]);

  matrixChainMultiplication();
  printf("%d\n",min[1][n]);
  return 0;
}


Measured memory_bytes: 2104
(* O(n) *)
Scanf.scanf " %d %d %d" @@ fun w h n ->
  let l, r, b, t = ref 0, ref w, ref 0, ref h in
  for i = 1 to n do
    Scanf.scanf " %d %d %d" @@ fun x y -> function
    | 1 -> l := max !l x
    | 2 -> r := min !r x
    | 3 -> b := max !b y
    | _ -> t := min !t y
  done;
  max 0 (!r - !l) * max 0 (!t - !b) |> Printf.printf "%d\n"

Measured memory_bytes: 512
n = int(input())
P = [int(i) for i in list(input().split())]
count = 0
for i in range(1, n-1):
  if P[i-1] < P[i] < P[i+1] or P[i-1] > P[i] > P[i+1]:
    count += 1

print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); 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 all(x) (x).begin(),(x).end()
#define srtarr(x, n) sort(x, x+n)
#define dsrtarr(x, n) sort(x, x+n, greater<>());
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007

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

using namespace std;
/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

 const int COM_MAX = 510000;

 long long fac[COM_MAX], finv[COM_MAX], inv[COM_MAX];

 // テーブルを作る前処理
 void COMinit() {
     fac[0] = fac[1] = 1;
     finv[0] = finv[1] = 1;
     inv[1] = 1;
     for (int i = 2; i < COM_MAX; i++){
         fac[i] = fac[i - 1] * i % mod;
         inv[i] = mod - inv[mod%i] * (mod / i) % mod;
         finv[i] = finv[i - 1] * inv[i] % mod;
     }
 }

 // 二項係数計算
 long long COM(int n, int k){
     if (n < k) return 0;
     if (n < 0 || k < 0) return 0;
     return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
 }


int main() {
    int n, k, r;
    cin >> n >> k;
    COMinit();
    r = n - k;
    reps(i, k) {
        cout << COM(r + 1, i) * COM(k-1, i - 1) % mod << endl;
    }
}




Measured memory_bytes: 12160
import math
n,m = map(int,input().split())
a = 1000000007
if not (0 <= abs(n-m) <= 1):
    print(0)
    exit()

if n == m:
    num = 2
else:
    num = 1
print(num*math.factorial(n)*math.factorial(m) % a)

Measured memory_bytes: 5112
//by Top1
#include <bits/stdc++.h>
     
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
 
const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 6e5 + 111;
     
using namespace std;

int q, n, w, a[maxn], b[maxn], dp[maxn][200], ans;

void solve(){    
	cin >> n >> w;

	for (int i = 1; i <= n; i++)
		cin >> a[i] >> b[i];


	for (int i = 1; i <= n; i++){
		for (int j = w; j > 0; j--){
			dp[i][j] = dp[i - 1][j];
			if (j - a[i] >= 0)
				dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]] + b[i]);
			ans = max(ans, dp[i][j]);
		}	
	}

	/*for (int i = 0; i <= w; i++)
		cout << dp[i] << " ";
	*/
	cout << ans;
}

main(){
    boost;
	    
	q = 1;

	while (q--){
		solve();
	}
}

Measured memory_bytes: 5248
#include <stdio.h>
 
int main(void){
  
  int N, R;
  scanf("%d %d", &N, &R);
  
  if((N < 1 || N > 100) || (R < 0 || R > 4111)){
    return 0;
  }
  
  if(N < 10){
    R = R + 100 * (10 - N);
    printf("%d\n", R);
  } else {
    printf("%d\n", R);
  }
  return 0;
}

Measured memory_bytes: 128
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=605;
const int mod=1e9+7;
int n,k;
int a[maxn],dp[2][maxn][maxn];
bool del[maxn],done[maxn];
void Add(int &a,int b){a+=b;if(a>=mod)a-=mod;}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d",&n);
	REP(i,n){
		scanf("%d%d",&a[2*i-1],&a[2*i]);
		if(a[2*i-1]<0&&a[2*i]<0)k++;
		else if(a[2*i-1]>0&&a[2*i]>0)del[a[2*i-1]]=del[a[2*i]]=true;
		else if(a[2*i-1]>0)done[a[2*i-1]]=true;
		else done[a[2*i]]=true;
	}
	int z=0;
	dp[z][0][0]=1;
	REP(i,2*n){
		if(del[i])continue;
		rep(j,2*n+1)rep(k,n+1)dp[z^1][j][k]=0;
		rep(j,2*n+1)rep(k,n+1){
			int cur=dp[z][j][k];
			if(!cur)continue;
			if(!done[i]){
				if(k)Add(dp[z^1][j][k-1],cur);
				Add(dp[z^1][j][k+1],cur);
				Add(dp[z^1][j+1][k],cur);
			}
			else{
				if(j)Add(dp[z^1][j-1][k],1LL*cur*j%mod);
				Add(dp[z^1][j][k+1],cur);
			}
		}
		z^=1;
	}
	int ans=dp[z][0][0];
	REP(i,k)ans=1LL*ans*i%mod;
	printf("%d\n",ans);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


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

#define fast_input() {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
#define For(i, l, r) for(int (i) = (l); (i) <= (r); ++(i))
#define For1(i, l, r) for(int (i) = (r); (i) >= (l); --(i))

/*
MIKUNO - 15/02/1999
*/
//	priority_queue <ll, vector<ll>, greater<ll> > q;
#define INF 1e9+5
using ll = long long;
const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
void add_self(int& a, int b) {
	a += b;
	if (a > mod)
		a -= mod;
}

int main() {
	fast_input();
	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	vector<vector<ll>>dp(n + 1, vector<ll> (n + 1));
	vector<vector<bool>>player(n + 1, vector<bool>(n + 1)); // 0 is first player
	// 1 is second player
	
	for (int l = n - 1; l >= 0; --l) {
		for (int r = l; r < n; ++r) {
			if (l == r) dp[l][r] = a[l];
			else
				dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
		}
	}
	cout << dp[0][n - 1];
}



Measured memory_bytes: 71936
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
signed main(){
int a,b;
  cin>>a>>b;
  if(b>=a)
    cout<<"unsafe";
  else
    cout<<"safe";
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const long long mod = 1e9+7;
long long power(long long a, long long b, long long m = mod) {
    if(b < 0) {
        return power(power(a, -b), mod-2);
    }
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
const int N = 3e5+9;
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    ll a, b, c, k; cin >> a >> b >> c >> k;
    if(k <= a) {
        cout << k << "\n";
        return 0;
    }
    if(k <= a+b) {
        cout << a << "\n";
        return 0;
    }
    if(k <= a+b+c) {
        cout << a-(k-a-b) << "\n";
        return 0;
    }
    




    return 0;
    
}


Measured memory_bytes: 3688
n = int(input())
a = list(map(int, input().split()))

b0 = 0
b = []
bodd0 = 0
bodd  = []
beven0 = 0
beven = []
for h,i in enumerate(a):
    b0 += i
    b.append(b0)
    if h%2 == 1:
        beven0 += i
        beven.append(beven0)
    else:
        bodd0 += i
        bodd.append(bodd0)

s1 = b[-1] - beven[-1]*2
ans = [s1]
for i in a:
    s1 = int((i - s1/2)*2)
    ans += [s1]

print(*ans[:-1])

Measured memory_bytes: 73700
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs              v.size()
#define ss               s.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii                pair<int,int>
#define ll                long long
#define ull              unsigned long long
#define pb              push_back
#define mpp          make_pair
#define Okay         0
#define pi               3.14159

using namespace std;
const int ll cont = 10e8;
static const ll inf = 1e18;

void solve(){
  string s;
  int n;
  cin>>n;
  cin>>s;
  int cnt = 0;
  int left = 0;
  int right = n-1;
  while(left < right){
    if(s[left] == 'W'){
        while(left < right){
           if(s[right] == 'R'){
            cnt++;
            s[left] = 'R';
            s[right] = 'W';
            left++;
            right--;
            break;
           }
           else right--;
        }
    }
    else left++;
   // cout<<s<<endl;
  }
  //cout<<s<<endl;
  for(int i =0;i<n; i++){
    if(s[i] == 'W'){
        for(;i<n; i++){
            if(s[i] == 'R')cnt++;
        }
    }
  }

  cout<<cnt<<endl;

}


int main(){
    Fast;
    solve();

    return Okay ;
}


Measured memory_bytes: 3704
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <limits>

using namespace std;

bool isStartWith(int pos, string str, string ans) {
    if (str.size() - pos < ans.size() ) {
        return false;
    }
    for(int i = 0; i < ans.size(); ++i){
        if (str[pos+i] != ans[i]) {
        	return false;
        }
    }
    return true;
}


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

    string str;
    cin >> str;

    set<int> unko;
    unko.insert(0);

    vector<string> anss;
    anss.push_back("dream");
    anss.push_back("dreamer");
    anss.push_back("erase");
    anss.push_back("eraser");
    auto set_pos = unko.begin();
    while( set_pos != unko.end() ) {
      int pos = *set_pos;
      for ( auto ans : anss) {
      	if(isStartWith(pos, str, ans)) {
      	    if(pos+ ans.size() == str.size()) {
      	    	cout << "YES" << endl;
      	    	return 0;
      	    }
      	    unko.insert(pos + ans.size());
      	}
      }
      set_pos++;
    }
cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 1872
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var nm=(Arr.shift()).split(" ").map(Number);
   if(nm[0]==0 && nm[1]==0)break;
   var n=nm[0];
   var m=nm[1];
   var N=[];
   var M=[];
   for(var i=0;i<n;i++)N.push(Arr.shift()-0);
   for(var i=0;i<m;i++)M.push(Arr.shift()-0);
   var x=0;
   for(var i=0;i<m;i++){
      x+=M[i];
      if(x>=n-1)break;
      x+=N[x];
      if(x>=n-1)break;
   }
   console.log(i+1);
}

Measured memory_bytes: 7904
#include <iostream>

using namespace std;

int main()
{
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	int t;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			t = x - 500 * i - 100 * j;
			if (t / 50 >= 0 && t / 50 <= c) {
				ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
main()
{
    int n=0;
    string s,t;
    cin>>s>>t;
    rep(i,3)if(s[i]==t[i])n++;
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())


d1 = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
d2 = ((x2 - x3) ** 2 + (y2 - y3) ** 2) ** 0.5
d3 = ((x3 - x1) ** 2 + (y3 - y1) ** 2) ** 0.5
D = max(d1, d2, d3)


s = (d1 + d2 + d3) / 2
S = (s * (s - d1) * (s - d2) * (s - d3)) ** 0.5
R = (2 * S) / (d1 + d2 + d3)


ok, ng = 0, 10000
eps = 1e-9

while abs(ok - ng) > eps:
    r = (ok + ng) / 2
    if 2 * r <= D * ((R - r) / R):
        ok = r
    else:
        ng = r

print(ok)


Measured memory_bytes: 3188
def main():
    n = int(input())
    a_lst = [int(input()) for i in range(n)]
    a_lst_descend = sorted(a_lst, reverse=True)

    max_value = a_lst_descend[0]
    second_value = a_lst_descend[1]

    for a in a_lst:
        if a == max_value:
            print(second_value)
        else:
            print(max_value)


if __name__ == "__main__":
    main()


Measured memory_bytes: 90472
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define ll long long
//map<key,value>

int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  s[k-1] = s[k-1]+32;
  cout << s;
  return 0;
}


Measured memory_bytes: 256
let white_cells h w h0 w0 = h * w - h0 * w - w0 * h + w0 * h0

let h, w = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a, b))
let h0, w0 = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a, b))

let () = Printf.printf "%d\n" (white_cells h w h0 w0)

Measured memory_bytes: 3852
import sys
from collections import deque

input = sys.stdin.readline


def bfs(G, v, visited):
    visited[v] = True
    queue = deque([v])
    while queue:
        v = queue.popleft()
        for u in G[v]:
            if visited[u]:
                continue
            visited[u] = True
            queue.append(u)


def main():
    N, M = map(int, input().split())
    G = [[] for _ in range(N)]
    a = [0] * M
    b = [0] * M
    for i in range(M):
        a[i], b[i] = map(int, input().split())
        a[i] -= 1
        b[i] -= 1
        G[a[i]].append(b[i])
        G[b[i]].append(a[i])

    ans = 0
    for i in range(M):
        G[a[i]].remove(b[i])
        G[b[i]].remove(a[i])

        visited = [False] * N
        bfs(G, 0, visited)

        if not all(visited):
            ans += 1

        G[a[i]].append(b[i])
        G[b[i]].append(a[i])

    print(ans)


if __name__ == "__main__":
    main()


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

#define pb push_back
#define ins insert 
#define ers erase 
#define all(x) x.begin(), x.end()
#define F first 
#define S second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef string str;
typedef long double ld;

const ll N = 2e5 + 10;
const ll INF = 1e18;
const ll MOD = 1e9 + 10;

ll Cnt, n, a[N], Max, t;
map<ll, ll> Cnt_Max;
map<ll, vector<ll>> koj;
map<ll, ll> joons;

int main(){
	cin >> n >> t;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		koj[a[i]].pb(i);
	}
	ll ans = 0;
	for (int i = n; i > 0; i--){
		ans = max(ans, Max - a[i]);
		Max = max(Max, a[i]);
	}
	Max = 0;
	ll cnMax = 0;
	for (int i = n; i > 0; i--){
		if (Max - a[i] == ans){
			joons[a[i]] ++;
			Cnt_Max[a[i]] = cnMax;
		}
		if (Max == a[i]){
			cnMax ++;
		}else if(Max < a[i]){
			cnMax = 1;
			Max = a[i];
		} 
	}
	for (auto u:joons){
		Cnt += min(Cnt_Max[u.F], u.S);
	}
	cout << Cnt;
	
	
	
	return 0;
}

Measured memory_bytes: 18176