akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var L = Console.ReadLine().Split().Select(int.Parse).OrderBy(o => o).ToArray();
            var count = 0;

            for (var i = 1; i < N; i++)
            {
                for (var j = i - 1; j >= 0; j--)
                {
                    if (L[j] * 2 <= L[i]) continue;
                    var valid = j;
                    var invalid = -1;

                    while (valid - invalid > 1)
                    {
                        var mid = (valid + invalid) / 2;
                        if (L[i] < L[mid] + L[j]) valid = mid;
                        else invalid = mid;
                    }

                    count += j - valid;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13416
#include<bits/stdc++.h>
using namespace std;
#define s second
#define f first
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define reset(a,b) memset(a,b,sizeof a)
#define ll long long
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define dalam fl<=l && r<=fr
#define kiwo 2*(idx),l,MID
#define tengen 2*idx+1,MID+1,r
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 400004
#define pc(x) putchar_unlocked(x);

int n,m,a[mx],tot;

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i],tot=tot+abs(a[i-1]-a[i]);
	tot=tot+abs(a[n]-a[0]);
	for(int i=1;i<=n;i++){
		int jaw=tot-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]);
		cout<<jaw<<endl;
	}
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int k,a,b;
  cin>>k>>a>>b;
  bool ok=false;
  for (int i = a; i <= b; i++)
  {
    if(i%k==0){
      ok=true;
      break;
    }
  }
  if(ok){
    cout<<"OK"<<endl;
  }else{
    cout<<"NG"<<endl;
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define mod 1000000007
int main() {
    ll h;
    int n;
    cin >> h >> n;
    ll damage = 0;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        damage += a;
    }
    if (damage >= h) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define FLOAT setprecision(16)
#define INSIDE(i,j,H,W) ((i) >= 0 && (i) < (H) && (j) >= 0 && (j) < (W))
#define YesNo(b) (b ? "Yes" : "No")
#define YESNO(b) (b ? "YES" : "NO")
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }

// all_of
// partial_sum, adjacent_difference

#if _DEBUG
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#endif

#if 1234567891
#include <array>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

int N, M;
vector<int> G[100000];
bool RED[100000];
bool used[100000];

bool rec(int i, bool red) {
	if (used[i]) return RED[i] == red;
	used[i] = true;
	RED[i] = red;

	bool ret = true;
	for (int to : G[i]) {
		ret &= rec(to, !red);
	}
	return ret;
}

map<int, vector<int>> MAP;
int main() {
	cin >> N >> M;
	REP(i, 0, M) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	LL sum = 0;
	auto ret = rec(0, true);
	if (ret) {
		LL reds = 0, blacks;
		REP(i,0,N) {
			reds += (RED[i]);
		}
		blacks = N - reds;
		sum += reds * blacks;
	} else {
		sum += (LL)N * (N - 1) / 2;
	}
	cout << sum - M << endl;
	return 0;
}

Measured memory_bytes: 6784
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<numeric>
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    double a,b;
    cin >> a >> b;
    if(a>b)
    {
        cout << "GREATER" << endl;
    }
    else if(a<b)
    {
        cout << "LESS" << endl;
    }
    else
    {
        cout << "EQUAL" << endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, n) for(long i = x; i < n; i++)
#define erep(i, x, n) for(long i = x; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define show(ans)  cout << ans << endl;


int main() {long N;
cin >> N;
vector<pair<long, long>> r; vector<pair<long, long>> b;
r.push_back(make_pair(0, 0)); b.push_back(make_pair(0, 0));
erep(i, 1, N){
    long a1, b1;
    cin >> a1 >> b1;
    r.push_back(make_pair(a1, b1));
}
erep(i, 1, N){
    long a1, b1;
    cin >> a1 >> b1;
    b.push_back(make_pair(a1, b1));
}
sort(b.begin()+1, b.end());
vector<bool> vis(N+1);
long ans = 0;

erep(i, 1, N){
    long rmax = -1;
    long maxval = -1;
    erep(j, 1, N){
        if(r[j].first < b[i].first && r[j].second < b[i].second &&
        r[j].second > maxval && vis[j] == false){
            rmax = j;
            maxval = r[j].second;
        }
    }
    if(rmax != -1){
        ans++;
        vis[rmax] = true;
    }
}
show(ans);
  return 0;
 
}



Measured memory_bytes: 256
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

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

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int main()
{
	int n, m;
	cin >> n >> m;
	cout << ((n - 1)*(m - 1)) << endl;
}

