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

class DisjointSet {
  vector<int> p, r;
  DisjointSet() {}

public:
  DisjointSet(int size) {
    p.resize(size, 0);
    r.resize(size, 0);
    for (int i = 0; i < size; i++) makeSset(i);
  }

  void makeSset(int i) {
    p[i] = i;
    r[i] = 0;
  }

  int same(int a, int b) {
    return (findSet(a) == findSet(b) ? 1 : 0);
  }

  void unite(int a, int b) {
    link(findSet(a), findSet(b));
  }

  void link(int a, int b) {
    if (r[a] < r[b]) {
      p[a] = b;
    } else {
      p[b] = a;
      if (r[a] == r[b]) r[a]++;
    }
  }

  int findSet(int i) {
    int x = i;
    while (i != p[i]) i = p[i];
    return p[i];
  }
};


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

  DisjointSet s(n);

  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com) {
      cout << s.same(x, y) << endl;
    } else {
      s.unite(x, y);
    }
  }
  return 0;  
}

Measured memory_bytes: 1276
n = gets.to_i
a, d = gets.split.map(&:to_i)
m = gets.to_i
ops = (1..m).map { gets.split.map(&:to_i) }
k = gets.to_i
stack = []
until ops.empty?
    x, y, z = ops.pop
    next unless (y..z).include?(k)
    if x == 0
        k = z - (k - y)
    elsif x == 1
        stack << 1
    else
        stack << 2
    end
end
x = a + (k - 1) * d
until stack.empty?
    if stack.pop == 1
        x += 1
    else
        x /= 2
    end
end
p x


