akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N;
	int[] a;
	public boolean dfs(int n,int left,int right){
		if(n == 10)return true;

		if(right < a[n]){
			boolean ret = dfs(n + 1,left,a[n]);
			if(ret)return true;
		}

		if(left < a[n]){
			boolean ret = dfs(n + 1,a[n],right);
			if(ret)return true;
		}
		return false;
	}

	public void solve() {
		N = nextInt();
		while(N-- > 0){
			a = new int[10];
			for(int i = 0;i < 10;i++){
				a[i] = nextInt();
			}
			out.println(dfs(0,0,0) ? "YES" : "NO");
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 24060
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long x=sc.nextLong();
        long y=sc.nextLong();
        long a=y/x;
        
        int ans=0;
        for(;a>=1;){
            a=a/2;
            ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = 123456;

int a[N];

signed main()
{
    int n,x;
    scanf("%lld %lld",&n,&x);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    int q = 0;
    for(int i=1;i<n-1;i++) {
        if(a[i] + a[i-1] > x){
            int p = a[i] + a[i-1] - x;
            if(p >= a[i]) {
                a[i] = 0;
                p -= a[i];
                a[i-1] -= p;
            } else {
                a[i] -= p;
            }
            q += p;
        }
    }
    if(a[n-2] + a[n-1] > x){
        q += (a[n-2] + a[n-1] - x);
    }
    printf("%lld\n",q);
    return 0;
}


Measured memory_bytes: 1024
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
res = 0
for i in range(1 << h):
    for j in range(1 << w):
        cnt = 0
        for a in range(h):
            for b in range(w):
                if not (i >> a & 1 or j >> b & 1) and c[a][b] == '#':
                    cnt += 1
        if cnt == k:
            res += 1
print(res)


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

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    int N = 0;
    cin >> N;

    vector<int> A(N, 0);
    for (size_t i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    bool approved = true;
    for (size_t i = 0; i < N; i++)
    {
        if ((A[i] % 2 == 1 || (A[i] % 3 != 0 && A[i] % 5 != 0)) && A[i] % 2 == 0)
        {
            approved = false;
            break;
        }
    }

    cout << (approved ? "APPROVED" : "DENIED") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
bool check(int x,int y){return x>=0&&x<4&&y>=0&&y<4;}

int main() {
  int n=8,m=4;
  P d[n];
  while(cin >> d[0].F >> d[0].S) {
    for(int i=1; i<m; i++) cin >> d[i].F >> d[i].S;
    for(int i=0; i<n; i++) {
      if(d[i].F<0) {
        d[i].F*=-1;
        d[i].S*=-1;
      }
      if(d[i].F==0&&d[i].S<0) d[i].S*=-1;
    }
    int ans=0;
    for(int t=0; t<(1<<(n*2)); t++) {
      P a[n];
      for(int i=0; i<n; i++) {
        int x=t/(1<<(i*2));
        x%=4;
        a[i]=d[x];
      }
      int c[m][m];
      memset(c,-1,sizeof(c));
      int k=0;
      for(int i=0; i<m; i++) {
        for(int j=0; j<m; j++) {
          if(c[i][j]==-1) {
            int x=i+a[k].F,y=j+a[k].S;
            if(!check(x,y)||c[x][y]!=-1) goto next;
            c[i][j]=k;
            c[x][y]=k;
            k++;
          }
        }
      }
      ans++;
    next:;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2992
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

template <typename T>
class UnionFind{
    public:
        int n;
        vector<T> p, rank;

        UnionFind(int n)
            : n(n), p(n+1, -1), rank(n+1) {}

        int find(int v){
            if(p[v] == -1){
                return v;
            }
            p[v] = find(p[v]);
            return p[v];
        }

        bool unite(int u, int v){
            u = find(u);
            v = find(v);

            if(u == v){
                return false;
            }

            if(rank[u] < rank[v]){
                swap(u, v);
            }

            if(rank[u] == rank[v]){
                rank[u]++;
            }

            p[v] = u;
            return true;
        }

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

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

    int n;
    cin >> n;
    UnionFind<int> uf(200000);
    rep(i, n){
        int a, b;
        cin >> a >> b;
        uf.unite(a, b + 100000);
    }

    vector<int> x(200001), y(200001);
    for(int i = 1; i <= 100000; i++){
        x[uf.find(i)]++;
    }
    for(int i = 100001; i <= 200000; i++){
        y[uf.find(i)]++;
    }

    int ans = 0;
    rep(i, 200001){
        ans += x[i] * y[i];
    }
    cout << ans - n << endl;

    return 0;
}


Measured memory_bytes: 6528
import bisect

if __name__ == "__main__":
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))
    BB = []
    CC = []

    # print(A)
    # print(B)
    # print(C)
    # print('-------')

    cnt = 0

    for i in range(N):
        b = B[i]
        a_index = bisect.bisect_left(A, b)
        if i == 0:
            BB.append(a_index)
        else:
            BB.append(BB[i-1] + a_index)

    for i in range(N):
        c = C[i]
        b_index = bisect.bisect_left(B, c)
        if b_index == 0:
            CC.append(0)
            continue
        if i == 0:
            CC.append(BB[b_index - 1])
        else:
            CC.append(CC[i-1] + BB[b_index - 1])

    # print(BB)
    # print(CC)

    print(CC[-1])


Measured memory_bytes: 26312
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int fibo(int n){
    if((n==0)||(n==1))return 1;
    else return fibo(n-1) + fibo(n-2);
}

int main(){
    int h, w, k;
    cin >> h >> w >> k;

    vector< vector<long> > pt(h+1, vector<long>(w+1, 0));
    pt.at(0).at(1) = 1;
    for(int i=0;i<h;i++){
        for(int j=1;j<=w;j++){
            if(j>1){
                pt.at(i+1).at(j-1) += (pt.at(i).at(j) * fibo(w-j) * fibo(j-2));
                pt.at(i+1).at(j-1) = pt.at(i+1).at(j-1) % 1000000007;
            }
            if(j<w){
                pt.at(i+1).at(j+1) += (pt.at(i).at(j) * fibo(w-(j+1)) * fibo(j-1));
                pt.at(i+1).at(j+1) = pt.at(i+1).at(j+1) % 1000000007;
            }
            pt.at(i+1).at(j) += (pt.at(i).at(j) * fibo(w-j) * fibo(j-1));
            pt.at(i+1).at(j) = pt.at(i+1).at(j) % 1000000007;
        }
    }

    cout << pt.at(h).at(k) << endl;

    return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

ll cnt(ll x) {
    ll ret = 0;
    while(x > 0) {
        x /= 10;
        ret++;
    }
    return ret;
}

int main() {
    ll n;
    cin >> n;
    ll ans = 9999;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i != 0) {
            continue;
        }
        ll j = n / i;
        ll k = max(cnt(i), cnt(j));
        if (k < ans) {
            ans = k;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    good = [1] * (N+1)
    for _ in range(M):
        a, b = map(int, input().split())
        ha = H[a-1]
        hb = H[b-1]
        if ha > hb:
            good[b] = 0
        elif ha < hb:
            good[a] = 0
        else:
            good[a] = 0
            good[b] = 0
    print(sum(good) - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84464
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int totaldigit(LL angka){
	int ret=0;
	while(angka>0)
	{
		ret++;
		angka/=10;
	}
	return ret;
}
int main()
{
	int ans;
	LL angka;
	cin>>angka;
	for(LL i=1;i*i<=angka;i++)
	{
		if(angka%i!=0)
			continue;
		ans=totaldigit(angka/i);
	}
	cout<<ans<<endl;
}

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

bool check(const char c){
    return(c=='A' or c=='C' or c=='G' or c=='T');
}

int main(void){
    string S;
    cin >> S;

    size_t len{0};

    for(size_t s{0}; s<S.size(); ++s){
        for(size_t n{0}; n<S.size()-s; ++n){

            if(not check(S.at(s+n))){
                break;
            }

            if(n+1>len){
                len = n+1;
            }
        }

    }


    cout << len << endl;
}


Measured memory_bytes: 3548
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            int n = s.length();
            for (int i = 0; i < n; i++) {
                if (i % 2 == 0) {
                    if (!"RUD".contains(Character.toString(s.charAt(i)))) {
                        out.println("No");
                        return;
                    }
                } else if (!"LUD".contains(Character.toString(s.charAt(i)))) {
                    out.println("No");
                    return;
                }
            }
            out.println("Yes");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = m - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  res+=a[0]-1;
  buf=2;
  rep(i,1,n){
    if(a[i]==buf)buf++;
    else res+=(a[i]-1)/buf;
  }
  cout<<res<<endl;
  return 0;
}

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

██╗    ██╗██████╗ ██╗████████╗████████╗███████╗███╗   ██╗    ██████╗ ██╗   ██╗
██║    ██║██╔══██╗██║╚══██╔══╝╚══██╔══╝██╔════╝████╗  ██║    ██╔══██╗╚██╗ ██╔╝
██║ █╗ ██║██████╔╝██║   ██║      ██║   █████╗  ██╔██╗ ██║    ██████╔╝ ╚████╔╝
██║███╗██║██╔══██╗██║   ██║      ██║   ██╔══╝  ██║╚██╗██║    ██╔══██╗  ╚██╔╝
╚███╔███╔╝██║  ██║██║   ██║      ██║   ███████╗██║ ╚████║    ██████╔╝   ██║
 ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝   ╚═╝      ╚═╝   ╚══════╝╚═╝  ╚═══╝    ╚═════╝    ╚═╝

     ███╗   ███╗   ██╗██████╗ ██████╗  █████╗ ██╗  ██╗██╗███╗   ███╗
     ████╗ ████║   ██║██╔══██╗██╔══██╗██╔══██╗██║  ██║██║████╗ ████║
     ██╔████╔██║   ██║██████╔╝██████╔╝███████║███████║██║██╔████╔██║
     ██║╚██╔╝██║   ██║██╔══██╗██╔══██╗██╔══██║██╔══██║██║██║╚██╔╝██║
     ██║ ╚═╝ ██║██╗██║██████╔╝██║  ██║██║  ██║██║  ██║██║██║ ╚═╝ ██║
     ╚═╝     ╚═╝╚═╝╚═╝╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝╚═╝     ╚═╝
*/
#define speed  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(n) for(int i=0;i<n;i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define E "\n"
#define all(e) e.begin(),e.end()
#define F first
#define S second
#define pi (acos(-1))
#define rad(x) ((x*pi)/(ld)(180))
#define perc(x) fixed<<setprecision(x)
/*****
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define rot(p,angle) (p)*polar((double)(1),angle)
#define rot2(p,angle,a) ((p)-(a)) *(polar((ld)(1),angle)+ (a))
#define x real()
#define y imag()
*****/
typedef long long int ll; typedef unsigned long long ull; typedef long double ld;typedef complex<ld> point; typedef tuple<double,double,double> line;
ll gcd(ll x,ll y){if(!y)return x; return gcd(y,x%y);};   ll lcm(ll x,ll y){return (x*y)/__gcd(x,y);}
const int N=3e3+1;
ll dp[N][N],n,k,mod=1e9+7;
string s1,s2;
ll arr[N];

ll solve(int i,int j)
{
    if(dp[i][j] != -1)return dp[i][j];
    if(i == s1.size() or j == s2.size())return 0;

    ll ret ;
    if(s1[i] == s2[j])
        ret = 1 + solve(i+1,j+1);

    else{
        ret = max(solve(i+1,j), solve(i,j+1));
    }
    return dp[i][j] = ret ;
}

void print(int i,int j)
{
    if(i == s1.size() or j == s2.size())
        return;

    ll ret ;
    if(s1[i] == s2[j]){

        cout<< s1[i] ;

        print(i+1,j+1);
    }

    else{

        ll ret2 = solve(i+1,j);
        ret = solve(i,j+1);

        if(ret > ret2)
            print(i,j+1);

        else
            print(i+1,j);
    }
}
int main(){ speed;
memset(dp,-1,sizeof dp);

cin>> s1 >> s2;
solve(0,-1);
//cout<< solve(0,0) << E;
print(0,0);

return 0;}


Measured memory_bytes: 71040
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

ll rep_power_modM(ll a, ll n, ll M = MOD){
    if(n == 0)return 1;
    if(n%2 == 0){ll tmp = rep_power_modM(a,n/2,M); return tmp*tmp%M;}
    return a*rep_power_modM(a,n-1,M)%M;
}

int main(){
	int N,P; cin>>N>>P;
	string s; cin>>s;
	if(10%P == 0){
		ll ans = 0;
		rep(i,N){
			if((s[i]-'0')%P == 0){
				ans += i+1;
			}
		}
		cout<<ans<<endl;
		return 0;
	}
	vector<int> rest(N);
	REP(i,N){
		ll t = s[N-i]-'0';
		rest[i-1] = (t*rep_power_modM(10,i-1, P)) % P;
	}
	vector<int> sum(N+1,0);
	map<ll,ll> cnt;
	cnt[0]++;
	rep(i,N){
		sum[i+1] = (sum[i]+rest[i]) % P;
		cnt[sum[i+1]]++;
	}
	ll ans = 0LL;
	for(auto x:cnt){
		ans += x.second*(x.second-1LL)/2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2564
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_N=10e5,MAX_M=10e5;


struct UnionFind{//MAX_N定義必要要素数
	
	int Par[MAX_N];//親は"-子供(自分含め)"を所持
	int N;
	UnionFind(int n){
		N=n;
		for(int i=0;i<N;i++)
			Par[i]=-1;
	}
	bool unite(int a,int b){
		int par_a=find(a);
		int par_b=find(b);
		if(par_a==par_b)
			return true;
		if(Par[par_a]>Par[par_b])
			swap(par_a,par_b);
		Par[par_a]+=Par[par_b];
		Par[par_b] =par_a;
		return false;
	}
	int find(int a){
		if(Par[a]<0)
			return a;
		else
			return find(Par[a]);
	}
	long sizek(int a){
		if(Par[a]<0)
			return Par[a]*(-1);
		else
			return sizek(Par[a]);
	}
};
/*
UnionFind XX(頂点の数)
XX.unite(a,b);a,b接続  既接続->true  新接続->false
find(a)aの親の番号返却
sizek(a)aの群れの頂点の数返却
*/
int A[MAX_M],B[MAX_M];
long ANS[MAX_M];
int main(void){
	int N,M;
		cin >> N >> M;
	UnionFind uni(N);
	for(int i=0;i<M;i++)
		cin >> A[i] >> B[i];
	ANS[M-1]=(long)N*(N-1)/2;
	
	for(int i=M-1;i>=1;i--){
		A[i]--;B[i]--;
		int ba=uni.find(A[i]);
		int bb=uni.find(B[i]);
		if(ba==bb){
			ANS[i-1]=ANS[i];
			continue;
		}
		long res=uni.sizek(A[i]);
		res*=(long)uni.sizek(B[i]);
		ANS[i-1]=ANS[i]-res;
		uni.unite(A[i],B[i]);
	}
	
	for(int i=0;i<M;i++)
		cout << ANS[i] << endl;
	return 0;
}


Measured memory_bytes: 10624
A, B = input().split()

order = ['2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '1']

if A == B:
  print('Draw')
elif order.index(A) > order.index(B):
  print('Alice')
else:
  print('Bob')

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

using namespace std;

#ifdef Lin1043
    #define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)
    #define massert(...) assert(...)
#else
    #define DEBUG(...)
    #define massert(...)
#endif

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

struct iopener
{
    iopener()
    {
#ifdef Lin1043
        freopen("./in" , "r" , stdin);
#endif
    }
} iop;

typedef long long LL;

template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }

template<typename T>inline T read(T &f)
{
    f = 0; int x = 1 ; char c = getchar();
    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
    return f = x * f;
}

const int N = 100000 + 5;

int n , m , x , y , vis[N] , cnt[N];

int main()
{
    read(n) , read(m);
    vis[1] = 1; // cnt[1] = 1;
    while(m--)
    {
        read(x) , read(y);
        if(vis[x])
        {
            if(cnt[x] == 0) vis[x] = 0;
            vis[y] = 1;
        }
        cnt[x]-- , cnt[y]++;
    }
    int Ans = 0;
    rep(i , 1 , n)
        Ans += vis[i];
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
)

func solve() {
	var N, L int
	fmt.Scan(&N, &L)
	preTaste := N * L + N * (N - 1) / 2

	eps := float64(1000000007)
	var ans float64
	for i := 0; i < N; i++ {
		diff := math.Abs(math.Abs(float64(preTaste)) - math.Abs(float64(preTaste - L - i)))
		if diff < eps {
			eps = diff
			ans = float64(preTaste - L - i + 1)
		}
	}
	fmt.Println(int(ans - 1))
}
func main() {
	solve()
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };
 
typedef long long ll;
using namespace std;
 
int main() {
  int mo[10];
  rep(i,0,10){
    cin >> mo[i];
  }
  sort(mo,mo+10);
  per(i,10,7){
    pout(mo[i]);
  }
  return 0;
}


Measured memory_bytes: 3232
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<bitset>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int N;
int t[20][20]={};//[ステージ][装備]
int dp[10000000];
int main(){
    while(cin>>N,N!=0){
        for(int i=0;i<N;i++){
            for(int j=0;j<=N;j++){
                cin>>t[i][j];
            }
        }
        for(int i=1;i<(1<<N);i++){
            dp[i]=10000000;
        }
        dp[0]=0;
        queue<bitset<20> > q;
        q.push(bitset<20>());
        while(!q.empty()){
            auto now=q.front();q.pop();
            for(int i=0;i<N;i++){
                if(!now[i]){//まだ行っていないなら
                    int minCost=t[i][0];
                    for(int j=0;j<N;j++){
                        if(now[j]){//アイテムが使えるなら
                            minCost=min(minCost,t[i][j+1]);
                        }
                    }
                    bitset<20> tmp=now;
                    tmp[i]=1;//行ったのでbitを立てる
                    int to=tmp.to_ulong();
                    int newCost=dp[now.to_ulong()]+minCost;
                    if(dp[to]>newCost){
                        q.push(to);
                        dp[to]=newCost;
                    }
                }
            }

        }
        
        cout<<dp[(1<<N)-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

/*
  I need to know how many times this subset will happen in the 2^n - 1 subsets
*/

const int maxN = 3e3 + 1; int n, s;
const lli mod = 998244353;
int a[maxN];

lli modPow(lli x, lli y)
{
  lli ans = 1;
  while (y)
  {
    if (y & 1LL) ans = ans * x % mod;
    x = x * x % mod, y >>= 1LL;
  }
  return ans;
}
lli inv(lli x)
{
  return modPow(x, mod - 2);
}

lli memo[maxN][maxN];
lli solve(int i = 0, int sum = 0, int cnt = 0)
{
  if (sum == s) return modPow(2, n - cnt*0);
  if (sum > s || i == n) return 0;
  if (memo[i][sum] != -1) return memo[i][sum];
  lli ans = (solve(i + 1, sum, cnt) % mod + solve(i + 1, sum + a[i], cnt + 1) * inv(2) % mod) % mod;
  return memo[i][sum] = ans;
}

int main()
{
  int t = 0;
  while (scanf("%d %d", &n, &s) != EOF)
  {
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);

    memset(memo, -1, sizeof(memo));
    lli ans = solve();
    printf("%lld\n", ans);
  }
  return 0;
}

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

ll solve() {
    ll N, M, a;
    cin >> N >> M;
    priority_queue<ll> A;
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        A.push(a);
    }
    for ( int i = 0; i < M; i++ ) {
        a = A.top();
        A.pop();
        A.push(a/2);
    }
    ll ans = 0;
    while ( !A.empty() ) {
        ans += A.top();
        A.pop();
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1400
def doSame(n):
	i = 0
	while i <= n:
		i += 1
		cn(i, n)
	print()

def cn(i, n):
	x = i
	if x % 3 == 0:
		if i <= n:
			print(' %d' % (i), end='')
		return
	i3(x, i, n)

def i3(x, i, n):
	if x % 10 == 3:
		if i <= n:
			print(' %d' % (i), end='')
		return
	x = int(x / 10)
	if x > 0:
		i3(x, i, n)

doSame(int(input()))


Measured memory_bytes: 5872
#include<bits/stdc++.h>
                #define ll long long
                #define f   first
                #define s   second
                #define pb          push_back
                #define mod        1000000007
                #define mod1       1000000009
                #define hell        998244353
                #define inf         1000000000000000000LL
                #define pi          3.14159265358979323
                //#define N           100005 
                const int N=200005;
                using namespace std;
                ll n,k,sum,q,res,m,val,ans;
                ll x,y;
                ll xx[]={1,0,-1,0};
                ll yy[]={0,1,0,-1};
                ll cnt[1000005];  
                void solve()    
                {   
                    cin>>n>>k;
                    for(int i=0;i<n;i++)
                    {
                        cin>>x>>y;
                        cnt[x]+=y;
                    }
                    ans=k;
                    for(int i=1;i<1000005;i++)
                    {   //cout<<cnt[i]<<" ";
                        ans-=cnt[i];
                        if(ans<=0) {cout<<i<<"\n";return;}
                    }


                }   
                int main()
                {   ios_base::sync_with_stdio(false);
                    cin.tie(0);cout.tie(0);
                    ll t=1; 
                   //cin>>t;
                     for(ll i=1;i<=t;i++)
                        solve();
                }            

Measured memory_bytes: 4404
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

main = do
 [n]<-readInt
 print $ n^3

Measured memory_bytes: 380
/* ex 9_1
   kohei0713 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//スタックに格納するデータの最大数
#define SIZE 15

//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    stk->top--;
    *(stk->top) = elem;
    stk->count++;
}

//データの取り出し
void pop(stack *stk){
    char latest;
    if(stk->count > 0){
        latest = *(stk->top);
        stk->top++;
        stk->count--;
    }
}

//スタックのデータを古い方から表示させる関数
void print_stack(stack *stk){
    char *key;
    int i;
    key = &(stk->data[SIZE - 1]);
    for(i = 0; i < stk->count; i++){
        printf("%c", *key--);
    }
    printf("\n");
}

int main(void){
    stack stk;
    char key[SIZE];
    int i;

    //スタックを初期化
    initialize_stack(&stk);

    //input
    scanf("%s", key);

    for (i = 0; i < strlen(key); i++){
        if(key[i] == 'B'){
            //スタックからデータを取り出す
            pop(&stk);
        }else{
            //スタックにデータを追加
            push(&stk, key[i]);
        }
    }

    //スタックのデータを古い方から表示
    print_stack(&stk);

    return 0;
}

Measured memory_bytes: 1644
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  int i,j,n;
  int num,d;
  while(1){
    pii p[200];
    cin>>n;
    if(n==0)break;   
    p[0].first=0;
    p[0].second=0;
    rep(i,n-1){
      cin>>num>>d;
      switch(d){
      case 0:p[i+1].first=p[num].first;
       	p[i+1].second=p[num].second-1;break;
 	
      case 1:p[i+1].first=p[num].first+1;
	p[i+1].second=p[num].second;break;
	
      case 2:p[i+1].first=p[num].first;
	p[i+1].second=p[num].second+1;break;
	
      case 3:p[i+1].first=p[num].first-1;
	p[i+1].second=p[num].second;break;
      }
      
      
    }
    
    int max1=-500,max2=-500;
    int min1=500,min2=500;
    rep(i,n){
      max1=max(max1,p[i].first);
      min1=min(min1,p[i].first);
      max2=max(max2,p[i].second);
      min2=min(min2,p[i].second);
    }
    cout<<max2-min2+1<<" "<<max1-min1+1<<endl;
  }
}

Measured memory_bytes: 3068
import itertools
n,m,x=map(int,input().split())
book=[]
for i in range(n):
  book.append(list(map(int,input().split())))
  
ans=-1

for hon in(itertools.product([0,1], repeat=n)):
  hoge=list(hon)
  #print(hoge)
  rikai=[0 for i in range(m+1)]
  for i in range(n):
    if(hoge[i]==1):
      for j in  range(m+1):
        rikai[j]+=book[i][j]
  #print(rikai)
  money=rikai[0]
  rikai=rikai[1:]
  if(min(rikai)>=x):
    if(ans==-1):
      ans=money
    else:
      ans=min(ans,money)
      
print(ans)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;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--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    N--;
    cout << (N + 1) * N / 2 << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 384
A,B=[int(x) for x in input().rstrip().split()]
count=0
for i in range(1,20000):
    ans1=int(0.08*i)
    ans2=int(0.1*i)
    if ans1==A and ans2==B:
        print(i)
        count=1
        break
if count==0:
    print(-1)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true){
      int h = 0;
      int n = Integer.parseInt(sc.next());
      int x = Integer.parseInt(sc.next());
      if(n == 0 && x == 0){
        break;
      }
      for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
          for(int k = j + 1; k <= n; k++){
            //System.out.printf("%d %d %d\n", i, j, k);
            if((i + j + k) == x){
              h += 1;
            }
          }
        }
      }
      System.out.printf("%d\n", h);
    }
  }
}


Measured memory_bytes: 27076
#include <stdio.h>
#include <stdlib.h>
#define ms_valtype int
#define inf (int)(2e9)

int min(int a, int b){
	return a <= b ? a : b;
}

//比較関数
int compare_ms(ms_valtype a, ms_valtype b){
	return a - b;
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

int main(){
	int N, K, Q, i, j, k, l, ans = inf;
	scanf("%d%d%d", &N, &K, &Q);
	int *A = (int *)malloc(sizeof(int) * N);
	int *B = (int *)malloc(sizeof(int) * (N + 1));
	int *C = (int *)malloc(sizeof(int) * N);
	int *D = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	for(i = 0; i < N; i++){
//		printf("i = %d\n", i);
		B[N] = 0;
		for(j = N - 1; j >= 0; j--){
			if(A[j] < A[i]){
				B[j] = 0;
			}
			else{
				B[j] = B[j + 1] + 1;
			}
		}
//		printf("test2\n");
/*		printf("B:\n");
		for(j = 0; j < N; j++){
			printf("%d ", B[j]);
		}
		printf("\n");
*/		for(j = 0; j < N; j++){
			if(B[j] > 0){
				C[j] = A[j];
			}
			else{
				C[j] = -1;
			}
		}
		l = 0;
//		printf("test4\n");
		for(j = 0; j < N; j++){
			if(B[j] > 0){
				sort(&C[j], B[j]);
			}
			for(k = j; k <= j + B[j] - K; k++){
				D[l] = C[k];
				l++;
			}
			j += B[j];
		}
/*		printf("C:\n");
		for(j = 0; j < N; j++){
			printf("%d ", C[j]);
		}
		printf("\n");
		printf("test6\n");
*/		sort(D, l);
//		printf("l = %d\n", l);
/*		printf("D:\n");
		for(j = 0; j < l; j++){
			printf("%d ", D[j]);
		}
		printf("\n");
*/		if(l >= Q){
			ans = min(ans, D[Q - 1] - A[i]);
		}
//		printf("ans = %d\n", ans);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(a) a.begin(), a.end()

signed main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n, W;
	cin >> n >> W;
	vector <int> v(n + 1), w(n + 1);

	for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];

	int dp[W + 10][n + 10];
	
	for(int row = 0; row < W + 10; row++) {
		dp[row][0] = 0;
	}

	for(int row = 0; row < n + 10; row++) {
		dp[0][row] = 0;
	}

	//row = wt, col = n

	for(int row = 1; row <= W; row++) {
		for(int col = 1; col <= n; col++) {
			if(row - w[col] >= 0) {
				dp[row][col] = max(dp[row - w[col]][col - 1] + v[col], dp[row][col - 1]);
			} else {
				dp[row][col] = dp[row][col - 1];
			}
		}
	}


	cout << dp[W][n] << endl;


	return 0;
}

Measured memory_bytes: 89508
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((numba.types.optional(i8), ) * 2, cache=True)
def seg_f(x, y):
    if x is None:
        return y
    if y is None:
        return x
    return max(x, y)


@njit((i8[:], ), cache=True)
def build(raw_data):
    N = len(raw_data)
    seg = np.empty(N + N, np.int64)
    seg[N:] = raw_data
    for i in range(N - 1, 0, -1):
        seg[i] = seg_f(seg[i << 1], seg[i << 1 | 1])
    return seg


@njit((i8[:], i8, i8), cache=True)
def set_val(seg, i, x):
    N = len(seg) // 2
    i += N
    seg[i] = x
    while i > 1:
        i >>= 1
        seg[i] = seg_f(seg[i << 1], seg[i << 1 | 1])


@njit((i8[:], i8, i8), cache=True)
def fold(seg, l, r):
    vl = vr = None
    N = len(seg) // 2
    l, r = l + N, r + N
    while l < r:
        if l & 1:
            vl = seg_f(vl, seg[l])
            l += 1
        if r & 1:
            r -= 1
            vr = seg_f(seg[r], vr)
        l, r = l >> 1, r >> 1
    return seg_f(vl, vr)


@njit((i8[:], i8, i8), cache=True)
def max_right(seg, l, x):
    """とりあえず愚直"""
    N = len(seg) // 2

    def is_ok(v, x):
        return v >= x

    ng, ok = l, N + 1
    while ng + 1 < ok:
        mid = (ok + ng) // 2
        if is_ok(fold(seg, l, mid), x):
            ok = mid
        else:
            ng = mid
    return ok

@njit((i8, i8[:], i8[:]), cache=True)
def main(N, A, query):
    seg = build(A)
    for i in range(0, len(query), 3):
        t, a, b = query[i:i + 3]
        if t == 1:
            set_val(seg, a - 1, b)
        elif t == 2:
            print(fold(seg, a - 1, b))
        elif t == 3:
            print(max_right(seg, a - 1, b))

N, Q = map(int, readline().split())
A = np.array(readline().split(), np.int64)
query = np.array(read().split(), np.int64)

main(N, A, query)

Measured memory_bytes: 140720
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        if((a<b)&&(b<c))System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 17160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
string s;
int x,y,cnt;
vector<int>a,b;
bool f,dp[8010][16010],DP[8010][16010];
int main(){
	cin>>s>>x>>y;
	rep(i,s.size()){
		if(s[i]=='T'){
			if(!f)a.push_back(cnt);
			else b.push_back(cnt);
			f^=1;
			cnt=0;
		}
		else cnt++;
	}
	if(cnt){
		if(!f)a.push_back(cnt);
		else b.push_back(cnt);
    }
	//Start:8010
	dp[0][8010]=1;
	bool B=1;
	if(s[0]=='T')B=0;
	rep(i,a.size()){
		for(int j=8010-s.size();j<=8010+s.size();j++){
			if(dp[i][j]){
				if(j-i>=0&&dp[i][j]&&!B)dp[i+1][j-a[i]]=1;
				dp[i+1][j+a[i]]=1;
			}
		}
		B=0;
	}
	DP[0][8010]=1;
	rep(i,b.size()){
		for(int j=8010-s.size();j<=8010+s.size();j++){
			if(DP[i][j]){
				if(j-i>=0&&DP[i][j])DP[i+1][j-b[i]]=1;
				DP[i+1][j+b[i]]=1;
			}
		}
	}
	if(dp[a.size()][8010+x]&&DP[b.size()][8010+y])puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 125696
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;

int main(){

	int n, a[200000], b[200000];
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	int s=n/2;
	for(int i=0; i<n; i++){
		s+=i*pow(-1, i);
		b[s]=a[i];
	}
	if(n%2==0){
		for(int i=0; i<n; i++){
			cout << b[i] <<" ";
		}
	} else {
		for(int i=n-1; 0<=i; i--){
			cout << b[i] <<" ";			
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
//~ #define MOD 1000000007
#define MOD 1000003
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main(){
	string s;cin>>s;
	int d=count(s.begin(),s.end(),'o');
	if(d+15-s.size()>=8)puts("YES");
	else puts("NO");
}

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

using namespace std;

int main() {
    ll N;
    ll M;
    cin >> N >> M;
    graph G(N + M);
    bool seen[N + M];
    for(int i = 0; i < (N + M); i++){
        G[i] = vector<ll>(0);
        seen[i] = false;
    }
    for(int i = 0; i < N; i++){
        ll K;
        cin >> K;
        for(int j = 0; j < K; j++){
            ll L;
            cin >> L;
            G[i].push_back(N - 1 + L);
            G[N - 1 + L].push_back(i);
        }
    }

    queue<ll> q = queue<ll>();
    q.push(0);
    seen[0] = true;
    while(q.empty() == false){
        ll current = q.front(); q.pop();
        for(int i = 0; i < G[current].size(); i++){
            ll next = G[current][i];
            if(seen[next]){
                continue;
            }
            seen[next] = true;
            q.push(next);
        }
    }
    for(int i = 0; i < (N); i++){
        if(seen[i] == false){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    string s;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    cin >>s;
    if (s == "ABC")
        cout <<"ARC";
    else
        cout <<"ABC";



    return 0;
}


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

s=[None]*m
c=[None]*m
t='a'*n
for i in range(m):
    s[i],c[i]=map(int,input().split())

for i in range(m):
    if t[s[i]-1]=='a':
        t=t[:s[i]-1]+str(c[i])+t[s[i]:]
    
    elif t[s[i]-1]==str(c[i]):
        continue
    else:
        print(-1)
        break
else:
    if n==1:
        if t[0]=='a':
            t=t[:0]+'0'+t[1:]
    elif n==2:
        if t[0]=='a':
            t=t[:0]+'1'+t[1:]
        if t[1]=='a':
            t=t[:1]+'0'+t[2:]
    elif n==3:
        if t[0]=='a':
            t=t[:0]+'1'+t[1:]
        if t[1]=='a':
            t=t[:1]+'0'+t[2:]
        if t[2]=='a':
            t=t[:2]+'0'+t[3:]
    if n>=2:
        if t[0]=='0':
            print(-1)
        else:
            print(int(t))
    else:
        print(int(t))
    
    
        





Measured memory_bytes: 9132
import numpy as np
N = int(input())
lst =  np.array([list(map(int,input().split())) for i in range(N)])
A = np.array([lst[i][0] for i in range(N)])
B = np.array([lst[i][1] for i in range(N)])
AB = np.array([A[i] + B[i] for i in range(N)])

loop = np.insert(lst,0,AB,axis=1)
loop = loop[loop[:,0].argsort()[::-1], :]
#loop = sorted(lst,reverse=True)

sumA = [i[1] for i in loop[0::2]]
sumB = [i[2] for i in loop[1::2]]

#print(lst)
#print(A)
#print(B)
#print(loop)
#print(sumA)
#print(sumB)

#print(loop)
print(sum(sumA)-sum(sumB))

Measured memory_bytes: 37912
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  ll a[n+1]={};
  ll p[n+1]={};
  set<ll> Set;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    p[a[i]]=i;
  }

  Set.insert(0);
  Set.insert(n+1);
  ll ans=0;

  for(int i=1;i<=n;i++){
    set<ll>::iterator it;
    it=Set.lower_bound(p[i]);
    ll r=*it;
    it--;
    ll l=*it;
    ans+=(p[i]-l)*(r-p[i])*i;
    Set.insert(p[i]);
  }

  cout<<ans<<endl;

  return 0;
}


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

int main()
{
    char s[3];
    int a=0,b=0;
    for(int i=0;i<3;i++)
    {
        cin>>s[i];
    }
        if((s[0]==s[1]) && (s[0]==s[2]) && (s[2]==s[1]))
           {
               a++;
           }
           else{
            b++;
           }
    if(a>b)
    {
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
    return 0;
}


Measured memory_bytes: 256
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
inline void modAdd(int& _a, int _b, int _m) { _a = (_a + _b) % _m; }
inline void modAdd(lint& _a, lint _b, lint _m) { _a = (_a + _b) % _m; }
inline void minUpdate(int& _a, int _b) { _a = min(_a, _b); }
inline void minUpdate(lint& _a, lint _b) { _a = min(_a, _b); }
inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }
inline void maxUpdate(lint& _a, lint _b) { _a = max(_a, _b); }

int n;

void rec(int x, Array& v, int sum) {
	if (sum > n) return;
	
	int len = size_of(v);
	
	if (sum == n) {
		for_(i,0,len) {
			if (i < len - 1) cout << v[i] << " ";
			else cout << v[i] << endl;
		}
	}

	for_rev(i,x,1) {
		if (len > 0 && v[len - 1] < i) continue;
		v.push_back(i);
		rec(i, v, sum + i);
		v.pop_back();
	}
}

void solve() {
	Array v;
	rec(n, v, 0);
}

int main() {
	while (cin >> n, n) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1220