akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

#define MAX_W 100
#define MAX_H 100

char room[MAX_W][MAX_H];
int W,H;

const int direc[4][2] = {
    {0, -1},
    {1, 0},
    {0, 1},
    {-1, 0},
};

void dfs(const int& row, const int& col, const char c);

int main() {
    while(cin>>H>>W, W > 0) {
        int step = 0;
        int col, row;
        for (row = 0; row < H; ++row) {
            for (col = 0; col < W; ++col) {
                cin >> room[row][col];
            }
        }
        for (row = 0; row < H; ++ row) {
            for(col = 0; col < W; ++ col) {
                if(room[row][col] != '!') {
                    dfs(row, col, room[row][col]);
                    ++ step;
                }
            }
        }
        cout<<step<<endl;
    }
    return 0;
}

void dfs(const int& row, const int& col, const char c) {
    room[row][col] = '!';
    for(int d = 0; d < 4; ++ d) {
        int curRow = row + direc[d][1];
        int curCol = col + direc[d][0];
        if(curRow >= 0 && curRow < H && curCol >= 0 && curCol < W && room[curRow][curCol] == c) {
            dfs(curRow, curCol, c);
        }
    }
}


Measured memory_bytes: 3848
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;

string s;
int main(void){
  cin >> s;
  int f = 0;
  for(int i = 0; i < s.size(); i++){
    if(f == 0 && s[i] == 'C')
      f++;
    if(f == 1 && s[i] == 'F')
      f++;
  }
  cout << (f==2?"Yes":"No") << endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i= s; i <t; i++)
using LL = long long; using ll = long long;
const int INF = 1e9;
const LL LINF = 1e18;
using pii = pair<int, int>; using PII = pii;
using PLL = pair<LL, LL>; using pll = PLL;


ll dp[220][110];
void solve() {
	ll D; cin >> D;
	ll x; cin >> x;
	vector<pll> events;
	for (int i = 0; i < x; i++) {
		string a; ll p; cin >> a >> p;
		if (a == "D") {
			events.push_back({ p,1 });
		}
	}
	ll y; cin >> y;
	for (int i = 0; i < y; i++) {
		string a; ll p; cin >> a >> p;
		if (a == "DD") {
			events.push_back({ p,2 });
		}
	}

	for (int i = 0; i < events.size(); i++) {
//		for (int j = 0; j <= 100; j++) {
			for (int k = 0; k <= 100; k++) {
				dp[i + 1][k] = max(dp[i + 1][k], dp[i][k]);
				if (k < events[i].second) continue;
				dp[i + 1][k] = max(dp[i + 1][k], dp[i][k - events[i].second] + events[i].first);
			}
//		}
	}
	
	ll ans = 0;
	for (int i = 0; i < D+1; i++) {
		ans = max(ans, (ll)dp[events.size()][i]);
	}
	cout << ans << endl;
}

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

	return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	long long a[n+1];
	a[0]=2;
	a[1]=1;
	for(int i=2;i<=n;i++) a[i]=a[i-1]+a[i-2];
	cout<<a[n];
	return 0;
}


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

#define ll long long int
 
ll dp[100005];
bool visited[100005];
vector<ll> edge[100005]; 

void visit(ll vertex)
{
	if(!visited[vertex])
	{
		visited[vertex] = 1;
		dp[vertex] = 0;
		for(auto child : edge[vertex] )
		{
			if(!visited[child] ) visit(child);
			dp[vertex] = max(dp[vertex], 1+dp[child]);
		}
	}	
	return;
}

int main()
{
	ll m,n,x,y,mx = -1;
	cin>>n>>m;
	
	for(ll i=1;i<=m;i++)
	{
		cin>>x>>y;
		edge[x].push_back(y);
	}
	
	for(ll i=1;i<=n;i++)
	{
		if(!visited[i]) 
		{
			visit(i);
		}
	}
	
	for(ll i=1;i<=n;i++)
	{
		mx = max(mx,dp[i]);
	}
	cout<<mx<<endl;
	
	return 0;
}


Measured memory_bytes: 12624
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
const int MOD = 1000000009;

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int64_t len[51], pat[51];

int64_t rec(int64_t k,int64_t x){
  
    if(x == len[k]) return pat[k];
  
    int64_t ans = 0;

	x--;
  	
  	if(x > 0){
      int64_t l = min(x,len[k-1]);
      ans+= rec(k-1, l);
      x-=l;
    }
  
  	if(x>0){
      ans++;
      x--;
    }
  
  	if(x > 0){
      int64_t l = min(x,len[k-1]);
      ans+= rec(k-1, l);
      x-=l;
    }
  
  return ans;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t n,x;
  cin >> n >> x;
  len[0] = pat[0] = 1;
  for(int i=1;i<=n;i++){
    len[i] = len[i-1] * 2 + 3;
    pat[i] = pat[i-1] * 2 + 1;
  }
  
  cout << rec(n,x) << endl;
}

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

int m;
int hell(int, int, int);
int hell(int ndebt, int debt, int n) {
  if(n == m) {
    return debt;
  };
  return hell(debt, ceil((double)debt * 1.05 / 1000) * 1000, n + 1);
}

