akhauriyash/Code-Regression huggingface dataset:
// code gen begin
// -------------------------
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func unUsedFunction() string {
	return "I am unused unexported function"
}
func UnUsedFunction() string {
	return "I am unused exported function"
}
func swap(a int, b int) (int, int) {
	return b, a
}
func (u UnionFind) Size(x int) int {
	return -u.par[u.Find(x)]
}
func (u UnionFind) Same(x, y int) bool {
	return u.Find(x) == u.Find(y)
}
func (u UnionFind) Union(x, y int) {
	xr := u.Find(x)
	yr := u.Find(y)
	if xr == yr {
		return
	}
	if u.Size(yr) > u.Size(xr) {
		yr, xr = swap(yr, xr)
	}
	u.par[yr] += u.par[xr]
	u.par[xr] = yr
}
func (u UnionFind) Find(x int) int {
	if u.par[x] < 0 {
		return x
	}
	u.par[x] = u.Find(u.par[x])
	return u.par[x]
}
func NewUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.par = make([]int, N)
	for i := range u.par {
		u.par[i] = -1
	}
	return u
}

type UnionFind struct{ par []int }

func ModPow() int64 {
	return int64(math.Max(1, 3))
}
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var n, m int
	fmt.Fscan(r, &n, &m)
	uf := NewUnionFind(n)
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Fscan(r, &a, &b)
		a--
		b--
		uf.Union(a, b)
	}
	ans := 0
	for i := 0; i < n; i++ {
		if ans < uf.Size(i) {
			ans = uf.Size(i)
		}
	}
	fmt.Fprintln(w, ans)
}
// -------------------------
// code gen end

Measured memory_bytes: 32816
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ans := n - 1
	for i := 1; i*i <= n; i++ {
		if n%i != 0 {
			continue
		}
		if v := i - 1 + (n / i) - 1; v < ans {
			ans = v
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
N = int(input())
S = list(input())
r = []
g = []
b = []
for i in range(N):
    if S[i] == 'R':
        r.append(i)
    elif S[i] == 'G':
        g.append(i)
    else:
        b.append(i)

r_kazu = len(r)
g_kazu = len(g)
b_kazu = len(b)

A = r_kazu * g_kazu * b_kazu

#print(A)

for i in range(N+1):
    for j in range((N-i+1)//2):
        if S[i] != S[i+j]:
            if S[i+j] != S[i+j+j]:
                if S[i+j+j] != S[i]:

                    A -= 1


print(A)
    

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(N);
  REP(i, N) { cin >> A.at(i); }
  int ans = 1 << 29;
  int sum = 0;

  REP(i, M) {
    if (A.at(i) < X) {
      ++sum;
    }
  }
  ans = min(ans, sum);

  sum = 0;
  REP(i, M) {
    if (A.at(i) > X) {
      ++sum;
    }
  }
  ans = min(ans, sum);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
X, K, D = [int(x) for x in input().split()]
if(D*K+X)>0:
  if(X-D*K)>=0:
    print(X-D*K)
  else:
    x = int((D*K+X) // (2*D))
    ans0 = abs(-2*D*(x-1)+(D*K+X))
    ans1 = abs(-2*D*x+(D*K+X))
    ans2 = abs(-2*D*(x+1)+(D*K+X))
    ans3 = abs(-2*D*(x+2)+(D*K+X))
    print(min(ans0, ans1, ans2, ans3))
elif(D*K+X)<=0:
  print(abs(D*K+X))

Measured memory_bytes: 9152
s = input()
b = int(s[:2])
a = int(s[-2:])
if 1 <= b <= 12 and 1 <= a <= 12:
    print("AMBIGUOUS")
elif 1 <= b <= 12:
    print("MMYY")
elif 1 <= a <= 12:
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 2940
N, M = [int(i) for i in input().strip().split()]
A=[]
for i in range(M):
    A.append(input().strip().split())
B =[]
for i in range(M):
    B.append(int(A[i][0]))
    B.append(int(A[i][1]))
for i in range(N):
    print(B.count(i+1))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

struct edge{
    edge(){};
    edge(ll f, ll t, ll c):f(f), t(t), c(c){};
    ll f, t, c;
};

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

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}


int main(){
    ll n,m; cin >> n >> m;
    ll s,t; cin >> s >> t;
    s--;t--;
    vector<vector<edge>> snuke(n), yen(n);
    rep(i,m){
        ll u,v; cin >> u >> v;
        u--;v--;
        ll a,b; cin >> a >> b;
        snuke[u].emplace_back(edge(u,v,b));
        snuke[v].emplace_back(edge(v,u,b));
        yen[u].emplace_back(edge(u,v,a));
        yen[v].emplace_back(edge(v,u,a));
    }

    auto dijkstra = [&](ll s, ll t, vector<vector<edge>> &graph){
        vector<ll> res(n,INF);
        priority_queue<Pll, vector<Pll>, greater<Pll>> pq;
        pq.push(Pll(0,s));

        res[s] = 0;
        // bitset<n_max> bs(0);
        while(!pq.empty()) {
            Pll p = pq.top();pq.pop();
            if(res[p.second] < p.first)continue;
            for(auto &e : graph[p.second]){
                if(p.first + e.c < res[e.t]){
                    res[e.t] = p.first + e.c;
                    pq.push(Pll(e.c + p.first, e.t));
                }
            }
            // if(bs.count() == n)break;
        }

        return res;
    };

    vector<ll> snu_path = dijkstra(t,s, snuke), yen_path = dijkstra(s,t,yen);
    vector<ll> ans(n);

    // print(snu_path);
    // print(yen_path);
    ll snu = 1e15;
    ll pre = 0;
    for(int i = n-1; 0 <= i; i--){
        chmax(pre, snu - (snu_path[i] + yen_path[i]));
        ans[i] = pre;
    }

    for(auto i : ans)cout << i << "\n";
}

Measured memory_bytes: 21836
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  string t;
  cin >> t;
  rep(i,t.size()){
    if(t.at(i) == '?') t.at(i) = 'D';
  }
  cout << t << endl;
}


Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

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

    int N = atoi(s.c_str());

    long long a = 1;

    bool overflow = false;

    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        long long x = atoll(s.c_str());

        if (x == 0) {
            a = 0;
            break;
        }

        if (overflow)
            continue;

      {
        bool f = (double)a <= 1000000000000000000.0 / (double)x; // a*x が 10^18 を超えないなら OK
        if (!f) {
            overflow = true;
            continue;
        }
      }
        a *= x;
        // 境界部の再チェック
      {
        bool f = a <= 1000000000000000000;
        if(!f){
          overflow = true;
          continue;
        }
      }
    }

    if (overflow && a != 0) {
        cout << -1 << endl;
    } else {
        cout << a << endl;
    }

    return 0;
}