Measured memory_bytes: 256
INF = 300

n = int(input())
a = [INF] + list(map(int, input().split())) + [-INF]

money = 1000
stock = 0
for e1, e2 in zip(a, a[1:]):
    if e1 < e2:
        buy = money // e1
        money -= buy * e1
        stock += buy
    else:
        money += stock * e1
        stock = 0

print(money)


Measured memory_bytes: 9172
s=input()

N=len(s)

L=[]

for i in range(N):
    if s[i]=='0':
        L.append('0')
    elif s[i]=='1':
        L.append('1')
    elif s[i]=='B':
        if L==[]:
            pass
        else:
            del L[-1]

A=''.join(L)
print(A)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_c() {
	string s, t;
	string ans;

	cin >> s >> t;

	reverse(ALL(s));
	reverse(ALL(t));

	ll cnt_t = -1;
	rep(i, s.size()) {
		rep(j, t.size()) {
			if (i + j >= s.size()) {
				break;
			}
			if (s[i + j] != '?' && s[i + j] != t[j]) {
				break;
			}

			if (j == t.size() - 1) {
				cnt_t = i;
				break;
			}
		}
		if (cnt_t != -1) {
			break;
		}
	}

	if (cnt_t == -1) {
		ans = "UNRESTORABLE";
	}
	else {
		rep(i, s.size()) {
			if (i >= cnt_t && i < cnt_t + t.size()) {
				ans += t[i - cnt_t];
			}
			else if (s[i] == '?'){
				ans += 'a';
			}
			else {
				ans += s[i];
			}
		}
		reverse(ALL(ans));
	}

	cout << ans << "\n";
}

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

	solve_abc_c();

	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#define MAX 100

int count = 0;

void print_array(int *A, int N) {
  int i;
  for(i = 0; i < N - 1; i++) {
    printf("%d ", A[i]);
  }
  printf("%d\n", A[i]);
}

void bubbleSort(int *A, int N) {
  int j, v, frag = 1;
  while(frag) {
    frag = 0;
    for(j = N - 1; j >= 1; j--) {
      if(A[j] < A[j-1]) {
	v = A[j];
	A[j] = A[j-1];
	A[j-1] = v;
	frag = 1;
	count++;
      }
    }
  }
}

int main() {
  int n, i, a[MAX];
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  bubbleSort(a, n);
  print_array(a, n);
  printf("%d\n", count);
  return 0;
}



Measured memory_bytes: 1972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct segtree {
    int N;
    vector<int> t;

    segtree(vector<int> a) {
        int n = a.size();
        N = 1;
        while (N < n) N <<= 1;
        t.resize(2 * N);
        for (int i = 0; i < n; i++) {
            t[i + N] = a[i];
        }
        for (int i = N - 1; i >= 1; i--) {
            t[i] = max(t[i * 2], t[i * 2 + 1]);
        }
    }

    int get(int l, int r) {
        l += N;
        r += N;
        int ans = -1;
        while (l <= r) {
            if (l & 1) ans = max(ans, t[l]);
            if (!(r & 1)) ans = max(ans, t[r]);
            l = (l + 1) >> 1;
            r = (r - 1) >> 1;
        }
        return ans;
    }

    void upd(int x, int y) {
        x += N;
        t[x] = y;
        while (x > 1) {
            x >>= 1;
            t[x] = max(t[x * 2], t[x * 2 + 1]);
        }
    }
};

int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif


    int r, c, n;
    while (cin >> r >> c >> n) {
        vector<int> x1(n), y1(n), x2(n), y2(n);
        for (int i = 0; i < n; i++) {
            cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        }

        auto onBorder = [&](int x, int y) {
            if (y == 0) return x;
            if (x == r) return r + y;
            if (y == c) return r + c + (r - x);
            if (x == 0) return r + c + r + (c - y);
            return -1;
        };
        vector<pair<int, int> > vct;
        for (int i = 0; i < n; i++) {
            int p1 = onBorder(x1[i], y1[i]);
            int p2 = onBorder(x2[i], y2[i]);
            if (p1 != -1 && p2 != -1) {
                vct.push_back(make_pair(p1, i));
                vct.push_back(make_pair(p2, i));
            }
        }
        sort(vct.begin(), vct.end());
        int m = vct.size();
        for (int i = 0; i < m; i++) vct.push_back({vct[i].first + 2 * r + 2 * c, vct[i].second});
        m *= 2;

        vector<int> nxt(2 * m);
        vector<int> last(n, -1);
        segtree t(nxt);
        bool fail = 0;
        for (int i = m - 1; i >= 0; i--) {
            if (last[vct[i].second] != -1) {
                t.upd(i, last[vct[i].second]);
                t.upd(last[vct[i].second], -1);
                int mx = t.get(i + 1, last[vct[i].second] - 1);
                if (mx > last[vct[i].second]) fail = 1;
            }
            last[vct[i].second] = i;
        }
        const string ss[2] = {"YES", "NO"};
        cout << ss[fail] << endl;
    }