int main() {
    int result;
    while(scanf("%d", &m) != EOF) {
    printf("%d\n", hell(100000, 100000, 0));
  };
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    int n, l;
    cin >> n >> l;
    int sum = 0, min_value = 1e9;
    rep(i, 1, n+1) {
        int taste = l+i-1;
        if (abs(min_value) > abs(taste))
            min_value = taste;
        sum += taste;
    }
    cout << sum - min_value << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())
ans = (N - 2) * (N - 2)

n = N - 2
fixed1 = [-1] * (N + 1)
fixed2 = [-1] * (N + 1)

cand1 = n
cand2 = n

ans = 0
for _ in range(Q):
    x, y = map(int, input().split())
    y -= 1
    if x == 1:
        if fixed1[y] != -1:
            ans += fixed1[y]
        else:
            ans += cand1
            for i in range(y + 1, n + 1):
                if fixed1[i] != -1:
                    break
                fixed1[i] = cand1
            cand2 = min(cand2, y - 1)
    else:
        if fixed2[y] != -1:
            ans += fixed2[y]
        else:
            ans += cand2
            for i in range(y + 1, n + 1):
                if fixed2[i] != -1:
                    break
                fixed2[i] = cand2
            cand1 = min(cand1, y - 1)

print(n * n - ans)

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

using namespace std;

int n, m, a[100005];

int main () {

cin >> n;

for (int i = 1; i <= n; ++i){
    cin >> a[i];
    if (a[i] % 2 == 1) m++;
}

if (m % 2 == 0) cout << "YES";
else cout << "NO";









return 0;

}


Measured memory_bytes: 640
// Lec10-C Standard Deviation
#include<iostream>
#include<cmath>
#include<iomanip>
double std_dev(int, int[]);
int main(){
  int n, *scr;
  while(std::cin >> n){
    if(!n) break;
    scr = new int[n];
    for(int i=0; i<n; i++) std::cin >> scr[i];
    std::cout << std::fixed << std::setprecision(8) << std_dev(n, scr) << std::endl;
    delete(scr);
  }
}
double std_dev(int n, int scr[]){
  double ave=0, a=0;
  for(int i=0; i<n; i++) ave += scr[i];
  ave /= n;
  for(int i=0; i<n; i++) a += pow(scr[i]-ave, 2);
  return sqrt(a/n);
}

Measured memory_bytes: 3252
#include <iostream>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <vector>
#define rep(i,n) for( int i = 0; i < n; i++)
using namespace std;
using ll = unsigned long long;

//https://www.kaoken.cg0.xyz
//template<typename TypeInt>
//std::string Itoa(const TypeInt v, int base)
std::string Itoa(long long  v, long long base)
{
    static const char table[] = "zabcdefghijklmnopqrstuvwxyz";
    string ret;
    long long n = v;

    while (n > base) {
        ret += table[n%base];
        if(n%base != 0 ){
            n /= base;
        }
        else{
            n /= base;
            n --;
        }
    }
    ret += table[n];

    std::reverse(ret.begin(), ret.end());

    return ret;
}

int main()
{
    
    long long n;
    cin >> n;
    cout << Itoa(n,26) << endl;

    return 0;
}


Measured memory_bytes: 3592
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,M=map(int, sys.stdin.readline().split())
al=[ [] for i in range(N+1) ]	#隣接リスト
rev_al=[ [] for i in range(N+1) ]	#リバース隣接リスト
O=[ 0 for i in range(N+1) ] #出次数
edge=[] #辺の集合

for _ in range(M):
    s,t=map(int, sys.stdin.readline().split())
    al[s].append(t)
    rev_al[t].append(s)
    #I[t]+=1
    O[s]+=1
    edge.append((s,t))


#頂点毎の到達する確立
P=[ 0 for i in range(N+1) ]   #確率
P[1]=1
 
for x in range(1,N+1):
    if O[x]!=0:
        p=float(1)/O[x]
        for to in al[x]:
            P[to]+=P[x]*p
        
#頂点毎の期待値
E=[ 0 for i in range(N+1) ]   #期待値

for x in range(N,0,-1):
    for to in rev_al[x]:
        p=float(1)/O[to]
        E[to]+=(E[x]+1)*p


#消す辺
ans=E[1]
for del_s,del_t in edge:
    if O[del_s]-1==0:
        continue
    new_E=float(E[del_s]*O[del_s]-(E[del_t]+1))/(O[del_s]-1)
    if new_E<E[del_s]:
        ans=min(ans,E[1]-(E[del_s]-new_E)*P[del_s])

print ans

Measured memory_bytes: 67100
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	READ(n);
	READARR(a, n);
	int sum = 0;
	FOR (i, 1, n)
	    FOR (j, i + 1, n) 
	        sum += a[i] * a[j];
	cout << sum;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> A(N);
    long long sum = 0;
    map<int, int> count;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        sum += A[i];
        ++count[A[i]];
    }
    int Q;
    cin >> Q;
    vector<int> B(Q), C(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> B[i] >> C[i];
        if (count.count(B[i])) {
            sum += (long long)(C[i] - B[i]) * count[B[i]];
            count[C[i]] += count[B[i]];
            count.erase(B[i]);
        }
        cout << sum << '\n';
    }
    return 0;
}