Measured memory_bytes: 21288
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,A,B;
    cin>>N>>A>>B;
    string s;
    cin>>s;
    int sum = A + B;
    int currentOverseasStudent = 0;
    int noStudentsPassed = 0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='c'){
            cout<<"No"<<endl;
        }else if(s[i]=='a'){
            if(noStudentsPassed < sum){
                noStudentsPassed++;
                cout<<"Yes"<<endl;
            }else{
                cout<<"No"<<endl;
            }
            
        }else if(s[i]=='b'){
            if(noStudentsPassed < sum && currentOverseasStudent < B){
                currentOverseasStudent++;
                noStudentsPassed++;
                cout<<"Yes"<<endl;
            }else{
                cout<<"No"<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n;
    cin>>n;
    vl as(n);
    cin>>as;

    ll M = -LINF, Mi = -1;
    ll m = LINF, mi = -1;
    rep(i, n) {
        if (as[i] > M) {
            M = as[i];
            Mi = i;
        }
        if (as[n - i - 1] < m) {
            m = as[n - i - 1];
            mi = n - i - 1;
        }
    }

    ll ans = 0;
    rep(i, n) {
        if (i == Mi || i == mi) continue;
        if (as[i] > 0) m -= as[i];
        else M -= as[i];
    }
    ans = M - m;
    cout<<ans<<endl;

    rep(i, n) {
        if (i == mi || i == Mi) continue;
        if (as[i] > 0) {
            cout<<as[mi]<<" "<<as[i]<<endl;
            as[mi] -= as[i];
        }
        else {
            cout<<as[Mi]<<" "<<as[i]<<endl;
            as[Mi] -= as[i];
        }
    }
    cout<<as[Mi]<<" "<<as[mi]<<endl;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
    int K, ans=0;
    cin >> K;
    string s;
    cin >> s;

    for(int i=0; i<K; i++){
	if(i==s.size())
	    break;	    
	cout << s[i];

	if(i!=s.size()-1 && i==K-1)
	    cout << "...";
    }
    cout << endl;
} 




Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int n,m;
struct people
{
	
	int x;
	int d;
};
vector<people> v[100010];
int flag[100010];
int pos[100010];
bool dfs(int index);
int main()
{
	cin>>n>>m;
	int l1,r1,d1;
	int i;
	people p;
	for(i=1;i<=m;i++)
	{
		cin>>l1>>r1>>d1;
		p.x=r1;
		p.d=d1;
		v[l1].push_back(p);
		p.x=l1;
		p.d=-d1;
		v[r1].push_back(p);
	}
	/*for(i=1;i<=n;i++)
	{
		cout<<v[i].size()<<endl;
	}*/
	bool tag;
	for(i=1;i<=n;i++)
	{
		if(v[i].size()!=0 && flag[i]==0)
		{
			flag[i]=1;
			tag=dfs(i);
			if(!tag)
			{
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
	return 0;
}
bool dfs(int index)
{
	int i;
	int temp;
	for(i=0;i<v[index].size();i++)
	{
		temp=v[index][i].x;
		if(!flag[temp])
		{
			flag[temp]=1;
			pos[temp]=pos[index]+v[index][i].d;
			//cout<<temp<<' '<<pos[temp]<<endl;
			bool tag=dfs(temp);
			//cout<<tag<<endl;
			if(!tag)
			{
				return false;
			}
		}
		else
		{
			int w=pos[index]+v[index][i].d;
			if(w!=pos[temp])
			{
				return false;
			}
		}
	}
	return true;
}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;
#define int long long
//template
int ans[530][530];
int N,k=1;
int line(int u,int v,int level){
  u%=k;v%=k;
  if(u>v)swap(u,v);
  if(ans[u][v])return -1;
  ans[u][v]=level;return 0;
}
void f(int s,int M,int d,int cnt){
  for(int j=1;j<=M/2;j+=2)
    for(int i=0;i<k;i+=d)
      if(line(s+i,s+i+j*d,cnt)<0)return;
  if(M==2){
    line(s+d/2,s+3*d/2,cnt);
    return;
  }
  f(s,M/2,d*2,cnt+1);
  f(s+d,M/2,d*2,cnt+1);
}
//main
signed main(){
  cin>>N;
  while(k<N)k<<=1;
  f(0,k,1,1);
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++)cout<<ans[i][j]<<" ";cout<<endl;
  }
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;

void Eratosthenes(ll n,vll &arr,vll &a){
	for(int i = 2; i < n; i++){
		arr[i] = 1;
      a[i]=1;
	}
	for(int i = 2; i < sqrt(n); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < n; j++){
				arr[i *(j + 2)] = 0;
              a[i*(j+2)]=0;
			}
		}
	}
	for(int i = 2; i < n; i++){
		if(arr[i]){
			if(a[(i+1)/2]){
            }
          else{
            arr[i]=0;
          }
		}
	}
}
int main(){
  ll n=100010;
  vll arr(n,0);
  vll a(n,0);
  Eratosthenes(n,arr,a);
  for(int i=1;i<n;i++){
    arr[i]+=arr[i-1];
  }
  ll q;
  cin>>q;
  rep(i,q){
    ll l,r;
    cin>>l>>r;
    COUT(arr[r]-arr[l-1]);
  }
}


Measured memory_bytes: 2176
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using lint = long long;

class UnionFind
{
private:
    std::vector<lint> data;
    std::vector<lint> tree_size;

public:
    UnionFind(lint n)
    {
        data = std::vector<lint>(n);
        tree_size = std::vector<lint>(n, 1);
        for (lint i = 0; i < n; ++i)
        {
            data[i] = i;
        }
    }

    lint root(lint a)
    {
        if (data[a] == a)
            return a;
        else
            return data[a] = root(data[a]);
    }

    lint merge(lint a, lint b)
    {
        lint root_a = root(a);
        lint root_b = root(b);
        if (root_a == root_b)
            return root_a;
        else
        {
            tree_size[root_b] += tree_size[root_a];
            tree_size[root_a] = 0;
            data[root_a] = root_b;
            return root_b;
        }
    }

    lint get_tree_size(lint a)
    {
        return tree_size[root(a)];
    }
};

int main()
{
    lint n, m, k;

    scanf("%lld", &n);
    scanf("%lld", &m);
    scanf("%lld", &k);

    UnionFind uf(n);
    std::vector<lint> friend_num(n, 0);
    std::vector<std::vector<lint>> block(n);

    for (int i = 0; i < m; ++i)
    {
        lint a, b;
        scanf("%lld", &a);
        scanf("%lld", &b);

        uf.merge(a - 1, b - 1);
        friend_num[a - 1]++;
        friend_num[b - 1]++;
    }

    for (int i = 0; i < k; ++i)
    {
        lint c, d;
        scanf("%lld", &c);
        scanf("%lld", &d);

        block[c - 1].push_back(d - 1);
        block[d - 1].push_back(c - 1);
    }

    for (int i = 0; i < n; ++i)
    {
        lint cand = uf.get_tree_size(i);
        cand--; //subtract hisself
        cand -= friend_num[i];
        for (auto bl = block[i].begin(); bl != block[i].end(); bl++)
        {
            if (uf.root(i) == uf.root(*bl))
                cand--;
        }
        printf("%lld ", cand);
    }

    return 0;
}


Measured memory_bytes: 9344
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


template<class T,class F>
bool _mysort(pair<T, F> a, pair<T, F> b) {
    return a.second < b.second;
}

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    vector<pair<int,int> > p(N);
    rep(i,N){
        p[i].first = i+1;
        cin >> p[i].second;
    }
    sort(All(p),_mysort<int,int>);
    rep(i,N){
        cout << p[i].first << " ";
    }
    cout << nn;
    return 0;
}

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

