akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7 ;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define input_from_file  freopen("input.txt", "r", stdin);
using namespace std::chrono; 

int main()
{
  // input_from_file 
  ll q;q=1;while(q--){
    ll n;cin>>n;
    if(n<=599)  cout<<8;
    else if(n<=599)  cout<<8;
    else if(n<=799)  cout<<7;
    else if(n<=999)  cout<<6;
    else if(n<=1199)  cout<<5;
    else if(n<=1399)  cout<<4;
    else if(n<=1599)  cout<<3;
    else if(n<=1799)  cout<<2;
    else if(n<=1999)  cout<<1;
  }
  return 0;
}

Measured memory_bytes: 3628
N = int(input())
g = [[-1 for _ in range(N)] for _ in range(N)]
for i in range(N):
    A = int(input())
    for _ in range(A):
        x, y = map(int,input().split())
        g[i][x-1] = y
ans = 0
for i in range(1 << N):
    hornest = [0] * N
    for j in range(N):
        if (i >> j)&1:
            hornest[j] = 1
    is_ok = 1
    for j in range(N):
        if hornest[j] and is_ok:
            for k in range(N):
                if g[j][k] == -1:
                    continue
                if g[j][k] != hornest[k]:
                    is_ok = 0
    if is_ok:
        ans = max(ans,hornest.count(1))
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <math.h>
using namespace std;

const int MAX_N=100000;
string s;

int main(){
	cin >> s;
	cout << s[0] << s.length()-2 << s[s.length()-1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<string>
#include<string.h>
#include<limits.h>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#define int long long
using namespace std;

signed main() {
	int a, b; cin >> a >> b;
	int c = b * 1900 + (a - b) * 100;
	cout << c*(1 << b) << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 * 
 * https://atcoder.jp/contests/abc056/submissions/4757789 と https://atcoder.jp/contests/abc056/submissions/3511073 にも参照
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			int[] a = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			if (1 == n) {
				System.out.println((k > a[0]) ? 1 : 0);
				return;
			}
			Arrays.sort(a);

			int ng = 0, ok = n + 1;
			while (ok - ng > 1) {
				int mid = (ok + ng) / 2;
				if (isNeeded(mid, n, k, a)) {
					ok = mid;
				} else {
					ng = mid;
				}
			}
			System.out.println(ng);
		}
	}

	/**
	 * @param now
	 * @param n
	 * @param k
	 * @param a
	 * @return now番目のカードが必要かどうか
	 */
	private static boolean isNeeded(int now, final int n, final int k, final int[] a) {
		boolean[][] dp = new boolean[n + 1][k + 1];
		IntStream.range(0, n + 1).forEach(i -> Arrays.fill(dp[i], false));
		dp[0][0] = true;
		IntStream.rangeClosed(1, n).forEach(i -> IntStream.rangeClosed(0, k).forEach(j -> {
			if (i == now) {
				// ぬくカードの場合
				dp[i][j] = dp[i - 1][j];
			} else {
				if (dp[i - 1][j]) {
					dp[i][j] = true;
					if (j + a[i - 1] <= k) {
						dp[i][j + a[i - 1]] = true;
					}
				}
			}
		}));
		for (int i = k - 1; i >= Math.max(k - a[now - 1], 0); i--) {
			if (dp[n][i]) {
				return true;
			}
		}
		return false;
	}
}


Measured memory_bytes: 147532
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N,A[200005];
int ans[200005];
signed main(){
	cin>>N;
	int now=0;
	rep(i,N){
		cin>>A[i];
		if(i)now^=A[i];
	}
	rep(i,N){
		cout<<now<<" ";
		now^=A[i];
		now^=A[i+1];
	}
	cout<<endl;
}


Measured memory_bytes: 5148
#include <iostream>
#include <string>
#include <algorithm>
 
using namespace std;
 