Measured memory_bytes: 7388
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;

class Program
{
	static void Main(string[] args)
	{
		string[] strArray = Console.ReadLine().Split(' ').ToArray();
		string S = strArray[0];
		string T = strArray[1];
		Console.WriteLine(T + S);

	}
}

//string s = Console.ReadLine();
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];
//int N = int.Parse(Console.ReadLine());

//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.ReadKey();

//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];


Measured memory_bytes: 11220
#include <bits/stdc++.h>
template <class T> inline bool chmin(T &x, const T &y) { return x > y ? x = y, true : false; }
template <class T> inline bool chmax(T &x, const T &y) { return x < y ? x = y, true : false; }

using namespace std;

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

    int minp=1e9;
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        int x; cin>>x;
        chmin(minp,x);
        if(x==minp) ++ans;
    }
    cout << ans << "\n";


}


Measured memory_bytes: 256
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

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

ll kai(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y&1){
    return (x*kai(x,y-1))%MOD;
  }else{
    ll t = kai(x,y/2);
    return (t*t)%MOD;
  }
}

ll comb(ll a,ll b,vector<ll> &p){
  if(a == 0)return 1;
  if(b == 0)return 1;
  ll ans = p[a+b];
  ans = (ans*kai(p[a],MOD-2))%MOD;
  ans = (ans*kai(p[b],MOD-2))%MOD;
  return ans;
}

ll mind(int x,vector<int> &v){
  int ok = v.size()-1,ng = -1;
  while(ok - ng > 1){
    int next = (ok+ng)/2;
    if(v[next] > x){
      ok = next;
    }else{
      ng = next;
    }
  }
  return ok;
}

ll maxd(int x,vector<int> &v){
  int ok = 0,ng = v.size();
  while(ng - ok > 1){
    int next = (ok+ng)/2;
    if(v[next] < x){
      ok = next;
    }else{
      ng = next;
    }
  }
  return ok;
}


int main(){
  int n;
  cin >> n;
  int ans = 8;
  ans -= (n-400)/200;
  cout << ans << endl;


  return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, cs = 0, in;
    int d, t, s; cin>>d>>t>>s;
    if(t*s >= d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  int rawN = N;
  string S = "";
  int count = 0;
  while (N != 0) {
    if (N & BIT(count)) {
      S += "1";
      N -= pow(-2, count);
    } else {
      S += "0";
    }
    count++;
  }
  reverse(ALL(S));
  cout << ((rawN == 0) ? "0" : S) << "\n";
  // print();
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

class LazySegmentTree {
    private:
        int N;
        std::vector<ll> dat, lazy;
    public:
        LazySegmentTree(int n) {
            N = 1;
            while (N < n) N *= 2;
            dat.assign(2*N, 0);
            lazy.assign(2*N, 0);
        }
        // a is 0-indexed
        void set(int a, const ll v) { dat[a+N] = v; }
        void build() { for (int i=N-1; i>0; --i) dat[i] = dat[2*i] + dat[2*i+1]; }
        void eval(int k, int l, int r) {
            if (lazy[k] == 0) return;

            dat[k] += lazy[k] * (r - l);
            if (r - l > 1) {
                lazy[2*k] += lazy[k];
                lazy[2*k+1] += lazy[k];
            }
            lazy[k] = 0;
        }
        // add v to [a, b)
        // a and b are 0-indexed
        void add(int a, int b, const ll v) { return add (a, b, v, 1, 0, N); }
        void add(int a, int b, const ll v, int k, int l, int r) {
            eval(k, l, r);

            if (b <= l || r <= a) return;
            if (a <= l && r <= b) {
                lazy[k] += v;
                eval(k, l, r);
            } else {
                add(a, b, v, 2*k, l, (l+r)/2);
                add(a, b, v, 2*k+1, (l+r)/2, r);
                dat[k] = dat[2*k] + dat[2*k+1];
            }
        }
        // get sum of [a, b)
        // a and b are 0-indexed
        ll get(int a, int b) { return get(a, b, 1, 0, N); }
        ll get(int a, int b, int k, int l, int r) {
            eval(k, l, r);

            if (b <= l || r <= a) return 0;
            if (a <= l && r <= b) return dat[k];
            ll vleft = get(a, b, 2*k, l, (l+r)/2);
            ll vright = get(a, b, 2*k+1, (l+r)/2, r);
            return vleft + vright;
        }
};

void solve() {
    int N;
    cin >> N;
    Graph la(N+1), sm(N+1);
    for (int i=0; i<N-1; ++i) {
        int a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        la[a].push_back(b);
        sm[b].push_back(a);
    }

    LazySegmentTree st(N+1);
    ll sum = 0;
    for (int i=1; i<N+1; ++i) {
        sum -= (int)sm[i].size() - 1;
        st.set(i, sum);
    }
    st.build();

    ll res = 0;
    for (int i=1; i<N+1; ++i) {
        res += st.get(i, N+1);
        for (int x : la[i]) st.add(x, N+1, 1);
        st.add(i, N+1, -1);
    }
    cout << res << '\n';
}

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

    solve();

    return 0;
}


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    int N; cin >> N;
    vector<int> A(N);
    int M = 0, m = inf;
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        M = max(M, A.at(i));
        m = min(m, A.at(i));
    }
    cout << M - m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;