#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 20460
#include <iostream>

using namespace std;

int main() {
	int N;
	int num = 0;
	int max = 0;

	cin >> N;
	char s[N];
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		num = (s[i] == 'I') ? num + 1 : num - 1;
		if (max < num)	max = num;
	}
	cout << max << endl;
}

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

int main()
{
  int n,q;
  std::cin>>n;
  int s[n];
  for(int i=0;i<n;i++){
    std::cin>>s[i];
  }
  std::cin>>q;
  int t[q];
  for(int i=0;i<q;i++){
    std::cin>>t[i];
  }

  int cnt=0;
  for(int j=0;j<q;j++){
    for(int i=0;i<n;i++){
      if(t[j]==s[i]){
	cnt++;
	break;
      }
    }
  }
  std::cout<<cnt<<"\n";

  return 0;
}


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

struct uft{
    vector<ll> par;
    uft(ll n) {
        par.resize(n);
        rep(i,n)par[i]=i;
    }

    ll find(ll a){
        if(par[a]==a){
            return a;
        }else {
            return find(par[a]);
        }
    }

    void unite(ll a,ll b){
        par[find(a)]=find(b);
    }

    bool same(ll a,ll b){
        return find(a) == find(b);
    }
};

struct edge{
    ll s,t,w;
};

bool sortw(edge a,edge b) {
    return a.w < b.w;
}

void q(ll v, ll e) {
    vector<edge> edges;
    rep(i,e){
        ll s,t,w;
        cin>>s>>t>>w;
        edges.push_back(edge{s,t,w});
    }
    sort(edges.begin(),edges.end(),sortw);
    ll sum=0;
    uft uni(v);
    rep(i,e){
        if(!uni.same(edges[i].s,edges[i].t)) {
            uni.unite(edges[i].s,edges[i].t);
            sum+=edges[i].w;
        }
    }
    cout<<sum<<endl;
}

int main() {
    while(true){
        ll v,e;
        cin>>v>>e;
        if(v==0&&e==0)break;
        q(v,e);
    }
}



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

using namespace std;

int dp[100001] = {};

int rec(int n) {
    if (n == 0) {
        return 0;
    }
    if (dp[n]) {
        return dp[n];
    }
    int ret = INT_MAX, tmp = 6;
    while (tmp <= n) {
        ret = min(ret, rec(n - tmp) + 1);
        tmp *= 6;
    }
    tmp = 9;
    while (tmp <= n) {
        ret = min(ret, rec(n - tmp) + 1);
        tmp *= 9;
    }
    dp[n] = ret;
    return ret;
}

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

    for (int i = 1; i < 6; i++) {
        dp[i] = i;
    }

    int N;
    cin >> N;

    cout << rec(N) << endl;

    return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
int solve(int,int);
int n,A[2000];

int main(){
  int i,q,m;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(solve(0,m)==1){
      printf("yes\n");
    }
      else{
	printf("no\n");
      }
   }
  return 0;
}


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



Measured memory_bytes: 2604
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[100];

        for(int i = 0; i < n; i++) {
            a[i] = scan.nextInt();
        }
 
        for(int i = n - 1; i >= 0; i--) {
            System.out.print(a[i]);
            if(i != 0) {
                System.out.print(" ");
            }
        }
        System.out.println("");
    }
}


Measured memory_bytes: 26344
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
typedef pair<int,int> P;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
	string s;
	cin>>s;
	if(s=="ABC")cout<<"ARC"<<endl;
	else cout<<"ABC"<<endl;
}