int main() {
    int n;
    cin >> n;
 
    long long a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
 
    int l = 0, r = 0;
    long long sum = 0, ans = 0;
    while (l < n) {
        while (r < n && (sum & a[r]) == 0) {
            sum ^= a[r];
            r++;
        }
        ans += r - l;
        sum ^= a[l];
        l++;
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 1792
from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()

num = defaultdict(int)
N = int(input())
for _ in range(N):
    num[input()] += 1
for s in ['AC', 'WA', 'TLE', 'RE']:
    print('{} x {}'.format(s, num[s]))


Measured memory_bytes: 74108
MOD=1000000007
ans=0
N=int(input())
def modpow(a,x):
    ret=1
    while x>0:
        if x%2==1:
            ret*=a
            ret%=MOD
        a*=a
        x>>=1
    return ret

ans=modpow(10,N)+2*(MOD-modpow(9,N))+modpow(8,N)
print(ans%MOD)


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


using namespace std;
typedef long long int ll;


int main() {
    ll ans;
    vector<vector<int> > c(4, vector<int>(4));
    for(size_t i = 1; i < 4; i++)
    {
        for(size_t j = 1; j < 4; j++)
        {
            cin >> c[i][j];
        }
    }

    vector<int> a(4);
    vector<int> b(4);

    int N = 100; 
    for(size_t i = 0; i <= N; i++)
    {   
        a[1] = i;
        b[1] = c[1][1] - a[1];
        b[2] = c[1][2] - a[1];
        b[3] = c[1][3] - a[1];
        a[2] = c[2][2] - b[2];
        a[3] = c[3][3] - b[3];
        if (b[1] >= 0 && b[1] <= 100 && 
            b[2] >= 0 && b[2] <= 100 &&
            b[3] >= 0 && b[3] <= 100 &&
            a[2] >= 0 && a[2] <= 100 && 
            a[3] >= 0 && a[3] <= 100 &&
            (a[2]+b[1] == c[2][1]) && (a[3]+b[1] == c[3][1]) && (a[3]+b[2] == c[3][2]) && (a[2]+b[3]==c[2][3])) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<char> S;
    vector<char> T;
    vector<char> F;
    for(int i=0;i<n;i++){
        char k;
        cin>>k;
        S.push_back(k);
    }
    for(int j=0;j<n;j++){
        char p;
        cin>>p;
        T.push_back(p);
    }
    for(int m=0;m<n;m++){
        F.push_back(S[m]);
        F.push_back(T[m]);
        
    }
    for(int u=0;u<2*n;u++){
        
       cout<<F[u];
    }


}

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

class Dice{
  int T,S,E,W,N,D;

  public:
  Dice(int T, int S, int E,
      int W, int N, int D)
    : T(T), S(S), E(E),
    W(W), N(N), D(D) {}

  int get_top(){ return T; }

  void rot(char c){
    int tmp;
    tmp = T;
    switch(c){
      case 'N':
        T = S; S = D; D = N; N = tmp;
        break;
      case 'S':
        T = N; N = D; D= S; S = tmp;
        break;
      case 'E':
        T = W; W = D; D = E; E = tmp;
        break;
      case 'W':
        T = E; E = D; D = W; W = tmp;
        break;
    }
  }
};

int main(){
  int num[6];
  for(int i=0;i<6;i++) cin>>num[i];
  Dice dice(num[0],num[1],num[2],num[3],num[4],num[5]);
  char dir;
  while(cin>>dir){
    dice.rot(dir);
  }
  cout<<dice.get_top()<<endl;
  return 0;

}

Measured memory_bytes: 3084
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=100001;
//int arr[SIZE]={};
//ここまでテンプレ

int main(){
	int H,W;
	int N;
	cin>>H>>W;
	cin>>N;
	int a[SIZE]={};
	for(int i=1;i<=N;i++){
		cin>>a[i];
	}
	int k=1;
	for(int i=0;i<H;i++){
		vector<int> s;
		for(int j=0;j<W;j++){
			s.push_back(k);
			a[k]--;
			if(a[k]==0)
				k++;
		}
		if(i%2){
			reverse(s.begin(),s.end());
		}
		int vs=s.size();
		for(int j=0;j<vs-1;j++){
			cout<<s[j]<<" ";
		}
		cout<<s[vs-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
// AGC039 B

#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int a[205], G[205][205];
queue <int> q;

int main() {
    
  int n; read(n);
  for (RI i = 1; i <= n; ++i)
    for (RI j = 1; j <= n; ++j) {
      char ch = gc();
      while (ch != '0' && ch != '1') ch = gc();
      if (ch == '1') G[i][j] = 1;
    }
  int ans = 0;
  for (RI i = 1; i <= n; ++i) {
    memset(a, 0, sizeof(a));
    a[i] = 1;
    q.push(i);
    while (!q.empty()) {
      int t = q.front(); q.pop();
      for (RI i = 1; i <= n; ++i)
        if (G[t][i]) {
          if (!a[i]) a[i] = a[t] + 1, q.push(i);
          else if (abs(a[i] - a[t]) != 1) return puts("-1"), 0;
        }
    }
    for (RI j = 1; j <= n; ++j)
      ans = max(ans, a[j]);
  }
  printf("%d\n", ans);

  return 0;
}

// created by Daniel yuan

Measured memory_bytes: 512
# Your code here!
def perfect_grundy(n)
    if n ==0 
        return 0
    end
    r = 1
    while (n&1)==0
        n>>=1
        r<<=1
    end
    return r
end

def tree_grundy(tree,l)
    stack = [ [0,0,tree[0]] ]
    grundy = 0
    while !(stack.empty?)
        nxt,depth,node = stack.pop
        if nxt == 0
            stack.push [nxt+1,depth,node]
        end
        if node[nxt] == nil
            grundy ^= perfect_grundy(l-depth)
        else
            stack.push [0,depth+1,node[nxt]]
        end
    end
    return grundy
end

def calc(sl,l)
    tree = [ [nil,nil] ]
    for x in sl
        xl = x.length
        node = tree[0]
        for i in 0...xl
            c = x[i]=="0" ? 0 : 1
            if node[c] == nil
                new_node = [nil,nil]
                tree.push new_node
                node[c] = new_node
            end
            node = node[c]
        end
    end
    return tree_grundy(tree,l)
end

def main()
    n,l = gets.chomp.split(" ").map(&:to_i)
    sl = []
    for i in 0...n
        sl.push(gets.chomp)
    end
    puts ( calc(sl,l) > 0 ? "Alice" : "Bob")
end

main()


Measured memory_bytes: 14204
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug (fprintf(stderr,"orzyrt\n"),fflush(stderr))
	#define debug(__a...) (fprintf(stderr,__a),fflush(stderr))
	#define setfile(__a) ('orzyrt')
	#define Compile(__a) system("g++ "__a".cpp -lm -o "__a)
#else
	#define Debug ('orzyrt')
	#define debug(__a...) ('orzyrt')
	#define setfile(__a) freopen(__a".in","r",stdin);freopen(__a".out","w",stdout)
	#define Compile(__a) ('orzyrt')
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(b<a)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

namespace Night{
	const int maxn = 100010;
	struct node{
		int x,y;
		int id;
		inline bool operator < (R const node &p)const{
			return x==p.x?y<p.y:x<p.x;
		}
	}a[maxn];
	inline int dis(R int p,R int q){
		return Max(Abs(a[p].x-a[q].x),Abs(a[p].y-a[q].y));
	}
	struct Edge{
		int to;
		Edge *next;
	}*head[maxn];
	inline void add(R int u,R int v){
		static Edge E[maxn<<3],*e=E;
		*e=(Edge){v,head[u]};head[u]=e++;
		*e=(Edge){u,head[v]};head[v]=e++;
	}
	int n,d,p,q;
	int f[maxn];
	inline void work(R int k){
		sort(a+1,a+1+n);
		for(R int i=1,j=1,l=1,r=1;i<=n;++i){
			for(;a[l].x<a[i].x-d||a[l].x==a[i].x-d&&a[l].y<a[i].y-k;++l);
			for(;a[r].x<a[i].x-d||a[r].x==a[i].x-d&&a[r].y<=a[i].y+k;++r);
			f[a[i].id]+=r-l;
			cmax(j,l);
			if(j>=r)continue;
			add(a[i].id,a[j].id);
			for(;j+1<r;++j)add(a[j].id,a[j+1].id);
		}
	}
	bool vis[maxn];
	LL ans=0;
	void dfs(R int u){
		vis[u]=1;ans+=f[u];
		for(R Edge *i=head[u];i;i=i->next)if(!vis[i->to])dfs(i->to);
	}
	int main(){
		read(n);read(p);read(q);
		for(R int i=1,x,y;i<=n;++i){
			read(x);read(y);
			a[i]=(node){x+y,x-y,i};
		}
		d=dis(p,q);
		work(d);
		for(R int i=1;i<=n;++i)swap(a[i].x,a[i].y);
		work(d-1);
		dfs(p);
		cout<<ans;
		return 0;
	}
}
int main(){
	return Night::main();
}

Measured memory_bytes: 16512
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define RREP(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define ALL(vector) vector.begin(), vector.end()

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin>>N>>M;
    vector<mint> fact(M+1, 1);
    vector<mint> ifact(M+1, 1);
    REP(i, M){
        fact[i+1] = fact[i] * (i+1);
    }
    ifact[M] = fact[M].inv();
    RREP(i, M){
        ifact[i] = ifact[i+1] * (i+1);
    }
    // mPn * sum_k(nCk * m-kPn-k *(-1)**k )
    mint ans=0;
    REP(k,N+1){
        // cout<< "nCk "<<(fact[N] * ifact[N-k] * ifact[k]) <<endl;
        // cout<< "m-kPn-k "<<(fact[M-k] * ifact[M-N]) <<endl;
        if ((k&1) == 0){
            ans +=  (fact[N] * ifact[N-k] * ifact[k]) * (fact[M-k] * ifact[M-N]);
        } else{
            ans -=  (fact[N] * ifact[N-k] * ifact[k]) * (fact[M-k] * ifact[M-N]);
        }
        // cout<<ans<<endl;
    }
    ans *= (fact[M] * ifact[M-N]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11076
#include <bits/stdc++.h>
#define ld long double
#define int long long
#define fi first
#define se second
using namespace std;
const int N = 20 + 12;
const int inf = 2e9;
const int mod = 1e9 + 7;

string s[N];
int t[N];

int bp(int x, int st) {
    if (st == 0)
        return 1;
    else if (st % 2 == 0)
            return bp((x * x) % mod, st / 2);
        else
            return (bp((x * x) % mod, st / 2) * x) % mod;
}

void run() {
    int i, j, k, n, need, cnt, cnt0 = 0, x;
    vector <pair<int, int> > v;
    cin >> n >> k;
    int ans = 1;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        if (x == 0)
            ++cnt0;
        if (x < 0)
            v.push_back({-x, -1});
        else
            v.push_back({x, 1});
    }
    sort(v.rbegin(), v.rend());
    int product = 1;
    int sign = 1;
    for (i = 0; i < k; ++i) {
        product = (product * v[i].fi) % mod;
        sign *= v[i].se;
    }
    ans = product;
    if (sign == 1) {
        cout << ans;
        return;
    }
    int leastpos;
    for (leastpos = k - 1; leastpos >= 0; --leastpos)
    if (v[leastpos].se == 1)
        break;
    int waspos = 0, newneg = 0;
    if (leastpos >= 0) {
        for (i = k; i < n; ++i)
        if (v[i].se < 0) {
            waspos = v[leastpos].fi;
            newneg = v[i].fi;
            break;
        }
    }
    int leastneg;
    for (leastneg = k - 1; leastneg >= 0; --leastneg)
    if (v[leastneg].se == -1)
        break;
    int wasneg = 0, newpos = 0;
    if (leastneg >= 0) {
        for (i = k; i < n; ++i)
        if (v[i].se > 0) {
            wasneg = v[leastneg].fi;
            newpos = v[i].fi;
            break;
        }
    }
    if (waspos == 0) {
        if (wasneg == 0) {
            if (cnt0 == 0) {
                sort(v.begin(), v.end());
                product = 1;
                for (i = 0; i < k; ++i) {
                    product = (product * v[i].fi) % mod;
                }
                cout << ((product * (mod - 1))) % mod;
            } else
                cout << 0;
        } else
            cout << (((ans * bp(wasneg, mod - 2)) % mod) * newpos) % mod;
    } else  {
        if (wasneg == 0 || waspos * newpos < wasneg * newneg)
            cout << (((ans * bp(waspos, mod - 2)) % mod) * newneg) % mod;
        else
            cout << (((ans * bp(wasneg, mod - 2)) % mod) * newpos) % mod;
    }



}

signed main() {
    #ifdef local
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test;
    run();
}


Measured memory_bytes: 7404
N, K = map(int, input().split())

A = list(map(int, input().split()))

left = 0
right = 10**10

while right - left > 1:
    cut = 0
    mid = left + (right - left) // 2
    for a in A:
        cut += (a+mid-1)//mid - 1
    if cut <= K:
        right = mid
    else:
        left = mid

print(right)




Measured memory_bytes: 30820
#include<stdio.h>


int m,f,r;
int n;
int x,y;
int total,ans;
char c;
int hoge[256];

main(){
	
	for(x=0;;x++){
		scanf("%d%d%d",&m,&f,&r);
		if(m==-1||f==-1){c='F';}
		else if(m+f>=80){c='A';}
		else if(m+f>=65){c='B';}
		else if(m+f>=50){c='C';}
		else if(m+f>=30&&m+f<=50&&r>=50){c='C';}
		else if(m+f>=30&&m+f<=50){c='D';}
		else if(m+f<30){c='F';}
		
		if(m==-1&&f==-1&&r==-1){break;}
		hoge[x]=c;

	}
	
	for(y=0;y<x;y++){
		printf("%c\n",hoge[y]);
	}	
		
		
	
	
	
	
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
typedef pair<int,int>pii;
const int mxN=2e5,M=1e9+7;
string s;
// LONG LONG CASE
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin>>s;
    b=(s[2]-'0')*10 + (s[3]-'0');
    a=(s[0]-'0')*10 + (s[1]-'0');
    //cout<<a<<" "<<b;
    if(a>=1 &&  a<=12 && b>=1 && b<=12)cout<<"AMBIGUOUS";
    else if(a>=1 && a<=12)cout<<"MMYY";
    else if(b>=1 && b<=12)cout<<"YYMM";
    else cout<<"NA";


}

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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

bool bio[100500];
vi adj[100500];
int d[100500];
stack <int> stk;

void dfs(int u){
	bio[u] = 1;
	for(int v : adj[u]){
		if(bio[v]) continue;
		dfs(v);
	}
	stk.push(u);
}	

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

	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
	}
	for(int i = 1; i <= n; i++){
		if(bio[i]) continue;
		dfs(i);
	}
	while(!stk.empty()){
		int u = stk.top();
		stk.pop();
		for(int v : adj[u]){
			d[v] = max(d[v], d[u] + 1);
		}
	}
	cout << *max_element(d, d + n + 1);
}

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



  
int main(){
  

  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  
  int water=0;
  int sugar=0;
  double densitymax=0;
  
  for (int i=0;i<=f/(100*a);i++){
    for (int j=0;j<=(f-100*a*i)/(100*b);j++){
      int idealsugar;
      idealsugar=min(e*(a*i+b*j),f-100*a*i-100*b*j);   
      for (int k=0;k<=idealsugar/c;k++){
        int l;
        l=(idealsugar-c*k)/d;
        double density=(c*k+d*l+0.0)/(a*i+b*j);
        if (density>=densitymax){
          densitymax=density;
          water=100*(a*i+b*j);
          sugar=(c*k+d*l);
        }
      }
    }
  }
  
  cout<<water+sugar<<" "<<sugar<<endl;

        
}

    











Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

ll MAX = 200005;

vll fac(MAX, 0), finv(MAX, 0), inv(MAX, 0);

void initCombTable() {
  fac.at(0) = 1; fac.at(1) = 1;
  finv.at(0) = 1; finv.at(1) = 1;
  inv.at(1) = 1;
  rep(i, 2, MAX) {
    fac.at(i) = fac.at(i-1) * i % MOD;
    inv.at(i) = MOD - inv.at(MOD%i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i-1) * inv.at(i) % MOD;
  }
}

ll nCk(ll n, ll k) {
  if (n < 0 || k < 0 || n < k) return 0;
  return fac.at(n) * (finv.at(k) * finv.at(n-k) % MOD) % MOD;
}

int main() {
  initCombTable();
  ll h, w, a, b; cin >> h >> w >> a >> b;
  ll ans = 0;
  for (ll i=b+1; i<=w; i++) {
    ans += ((fac[i-1+h-a-1] * finv[i-1] % MOD) * finv[h-a-1] % MOD) * ((fac[w-i+a-1] * finv[w-i] % MOD) * finv[a-1] % MOD) % MOD;
    if (ans >= MOD) ans -= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int r[11],l[11],t[11];
int kyes;

void dfs(int i,int j,int k)//j->left,k->right
{
    if(i>10)
    {
        kyes=1;
    }
    if(kyes)
    return;
    if(t[i]>l[j-1])
    {
        l[j]=t[i];
        dfs(i+1,j+1,k);
    }
    if(t[i]>r[k-1])
    {
        r[k]=t[i];
        dfs(i+1,j,k+1);
    }
}
int main()
{
    int i;
    int n;
    cin>>n;
    while(n--)
    {
        for(i=1; i<=10; i++)
            cin>>t[i];
        kyes=0;
        dfs(1,1,1);
        if(kyes)
        cout<<"YES"<<endl;
        else
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3028
#include <bits/stdc++.h>
#define PI 3.14159265359
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
typedef vector<pair<ll,ll> > vpii;
typedef vector<ll> vi;
const ll INF=1e13+7;
void input(ll *a,ll n){
    for(ll i=0;i<n;i++)cin>>a[i];
}
ll lcm(ll a,ll b){return (a*b)/__gcd(a,b);}
bool isprime(ll n){
    if(n==1)return false;
    if(n==2 || n==3)return true;
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0)return false;
    }
    return true;
}
//ll x[100001]={0};
ll a[100001]={0};
//ll b[100001]={0};

//bool c[1000001]={0};
//vector<pair<ll,ll> > adj[100001];
//vector<ll> adj[200001];
//vpii edges;
//bool visited[200001]={0};
//bool color[200001]={0};
//ll dist[100001]={0};
ll binary_expon(ll a,ll b){
    ll res=1;
    while(b){
        if(b%2)res=(res*a)%INF;
        a=(a*a)%INF;
        b/=2;
    }
    return res%INF;
}

void sieve(ll n,bool *a)
{
    for (ll p=2; p*p<=n; p++){
        if (!a[p]){
            for (ll i=p*p;i<=n;i+=p)
                a[i]=true;
        }
    }
}

ll fact(ll n){
    ll res=1;
    for(ll i=1;i<=n;i++)res*=i;
    return res;
}

double distance(ll x1,ll y1,ll x2,ll y2){
    return (sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}

/*void tree_dfs(ll curr,ll prev){
    for(auto u:adj[curr]){
        if(u!=prev){
            tree_dfs(u,curr);
        }
    }
}*/

/*void dfs(ll x,ll y){
    if(x<0 || y<0 || x>=n || y>=m)return;
    //if(grid[x][y]!=color)return;
    if(visited[x][y] || Map[x][y]=='#'){
        //f=true;
        return;
    }
    visited[x][y]=true;
    Map[x][y]='#';
    //if(px!=(x+1) || py!=y)
        dfs(x+1,y);
    //if(px!=(x-1) || py!=y)
        dfs(x-1,y);
    //if(px!=(x) || py!=y+1)
        dfs(x,y+1);
    //if(px!=(x) || py!=y-1)
        dfs(x,y-1);
}*/

/*bool isVowel(char c){
    return(c=='a'||c=='e'||c=='i'||c=='o'||c=='u');
}*/
//ll grid[1001][1001]={0};

/*void dfs(ll s){
    if(visited[s])return;
    visited[s]=true;
    for(auto u:adj[s]){
        dfs(u);
        dp[s]=max(dp[s],1+dp[u]);
    }
}*/
//set<pair<ll,ll> >edges;
/*vector<ll> z(string s) {
    ll n=s.length();
    vector<ll> z(n);
    ll x=0,y=0;
    for(ll i=1;i<n;i++) {
        z[i]=max(0ll,min(z[i-x],y-i+1));
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]){
            x = i; y = i+z[i]; z[i]++;
        }
     }
    return z;
}*/

void solve(){
   ll n,k;
   cin>>n>>k;
   input(a,n);

   vector<bool> dp(k+1);

   for(ll i=0;i<=k;i++){
        for(ll j=0;j<n;j++){
            if(i-a[j]>=0 && !dp[i-a[j]]){
                dp[i]=1;
                break;
            }
        }
   }
   if(dp[k])cout<<"First";
   else cout<<"Second";
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    //sieve(1000001,c);
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++){
        solve();
    }
}


Measured memory_bytes: 3680
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define P pair<int, int>

using namespace std;
const int MAX = 1<<30;

int main(){
  int n, d[10009];
  vector<P> G[10009];
  queue<int> Q;
  cin >> n;
  for(int i=0;i<n;i++){
    int u, k, v, c;
    cin >>u >> k;
    for(int j=0;j<k;j++){
      cin >> v >> c;
      G[u].push_back(P(v, c));
    }
    d[i] = MAX;
  }
  d[0] = 0;
  Q.push(0);
  while(!Q.empty()){
    int cur = Q.front();Q.pop();
    for(int i=0;i<G[cur].size();i++){
      int next = G[cur][i].first, weight = G[cur][i].second;
      if(weight + d[cur]< d[next]){
        d[next] = weight + d[cur];
        Q.push(next);
      }
    }
  }
  for(int i=0;i<n;i++)cout << i << ' ' << d[i] << endl;
}


Measured memory_bytes: 7904
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>

using namespace std;

int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    int maxDiff = -1;
    int ans = -1;
    int large = a[n - 1];
    for(int i = 0; i <= n - 2; i++){
        int temp = a[i];
        int tempDiff = min(temp, large - temp);

        if(tempDiff > maxDiff){
            maxDiff = tempDiff;
            ans = temp;
        }
    }

    cout << large << " " << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll mod=1000000007;
double pi=3.14159265359;
ll f( pair <ll,ll> a , pair <ll,ll> b) // J'utilise cette fonction pour trier les points selon les abscisses croissants
{
    return a.first < b.first;
}

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

    ll n;
    cin>>n;
    vector < pair <ll,ll> > v; //pour stocker les points
    map < pair <ll,ll> , int > mp; // pour différencier entre les points rouges et bleus

    map < pair <ll,ll> , int > visited; // pour s'assurer qu'un point appartient à un seul friendly couple

    for(ll i=0;i<2*n;i++)
    {
        ll a,b;
        cin>> a>> b;
        v.push_back( make_pair(a,b) );
        if(i<n) mp[make_pair(a,b)]=1; // red point
        else mp[make_pair(a,b)]=2; // blue point
    }
    sort(v.begin(),v.end(),f); // sort des points selon l'abscisse croissant

    ll res=0; // contiendra le resultat

    for(ll i=2*n-1;i>=0;i--)
    {
        ll y=2*n+1; //initialisation
        ll x=2*n+1; //initialisation

        // les initialisations edhoukom bech nesta3malhom bech ntalla3 le point j li 3andou le plus petit ordonnées akber men l'ordonné mta3 i
        ll test=0;
        for(ll j=2*n-1;j>i;j--) // je suis sur que les points j ont un abscisse > i car le vecteur est maintenant trié
        {
            if(mp[v[i]]==1 && mp[v[j]]==2 && visited[v[j]]==0 && v[j].second < y && v[j].second > v[i].second) // point i lezmou rouge; point j lezmou bleu ; wnlawwej 3al point j li 3andou asgher ordonnée mebinet les points li 3andhom ordonnée akber mel ordonnée mta3 i.
            {
                test=1; // ki test=1 ma3neha c bn l9it point j yveriy les conditions, ema bech nlawwej 3al optimal ( li 3andou asgher ordonnée mebinet les points li 3andhom ordonnée akber mel ordonnée mta3 i. )
                y=v[j].second;
                x=v[j].first;
            }
        }
        if(test)
        {
            res++;
            visited[make_pair(x,y)]=1; // n7ottou visited bech me3adech nesta3mlou fi couple e5er
        }
    }

    cout<< res;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
int main(){
    ll q,h,s,d,n;
    cin>>q>>h>>s>>d>>n;
    
    ll ans=0;
    if(n%2==0){
        ans=min({q*8,h*4,s*2,d})*n/2;
    }
    else{
        ll x=min({q*4,h*2,s});
        ans=min(x*n,x+d*(n/2));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){
    int l,r,d;cin>>l>>r>>d;
    int ans=0;
    rep(l,r+1) if(i%d==0) ans++;
    cout<<ans;



    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

const int mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

int main() {
    int x, y;
    cin >> x >> y;
    if ((x + y) % 3) {
        cout << 0 << endl;
        return 0;
    }
    int n = (x + y) / 3;
    x -= n;
    y -= n;
    if (x < 0 || y < 0) {
        cout << 0 << endl;
        return 0;
    }
    combination c(x + y);
    mint ans = c(x + y, x);
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 10624
#include <iostream>

int k,s;

int main() {
	std::cin>>k>>s;
	int ans=0;
	for(int i=0;i<=k;++i) {
		for(int j=0;j<=k;++j) {
			int z=s-i-j;
			if(0<=z&&z<=k)
				++ans;
		}
	}
	std::cout<<ans<<std::endl;
	return 0;
}

Measured memory_bytes: 888
n, m, q = map(int, input().split())

query = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    query.append([a - 1, b - 1, c, d])


results = []
def f(x, A, depth=0):
    if depth == n:
        # print(A, "---------" if A == [1, 3, 4] else '')
        score = 0
        for a, b, c, d in query:
            # print(A[b], A[a], A[b] - A[a], c, ":", d)
            if A[b] - A[a] == c:
                score += d
        results.append(score)
        return

    for i in range(1, x + 1):
        A[n - depth - 1] = i
        f(i, A, depth + 1)

f(m, [0] * n)
print(max(results))



Measured memory_bytes: 12420
#include <iostream>
#include <string>
#include <vector>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int N;

int a[200000];
int main(void){
    // Your code here!
    cin >> N;
    for(int i = 0; i < N; i++) cin >> a[i];
    
    int cnt = 0;
    int i_start = -1;
    for(int i = 0; i < N; i++){
        if(a[i] == 1) {
            i_start = i;
            break;
        }
    }
    
    if(i_start == -1) {
        cout << -1 << endl;
        return 0;
    } else{
        cnt = 1;
    }
    
    int hoge = 2;
    for(int j = i_start; j < N; j++){
        if(a[j] == hoge){
            cnt++;
            hoge++;
        }
    }
    
    
    cout << N - cnt << endl;
    
}


Measured memory_bytes: 1024
//
//  main.cpp
//  CP-C++
//
//  Created by ALOK KUMAR THAKUR on 05/05/20.
//  Copyright © 2020 ALOK KUMAR THAKUR. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define tc ll T;cin>>T;while(T--)
#define pb push_back
#define Max3(a,b,c) max(a,max(b,c))
#define Min3(a,b,c) min(a,min(b,c))
#define all(v) v.begin(),v.end()

struct cmp {
    bool operator() (ll a,ll b){
        return a < b;
    }
};

/*ll modp(ll a,ll p,ll n)
{
    int d[100];
    int i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    ll e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1)
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}

ll modInverse(ll n, ll p)
{
    return modp(n, p, p-2);
}
 
ll nCrModPFermat(ll n, ll r,ll p)
{
   // Base case
   if (r==0)
      return 1;
    
    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;
  
    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}*/

int main() {
    
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    /*-----------------Code Begins Here------------------*/
    
    ll n; cin>>n;
    ll ans = 0;
    for(ll i=1 ; (i*i) < n ; i++){
        ans += (n/i-i)*2+1;
        if(n%i == 0) ans -= 2;
    }
    cout<<ans;
    
    /*------------------Code Ends Here-------------------*/
    
    return 0;
}


Measured memory_bytes: 3644
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, ) = input!(usize);
    let arr = invec!(i64);

    let count = arr.iter().filter(|&&x| x < 0).count();

    let mut total: i64 = arr.iter().map(|&x| x.abs()).sum();

    if count % 2 == 1 {
        if let Some(abs_min) = arr.iter().map(|&x| x.abs()).min() {
            total -= 2 * abs_min;
        }
    }

    println!("{}", total);
}

fn main() {
    solve();
}


Measured memory_bytes: 8444
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<functional>
#include<algorithm>
#include<bitset>
#include<utility>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;
int n,m,a[100005];
int par[100005],ran[100005];
void iint()
{
	for(int i=0;i<100005;i++)
		par[i]=i;
}
int find(int x)
{
	if(x==par[x])
		return x;
	return par[x]=find(par[x]);
}
void unite(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x==y)
		return;
	if(ran[x]<ran[y])
		par[x]=y;
	else
	{
		par[y]=x;
		if(ran[x]==ran[y])
			ran[x]++;
	}
}
bool same(int x,int y)
{
	return find(x)==find(y);
}
pair<int,int>val[100005];
bool used[100005];
vector<int>zan;
long long ret;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	iint();
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		unite(a,b);
	}
	for(int i=0;i<n;i++)
		val[i]={1e9,1e9};
	for(int i=0;i<n;i++)
		val[find(i)]=min(val[find(i)],{a[i],i});
	int cnt=0;
	for(int i=0;i<n;i++)
		if(find(i)==i)
		{
			cnt++;
			ret+=val[i].first;
			used[val[i].second]=1;
		}
	if(cnt==1)
	{
		cout<<0;
		return 0;
	}
	for(int i=0;i<n;i++)
		if(!used[i])
			zan.push_back(a[i]);
	sort(zan.begin(),zan.end());
	if(zan.size()<cnt-2)
	{
		cout<<"Impossible";
		return 0;
	}
	for(int i=0;i<cnt-2;i++)
		ret+=zan[i];
	cout<<ret;
	return 0;
}

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

int main()
{
ll n ;
cin >> n ;
multiset<ll> s;
rep(i, 1LL<<n){
  ll a;
  cin >> a;
  s.insert(a);
}
vector<ll> v;
auto itr=s.end();
itr--;
v.push_back(*itr);
s.erase(itr);

ll num=1;
rep(i,n){
  sort(v.rbegin(),v.rend());
  ll siz=v.size();
  itr=s.end();
  itr--;
  rep(j,siz){
    if(v[j]<=*itr){
      if(itr==s.begin()){
        cout << "No" << endl;
        return 0;
      }
      j--;
      itr--;
    }
    else{
      v.push_back(*itr);
      if(s.size()!=1){
        if(itr==s.begin()&&j!=siz-1){
          cout << "No" << endl;
          return 0;
        }
        itr=s.erase(itr);
        itr--;
        }

    }
  }
  num=v.size();
}

cout << "Yes" << endl;
return 0;
}


Measured memory_bytes: 14712
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    int n;
    cin >> n;
    vector<LL> a(n + 1);
    vector<LL> b(n);
    rep(i, n + 1) {
        cin >> a[i];
    }
    rep(i, n) {
        cin >> b[i];
    }
    LL ans = 0;
    rep(i, n) {
        LL rest = b[i] - a[i];
        if (rest <= 0) {
            ans += b[i];
            continue;
        } else {
            ans += a[i];
            if (a[i + 1] - rest >= 0) {
                ans += rest;
                a[i + 1] = a[i + 1] - rest;
            } else {
                ans += a[i + 1];
                a[i + 1]  = 0;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int a[100005];
int main()
{
	int n;
	scanf("%d",&n);
	long long sum=0;
	int npos=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	int ans=-1;
	for(int i=1;i<=n;i++)
	{
		if(abs(a[i]*n-sum)<abs(ans*n-sum))
			ans=a[i],npos=i-1;
	}
	printf("%d\n",npos);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	

    stack<int> st;
    int a,b;
    char s[100];

    while( scanf("%s", s) != EOF)
    {
        if(s[0] == '+')
        {
            a = st.top(); st.pop();
            b = st.top(); st.pop();
            st.push(a+b);
        }
        else if(s[0] == '-')
        {
            a = st.top(); st.pop();
            b = st.top(); st.pop();
            st.push(b-a);
        }
        else if(s[0] == '*')
        {
            a = st.top(); st.pop();
            b = st.top(); st.pop();
            st.push(a*b);
        }
        else
        {
            st.push(atoi(s));
        }
    }
    cout << st.top() << endl;

}



Measured memory_bytes: 3284
S = input()

for n in range(1 << 3):
    s = S
    for i in range(3):
        if (n >> i) & 1 == 1:
            op = "+"
        else:
            op = "-"
        s = s[:2*i+1] + op + s[2*i+1:]
    if eval(s) == 7:
        ans = s + "=7"
        break

print(ans)


Measured memory_bytes: 3064
#https://atcoder.jp/contests/abc167/tasks/abc167_c C - Skill Up
import numpy as np
import math
from itertools import combinations
N,M,X=list(map(int,input().split()))
book_dict={}
for i in range(N):
    book_dict[i] = list(map(int,input().split()))

answer = (10**5*12)+1
for i in range(N,0,-1):
    current_book_number=0    
    for v in combinations(book_dict.keys(), i):
        ##要件を満たさない組み合わせカウント
        search_book = list(map(lambda x:book_dict[x],list(v)))
        sum_search_book = np.array(np.sum(search_book,axis = 0))
        if (np.count_nonzero(sum_search_book[1:] >= X) == M) and sum_search_book[0] < answer:
            answer = sum_search_book[0]
        else:
            current_book_number+=1
    ##どの組み合わせでも達成できない場合は、これ以上本を減らしても意味ない    
    if current_book_number==int(math.factorial(N)/(math.factorial(i)*math.factorial(N-i))):
        break                                                                                 
    
if answer == (10**5*12)+1:
    answer = -1

print(answer)


Measured memory_bytes: 27256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = new int[n];
			Map<Integer, Integer> map = new HashMap<>();
			IntStream.range(0, n).forEach(i -> {
				a[i] = scanner.nextInt();
				map.put(a[i], map.getOrDefault(a[i], 0) + 1);
			});
			long sum = map.entrySet().stream().mapToLong(entry -> c(entry.getValue(), 2)).sum();
			Arrays.stream(a).forEach(i -> System.out.println(sum - c(map.get(i), 2) + c(map.get(i) - 1, 2)));
		}
	}

	private static long c(int n, int m) {
		if (m <= n) {
			long answer = 1L;
			for (int i = 1; i <= m; i++) {
				answer *= n + 1 - i;
				answer /= i;
			}
			return answer;
		}
		return 0L;
	}
}


Measured memory_bytes: 98192
#include <time.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll GCD(ll a, ll b) {
    return (a == 0) ? b : GCD(b % a, a);
}
ll LCM(ll a, ll b) {
    return a*b/GCD(a, b);
}
int main() {
    int a[3], m[3];
    while (1) {
        cin >> a[0] >> m[0] >> a[1] >> m[1] >> a[2] >> m[2];
        if (!a[0]) {
            break;
        }
        int move[3];
        for (int i=0; i<3; ++i) {
            int val = 1;
            for (int j=1; j<=m[i]; ++j) {
                val = a[i] * val % m[i];
                if (val == 1) {
                    move[i] = j; break;
                }
            }
        }
        ll ans = LCM(LCM(move[0], move[1]), move[2]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 1156