Measured memory_bytes: 3120
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int d[101][101];
int s[1000][3];
int main(void){
	int n=nextint();
	int m=nextint();
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			if(i!=j){
				d[i][j]=INT_MAX;
			}
		}
	}
	for(int i=0; i<m; i++){
		int a=s[i][0]=nextint();
		int b=s[i][1]=nextint();
		int c=s[i][2]=nextint();
		d[a][b]=c;
		d[b][a]=c;
	}
	for(int k=1; k<=n; k++){
		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				if(d[i][k]!=INT_MAX && d[k][j]!=INT_MAX && d[i][j]>d[i][k]+d[k][j])
					d[i][j]=d[i][k]+d[k][j];
			}
		}
	}
	int ans=0;
	for(int k=0; k<m; k++){
		int a=s[k][0];
		int b=s[k][1];
		int c=s[k][2];
		bool f=false;
		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				if(d[i][a]!=INT_MAX && d[b][j]!=INT_MAX && d[i][j]==d[i][a]+c+d[b][j])
					f=true;
			}
		}
		if(!f) ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
Module Module1

    Sub main()
        Dim user2 As List(Of String) = New List(Of String)(Split(Console.ReadLine(), " "))
        Dim rangeA As Long = user2(0)
        Dim rangeB As Long = user2(1)
        Dim timeA As Long = user2(2)
        Dim timeB As Long = user2(3)

        ' 中心の角度を求める
        Dim arc As Double = (60 * timeA + timeB) * 0.5 - timeB * 6
        arc = arc - 2 * (arc - 180)
        'Console.WriteLine("角度：" & arc)

        ' 辺の長さを求める
        Dim ans = rangeA ^ 2 + rangeB ^ 2 - 2 * rangeA * rangeB * Math.Cos(arc * Math.PI / 180)

        'Console.WriteLine(ans)
        ans = Math.Sqrt(ans)

        Console.WriteLine(ans)
    End Sub
End Module

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W;
char C[405][405];
bool visited[405][405];
int di[4] = {0, 1, 0, -1}, dj[4] = {1, 0, -1, 0};
ll ans = 0, b = 0, w = 0;

int Solve(int i, int j){
  b = 0; w = 0;
  if (C[i][j] == '.') w++;
  else b++;
  visited[i][j] = true;

  queue <Pii> que; que.push({i, j});
  while (!que.empty()){
    Pii Q = que.front(); que.pop();
    for (int k = 0; k < 4; k++){
      int I = Q.fi + di[k], J = Q.se + dj[k];
      if (0 <= I && I < H && 0 <= J && J < W){
        if (visited[I][J]) continue;
        if (C[I][J] == C[Q.fi][Q.se]) continue;
        
        que.push({I, J});
        visited[I][J] = true;
        if (C[I][J] == '.') w++;
        else b++;
      }
    }
  }

  ans += b * w;
  return 0;
}


int main(){
  cin >> H >> W;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> C[i][j];
    }
  }

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (!visited[i][j]) Solve(i, j);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
int main(){
	int H,W,i,j;
	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==0  || i==H-1 || j==0 || j==W-1){
            cout<<"#";
        } else {
            cout<<".";
        }
    }
    cout<<endl;
}
cout<<endl;
}return 0;
}