Measured memory_bytes: 3612
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
typedef long long ll;
ll n,p,arr[55],memo[55][1005];
ll f(ll idx,ll sum){
    if(idx==n+1){
        if(sum==p) return 1;
        return 0;
    }
    if(memo[idx][sum]!=-1) return memo[idx][sum];
    ll res=f(idx+1,sum)+f(idx+1,(sum+arr[idx])%2);
    return memo[idx][sum]=res;
}
int  main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>p;
    memset(memo,-1,sizeof(memo));
    for(ll i=1;i<=n;i++){
        cin>>arr[i];
        arr[i]%=2;
    }
   ll ans=f(1,0);
   cout<<ans<<endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N, x;
    cin >> N >> x;
    vector<ll> a(N);
    REP(i, N) cin >> a[i];
    sort(a.begin(), a.end());

    ll S = 0;
    ll res = 0;
    REP(i, N){
    	S += a[i];
    	if(i==N-1){
    		if(x==S) res++;
    	}else{
    		if(x>=S) res++;
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import math
def LCM(X,Y):
    return (X*Y)//math.gcd(X,Y)
  
N = int(input())
A = [int(input()) for T in range(0,N)]
TLCM = 1
for T in range(0,N):
    TLCM = LCM(TLCM,A[T])
print(TLCM)

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

int main(){
    int h,w;
    cin>>h>>w;
    while(h!=0||w!=0){
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                if(j==0||j==w-1||i==0||i==h-1)cout<<'#';
                else cout<<'.';
            }
            cout<<endl;
        }
        cout<<endl;
        cin>>h>>w;
    }
    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

LL gcd(LL a, LL b)
{
    return b ? gcd(b, a % b) : a;
};

void solve()
{
    int N;
    int K;
    cin >> N >> K;
    LL M = 0;
    vector<LL> A(N);
    LL G = 0;

    REP0 (i, N)
    {
        cin >> A[i];
        M = max(M, A[i]);
        if (i == 0)
        {
            G = A[i];
        }
        else
        {
            G = gcd(G, A[i]);
        }
    }

    cout << (K % G == 0 and K <= M ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


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

using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define inf 10000000
#define sz(x) (ll)x.size()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef  double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair< int , pii> piii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
typedef pair<ld , ld> pdd;
typedef vector<pdd> vdd;
typedef vector<ld> vd;
const int MOD = 1e9 + 7; //998244353;

int main() {
    boost;
    int n;
    cin >> n;
    vi a(n);
    for(int &i : a)cin >> i;
    int dp[n+1];
    fill(dp , dp + n + 1,inf);
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(a[1] - a[0]);
    for(int i=3;i<=n;i++){
        dp[i] = min(abs(a[i-1] - a[i-2]) + dp[i-1] , abs(a[i-1] - a[i-3]) + dp[i-2]);
    }
    cout << dp[n];
}


Measured memory_bytes: 3872
#include <iostream>

using namespace std;

int num_comp = 0;
const int MAX = 500000;
int L[MAX/2 + 2];
int R[MAX/2 + 2];
const int SENTINEL = 2000000000;


// Merge
void Merge(int A[], int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++)
		L[i] = A[left + i];
	for (int i = 0; i < n2; i++)
		R[i] = A[mid + i];
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;

	int i = 0;
	int j = 0;
	for (int k = left; k < right; k++) {
		num_comp++;
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		}
		else {
			A[k] = R[j];
			j++;
		}
	}
}

// Merge sort
void Mergesort(int A[], int left, int right)
{
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		Mergesort(A, left, mid);
		Mergesort(A, mid, right);
		Merge(A, left, mid, right);	
	}

}

// MAIN FUNCTION
int main(int argc, char** argv)
{
	// Input
	int A[MAX];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];

	// Merge sort
	Mergesort(A, 0, n);

	// Print all elements
	for (int i = 0; i < n; i++) {
		if (i)
			cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << num_comp << endl;

	return 0;
}


Measured memory_bytes: 6912
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 2e3 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , m , ans;
string s[MAXN];
vector<ll> x[MAXN] , y[MAXN];