int main(){
  long long n, a[5], v, t;
  cin >> n;
  for(int i = 0; i < 5; i++) cin >> a[i];
  v = *min_element(a,a+5);
  t = (n+v-1)/v;
  cout<<(t + 4)<<endl;
}
  


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
    int N; cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    vector<ll> sum(N + 1);
    rep(i, N) sum[i + 1] = sum[i] + a[i];
    ll mi = LLONG_MAX;
    for (int i = 1; i <= N - 1; i++) {
        ll l = sum[i];
        ll r = sum[N] - sum[i];
        mi = min(mi, abs(l - r));
    }
    cout << mi << endl;
}


Measured memory_bytes: 3328
#include<iostream>

int a,b;

int main(void)
{
	while( std::cin >> a >> b ){
		int i,j;
		for( i = 10, j = 1; ( a + b ) / i >= 1; i *= 10, j++){}

		std::cout << j << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };

 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int H,W; cin >> H >> W;
    int CH,CW,DH,DW; cin >> CH >> CW >> DH >> DW;
    --CH, --CW, --DH, --DW;
    vector<string> G(H);
    for(int i=0;i<H;i++) cin >> G[i];
    
 
    vector<vector<int>> warpCnt(H, vector<int>(W, -1));
    deque<pair<int,int>> q;
    q.push_front({DH, DW});
    warpCnt[DH][DW] = 0;
 
    while(!q.empty()) {
        pair<int,int>  top = q.front(); q.pop_front();
        int curH = top.first, curW = top.second;
        int curCnt = warpCnt[curH][curW];
 
         for(int i=0;i<4;i++) {
            int nh = curH + dy[i], nw = curW + dx[i];
            if(nh >= 0 && nh < H && nw >= 0 && nw < W) {
                if(G[nh][nw] == '.') {
                    if(warpCnt[nh][nw] == -1 || warpCnt[nh][nw] > curCnt) {
                        warpCnt[nh][nw] = curCnt;
                        q.push_front({nh, nw});
                    }
                }
            }
        }
 
        for(int h=-2;h<3;h++) {
           for(int w=-2;w<3;w++){
                if(h == 0 && w == 0) continue;
 
                int nh = curH + h, nw = curW + w;
                if(nh >= 0 && nh < H && nw >= 0 && nw < W && G[nh][nw] == '.') {
                    if(warpCnt[nh][nw] == -1 || warpCnt[nh][nw] > curCnt + 1) {
                        warpCnt[nh][nw] = curCnt + 1;
 
                        q.push_back({nh, nw});
                    }
                }
            }
        }
    }
 
    cout<<(warpCnt[CH][CW]);
}

Measured memory_bytes: 8788
import numpy as np

H = int(input())

candidate = []
for i in range(49):
    candidate.append(2**i)

candidate_array = np.array(candidate).reshape(-1, 1)

for i in range(49):
    if candidate_array[i, 0] > H:
        candidate_select = candidate_array[:i, 0]
        print(np.sum(candidate_select))
        break