Measured memory_bytes: 3088
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int main(){
	ll n;
	cin >> n;
	multiset<ll> S;
	ll b[n];
	rep(i,n){
		ll a;
		cin >> a;
		b[i]=a;
		S.insert(a);
	}
	ll tot=0;
	ll d[200005];
	rep(i,200001){
		ll m=S.count(i);
		d[i]=m;
		tot+=m*(m-1)/2;
	}
	rep(i,n){
		ll ans=tot;
		ll e=d[b[i]];
		ans-=(e-1)*e/2;
		ans+=(e-1)*(e-2)/2;
		cout<<ans<<endl;
	}
    return 0;
}



Measured memory_bytes: 15232
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
if b.count(0)==n:
    print("Yes")
elif n%3==0:
    if b.count(0)==n//3 and b.count(b[n-1])==n-(n//3):
        print("Yes")
    elif b[0]^b[n//3]^b[n-1]==0 and b.count(b[0])==n//3 and b.count(b[n//3])==n//3 and b.count(b[n-1])==n//3:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 60784
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
typedef long long ll;

int main(){
    ll n,a,b; cin >> n >> a >> b;
    cout << n/(a+b)*a+min(a,n%(a+b)) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

struct UnionFind {
#define rep(i,n) for (int i=0; i < int(n); i++)
  vector<int> par;
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }

  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y) return;

    if (sizes[x] < sizes[y]) swap(x, y);

    par[y] = x;
    sizes[x] += sizes[y];
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int x) {
    return sizes[find(x)];
  }

  int count() {
    vector<int> p = par;
    sort(p.begin(), p.end());
    return unique(p.begin(), p.end()) - p.begin();
  }
#undef rep
};


const int N = 1001;

int main()
{
    for (;;) {
        int v, d;
        if (scanf("%d %d", &v, &d) != 2)
            break;

        vector<int> f(v);
        f[0] = 2;
        f[1] = 3;
        for (int i = 2; i < v; ++i)
            f[i] = (f[i - 2] + f[i - 1]) % N;
        sort(f.begin(), f.end());
        f.erase(unique(f.begin(), f.end()), f.end());

        UnionFind uf(f.size());
        for (int i = 1; i < f.size(); ++i)
            if (f[i] - f[i - 1] < d)
                uf.unite(i - 1, i);

        printf("%d\n", uf.count());
    }
    return 0;
}

Measured memory_bytes: 1052
class Uf:
    def __init__(self, N):
        self.p = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def root(self, x):
        if self.p[x] != x:
            self.p[x] = self.root(self.p[x])

        return self.p[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        u = self.root(x)
        v = self.root(y)

        if u == v: return

        if self.rank[u] < self.rank[v]:
            self.p[u] = v
            self.size[v] += self.size[u]
            self.size[u] = 0
        else:
            self.p[v] = u
            self.size[u] += self.size[v]
            self.size[v] = 0

            if self.rank[u] == self.rank[v]:
                self.rank[u] += 1

    def count(self, x):
        return self.size[self.root(x)]

n,m=map(int,input().split())

x=[]
y=[]
z=[]
for i in range(m):
    p,q,r=map(int,input().split())
    x.append(p-1)
    y.append(q-1)
    z.append(r)

cost=0

uf=Uf(n)
for i in range(m):
    uf.unite(x[i],y[i])
cnt=set()
for i in range(n):
    tmp=uf.root(i)
    cnt.add(tmp)

print(len(cnt))





Measured memory_bytes: 23476
#include<iostream>
using namespace std;
int main(){
  int a,b,c,tar;
  int cnt=0;
  cin>>a>>b>>c>>tar;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++)
      {
        if(500*i+100*j+50*k==tar)cnt++;
      }
    }
  }
  cout<<cnt<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};

int dp[5001][5001];

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::string s; std::cin >> s;
  rep(i, 0, n) rep(j, i + 1, n)
    { dp[i][j] = s.at(i) == s.at(j); }
  loop(30) {
    rep(i, 0, n + 1) rep(j, i + 1, n) {
      auto& crr = dp[i][j];
      crr += dp[i + crr][j + crr];
    }
  }
  auto ret = 0;
  rep(i, 0, n + 1) rep(j, i + 1, n + 1)
    { cmx(ret, std::min(dp[i][j], j - i)); }
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 96768
#include <iostream>
#include <cstdio>
using namespace std;
int h,w;
int m[10][10];
int main(void){
   scanf("%d%d",&h,&w);
   for(int i=0;i<h;i++){
       for(int j=0;j<w;j++){
           char c;
           scanf(" %c",&c);
           if(c=='#')m[i][j]=1;
       }
   }
   bool ok=true;
   int x=0,y=0;
    while(ok){
        m[y][x]=0;
        if(x==w-1&&y==h-1)break;
        if(y+1<h&&m[y+1][x]==1){
            if(x+1<w&&m[y][x+1]==1)ok=false;
            else y++;
        }else if(x+1<w&&m[y][x+1]==1){
            if(y+1<h&&m[y+1][x]==1)ok=false;
            else x++;
        }else ok=false;
    }
    for(int i=0;i<h&&ok;i++){
        for(int j=0;j<w&&ok;j++){
            if(m[i][j])ok=false;
        }
    }
    if(ok)printf("Possible\n");
    else printf("Impossible\n");
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll a(n) ;
	for(int i=0;i<n;i++) cin >> a.at(i) ;
	mysort(a) ;
	vll sum(n) ;
	sum.at(0) = a.at(0) ;
	for(int i=1;i<n;i++){
		sum.at(i) = sum.at(i-1)+a.at(i) ;
	}
	for(int i=n-2;i>=0;i--){
		if(sum.at(i)*2<a.at(i+1)){
			cout << n-i-1 << endl ;
			return 0 ;
		}
	}
	cout << n << endl ;
}