int main() {
    fast_io;

    cin >> n >> m;
    s[0] = string(m + 2 , '#');
    s[n + 1] = s[0];
    for(ll i = 1 ; i <= n ; i++){
        cin >> s[i];
        s[i] = '#' + s[i] + "#";
    }

    for(ll i = 0 ; i <= n + 1 ; i++){
        for(ll j = 0 ; j <= m + 1 ; j++){
            if(s[i][j] == '#'){
                x[i].push_back(j);
                y[j].push_back(i);
            }
        }
    }

    for(ll i = 1 ; i <= n ; i++){
        for(ll j = 1 ; j <= m ; j++){
            if(s[i][j] == '#')  continue;
            ll indx = lower_bound(all(x[i]) , j) - x[i].begin();
            ll indy = lower_bound(all(y[j]) , i) - y[j].begin();
            ans = max(ans , x[i][indx] - x[i][indx - 1] + y[j][indy] - y[j][indy - 1] - 3);
        }
    }
    cout << ans << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 75136
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

from collections import defaultdict

n, m = na()
a = []
for i in range(n):
    b = na()
    a.append(b)
d = defaultdict(int)

for i in range(n):
    k = a[i][0]
    for j in range(1, k + 1):
        d[a[i][j]] += 1

ans = 0
for i in d.values():
    if i == n:
        ans += 1

print(ans)

Measured memory_bytes: 3316
#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
const int MAX=1e6+7;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
	ll a,b,c,d;cin>>a>>b>>c>>d;
	ll ans=-LLONG_MAX;
	ans=max(ans,a*c);
	ans=max(ans,a*d);
	ans=max(ans,b*c);
	ans=max(ans,b*d);
	/*
	if(b<=0&&d<=0)ans=1ll*a*c;
	else if(a>0&&c>0)ans=1ll*b*d;
	else if(b>0)
	else if(b<=0&&d>0)ans=1ll*a*c;
	else if(b>0&&d<=0)ans=1ll*a*d;
	*/
	cout<<ans;
   return 0;
} 

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