typedef long long ll;

bool G[705][705];
int n,col[706];
bool a[2][705];
int m;
int cnt1 = 0,cnt2 = 0;

int doit(int n){
	return (n * (n - 1)) / 2;
}

bool dfs(int x,int c){
	if(col[x] == 0){
		col[x] = c;
		if(c == 1){
			cnt1++;
		}
		else{
			cnt2++;
		}
		//cout<<cnt1<<endl;
		//cout<<cnt2<<endl;
	}
	else{
		return col[x] == c;
	}
	for(int i = 0;i < n; ++i){
		if(x != i && !G[x][i]){
			if(!dfs(i,(-1)*c)){
				return 0;
			}
		}
	}
	return 1;
}

int main(int argc, char const *argv[]){
	cin>>n>>m;
	memset(G,0,sizeof(G));
	for(int i = 0;i < m; ++i){
		int x,y;
		cin>>x>>y;
		--x,--y;
		G[x][y] = G[y][x] = 1;
	}
	a[0][0] = 1;
	bool flag = 0;
	for(int i = 0;i < n; ++i){
		if(col[i] == 0){
			cnt1 = 0,cnt2 = 0;
			if(!dfs(i,1)){
				printf("-1\n");
				exit(0);
			}
			bool cur = flag ^ 1;
			/*printf("cur=%d\n",cur);
			cout<<cnt1<<endl;
			cout<<cnt2<<endl;*/
			memset(a[cur],0x00,sizeof(a[cur]));
			for(int j = 0;j <= n; ++j){
				if(a[flag][j]){
					a[cur][j + cnt1] = a[cur][j + cnt2] = 1;
				}
			}
			flag ^= 1;
		}
	}
	for(int i = n / 2;i >= 0; --i){
		if(a[flag][i]){
			//printf("%d\n",i);
			printf("%d\n",doit(i) + doit(n - i));
			exit(0);
		}
	}
	return 0;
}
/*
input1:
5 5
1 2
1 3
3 4
3 5
4 5
input2:
5 1
1 2
input3:
4 3
1 2
1 3
2 3
*/

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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	bool elf = false;
	for (int i = 0; i <= 100; ++i) {
		for (int j = 0; j <= 100; ++j) {
			if (4 * i + 7 * j == n) {
				elf = true; break;
			}
		}
	}
	if (elf) cout << "Yes" << endl;
	else cout << "No" << endl;
 	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int a,b;

int extgcd(int a,int b,int& x,int& y){
	int d=a;
	if(b){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}
	else{
		x=1;
		y=0;
	}
	return d;
}

int main(){
	cin>>a>>b;
	int x,y;
	int d=extgcd(a,b,x,y);
	cout<<x<<' '<<y<<endl;
}

Measured memory_bytes: 1164
#include<cstdio>
#include<string.h>
using namespace std;
char s[1000000];
int len;
bool b=true;
int main(){
	scanf("%s",&s);
	len=strlen(s);
	for (int i=0;i<len;i++){
		if ((s[i]=='d')&&(s[i+1]=='r')&&(s[i+2]=='e')&&(s[i+3]=='a')&&(s[i+4]=='m')&&(s[i+5]=='e')&&(s[i+6]=='r')){
			i+=6;
			if ((s[i-1]=='e')&&(s[i]=='r')&&(s[i+1]=='a')&&(s[i+2]=='s')&&(s[i+3]=='e')&&(s[i+4]=='r')){
				i+=4;
			}else if ((s[i-1]=='e')&&(s[i]=='r')&&(s[i+1]=='a')&&(s[i+2]=='s')&&(s[i+3]=='e')){
				i+=3;
			}
		}else if ((s[i]=='d')&&(s[i+1]=='r')&&(s[i+2]=='e')&&(s[i+3]=='a')&&(s[i+4]=='m')){
			i+=4;
		}else if ((s[i]=='e')&&(s[i+1]=='r')&&(s[i+2]=='a')&&(s[i+3]=='s')&&(s[i+4]=='e')&&(s[i+5]=='r')){
			i+=5;
		}else if ((s[i]=='e')&&(s[i+1]=='r')&&(s[i+2]=='a')&&(s[i+3]=='s')&&(s[i+4]=='e')){
			i+=4;
		}else {
			b=false;
		}
		if (b==false){
			break;
		}
	}
if (b==true){
	printf("YES");
}else{
	printf("NO");
}
return 0;}

Measured memory_bytes: 1824
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		for(int i = 0 ; i<input.length(); i++){
			if(i%2==0){
				System.out.print(input.charAt(i));
			}
		}
		System.out.println();
	}
}


Measured memory_bytes: 31516
#include <bits/stdc++.h>
using namespace std;
 
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
 
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
 
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
 
const int MAX = 100005;
 
LL a[MAX];
LL b[MAX];
 