Measured memory_bytes: 1792
def bfs(n):
    graph = [[] for i in range(N)]

    for i in range(n):
        v, u = map(int, input().split())
        graph[v-1].append(u-1)
        graph[u-1].append(v-1)
    
    root = [i for i in range(N)]
    visited = [False] * N
    
    for i in range(N):
        if not visited[i]:
            q = graph[i]
            visited[i] = True
            
            while q:
                v = q.pop()
                root[v] = i
                visited[v] = True
                for u in graph[v]:
                    if not visited[u]:
                        visited[u] = True
                        q.append(u)
                        root[u] = i
                        
    return root

def main():
    load_root = bfs(K)
    train_root = bfs(L)
    
    count = {}
    
    city = [(i, j) for i, j in zip(load_root, train_root)]
    
    for c in city:
        if c in count:
            count[c] += 1
        else:
            count[c] = 1
            
    for c in city:
        print(count[c], '', end='')

if __name__ == '__main__':
    N, K, L = map(int, input().split())
    main()

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

#define int int64_t

signed main() {
  int n, m; cin >> n >> m;
  int extime = m*1900 + (n-m)*100;
  double failprob = pow(0.5, m);
  cout << int(extime/failprob + 0.5) << '\n';
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
	int i,j,flag = 0;
	char s[28];
	scanf("%s",s);
	for(i = 0;s[i] != '\0';i++)
	{
		for(j = 0;s[j] != '\0';j++)
		{
			if(i != j && s[i] == s[j])
			{
				flag = 1;
				break;
			}
		}
	}
	if(flag == 0)
		printf("yes\n");
	else
		printf("no\n");
	return 0;
}


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

using namespace std;

typedef pair<int,int> P;
typedef long long ll; 

#define int ll