int main() {
    string s, t;
    cin >> s >> t;
    rep(i, s.size()) {
        if (t[i] != s[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

const int N=200100;
int n,S,T,dis1[N],dis2[N],lst[N];
vector<int>g1[N],g2[N];
queue<int>q;
void bfs(int s,int*dis,vector<int>*g){
	for(int i=1;i<=n;++i)dis[i]=n,lst[i]=0;
	dis[s]=0;q.push(s);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i:g[u])
			if(dis[i]>dis[u]+1){
				lst[i]=u;dis[i]=dis[u]+1;
				q.push(i);
			}
	}
}
int ans;
void dfs(int x,int fa=-1){
	for(int i:g1[x])if(i!=fa){
		if(dis1[i]<dis2[i])dfs(i,x);
		if(lst[i]!=x&&lst[x]!=i&&lst[x]!=lst[i]&&lst[lst[x]]!=i&&lst[lst[i]]!=x){
			cout<<-1<<'\n';
			exit(0);
		}
	}
	ans=max(ans,dis2[x]);
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>S>>T;
	for(int i=1;i<n;++i){
		int x,y;cin>>x>>y;
		g1[x].push_back(y);g1[y].push_back(x);
	}
	for(int i=1;i<n;++i){
		int x,y;cin>>x>>y;
		g2[x].push_back(y);g2[y].push_back(x);
	}
	bfs(S,dis1,g1);bfs(T,dis2,g2);
	dfs(S);
	cout<<2*ans<<'\n';
	return 0;
}


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

using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;
#define vec vector
#define rep(_i,_n) for(ll _i = 0; _i < _n; _i++)
#define rep2(_i,_s,_n) for(ll _i = _s; _i < _n; _i++)
#define elif else if
#define push(_a) push_back(_a)
#define fullSort(_a) sort(_a.begin(), _a.end())
#define inputVecI(_name, _n) vec<int> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecL(_name, _n) vec<long> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecLL(_name, _n) vec<ll> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecS(_name, _n) vec<string> _name(_n);rep(_i, _n)cin >> _name[_i];
#define findMaxIdx(_name) distance(_name.begin(), max_element(_name.begin(), _name.end()))
#define printVec(_vec) cout << "{";rep(i, _vec.size()-1)cout << _vec[i] << ",";cout << _vec[_vec.size()-1];cout << "}\n";
#define append(_x) push_back(_x)
#define mapLoop(_i, _name) for(auto i = _name.begin(); i != _name.end(); i++)

#define pow5(_a) _a*_a*_a*_a*_a

int main()
{
    ll X;
    cin >> X;
    ll buf1;
    rep2(A, -119, 120){
      buf1 = pow5(A);
      rep2(B, -119, A){
        if(buf1 - pow5(B) == X){
           cout << A << " " << B << endl;
           return 0;
        }
      }
    }
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, m, deg[maxn + 10], ans, cnt;
struct edge {
	int to, id;
};
vector<edge> g[maxn + 10];
bool vis[maxn + 10];
int cur[maxn + 10];
bool ban[maxn + 10];

int dfs(int p, int fae) {
	vis[p] = 1;	
	for (int &i = cur[p]; i < (int)g[p].size(); ++i) {
		edge e = g[p][i];
		if (e.id != fae && !ban[e.id]) {
			if (vis[e.to]) {
				ban[e.id] = 1; ban[fae] = 1;
				vis[p] = 0; ++i; return e.to;
			} else {
				int w = dfs(e.to, e.id);
				if (w == p) ++ans;
				else {
					vis[p] = 0; ban[fae] = 1; ++i;
					return w;
				}
			}
		}
	}
	assert(!fae);
	vis[p] = 0;
	return 0;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		int l, r; scanf("%d%d", &l, &r);
		++deg[l]; ++deg[r];
		g[l].push_back((edge){r, i}); g[r].push_back((edge){l, i});
	}
	for (int i = 1; i <= n; ++i)
		if (deg[i] & 1) {
			printf("No"); return 0;
		}
	for (int i = 1; i <= n; ++i)
		if (deg[i] >= 6) {
			printf("Yes"); return 0;
		} else if (deg[i] == 4) ++cnt;
	if (cnt != 2) {
		printf("%s", cnt >= 3 ? "Yes" : "No");
		return 0;
	}
	for (int i = 1; i <= n; ++i) dfs(i, 0);
	printf("%s", ans >= 3 ? "Yes" : "No");
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep1(i, n){
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    ll ans;
    if (n%2 != 0){
        ll min, max;
        ll index = n/2;
        min = a[index];
        max = b[index];
        ans = abs(max - min)+1;
    }
    else{
        ll min, max;
        ll index_a = n/2-1;
        ll index_b = n/2;
        min = a[index_a]+a[index_b];
        max = b[index_a]+b[index_b];
        ans = abs(max - min) + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6416
import java.util.Scanner;
import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double pi = Math.PI;
        double area = r*r*pi;
        double length = r*2*pi;
        System.out.printf("%f %f\n",area, length);
        sc.close();
    }
}


Measured memory_bytes: 28320
s = int(input())
a = [s]
tmp = s
while tmp != 1:
    if tmp % 2 == 0:
        tmp //= 2
        a.append(tmp)
    else:
        tmp = 3*tmp + 1
        a.append(tmp)
if s == 1 or s == 2 or s == 4:
    print(4)
else:
    print(len(a)+1)

Measured memory_bytes: 3060
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int M, N,dp[2048][2048],POW[13];
char table[128][12];

int dfs(int question_state, int answer_state){

	if(dp[question_state][answer_state] != -1) return dp[question_state][answer_state];

	int count = 0,tmp;

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

		tmp = 0;
		for(int col = 0; col < M; col++){
			if((question_state  & (1 << col)) && table[i][col] == '1'){
				tmp += POW[col];
			}
		}
		if(tmp == answer_state)count++;
	}

	if(count <= 1){
		return dp[question_state][answer_state] = 0;
	}

	int minimum = M;
	int next_question_state;

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

		if(question_state  & (1 << new_quest))continue;

		next_question_state = question_state + POW[new_quest];

		minimum = min(minimum,max(dfs(next_question_state,answer_state+POW[new_quest]),dfs(next_question_state,answer_state))+1);
	}

	return dp[question_state][answer_state] = minimum;
}


void func(){
	for (int i = 0; i < N; i++) {
		scanf("%s",table[i]);
	}

	for(int i = 0; i < POW[M];i++){
		for(int k = 0; k < POW[M];k++)dp[i][k] = -1;
	}

	printf("%d\n",dfs(0,0));
}

int main() {

	for(int i = 0; i < 13; i++)POW[i] = pow(2,i);

	while(true){
		scanf("%d %d",&M,&N);
		if(M == 0 && N == 0)break;

		func();
	}
	return 0;
}

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

l = [0]*n #l[i]: i~i+1

for _ in range(m):
    a,b = map(int,input().split())
    a,b = min(a,b),max(a,b)
    l[a-1] += 1
    l[b-1] += -1

for i in range(1,n):
    l[i] += l[i-1]

if all(x%2 == 0 for x in l):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 47832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
vector<ll> V;
int pre[maxn];
int main() {
    int n;cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        if(i%3!=0&&i%5!=0) sum+=i;
    }cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3640
/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

ll dp[3010][3010],a[3010];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,s;cin>>n>>s;
    for(int i=1;i<=n;i++)cin>>a[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
        for(int j=s;j>=0;j--){
            dp[i][j]=(dp[i-1][j]*2+dp[i][j])%mod;
            if(j>=a[i])dp[i][j]=(dp[i][j]+dp[i-1][j-a[i]])%mod;
        }
    cout<<dp[n][s];
    return 0;
}


Measured memory_bytes: 74160
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using plpii = std::pair<long long, std::pair<int, int>>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

pii findRoop(int i, pii* a) {
	if (a[a[i].first].second >= 0) {
		return pii(a[i].first, a[i].second + 1);
	}
	else {
		a[a[i].first].second = a[i].second + 1;
		return findRoop(a[i].first, a);
	}
}

int solve(int i, int k, pii* a) {
	if (k) {
		return solve(a[i].first, k - 1, a);
	}
	else {
		return i;
	}
}

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

	int n;
	ll k;
	cin >> n >> k;
	pii* a = new pii[n];
	rep(i, n) {
		cin >> a[i].first;
		--a[i].first;
		a[i].second = -1;
	}

	a[0].second = 0;
	pii t = findRoop(0, a);
	
	if (k <= t.second) {
		cout << solve(0, k, a) + 1 << "\n";
	}
	else {
		k -= a[t.first].second;
		k %= t.second - a[t.first].second;

		cout << solve(t.first, k, a) + 1 << "\n";
	}

	return 0;
}