Measured memory_bytes: 14444
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main(){
  ll n,m,a[1000000],sum=0,cun=0;
  double b,f;
  cin>>n>>m;
  for(ll i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  b = 1.0 / (4.0*m);
  f = sum * b;
  for(ll i=0;i<n;i++){
    if(a[i]>=f){
      cun++;
    }
  }
  if(cun>=m){
    cout<<"Yes\n";
  }else{
    cout<<"No\n";
  }
  return(0);
}


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

#define REP(i,n) for(i=0;i<n;i++)

//prototype declaration
int iin();
long long llin();
double din();
char cin();
void stin(char *s);
void iout(int i);
void llout(long long i);
void dout(double i);
void cout(char c);
void stout(char *s);
int gcd(int a, int b);
int lcm(int a, int b);
long long llgcd(long long a, long long b);
long long lllcm(long long a, long long b);
int asc(const void *a, const void *b);
int desc(const void *a, const void *b);

//main function
int main() {
    char s[19];
    stin(s);
    s[5] = ' ';
    s[13] = ' ';
    stout(s);
    return 0;
}

//body function
int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

/*
    int型の最大公約数
*/

int gcd(int a, int b) {
    int r;

    if (a < b) {
        r = a;
        a = b;
        b = r;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

/*
    int型の最小公倍数
*/

int lcm(int a, int b) {
    int r = llgcd(a, b);
    a /= r;
    return a * b;
}

/*
    long long型の最大公約数
*/

long long llgcd(long long a, long long b) {
    long long r;

    if (a < b) {
        r = a;
        a = b;
        b = r;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

/*
    long long型の最小公倍数
*/

long long lllcm(long long a, long long b) {
    long long r = llgcd(a, b);
    a /= r;
    return a * b;
}

/*
    int型の昇順用比較関数
*/

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

/*
    int型の降順用比較関数
*/

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}


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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    
    int ans = 0;
    if(B>=C){
        cout << B + C << endl;
    }else{
        if(A+B>=C){
            cout << B + C << endl;
        }else{
            cout << 2*B + A + 1 << endl;
        }
    }
}


Measured memory_bytes: 256
let max_m = 2000

let to_int_list str =
  Str.split (Str.regexp_string " ") str |> List.map int_of_string

let make_dp a n =
  let dp = Array.make_matrix (n + 1) (max_m + 1) false in
  let rec duduwa i j =
    if j > max_m then ()
    else begin
      if dp.(i - 1).(j) then dp.(i).(j) <- true
      else if j > a.(i - 1) && dp.(i - 1).(j - a.(i - 1)) then dp.(i).(j) <- true;
      duduwa i (j + 1)
    end
  in
  let rec doit i =
    if i > n then dp
    else (dp.(i).(a.(i - 1)) <- true; duduwa i 1; doit (i + 1))
  in
  doit 1

let _ =
  let n = read_int () in
  let a = Array.of_list (to_int_list (read_line ())) in
  let _ = read_int () in
  let m = to_int_list (read_line ()) in
  let dp = make_dp a n in
  List.iter (fun e -> Printf.printf "%s\n" (if dp.(n).(e) then "yes" else "no")) m

Measured memory_bytes: 2592
#include <bits/stdc++.h>
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++)
typedef long long ll;

int main(){
	string s;
	cin >> s;
	int n = s.size();
	int ans = 1;
	REP(i,n/2-1){
		if(s.substr(0,i) == s.substr(i,i)) ans = i;
	}
	cout << 2*ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.*;

class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try{
			while(true){
				String line = reader.readLine();
				int n = Integer.parseInt(line);
				if(n==0)break;
				char[] bcon; char[] acon;
				bcon = new char[n];
				acon = new char[n];
				for(int i = 0;i < n;++i){
					line = reader.readLine();
					bcon[i] = line.charAt(0);
					acon[i] = line.charAt(2);
					//System.out.println(bcon[i]+" "+acon[i]);
				}
				line = reader.readLine();
				int m = Integer.parseInt(line);
				for(int i = 0;i < m;++i){
					line = reader.readLine();
					char con  = line.charAt(0);
					int j = 0;
					do{
						if(con == bcon[j]){
							System.out.printf("%c",acon[j]);break;
						}else if(j+1 == n){
							System.out.printf("%c",con);break;
						}
						j++;
					}while(j < n);
					
				}
				System.out.println();
			}
		}catch(IOException e){
				System.out.println(e);
		}
	}
}

Measured memory_bytes: 100248
N = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N):
    for j in range(i):
        for k in range(j):
            if L[i] != L[j] and L[i] != L[k] and L[j] != L[k] and\
                L[k] + L[j] > L[i]:
                cnt += 1
print(cnt)

Measured memory_bytes: 9068
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    string s;
    cin >> s;
    string t=s;
    int ans=1e6;
    int b=0,w=0;
    REP(i,n) if ( s[i]=='.' ) b++;
    chmin(ans,b);
    REP(i,n) {
        if ( s[i]=='.' ) b--;
        else w++;
        chmin(ans, b+w);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 788
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 101010;
int main(){
	 string s;
	 cin>>s;
	 int n=0;
	 for(int i=0;i<s.length();i++){
	 	if(s[i]=='1')n++;
	 }
	 cout<<n;
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){



		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int m = sc.nextInt();
		
		int[] p = new int[m];
		boolean[] s = new boolean[m];
		boolean[] c = new boolean[n];
		int[] isum = new int[n];
		
		int penalty = 0;
		int gain = 0;
		
 		for(int i =0; i<m;i++) {
			p[i]= sc.nextInt();
			if(sc.next().equals("AC")) {
				s[i]=true;
			}else {
				s[i]=false;
			}
		}
 		for(int i =0; i<n;i++) {
			c[i]= false;
			isum[i] = 0;
		}
 		for(int i =0; i<m;i++) {
 			if(!c[p[i]-1]) {
 				if(s[i]) {
 					gain++;
 					c[p[i]-1]=true;
 				}else {
 					isum[p[i]-1]++;
 				}
 			}
		}
 		for(int i =0; i<n;i++) {
			if(c[i]) {
				penalty+=isum[i];
			}
		}
		System.out.println(gain+" "+penalty);
	}
	
}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 65708
n = int(input())
As = list(map(int,input().split(" ")))