main(){
	string s;
	cin >> s;

	if(s.length()==2){
		cout << s << endl;
	}else{
		cout << s[2] << s[1] << s[0] << endl;
	}

	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for (int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clar(a, b) memset((a), (b), sizeof(a))
#define debug(...) fprintf(stderr, __VA_ARGS__)
template <typename T> bool chkmax(T &a, const T &b) { return a < b ? a = b, true : false; }
template <typename T> bool chkmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template <typename T> T getSign(const T&a) { return (a > T(0)) - (a < T(0)); }
typedef long long LL;
typedef long double LD;
const double pi = acos(-1);
void procStatus() {
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}
int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1;
	for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
	return x * flag;
}
void write(LL x) {
	if (x < 0) putchar('-'), x = -x;
	if (x >= 10) write(x / 10);
	putchar(x % 10 + '0');
} 

const int Maxn = 2e5 + 9, Mod = 1e9 + 7;
struct edge {
	int to, nxt;
}g[Maxn << 2];
int n, head[Maxn];

void add(int u, int v) {
	static int e = 0;
	g[++e] = (edge){v, head[u]}, head[u] = e;
}

int dep[Maxn], son[Maxn], top[Maxn], size[Maxn], maxDep[Maxn], sed[Maxn], power[Maxn];
int localdep[Maxn];
void Init() {
	clar(head, -1), clar(son, -1);

	n = read();
	rep (i, 1, n) {
		int u = read();
		add(i, u), add(u, i); 
	}
}

void dfs1(int u, int pa) {
	dep[u] = dep[pa] + 1; ++size[dep[u]];
	chkmax(maxDep[u], dep[u]);
	for (int i = head[u]; ~i; i = g[i].nxt) {
		int v = g[i].to;
		if (v != pa) {
			dfs1(v, u);
			if (son[u] == -1 || maxDep[v] > maxDep[u]) {
				if (~son[u]) chkmax(sed[u], maxDep[u] - dep[u]);
				son[u] = v, maxDep[u] = maxDep[v];
			} else chkmax(sed[u], maxDep[v] - dep[u]);
		}
	}
	localdep[u] = maxDep[u] - dep[u] + 1;
}

int _f[Maxn], _f1[Maxn], _depsize[Maxn], clk, dfn[Maxn];
int *f[Maxn], *f1[Maxn], *depsize[Maxn];
void dfsDp(int u, int pa) {
	dfn[u] = clk++;
	f[u] = _f + dfn[u]; f1[u] = _f1 + dfn[u]; depsize[u] = _depsize + dfn[u];
	f[u][0] = f1[u][0] = depsize[u][0] = 1;
	if (~son[u]) {
		dfsDp(son[u], u);
		rep (i, 0, sed[u]) f1[u][i] = (1ll * power[depsize[u][i]] - f[u][i] + Mod) % Mod;
	} else return ;
	
	for (int usa = head[u]; ~usa; usa = g[usa].nxt) {
		int v = g[usa].to;
		if (v != son[u] && v != pa) {
			dfsDp(v, u);

			rep (i, 0, localdep[v] - 1) {
				int tmp = (1ll * power[depsize[v][i]] - f[v][i] + Mod) % Mod;
				f[u][i + 1] = (1ll * f[u][i + 1] * tmp % Mod + 1ll * f1[u][i + 1] * f[v][i] % Mod) % Mod;
				f1[u][i + 1] = 1ll * f1[u][i + 1] * tmp % Mod;
				depsize[u][i + 1] += depsize[v][i];
			}
		}
	}
}

void Solve() {
	dfs1(0, 0);
	power[0] = 1;
	rep (i, 1, n) power[i] = power[i - 1] * 2ll % Mod;
	dfsDp(0, 0);

	LL ans = 0;
	rep (i, 0, maxDep[0] - 1) {
		ans += 1ll * power[n + 1 - depsize[0][i]] * f[0][i] % Mod;
		if (ans >= Mod) ans -= Mod;
	}
	cout << ans << endl;
}

int main() {


	Init();
	Solve();

#ifdef Qrsikno
	debug("\nRunning time: %.3lf(s)\n", clock() * 1.0 / CLOCKS_PER_SEC);
#endif
	return 0;
}


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

struct Plan {
  int t, x, y;
  Plan operator-(const Plan &other) {
    Plan ret;
    ret.t=t-other.t;
    ret.x=x-other.x;
    ret.y=y-other.y;
    return ret;
  }
};
bool TravelersCheck(Plan dp) {
  int total=abs(dp.x)+abs(dp.y);
  if (dp.t < total) {return false;}
  if (dp.t%2 != total%2) {return false;}
  return true;
}
int main() {
  int N;
  int ti, xi, yi;
  cin >> N;
  unordered_map<int,Plan> travel;
  Plan tmp={0, 0, 0};
  travel[0]=tmp;
  for (int i=1; i<=N; i++) {
    cin >> ti >> xi >> yi;
    Plan tmp={ti ,xi ,yi};
    travel[i]=tmp;
  }
  for (int i=0; i<N; i++) {
    if (TravelersCheck(travel[i+1]-travel[i])) {continue;}
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 7300
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

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

    vector<int> a(26,0);

    for(int i = 0; i < S.length(); i++){
        int n = S[i]-97;
        a[n] = 1;
    }

    for(int i = 0; i < 26; i++){
        if(a[i] == 0){
            printf("%c\n", i+97);
            exit(0);
        }
    }

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


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y << endl;
    return 0;
}


Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    int a[n];
    int b[n];
    forn(i,n)
    {
        cin>>a[i];
        b[i] = a[i];
    }
    
    sort(a,a+n);
    
    for(int i=0;i<n;i++){
        if(b[i]==a[n-1])    cout<<a[n-2]<<endl;
        else                cout<<a[n-1]<<endl;
    }
    return 0;
}



Measured memory_bytes: 3200
/*
 ~ author - Sayan Bose
 ~ Do Good Die Great
*/
#include<bits/stdc++.h>
#define ll long long
#define amaterasu ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;

void solve()
{
	int n, m;
	cin >> n >> m;
	int work = 0;
	while(m--)
	{
		int t;
		cin >> t;
		work += t;
	}
	if(work > n)
		cout << -1 << '\n';
	else
		cout << n-work << '\n';
}

int main()
{
	amaterasu
	solve();
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;using vll = vector<ll>;
ll combi(ll n, ll r) {
  ll ans = 1;
  if (r == 0) return 0;
  for (ll i = 1 ; i <= r; i++) {
    ans *= n-i+1;
    ans /= i;
  }
  return ans;
}
int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  vll v(n);
  for (ll i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  ll sum = 0;
  for (ll i = 0; i < a; i++) sum += v[i];
  ll cnt_same = 0, idx;
  for (ll i = 0; i < n; i++) {
    if (v[i] == v[a-1]) {
      cnt_same++;
      idx = i;
    }
  }
  
  ll choose_min = cnt_same - idx + a - 1, choose_max = choose_min;
  if (sum == v[a-1]*a) {
    choose_max = choose_min + min(idx, b - 1) - a + 1;
  }
  
  ll ans = 0;
  for (ll i = choose_min; i <= choose_max; i++) {
    ans += combi(cnt_same, i);
  }
  
  long double mean = sum / (long double)a;
  cout << fixed << setprecision(6);
  cout << mean << endl;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut div: Vec<u32> = vec![0; 101];

    for mut i in 2..n + 1 {
        // iを祖神う分解
        let mut j = 2;
        while j * j <= i {
            while i % j == 0 {
                div[j] += 1;
                i /= j;
            }
            j += 1;
        }
        if i != 1 {
            div[i] += 1;
        }
    }
    let mut cnt75 = 0;
    let mut cnt25 = 0;
    let mut cnt15 = 0;
    let mut cnt5 = 0;
    let mut cnt3 = 0;
    for i in 2..n + 1 {
        if div[i] >= 2 {
            cnt3 += 1;
        }
        if div[i] >= 4 {
            cnt5 += 1;
        }
        if div[i] >= 14 {
            cnt15 += 1;
        }
        if div[i] >= 24 {
            cnt25 += 1;
        }
        if div[i] >= 74 {
            cnt75 += 1;
        }
    }
    let mut ans = cnt75;
    ans += cnt25 * (cnt3 - 1);
    ans += cnt15 * (cnt5 - 1);
    ans += cnt5 * (cnt5 - 1) * (cnt3 - 2) / 2;
    println!("{}", ans);
}

Measured memory_bytes: 4352
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] p = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        int min = int.MaxValue;
        int count = 0;
        for (int i = 0; i < p.Length; i++)
        {
            min = Math.Min(min, p[i]);
            if (p[i] == min) count++;
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 31964
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *H = map(int, read().split())

ans = 0
temp = H[0]
for h in H:
    if h >= temp:
        ans += 1
        temp = h

print(ans)


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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int start=A, end=B;
	if (C > A) {
		start = C;
	}
	if (D < B) {
		end = D;
	}
	if (start<end) {
		cout << end - start;
	}
	else {
		cout << 0;
	}
}

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

using namespace std;

int main() {
  int N,answer;
  answer = 0;
  cin >> N;
  vector<char> vec(N + 2);
  vec.at(N) = '0';
  vec.at(N + 1) = '0';
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  
  
  for(int i = 0; i < N; i++){
    if(vec.at(i) == 'A'){
      if(vec.at(i + 1) == 'B'){
        if(vec.at(i + 2) == 'C'){
      	  answer++;
        }
      }
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
function main()
	N=parse(Int,readline())
	A=[map(x->parse(Int,x),split(s)) for s=readlines()]
	f=zeros(Int,N,N)
	for k=1:N,i=1:N,j=1:N
		if A[i][k]+A[k][j]<A[i][j]
			println(-1)
			exit()
		end
		if A[i][k]+A[k][j]==A[i][j]&&i!=k!=j
			f[i,j]=1
		end
	end
	ans=0
	for i=1:N,j=i:N
		ans+=A[i][j]*(1-f[i,j])
	end
	println(ans)
end
main()


Measured memory_bytes: 120252
#include<bits/stdc++.h>
using namespace std;
int fa[200001];
int num[200001];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1,a,b;i<n;++i){ 
        scanf("%d %d",&a,&b);
        fa[b]=a;
    }
    for(int i=1,a,x;i<=m;++i)
	{
        scanf("%d %d",&a,&x);
    	num[a]+=x;
	}
	for(int i=1;i<=n;++i){
		num[i]+=num[fa[i]];
		cout<<num[i]<<' ';
	}
  cout<<endl;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define Accepted 0
using namespace std;
int n,p[255555],dist[555][555],ans,x,y,lst[555][555];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
bool In(int x,int y)
{
	return (x>=1 && x<=n && y>=1 && y<=n);
}
void bfs(int x,int y)
{
	queue<pair<int,int> > q;
	q.push(make_pair(x,y));
	while(!q.empty())
	{
		x=q.front().first;y=q.front().second;q.pop();
		for (int i=0;i<4;i++)
		{
			int xx=x+dx[i],yy=y+dy[i];
			if (!In(xx,yy)) continue;
			if (dist[xx][yy]>dist[x][y]+lst[xx][yy])
			{
				dist[xx][yy]=dist[x][y]+lst[xx][yy];
				q.push(make_pair(xx,yy));
			}
		}
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n*n;i++) scanf("%d",&p[i]);
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			dist[i][j]=min(n-j+1,min(j,min(i,n-i+1)));
			lst[i][j]=1;
		}
	}
	for (int i=1;i<=n*n;i++)
	{
		x=(p[i]-1)/n+1;y=(p[i]-1)%n+1;
		ans+=(dist[x][y]-1);
		dist[x][y]--;lst[x][y]=0;
		bfs(x,y);
	}
	printf("%d\n",ans);
	return Accepted;
}

Measured memory_bytes: 6916
#include<bits/stdc++.h>
using namespace std;
const int MN = 20;
using pii = pair<int,int>;
vector<pii> test[MN];
int main () {
	int n;
	scanf ("%d",&n);
	for (int i = 0; i < n; i++) {
		int len;
		scanf ("%d",&len);
		test[i].resize(len);
		for (auto &au : test[i]) scanf ("%d %d",&au.first,&au.second), --au.first;
	}
	int ans = 0;
	for (int i = 1; i < (1 << n); i++) {
		for (int j = 0; j < n; j++) if (i>>j&1) {
			for (auto &au : test[j]) {
				if (au.second == 0 && (i>>au.first&1)) goto fail;
				else if (au.second == 1 && !(i>>au.first&1)) goto fail;
			}
		}
		ans = max(ans,__builtin_popcount(i));
		fail:;
	}
	printf ("%d\n",ans);
	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 x = sc.nextInt();
		if(x >= 1200) {
			System.out.println("ARC");
		} else {
			System.out.println("ABC");
		}
	}
}