Measured memory_bytes: 5164
/*
  AUTHOR:SOURABH
  CREATED:12:10:19
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll n,i,j,sum=0;
    cin>>n;
    vll a(n);
    fn(i,n)
    cin>>a[i];
    fn(i,n)
    {
        fs(j,i+1,n)
        sum+=a[i]*a[j];
    }
    cout<<sum;
    return 0;
}








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

int main()
{
    while (true) {
        int m, f, r;
        cin >> m >> f >> r;
        int sum = m + f;
        if ( m == -1 && f == -1 && r == -1) break;
        if ( m == -1 || f == -1) {
            cout << "F";
        } 
        else if (sum >= 80) {
            cout << "A";
        }
        else if (sum >= 65) {
            cout << "B";
        } 
        else if (sum >= 50) {
            cout << "C";
        } 
        else if (sum >= 30) {
            if (r >= 50) cout << "C";
            else cout << "D";
        }
        else if (sum < 30) {
            cout << "F";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3052
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			while (true)
			{
				string s = Console.ReadLine();
				string[] sar = s.Split(' ');
				int H = int.Parse(sar[0]);
				int W = int.Parse(sar[1]);

				if (H == 0 && W == 0) { break;}

				char[] c = new char[W];
				for (int i = 0; i < W; i++)
				{
					c[i] = '.';
				}
				c[0] = '#';
				c[W - 1] = '#';

				for (int i = 0; i < H; i++)
				{
					for (int j = 0; j < W; j++)
					{
						if (i == 0 || i == H - 1) { Console.Write("#");}
						else { Console.Write(c[j]); }
					}
					Console.Write("\n");
				}
				Console.Write("\n");
			}
		}
	}
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{

string S;
	cin >> S;
	bool flag = true;
	if (S.size()==2) {
		if (S[0]==S[1]) {
			doublece(1,2)
		}
		else {
			doublece(-1, -1)
		}

			return 0;
	}

	fx(S.size()-2) {
		if (S[x]==S[x+1]||S[x]==S[x+2]||S[x+1]==S[x+2]) {
			doublece(x + 1, x + 3);
			flag = false;
			break;
		}
	}
	for (int x = S.size() - 1; x >= 2 && flag; x--) {
		if (S[x] == S[x - 1] || S[x] == S[x - 2] || S[x - 1] == S[x - 2]) {
			doublece(x - 1, x + 1);
			flag = false;
			break;
		}
	}
	if (flag) {
		doublece(-1,-1)
	}
    return 0;
}



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

const int MAX_N = 110;
const int MAX_H = 1010;

bool amida[MAX_H][MAX_N][MAX_N];

void solve(int N, int M, int A) {
    int H, P, Q;
    for (int i = 0; i < MAX_H; i++) {
        for (int j = 0; j < MAX_N; j++) {
            for (int k = 0; k < MAX_N; k++) {
                amida[i][j][k] = false;
            }
        }
    }
    int max_h = 0;
    for (int i = 0; i < M; i++) {
        cin >> H >> P >> Q;
        max_h = max(max_h, H);
        amida[H][P][Q] = amida[H][Q][P] = true;
    }
    for (int h = max_h; h >= 1; h--) {
        for (int w = 1; w <= N; w++) {
            if (amida[h][A][w]) {
                A = w;
                break;
            }
        }
    }
    cout << A << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, A;
    while (true) {
        cin >> N >> M >> A;
        if (N == 0 && M == 0 && A == 0) break;
        solve(N, M, A);
    }
    return 0;
}


Measured memory_bytes: 15032
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define str string
#define pb push_back
#define vc vector
#define ci cin
#define co cout
// remove fropen in online judge
int main()
{ 
   // #ifndef ONLINE_JUDGE 
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   // freopen("error.txt","w",stderr);
   //  #endif 

  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
      cin>>a[i];
    ll sum=0;
    for(int i=1;i<n;i++)
    {
      if(a[i]<a[i-1])
      {sum+=(a[i-1]-a[i]);
          a[i]=a[i-1];}
    }
    cout<<sum;
    
}


Measured memory_bytes: 5212
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

vector <int> g;
int n, m, k;
int a[N];
string ss;

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	multiset <int> S;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		S.in(a[i]);
	}
	int ans = 0;
	while (S.size()){
		int x = *S.rbegin();
		S.erase(S.find(x));
		for (int i = 30; i >= 0; i--){
			if (S.find((1ll << i) - x) != S.end()){
				S.er(S.find((1ll << i) - x));
				ans++;
				break;
			}
		}
	}
	cout << ans;
	return 0;
}












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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    double ave = 0;
    vector<int> vec (N);
    for(int i = 0;i < N;i++){
        cin >> vec[i];
        ave += vec[i];
    }
    ave /= N;
    int near;
    double avenear = 999999;
    for(int i = 0;i < N;i++){
        if(abs(ave - vec[i]) < avenear){
            near = i;
            avenear = abs(ave - vec[i]);
        }
    }
    cout << near << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<int> A;
    auto fun = [](int& a, int& b){
        return a > b;
    };
    vector<int> kaburi(1000001,0);
    priority_queue<int, vector<int>, decltype(fun)> dame(fun);
    map<int,int> gyaku;
    int p = N;
    for(int i = 0;i < p;i++){
        int _a;cin>>_a;
        if(gyaku.size() != 0 && gyaku.find(_a) != gyaku.end()){
            N--;
            // cout<<_a<<"?"<<endl;
            kaburi[_a] = 1;
            continue;
        }
        // cout<<_a;
        A.push_back(_a);
        gyaku[_a] = i;
    }
    sort(A.begin(), A.end(), [](int& a, int& b){return a < b;});
    for(int i = 0;i < N;i++){
        gyaku[A[i]] = i;
    }
    int res = 0;
    // cout<<N<<A.size()<<endl;
    for(int i = 0;i < N;i++){
        if(dame.size() != 0 && i == dame.top()){
            dame.pop();
            continue;
        }
        
        // cout<<A[i]<<dame.size()<<endl;
        int a = A[i];
        if(kaburi[A[i]] != 1)res++;
        for(int j = 2;a*j <= 1000000;j++){
            if(gyaku.find(a*j) == gyaku.end())continue;
            dame.push(gyaku[a*j]);
            // cout<<a*j<<"!"<<gyaku[a*j]<<endl;
            gyaku.erase(a*j);
        }

    }
    cout<<res<<endl;
    
}

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

int main() {
	int a,b,c,d;
  	cin >> a >> b >> c >> d;
  
  	int left = max(a,c);
  	int right = min(b,d);
  	int ans = right - left;
  
  	if(ans > 0) {
    	cout << ans << endl;
    }else {
      	cout << 0 << endl;
    }
  	
  
}


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

int main(){
  int a, b;
  cin >> a >> b;
  if ((a == 1)&&(b == 2)){
    cout << 3 << endl;
  }else if((a == 2 )&&(b == 1)){
    cout << 3 << endl;
  }else if ((a == 3)&&(b == 1)){
    cout << 2 << endl;
  }else if ((a == 1) && (b == 3)){
    cout << 2 << endl;
  }else{
    cout << 1 << endl;
  }
}

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

int main(void) {
    int64_t N,M;
    int64_t p;
    string S;
    int64_t wasum = 0;

    unordered_set<int64_t> chk;
    unordered_map<int64_t,int64_t> wa;
    cin >> N >> M;
    for(int i=0;i<M;i++) {
        cin >> p >> S;
        if(S == "WA") {
            if(chk.find(p) != chk.end()) {
            } else {
                wa[p]++;
            }
        } else {
            chk.insert(p);
        }
    }

    // 正解していないwaは除く
    for(auto it:wa) {
        if(chk.find(it.first) != chk.end()) {
            wasum += it.second;
        }
    }
    
    cout << chk.size() << " " << wasum << "\n";
    return 0;
}

Measured memory_bytes: 4388