As.sort()
if As[-1] % 2 == 0:
    r = As[-1]//2
    l = As[-1] // 2
else:
    r = As[-1] // 2
    l = As[-1] -r

ans = 10e9
for a in As:
    if abs(a-r) < abs ( ans - r ):
        ans = a
    if abs(a-l) < abs ( ans - l ):
        ans = a

print(As[-1],ans)

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

int main() {
	int h, w;

	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (i % 2 == 0 && j % 2 == 0) cout << "#";
				else if (i % 2 == 0 && j % 2 != 0) cout << ".";
				else if (i % 2 != 0 && j % 2 == 0) cout << ".";
				else cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repi(i,a,b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;

int main() {
  int N, M; cin >> N >> M;
  vs A(N); rep(i,N) cin >> A.at(i);
  vs B(M); rep(i,M) cin >> B.at(i);
  
  
  bool exist = false;
 
  for (int ly = 0; ly < N; ly++) {
    for (int lx = 0; lx < N; lx++) {
      if (ly+M-1>=N || lx+M-1>=N) continue;
      
      bool match = true;
      for (int y = 0; y < M; y++) {
        for (int x = 0; x < M; x++) {
          if (A.at(ly+y).at(lx+x) != B.at(y).at(x)) match = false;
        }
      }
      if(match) exist = true;
    }
  }
  
  cout << (exist ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <complex>
#include <iomanip>
#include <random>

using namespace std;

typedef long long ll;
#define int long long

int M = 998244353;
#define msum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define msub(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define mmult(a, b) (((a) * (b)) % M)

typedef long double ld;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vlll;
typedef vector<double> vd;
typedef vector<vd> vdd;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpi;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SZ(a) ((int)(a).size())
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);
const int oo = 1e18 + 100;
const string DIGITS = "0123456789", alph = "abcdefghijklmnopqrstuvwxyz", ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//THE END OF TEMPLATE////////////////////////////////////////////////////////////////////////////////

#define N 100100

vi g[N];
int dp[N];
bool used[N];


void dfs(int v)
{
	dp[v] = 1;
	for (int i = 0; i < g[v].size(); i++)
	{
		int to = g[v][i];
		if (!used[to]) {
			used[to] = true;
			dfs(to);
		}
		inmax(dp[v], dp[to] + 1);
	}
}




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

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
	}


	for (int i = 1; i <= n; i++)
	{
		if (!used[i])
		{
			used[i] = true;
			dfs(i);
		}
	}

	int mx = 0;
	for (int i = 1; i <= n; i++)
		inmax(mx, dp[i]);
	cout << mx - 1;
}

//m1.codeforces.com, m2.codeforces.com или m3.codeforces.com

Measured memory_bytes: 8704
import sys
from collections import deque
import copy
import heapq
import math

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] = [long(input_raw[0]), long(input_raw[1])]
    A_list = []
    B_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [A, B] = [long(input_raw[0]), long(input_raw[1])]
        A_list.append(A)
        B_list.append(B)

    if K == 0:
        value = 0
        for i in range(N):
            if A_list[i] == 0:
                value += B_list[i]
        print value
        exit()
    max_value = 0
    for r in range(int(math.log(K, 2))+1 + 1):
        if ((K>>r) & 0x01) == 1 or r > int(math.log(K, 2)):
            if r <= int(math.log(K, 2)):
                Kr = ((K & ~(0x01<<r)) | ((0x01<<r) - 1))
            else:
                Kr = K
            value = 0
            for i in range(N):

                if (A_list[i] | Kr) == Kr:
                    value += B_list[i]
            max_value = max(max_value, value)

    print max_value



if __name__ == '__main__':
    main()


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