Measured memory_bytes: 21204
N = input()
a = []
for i in range(N):
	a.append(input())
a.sort()
if(N % 2 == 1):
	print((sum(a[(N+1)/2:])-sum(a[:(N+1)/2-1]))*2-min([a[(N+1)/2-1]-a[(N+1)/2-2],a[(N+1)/2]-a[(N+1)/2-1]]))
else:
	print((sum(a[N/2:])-sum(a[:N/2]))*2-(a[N/2]-a[N/2-1]))

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

using namespace std;

const int maxn = 110;
const int maxs = 1010;

typedef pair<int,int> seg;

seg operator+(const seg &s1, const seg &s2) {
	return seg(max(s1.first, s2.first), min(s1.second, s2.second));
}

int n, sum, lastp;
int ans[maxs], a[maxn], cur_a[maxn], vis[maxn], _vis[maxn], ok[maxn];
seg pre[maxn], suf[maxn], s[maxn];

// 是否第一步必须 -1
seg calseg(int x, int ty) {
	if (!ty) {
		return seg(x, 2 * x);
	} else {
		return seg(x, 2 * x - 1);
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		sum += a[i];
	}
	for (int i = 1; i <= sum; i++) {
		for (int j = 1; j <= n; j++) {
			vis[j] = 0;
			cur_a[j] = a[j];
			ok[j] = 0;
		}
		for (int j = 0; j < i; j++) {
			if (i - j <= lastp + 1) {
				for (int k = 1; k <= n; k++) s[k] = calseg(cur_a[k], vis[k]);
				pre[0] = suf[n+1] = seg(0, 0x3f3f3f3f);
				for (int k = 1; k <= n; k++) pre[k] = pre[k-1] + s[k];
				for (int k = n; k >= 1; k--) suf[k] = suf[k+1] + s[k];
				for (int k = 1; k <= n; k++) {
					seg t = pre[k-1] + suf[k+1] + calseg(cur_a[k], 1);
					if (!vis[k] && t.first <= t.second) {
						ok[k] = 1;
					}
				}
			}
			if (j < i-1) {
				if (vis[ans[i - 1 - j]]) break;
				vis[ans[i - 1 - j]] = 1;
				++ cur_a[ans[i - 1 - j]];
			}
		}
		for (int j = 1; j <= n; j++) {
			vis[j] = 0;
			cur_a[j] = a[j];
		}
		for (int j = 0; j < i; j++) {
			for (int k = 1; k <= n; k++) _vis[k] = 0;
			int t = i-j-1;
			while (t > 0 && !vis[ans[t]] && !_vis[ans[t]]) {
				_vis[ans[t]] = 1;
				-- t;
			}
			for (int k = 1; k <= n; k++) s[k] = calseg(cur_a[k], vis[k] || !_vis[k]);
			seg total = seg(0, 0x3f3f3f3f);
			for (int k = 1; k <= n; k++) total = total + s[k];
			if (total.first <= total.second) {
				int mn = 0x3f3f3f3f;
				for (int k = n; k >= 1; k--) if (!vis[k] && !_vis[k] && cur_a[k] * 2 - 1 >= total.first) mn = min(mn, k);
				for (int x = t+1; x <= i-j-1; x++) {
					if (x > lastp+1) break;
					if (mn < 0x3f3f3f3f) ok[mn] = 1;
					_vis[ans[x]] = 0; if (2 * cur_a[ans[x]] - 1 < total.first) break;
					mn = min(mn, ans[x]);
				}
			} 
			if (j < i-1) {
				if (vis[ans[i - 1 - j]]) break;
				vis[ans[i - 1 - j]] = 1;
				++ cur_a[ans[i - 1 - j]];
			}
		}
		for (int j = 1; j <= n; j++) {
			if (ok[j]) {
				ans[i] = j;
				break;
			}
		}
		-- a[ans[i]];
		if (!ans[i]) {
			puts("-1");
			return 0;
		}
		for (int j = 1; j <= n; j++) vis[j] = 0;
		if (i >= n) {
			int flag = 1;
			for (int j = i; j >= i-n+1; j--) {
				if (vis[ans[j]]) {
					flag = 0;
					break;
				}
				vis[ans[j]] = 1;
			}
			if (flag) lastp = i;
		}
	}
	for (int i = 1; i <= sum; i++) printf("%d ", ans[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 998244353;
int dp[3010][3010];

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

	int n, s;
	cin >> n >> s;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	rep(i, n + 1) dp[i][0] = 1;
	rep(i, n) {
		rep(j, 3010) {
			if (j >= a[i]) {
				dp[i + 1][j] += dp[i][j - a[i]];
				dp[i + 1][j] %= mod;
			}
			dp[i + 1][j] += dp[i][j];
		}
	}
	int ans = 0;
	rep(i, n + 1) {
		ans += dp[i][s];
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 70784
using System;
using System.Linq;
public class Hello
{
    public static int D;
    public static int G;
    public static int[] S;
    public static int score = 0;
    public static int count = 0;
    public static void Main()
    {
        //入力受け取り
        int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        D = a[0];
        G = a[1];
        int[] p = new int[10];
        int[] c = new int[10];
        S = new int[D];
        int ans = 1000;
       
        for(int i = 0; i < D; i++)
        {
            int[] b = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            p[i] = b[0];
            c[i] = b[1];
        }
        
        //ビット全探索
        for(int mask = 0; mask < (1 << D); mask++)
        {
            int S = 0;
            int num = 0;
            int need = 0;
            int rest_max = -1;
            
            for(int i = 0; i < D; i++)
            {
                if((mask >> i & 1) == 1)
                {
                    S += 100 * (i + 1) * p[i] + c[i];
                    num += p[i];
                }
                else
                {
                    rest_max = i;
                }
            }
            
            if(S < G)//目標点に届かない場合
            {
                int S1 = 100 * (rest_max + 1);
                need = (G - S + S1 - 1) / S1; //中途半端に解かなければならない問題数
                if(need >= p[rest_max])
                {
                    
                    continue;
                    
                }
                else
                {
                    num += need;
                }
            }
            
            //最小値の更新
            ans = Math.Min(ans, num);
        }
        
        Console.WriteLine(ans);
    }

}

Measured memory_bytes: 13396
import sys
input = sys.stdin.readline
n = int(input())
s = list(input().strip())

s0dic = {}
s1dic = {}
s2dic = {}
key = {}

for i0, s0 in enumerate(s):
    #print('s0 = {}'.format(s0))
    if s0 in s0dic:
        continue
    s0dic[s0] = 1
    for i1, s1 in enumerate(s[i0+1:], start=i0+1):
        #print('  s1 = {}'.format(s1))
        if (s0, s1) in s1dic:
            continue
        s1dic[(s0, s1)] = 1
        for i2, s2 in enumerate(s[i1+1:], start=i1+1):
            #print('    s2 = {}'.format(s2))
            if (s0, s1, s2) in key:
                continue
            #print('      new key ({}, {}, {})'.format(s0, s1, s2))
            key[(s0, s1, s2)] = 1
print(len(key))

Measured memory_bytes: 4012
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, W = map(int, input().split())
    items = [tuple(map(int, input().split())) for _ in range(N)]
    MAX_V = 10 ** 3 * N + 1

    dp = [[W+1 for _ in range(MAX_V)] for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0

    for mv in range(MAX_V):
        for i, (w, v) in enumerate(items):
            if mv - v >= 0:
                dp[i+1][mv] = min(dp[i][mv], dp[i][mv - v] + w)
            else:
                dp[i+1][mv] = dp[i][mv]

    print(max([v for v, w in enumerate(dp[N]) if w <= W]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 171116
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
typedef long long ll;
 
int main() {
    int N;
    cin >> N;
    if (N == 0) cout << "0\n";
    else {
        vector<int> ans(0);
        while (N != 0) {
            if (N % 2) {
                ans.push_back(1);
                N--;
            } else {
                ans.push_back(0);
            }
            N = - N / 2;
        }
        rep(i, ans.size()) cout << ans[ans.size() - 1 - i];
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int a, b, c, cnt = 0;
	scanf("%d%d%d", &a, &b, &c);
	if (a == b && b == c) {
		printf("%d\n", a % 2 == 0 ? -1 : 0);
		return 0;
	}
	while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
		int A = a / 2;
		int B = b / 2;
		int C = c / 2;
		a = B + C;
		b = C + A;
		c = A + B;
		cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
#include<cstdio>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >=0; i--)
#define lint long long
#define all(x) (x).begin(), (x).end()

vector<int> vec[10];

int main(){
    int N; string S; cin>>N>>S;
    rep(i,N){
        char c = S[i];
        int intc = (int)(c-'0');
        vec[intc].push_back(i);
    }
    int ans = 0;
    rep(i,10)rep(j,10)rep(k,10){
        if(vec[i].empty()) continue;
        int a = vec[i][0];

        auto itr = upper_bound(all(vec[j]), a);
        if(itr == vec[j].end()) continue;
        int b = *itr;

        auto itr2 = upper_bound(all(vec[k]), b);
        if(itr2 == vec[k].end()) continue;
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,m,a,b,ans;
	cin >> n >> m;
	a=0;b=0;
	if(n>=2)
	{
		a = (n*(n-1))/2;
	}
	if(m>=2)
	{
		b = (m*(m-1))/2;
	}
	cout << a+b << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    inf = 10**17

    def dijkstra_heap(start,edge):
        #始点から各頂点への最短距離(頂点番号:0~N-1)
        d = [inf]*N
        used = [False]*N
        d[start] = 0
        used[start] = True
        edgelist = []
        #a:重み(//), b:次の頂点(%)
        for a,b in edge[start]:
            heappush(edgelist,a*(10**6)+b)

        while len(edgelist):
            #まだ最短距離が決まっていない頂点の中から最小の距離のものを探す
            minedge = heappop(edgelist)
            if used[minedge%(10**6)]:
                continue
            node = minedge%(10**6)
            d[node] = minedge//(10**6)
            used[node] = True

            for e in edge[node]:
                if not used[e[1]]:
                    heappush(edgelist,(e[0]+d[node])*(10**6)+e[1])
        return d

    #N:頂点数   W:辺数
    edge = [[] for i in range(N)]
    #edge[i] : iから出る道の[重み,行先]の配列
    for _ in range(N-1):
        x,y,z = map(int,input().split())
        edge[x-1].append((z,y-1))
        edge[y-1].append((z,x-1))

    q,k = map(int, input().split())
    d = dijkstra_heap(k-1, edge)

    for _ in range(q):
        x,y = map(int, input().split())
        print(d[x-1]+d[y-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 84272