LL s[MAX];
int main()
{
 //  freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false); cin.tie(0);
 
    int n;
    cin>>n;
    FOR(i,0,n)
    {
    	cin>>a[i]>>b[i];
    }
 
    FOR(i,0,n)
    {
    	s[i] = (b[i] - a[i]%b[i])%b[i];
    }
 
    LL ans = s[n-1];
 
    RFOR(i,n-1,0)
    {
    	a[i] += ans;
    	ans += (b[i]-a[i]%b[i])%b[i];
    }
 
    cout<<ans;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int main(){
    fastcin();

    int a[] = {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;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define MAXN 500010

using namespace std;


int ap[MAXN];
int seg[4*MAXN];
int c[MAXN];
int ans[MAXN];

void update(int l, int r, int id, int i, int val){
	if(l == r){seg[id] = val; return;}
	int m = (l + r)/2;
	if(i <= m)
		update(l, m, 2*id+1, i, val);
	else
		update(m+1, r, 2*id+2, i, val);
	seg[id] = seg[2*id+1] + seg[2*id+2];
}

int query(int l, int r, int id, int a, int b){
	if(a <= l && r <= b) return seg[id];
	int m = (l + r)/2;
	if(b <= m)
		return query(l, m, 2*id+1,a,b);
	else if(a > m)
		return query(m+1, r, 2*id+2, a, b);	
	else
		return query(l, m, 2*id+1,a,b) + query(m+1, r, 2*id+2, a, b);
}



int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	memset(ap, -1, sizeof ap);
	
	int n, q;
	cin>>n>>q;
	
	vector<pair<pair<int,int>, int>> que(q);
	
	for(int i=0;i<n;i++){
		cin>>c[i];
	}	
	for(int i=0;i<q;i++){
		cin>>que[i].st.nd>>que[i].st.st;
		que[i].st.st--; que[i].st.nd--;
		que[i].nd=i;	
	}
	
	sort(que.begin(), que.end());
	int idq=0;
	
	for(int i=0;i<n && idq<q;i++){
		if(ap[c[i]] == -1){
			update(0, n-1, 0, i, 1);
		}else{
			update(0, n-1, 0, ap[c[i]], 0);
			update(0, n-1, 0, i, 1);
		}
		ap[c[i]] = i;
		while((idq<q) && que[idq].st.st == i){
			ans[que[idq].nd] = query(0, n-1, 0, que[idq].st.nd, que[idq].st.st);
			idq++;
		}
	}
	for(int i=0;i<q;i++)
		cout<<ans[i]<<"\n";
	
	return 0;	
}


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

int n, m, all_time;

int main() {
  cin >> n;
  int entire = 0;
  vector<int> t(n);
  rep (i, n) {
    cin >> t[i];
  }
  all_time = 0;
  rep (i, n) {
    all_time += t[i];
  }
  cin >> m;
  vector<int> p(m);
  vector<int> x(m);
  rep (i, m) {
    cin >> p[i] >> x[i];
  }
  rep (i, m) {
    cout << all_time - t[p[i]-1] + x[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3600
program main
  
  implicit none
  integer(8) :: n
  integer(8),allocatable :: a(:)
  integer(8),allocatable :: b(:)
  integer :: ans, i
  
  read(*,*) n
  allocate(a(1:n))
  allocate(b(1:n))
  read(*,*) a(2:n)
  
  b = 0
  do i = 2, n
    b(a(i)) = b(a(i)) + 1
  end do
  do i = 1, n
    print*,b(i)
  end do
  
  
  
end program main


Measured memory_bytes: 8400
import java.util.Scanner;
import java.util.HashSet;
import java.util.Arrays;

public class Main {

  public static Integer getMinNode(HashSet<Integer> Q, Integer[] C) {
    Integer min = Integer.MAX_VALUE;
    Integer minNode = null;
    for (Integer i = 0; i < C.length; i++) {
      if (C[i] < min && Q.contains(i)) {
        minNode = i;
        min = C[i];
      }
    }
    return minNode;
  }

  public static int mst(int[][] graph) {
    // Initialize Q (unhandled nodes) to contain all nodes
    HashSet<Integer> Q = new HashSet<Integer>();
    for (int i = 0; i < graph.length; i++) {
      Q.add(i);
    }

    // Initialize E (edges included in mst) to be null
    Integer[] E = new Integer[graph.length];
    for (int i = 0; i < graph.length; i++) {
      E[i] = null;
    }

    // Initialize C (minimum edge path to given nodes) to be infinity-1
    Integer[] C = new Integer[graph.length];
    for (int i = 0; i < graph.length; i++) {
      C[i] = Integer.MAX_VALUE-1;
    }

    // Initialize F (all nodes included in the final mst) to be empty
    HashSet<Integer> F = new HashSet<Integer>();

    while (!Q.isEmpty()) {
      Integer node = getMinNode(Q, C);
      Q.remove(node);
      F.add(node);
      if (E[node] != null)
        F.add(E[node]);
      for (int j = 0; j < graph[node].length; j++) {
        if (Q.contains(j) && graph[node][j] != -1 && graph[node][j] < C[j]) {
          C[j] = graph[node][j];
          E[j] = node;
        }
      }
    }

    int mstCost = 0;
    for (int i = 0; i < graph.length; i++) {
      if (E[i] != null) {
        mstCost += C[i];
      }
    }

    return mstCost;
  }

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int[][] graph = new int[n][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        graph[i][j] = s.nextInt();
      }
    }
    s.close();
    System.out.println(mst(graph));
  }
}



Measured memory_bytes: 41156
#include <iostream>
#include<vector>
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;
typedef long double ld;
const double EPS = 1e-9;
const int N = 1e3+2, M = 3e5+5, OO = 0x3f3f3f3f;
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction
// int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1}; // 8 Direction
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; // Hexagonal Direction
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
  int n,m;
	cin>>n>>m;
	vector<int> in;
	int input;
	int sum = 0;
	for(int i=0;i<m;i++){
		cin>>input;
		sum+=input;
	}
	if(n<sum)	cout<<"-1"<<endl;
	else	cout<<n-sum<<endl;

	return 0;

}


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

int main(){
  int N;
  int t[110000], x[110000], y[110000];
  cin >> N;
  t[0] = x[0] = y[0] = 0;
  for (int i = 0; i < N; i++)cin >> t[i+1] >> x[i+1] >> y[i+1];

  bool can = true;
  for(int i = 0; i < N; i++){
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
    if(dt< dist) can = false;
    if (dist % 2 != dt% 2) can = false;
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main() {
  ll n, a, b;
  cin >> n >> a >> b;

  ll initial = n / (a + b);

  ll ans = initial * a;
  n -= initial * (a + b);
  ll diff = 0;

  while (n > 0) {
    diff = min(n, a);
    n -= diff;
    ans += diff;

    diff = min(n, b);
    n -= diff;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
import sys
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()


def main():
    while True:
        W,H=map(int,input().split())
        if W==H==0:
            exit()
        C=[[] for _ in range(H+2)]
        C[0]=C[H+1]=[-1]*(W+2)
        used=[[False]*(W+2) for _ in range(H+2)]
        rands=[]
        for column in range(1,H+1):
            C[column]=[-1]+list(map(int,input().split()))+[-1]
            for row,x in enumerate(C[column]):
                if x==1:
                    rands.append((column,row))

        ans=0
        
        if rands:
            s=[]
            while rands:
                y,x=rands.pop()
                if used[y][x]:
                    continue
                s.append((y,x))
                while s:
                    y,x=s.pop()
                    if used[y][x]:
                        continue
                    used[y][x]=True
                    for dy in range(-1,2):
                        for dx in range(-1,2):
                            ny,nx=y+dy,x+dx
                            if dy==dx==0 or used[ny][nx]:
                                continue
                            if C[ny][nx]==1:
                                s.append((ny,nx))
                ans+=1
        print(ans)
                

if __name__ == '__main__':
    main()





Measured memory_bytes: 6328
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    D, G = read_ints()
    p: List[int]= []
    c: List[int]= []
    for _ in range(D):
        pc = read_ints()
        p.append(pc[0])
        c.append(pc[1])
    count = [0]*(1<<D)
    score = [0]*(1<<D)
    for i in range(D):
        count[1<<i] = p[i]
        score[1<<i] = c[i]+(p[i]*100*(i+1))
    for i in range(1, 1<<D):
        submask = i&(i-1)
        submask_complement = i-submask
        count[i] = count[submask]+count[submask_complement]
        score[i] = score[submask]+score[submask_complement]
    min_count = 10**9
    for i in range(1<<D):
        for j in range(D):
            if i&(1<<j) == 0 and score[i] < G and score[i]+score[1<<j] >= G:
                required_count = math.ceil((G-score[i])/((j+1)*100))
                if required_count < count[1<<j]:
                    min_count = min(min_count, required_count+count[i])
                else:
                    min_count = min(min_count, count[1<<j]+count[i])
    return min_count


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 75832
IDENTIFICATION DIVISION.
 PROGRAM-ID. TEST120.
      
 DATA DIVISION.
 WORKING-STORAGE SECTION.
    
 01 B     PIC X(1).
      
 PROCEDURE DIVISION.
  ACCEPT B.
 
  EVALUATE TRUE
      WHEN B = 'A'
        DISPLAY 'T'
      WHEN B = 'T'
        DISPLAY 'A'
      WHEN B = 'C'
        DISPLAY 'G'
      WHEN B = 'G'
        DISPLAY 'C'
      WHEN OTHER
        CONTINUE
   END-EVALUATE.
 
   STOP RUN.

Measured memory_bytes: 636
#include <stdio.h>
#include <string.h>

int main(void) {
	char w[201];
	char k[201];
	char q[201];
	int m = 0;
	int n = 0;
	for (int i = 0; i < 201; i++) {
		w[i] = 0;
		k[i] = 0;
		q[i] = 0;
	}
	while (1) {
		scanf("%s", &w);
		if (strstr(w,"-")) {
			break;
		}
		int t = strlen(w);
		scanf("%d", &m);
		for (int i = 0; i < m; i++) {
			scanf("%d", &n);
			for (int p = 0; p < t; p++) {
				if (p < n) {
					k[p] = w[p];
				}
				else{
					q[p-n] = w[p];
				}
			}
			sprintf(w,"%s%s", q, k);
			for (int i = 0; i < 201; i++) {
				k[i] = 0;
				q[i] = 0;
			}
			
		}
		printf("%s\n", w);
	}
	return 0;
}


Measured memory_bytes: 2068
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;


public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		while(true){
			int n = Integer.parseInt(scan.next());
			int m = Integer.parseInt(scan.next());
			if(n==0) break;
			V[] ver = new V[n];
			for (int i = 0; i < n; i++) ver[i] = new V();
			boolean[] used = new boolean[n];

			for (int i = 0; i < m; i++) {
				int a = Integer.parseInt(scan.next())-1;
				int b = Integer.parseInt(scan.next())-1;
				ver[a].to.add(b);
				ver[b].to.add(a);
			}

			Stack<int[]> stk = new Stack<int[]>();
			stk.push(new int[]{0,0});
			used[0]=true;
			int ans = 0;
			while(!stk.isEmpty()){
				int[] p = stk.pop();
				int num = p[0],deep = p[1];
				ans++;
				if(deep!=2) for (Integer i : ver[num].to) {
					if(!used[i]){
						used[i]=true;
						stk.push(new int[]{i,deep+1});
					}
				}
			}
			out.println(ans-1);
		}
		out.flush();
	}
}

class V{
	HashSet<Integer> to = new HashSet<Integer>();
}

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

bool has3(int x){
    while(x>0){
        if(x%10==3) return true;
        x/=10;
    }
    return false;
}

int main(){
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        if(i%3==0 || has3(i)){
            cout << " " << i;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define rep(i,a,b) for(int (i) = (a); (i) <= (b); i++)
#define repd(i,a,b) for(int (i) = (a); (i) >= (b); i--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define mp make_pair
#define pb push_back
#ifndef ONLINE_JUDGE
	#define debug 1
#else
	#define debug 0
#endif
using namespace std;
#define is_digit(c) ((c) >= '0' && (c) <= '9')
#define is_upper(c) ((c) >= 'A' && (c) <= 'Z')
#define is_lower(c) ((c) >= 'a' && (c) <= 'z')
#define readchar() ((char)fgetc(stdin))
#define printchar(c) fputc((c), stdout)
void readline(char *s) {int len=0;char c;for(c=readchar(); c!='\n'; s[len++]=c, c=readchar());}
void readstr(char *s) {int len=0;char c;for(c=readchar(); c!=' '&&c!='\n'; s[len++]=c, c=readchar());}
void printstr(const char *s) {int len=strlen(s);rep(i,0,len-1) printchar(s[i]);}
void to_lower(char *s, int L, int R) {rep(i,L,R) if (is_upper(s[i])) s[i]=s[i]-'A'+'a';}
void to_upper(char *s, int L, int R) {rep(i,L,R) if (is_lower(s[i])) s[i]=s[i]-'a'+'A';}
ll readll() {
	char c;ll ans=0, x=1;for (c=readchar(); !is_digit(c)&&c!='-'; c=readchar());
	if (c=='-') x=-1, c=readchar();for (; is_digit(c); ans=ans*10+c-'0', c=readchar());return ans*x;
}
void printll(ll x) {
	int a[25], cnt=0;if (x==0) { printchar('0'); return; }if (x<0) printchar('-'), x=-x;
	for (; x; a[cnt++]=x-x/10*10, x/=10);repd(i,cnt-1,0) printchar(a[i]+'0');
}
#define readint() ((int)readll())
#define printint(x) printll((ll)(x))
int n, m, a[100005], mx, mn, b[100005], cnt[100005];
bool can() {
	rep(i,1,n) cnt[b[i]]++;
	int total=0;
	rep(i,1,n) if (cnt[i]) total++;
	rep(i,1,n) if (a[i]!=total-(cnt[b[i]]==1)) return false;
	return true;
}
int main() {
	n=readint();
	rep(i,1,n) {
		a[i]=readint();
		mx=(i==1?a[i]:max(mx,a[i]));
		mn=(i==1?a[i]:min(mn,a[i]));
	}
	if (mx-mn>1) {
		printstr("No\n");
		return 0;
	}
	int cnt=0, tms=0;
	if ((mx==n-1&&mn!=mx)||mx<n-1) m=mx; else m=n;
	if (mn<mx) {
		rep(i,1,n) if (a[i]==mn) b[i]=++cnt;
		cnt++;
		rep(i,1,n) if (a[i]==mx) {
			if (tms++==2) cnt++,tms=1;
			if (cnt>m) break;
			b[i]=cnt;
		}
		rep(i,1,n) if (a[i]==mx&&!b[i]) {
			b[i]=m;
		}
	} else {
		if (mx==n-1) {
			rep(i,1,n) b[i]=++cnt;
		} else {
			rep(i,1,n) {
				if (tms++==2) cnt++,tms=1;
				if (cnt>m) break;
				b[i]=cnt;
			}
			rep(i,1,n) if (!b[i]) b[i]=m;
		}
	}
//	rep(i,1,n) cerr<<b[i]<<(i==n?'\n':' ');
	if (can()) printstr("Yes\n");
	else printstr("No\n");
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
using namespace std;
int main(void){
 int n,m,o,p,q,r,s,t;
 cin>>n>>m>>o>>p;
 /* if(n == o){
   q = m - p;
   r = p - m;
   s = q;
   t = m;
  }
 if( m == p){
     q = o;
     r = m - p;
     s = n;
     t = r; 
 }*/
 //else{
     q = o - (p - m);
     r = p + (o - n);
     s = q - (o - n);
     t = r - (p - m);
 //}
 cout<<q<<" "<<r<<" "<<s<<" "<<t;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <functional>
#include <stack>
#include <cmath>
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define llong long long

int main() {
  while(1){
    int n;
    scanf("%d",&n);
    if(n == 0) break;
    int a[n];
    REP(i,n) scanf("%d",a+i);
    int maxseq = a[0];
    int sum = 0;
    REP(i,n) {
      sum = max(sum+a[i], a[i]);
      if(maxseq < sum) maxseq = sum;
    }
    if(maxseq < sum) maxseq = sum;
    printf("%d\n",maxseq);
  }
  return 0;
}

Measured memory_bytes: 2588
#include <iostream>
using namespace std;
int main(void){
    int N,a[100];
    int max=0,min=1001;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a[i];
        if(max<a[i])max=a[i];
        if(min>a[i])min=a[i];
    }
    cout<<max-min<<endl;
    
    return 0;
    
}

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

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

int main() {
  ll n, r, ans = 0;
  cin >> n >> r;

  if (n < 10)
    ans = r + (10 - n) * 100;
  else
    ans = r;

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


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

using namespace std;

string s;
int a, b;

int main()
{
  	ios::sync_with_stdio(false);
  	cin.tie(NULL);
  
  	cin >> s;
  	
  	for(char &c: s){
      	if(c == 'S') b ++;
      	else if(b > 0) b --;
      	else a ++;
    }
  
  	cout << a + b << endl;
  	
  	return 0;
}

Measured memory_bytes: 720
#include<cstdio>
#include<algorithm>
using namespace std;
struct Node
{
	int x,y;
}a[100010];
bool cmp(Node a,Node b)
{
	return a.x<b.x;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].x);
		a[i].y=i;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++) printf("%d ",a[i].y);
	printf("\n");
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int N;
  while(cin>>N){
    int cost1, cost2, cl1;
    vector<int> cl2(N);
    cin>>cost1>>cost2>>cl1;
    REP(i,N)cin>>cl2[i];
    sort(cl2.begin(), cl2.end());
    reverse(cl2.begin(), cl2.end());
    int yen = cost1;
    int clorie = cl1;
    REP(i,N){
      if(clorie * (yen + cost2) < (clorie + cl2[i]) * yen){
        yen += cost2;
        clorie += cl2[i];
      }else{
        break;
      }
    }
    cout<<clorie/yen<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5+1;
int n, m,c[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(_, 0, n){
    int x;
    cin >> x;
    c[x]++;
  }
  int ans = 0;
  FOR(i, 0, m/2+1){
    int j = (m-i)%m;
    if(i==j){
      int s=0;
      for(int k=i; k<N; k+=m) s += c[k];
      ans += s/2;
    }else{
      int s=0, ss=0; for(int k=i; k<N; k+=m) s += c[k]/2*2, ss += c[k]%2;
      int t=0, tt=0; for(int k=j; k<N; k+=m) t += c[k]/2*2, tt += c[k]%2;
      int mi = min(ss, tt);
      ans += mi;
      ss -= mi;
      tt -= mi;
      mi = min(s, tt); ans += mi; s -= mi;
      mi = min(t, ss); ans += mi; t -= mi;
      ans += s/2 + t/2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
N, M, K = list(map(int, input().split()))

#N, Mの倍数ならできる
#N + M -2もできる
#l*k*(N - 1) + l*(M - k)もできる
#反転もできる
#よって、
b = int(N*M/2)
if N*M % 2 == 1:
    b += 1

al = set([])
for i in range(M + 1):
    for j in range(N + 1):
        a = i*(N - j) + j*(M - i)
        if a <= b:
            al.add(a)
            al.add(N*M - a)

if K in al:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 20856
#include <bits/stdc++.h>
using namespace std;
 
#define lglg long long
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
#define ROF(i, b, a) for (int i=(b); i>(a); --i)
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)

long long INF = 1LL<<60;
long long MOD = 998244353;

template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &pr) {is >> pr.first >> pr.second; return is;}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {for (auto &x : v) is >> x; return is;}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> &pr) {os << '(' << pr.first << ", " << pr.second << ')'; return os;}
ostream &operator<<(ostream &os, vb &v) {
    bool first = true;
    os << '[';
    for (const bool &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
template <class C> ostream &operator<<(ostream &os, C &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    FOR(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vector<long double> a(n);
    FOR(i, 0, n) {
        cin >> a[i];
        a[i] = (a[i]+1) / 2.0;
    }

    long double cur = 0;
    FOR(i, 0, k) {
        cur += a[i];
    }
    long double res = cur;
    FOR(i, k, n) {
        cur += a[i];
        cur -= a[i-k];
        res = max(res, cur);
    }
    cout << fixed << setprecision(20) << res << '\n';
}

Measured memory_bytes: 3456