int n, st, mx, a, b, m;
int main()
{
	int i;
	cin >> n >> m;
	mx = n;
	st = 1;
	while (m--) {
		scanf ("%d %d", &a, &b);
		st = max(st, a);
		mx = min(mx, b);
	}
	if (mx < st) cout << 0;
	else cout << mx - st + 1;
    return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SORT(v, n) sort(v, v+n);
#define SSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	string s;

	cin >> s;
	cout << s[0] << s.length()-2 << s[s.length()-1] << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

int sx,sy,tx,ty;

int main(){
    IN sx>>sy>>tx>>ty;
    
    rep(i,0,tx-sx)cout << "R";
    rep(i,0,ty-sy+1)cout << "U";
    rep(i,0,tx-sx+1)cout << "L";
    rep(i,0,ty-sy+1)cout << "D";
    cout << "R";
    rep(i,0,ty-sy)cout << "U";
    rep(i,0,tx-sx+1)cout << "R";
    rep(i,0,ty-sy+1)cout << "D";
    rep(i,0,tx-sx+1)cout << "L";
    cout << "U" << endl;
    
	return  0;
}

Measured memory_bytes: 256
N = int(input())
A = [0]*N
for x in range(1,N):
    for y in range(1,N):
        if x**2 + y**2 + x*y > N:
            break
        for z in range(1,N):
            s = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if s>N:
                break
            A[s-1] = A[s-1]+1
for i in range(N):
    print(A[i])


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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int r,g;
  cin >> r >> g;
  cout << 2*g-r << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

int main() {
    string s = "";
    cin >> s;

    int a = 0;
    int b = 0;
    rep(i, 0, s.size()) {
        if (s[i] == 'A') {
            a++;
        } else {
            b++;
        }
        if (a > 0 && b > 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
include Math
# 入力
X = gets.to_i

# 素数判定関数
def is_prime(n)
  if n == 2
    return true
  end
  cnt = 0
  2.upto Math.sqrt(n).ceil do |i|
    if n % i == 0
      return false
    end
  end
  return n != 1
end

X.upto 10e5 do |i|
  if is_prime(i)
    puts i
    exit
  end
end

Measured memory_bytes: 1788
def toi(a)
	b = []
	a.each do |n|
		b << n.to_i
	end
	b	
end
a = gets().to_i
b = toi(gets().split)
max = b[0]
min = b[0]
sum = b[0]

for n in 1 ... a
sum += b[n]
if max < b[n]
	max = b[n]
end
if min > b[n]
	min = b[n]
end
end

print("#{min} #{max} #{sum}\n")

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

using namespace std;

int si[100010],penal[100010],n,m,p,acpt,pf;
string res;

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

    for(int i=0;i<m;i++){
        cin >> p >> res;
        if(si[p] == 0){
            if(res == "AC"){
                acpt++;
                si[p]++;
                pf += penal[p];
            }else{
                penal[p]++;
            }
        }
    }

    cout << acpt << " " << pf << "\n";
}


Measured memory_bytes: 1024
S=input()
L=len(S)
mod=10**9+7
DP=[0]*13
DP[0]=1

for i in range(L):
    NDP=[0]*13
    POW=pow(10,L-i-1,13)

    #print(POW)

    if S[i]=="?":
        
        for j in range(10):
            plus=POW*j%13

            for k in range(13):
                NDP[(k+plus)%13]=(NDP[(k+plus)%13]+DP[k])%mod

    else:
        plus=POW*int(S[i])%mod

        for k in range(13):
            NDP[(k+plus)%13]=(NDP[(k+plus)%13]+DP[k])%mod
        

    DP=NDP
    #print(DP)

print(DP[5])

Measured memory_bytes: 43372
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef int weight;
typedef vector<weight> array;
typedef vector<array> matrix;

weight minimum_steiner_tree(const vector<int>& T, const matrix &g) {
  const int n = g.size();
  const int numT = T.size();
  if (numT <= 1) return 0;

  matrix d(g); // all-pair shortest
  for (int k = 0; k < n; ++k)
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        d[i][j] = min( d[i][j], d[i][k] + d[k][j] );

  weight OPT[(1 << numT)][n];
  for (int S = 0; S < (1 << numT); ++S)
    for (int x = 0; x < n; ++x)
      OPT[S][x] = INF;

  for (int p = 0; p < numT; ++p) // trivial case
    for (int q = 0; q < n; ++q)
      OPT[1 << p][q] = d[T[p]][q];

  for (int S = 1; S < (1 << numT); ++S) { // DP step
    if (!(S & (S-1))) continue;
    for (int p = 0; p < n; ++p)
      for (int E = 0; E < S; ++E)
        if ((E | S) == S)
          OPT[S][p] = min( OPT[S][p], OPT[E][p] + OPT[S-E][p] );
    for (int p = 0; p < n; ++p)
      for (int q = 0; q < n; ++q)
        OPT[S][p] = min( OPT[S][p], OPT[S][q] + d[p][q] );
  }
  weight ans = INF;
  for (int S = 0; S < (1 << numT); ++S)
    for (int q = 0; q < n; ++q)
      ans = min(ans, OPT[S][q] + OPT[((1 << numT)-1)-S][q]);
  return ans;
}

int main() {
  int w,h;
  while(cin>>h>>w,h||w) {
    vector<int> v;
    int n = w*h;
    matrix g(n,array(n,INF));
    REP(y,h) {
      REP(x,w) {
        bool f;
        cin >> f;
        if (f)
          v.push_back(y*w+x);
        if (y+1<h) {
          g[y*w+x][(y+1)*w+x] = 1;
          g[(y+1)*w+x][y*w+x] = 1;
        }
        if (x+1<w) {
          g[y*w+x][y*w+x+1] = 1;
          g[y*w+x+1][y*w+x] = 1;
        }
        g[y*w+x][y*w+x] = 0;
      }
    }
    cout << n-minimum_steiner_tree(v,g)-1 << endl;
  }
}

Measured memory_bytes: 1112
#![allow(non_snake_case,unused_imports)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;

fn check(N:usize,E:&Vec<Vec<usize>>,i:usize,done:usize) -> usize{
    if done == ((1<<N) -1){
        return 1;
    }
    let mut ans = 0;
    for &j in &E[i]{
        if done>>j &1 == 1 { continue; }
        ans += check(N,&E,j,done | 1<<j);
    }
    ans
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let N:usize = iter.next().unwrap().parse().unwrap();
    let M:usize = iter.next().unwrap().parse().unwrap();
    let mut AB = Vec::new();
    let mut E = Vec::new();
    for _ in 0..N{
        E.push(Vec::new());
    }
    for i in 0..M{
        AB.push((iter.next().unwrap().parse::<usize>().unwrap(),
                 iter.next().unwrap().parse::<usize>().unwrap()));
        E[AB[i].0-1].push(AB[i].1-1);
        E[AB[i].1-1].push(AB[i].0-1);
    }
    println!("{}",check(N,&E,0,1));
}

Measured memory_bytes: 4352
n,m = map(int,input().split())
a = int((m**0.5)//1)
b = 0
if n == 1:
    print(m)
else:
    for i in range(1,a+1):
        if m % i == 0:
            if (m//i) >= n:
                b = max(b,i)
            if i >= n:
                b = max(b,m//i)

    print(b)

Measured memory_bytes: 3188
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	/** 羊の定義 */
	private static final char SHEEP = 'S';
	/** 狼の定義 */
	private static final char WOLF = 'W';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			char[] s = scanner.next().toCharArray();
			boolean[] b = new boolean[n];
			IntStream.range(0, n).forEach(i -> b[i] = (s[i] == 'o'));
			char[] result = new char[n];
			result[0] = SHEEP;
			result[1] = SHEEP;
			if (checkResult(n, b, result)) {
				System.out.println(result);
				return;
			}
			result[0] = SHEEP;
			result[1] = WOLF;
			if (checkResult(n, b, result)) {
				System.out.println(result);
				return;
			}
			result[0] = WOLF;
			result[1] = WOLF;
			if (checkResult(n, b, result)) {
				System.out.println(result);
				return;
			}
			result[0] = WOLF;
			result[1] = SHEEP;
			if (checkResult(n, b, result)) {
				System.out.println(result);
				return;
			}
			System.out.println(-1);
		}
	}

	/**
	 * @param n
	 * @param b
	 * @param result
	 * @return このまま矛盾することなく計算できるかどうか
	 */
	private static boolean checkResult(int n, boolean[] b, char[] result) {
		// 2〜n-1まで動物を計算
		IntStream.range(2, n).forEach(i -> {
			if (WOLF == result[i - 1]) {
				result[i] = (b[i - 1]) ? reverse(result[i - 2]) : result[i - 2];
			} else {
				result[i] = (b[i - 1]) ? result[i - 2] : reverse(result[i - 2]);
			}
		});
		boolean lastOk = false, firstOk = false;
		if (WOLF == result[n - 1]) {
			lastOk = (b[n - 1]) ? (result[0] != result[n - 2]) : (result[0] == result[n - 2]);
		} else {
			lastOk = (b[n - 1]) ? (result[0] == result[n - 2]) : (result[0] != result[n - 2]);
		}
		if (WOLF == result[0]) {
			firstOk = (b[0]) ? (result[1] != result[n - 1]) : (result[1] == result[n - 1]);
		} else {
			firstOk = (b[0]) ? (result[1] == result[n - 1]) : (result[1] != result[n - 1]);
		}
		return lastOk && firstOk;
	}

	/**
	 * @param c
	 * @return cの反対の動物
	 */
	private static char reverse(char c) {
		return (c == SHEEP) ? WOLF : SHEEP;
	}
}


Measured memory_bytes: 40604
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;


int main(void){
    string a;
    cin >> a;
  	for(int i =0; i < a.size(); i++)
      cout << "x";
	cout << endl;
    return 0; 
}   

Measured memory_bytes: 3616
from heapq import heappush, heappop
N = int(input())
s = list(map(int,input().split()))
a, b = s[1], s[2]
L = []
R = []
heappush(L,-a)
heappush(R,a)

bsum = b
t = 0
for k in range(N-1):
    s = input()
    if s[0] == "1":
        s = list(map(int,s.split()))
        a = s[1]
        b = s[2]
        bsum += b
        if -L[0] <= a <= R[0]:
            pass
        else:
            t += min(abs(a+L[0]),abs(a-R[0]))
        heappush(L,-a)
        heappush(R,a)
        if -L[0] > R[0]:
            c = heappop(L)
            d = heappop(R)
            heappush(R,-c)
            heappush(L,-d)
    else:
        print(-L[0], t+bsum)

Measured memory_bytes: 19056
n = int(input())
if n <= 111: print(111)
elif n <= 222: print(222)
elif n <= 333: print(333)
elif n <= 444: print(444)
elif n <= 555: print(555)
elif n <= 666: print(666)
elif n <= 777: print(777)
elif n <= 888: print(888)
elif n <= 999: print(999)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

const int limit = 8;
vector<vbool> graph(limit,vbool(limit));
vbool visited(limit);

int dfs(int v,int n);

int main(){
  ll N,T;
  cin >> N >> T;
  vll A(N);
  ll X = 0;
  rep(i,N){
    cin >> A[i];
    X = max(X,A[i]);
  }
  ll ans = 0;
  ll dp[N+1][N+1][N*X+1];
  //i:何枚まで見ているか
  //j:そのうち何枚選ぶか
  //k:合計値はいくらか
  erep(j,N){
    erep(k,N*X){
      if(j == 0 && k == 0) dp[0][j][k] = 1;
      else dp[0][j][k] = 0;
    }
  }
  erep1(i,N){
    erep(j,N){
      erep(k,N*X){
        if(i > 0 && A[i-1] > k){
          dp[i][j][k] = dp[i-1][j][k];
        }
        else if(i > 0 && j > 0 && k - A[i-1] >= 0){
          dp[i][j][k] = dp[i-1][j-1][k-A[i-1]] + dp[i-1][j][k];
        }
        else{
           dp[i][j][k] = 0;
        }
      }
    }
  }
  /*erep(i,N){
    erep(j,N){
      erep(k,N*X){
        cout << dp[i][j][k];
      }
      cout << endl;
    }
    cout << endl;
  }*/
  erep(j,N){
    erep(k,N*X){
      if(k == j*T){
        ans += dp[N][j][k];
      }
    }
  }
  cout << ans-1 << endl;
}

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

int main(){
	int n;
	string s;
	cin>>n>>s;
	for(int i=0; s[i]; i++){
		int num = (int)(s[i]-'A');
		num+=n;
		num%=26;
		s[i] = (char)(num+'A');
	}
	cout<<s;
}

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

int main() {
  string s;
  cin >> s;
  bool k=true;
  for(int i=0;i<3;i++) {
    if(s.at(i)=='A') {
      continue;
    }
    else if(s.at(1)=='B') {
      break;
    }
    else if(s.at(i)=='B') {
      k=false;
      break;
    }
    else{
    }
  }
  for(int i=0;i<3;i++) {
    if(s.at(i)=='B') {
      continue;
    }
    else if(s.at(1)=='A') {
      break;
    }
    else if(s.at(i)=='A') {
      k=false;
      break;
    }
    else{
    }
  }
  if(k==true) {
    cout << "No" <<endl;
  }
  else {
    cout << "Yes" <<endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
   
using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;
   
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  
  vector<int> a(3 * n);

  rep(i,n*3){
    cin >> a[i];
  }

  sort(all(a));

  int res = 0, cnt = 0;
  for(int i = n*3-2; i >= 0 && cnt < n; i -= 2){
    res += a[i];
    ++cnt;
  }

  cout << res << '\n';

  return 0;
}

Measured memory_bytes: 2560