akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
	int a,b,c,d[500],i,j,e=0,tmp,res=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=1;i*i<=c;i++){
		if(c%i==0){
			d[e++]=i;
			if(i!=c/i)d[e++]=c/i;
		}
	}
	for(i=0;i<e;i++){
		for(j=i+1;j<e;j++){
			if(d[i]>d[j]){
				tmp=d[i];d[i]=d[j];d[j]=tmp;
			}
		}
	}
	for(i=0;i<e;i++){
		if(a<=d[i]&&d[i]<=b)res++;
	}
	printf("%d\n",res);
	return 0;
}
	
	

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
const int N = 100001;
int n,k;
int a[1001];
int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",a+i);
    sort(a,a+n);
    ll ans=0;
    for(int i=0;i<k;i++)
        ans+=a[i];
    cout<<ans;
}



Measured memory_bytes: 3252
n=int(input())
s=list(input())

dp=[[0]*(n+1) for i in range(n+1)]
ans=0

for i in range(1,n):
    for j in range(i+1,n+1):
        if s[n-i]==s[n-j]:
            dp[n-i][n-j]=min((n-i)-(n-j),dp[n-i+1][n-j+1]+1)
            ans=max(dp[n-i][n-j],ans)
        else:
            pass
print(ans)
        


        
            
        
            
            

            
            




Measured memory_bytes: 231944
import java.util.*;

public class Main { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int ans =0;
    int N = sc.nextInt();
    int[] count = new int[100001];
    Set<Integer> setA = new HashSet<Integer>();
    for (int i =1; i<=N; i++) {
      int a = sc.nextInt();
      if (a >= 100001) {
        ans ++;
        continue;
      }
      count[a]++;
      setA.add(a);
    }
    for (int i : setA) {
      if (count[i] > i ) {
        ans += count[i] - i;
      } else if (count[i] < i) {
        ans += count[i];
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 49088
#include<stdio.h>
#define M 100000

typedef struct{
  char chara;
  int num;
  int no;
} trump;

int partition(trump *,int,int);
void quickSort(trump *,int,int);

int main(){
  trump T[M];
  int i;
  int j;
  int n;
  int check = 0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&T[i].chara,&T[i].num);
    T[i].no = i;
  }

  quickSort(T,0,n-1);

  for(i=0;i<n;i++){
    if(T[i].num == T[i+1].num && T[i].no > T[i+1].no){
      check = 1;
    }
  }
  
    if(check == 0) printf("Stable\n");
    else printf("Not stable\n");
  
  for(i=0;i<n;i++) printf("%c %d\n",T[i].chara,T[i].num);
  
  return 0;
}

int partition(trump *A,int p,int r){
  int a = A[r].num;
  int i = p-1;
  int j;
  trump tmp;

  for(j=p;j<r;j++){
    if(A[j].num <= a){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }

  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;

  return i+1;
}

void quickSort(trump *A,int p,int r){
  int q;
  if(p < r){
    q = partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int k;
  cin >> k;
  // 1, 1, 1, 2, 1,
  // 2, 1, 5, 2, 2,
  // 1, 5, 1, 2, 1,
  // 14, 1, 5, 1, 5,
  // 2, 2, 1, 15, 2,
  // 2, 5, 4, 1, 4,
  // 1, 51
  if (k == 4 || k == 6 || k == 9 || k == 10 || k == 14 || k == 21 || k == 22 ||
      k == 25 || k == 26) {
    cout << 2;
  } else if (k == 8 || k == 12 || k == 18 || k == 20 || k == 27) {
      cout << 5;
  } else if (k == 28 || k == 30) {
      cout << 4;
  } else if (k == 16) {
      cout << 14;
  } else if (k == 24) {
      cout << 15;
  } else if (k == 32) {
      cout << 51;
  } else {
      cout << 1;
  }
}

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

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
  int H, i, A[MAX+1];
  cin >> H;
  for (i = 1; i <= H; i ++) cin >> A[i];

  for (i = 1; i <= H; i ++) {
    cout << "node " << i << ": key = " << A[i] << ", ";
    if (parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
    if (left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
    if (right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }
}


Measured memory_bytes: 3104
#include<iostream>
#include<cmath>

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

using namespace std;

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

    if(n <= 99){
        cout << n;
    }
    else{
        cout << 101;
    }
  
    int i = 0;
    while(i < d){
        cout << "00";
        i++;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template <typename T>
inline bool chmax (T& a, T b)
{
  if(a < b)
  {
    a = b;
    return true;
  }
  return false;
}

int main()
{
  int l, r, d;
  cin >> l >> r >> d;
  int ans = 0;
  for(int i = l; i <= r; i++)
  {
    if(i % d == 0)
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include<stdio.h>
#include<math.h>

double pi(double x) {
	double n = x*x*M_PI;
	return n;
}

double pi2(double y) {
	double m = 2 * y*M_PI;
	return m;
}

int main(){
	double r;

	scanf("%lf", &r);
	printf("%f %f", pi(r), pi2(r));

	return 0;
}

Measured memory_bytes: 1824
#include<stdio.h>
using namespace std;

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    
    double fa = a, fb = b;
    int d = a / b;
    int r = a % b;
    double f = fa / fb;
    printf("%d %d %.8f\n", d, r, f);
}


Measured memory_bytes: 2700
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;

const int MOD = 1000000007;
const int INF = 1000000000;

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




int main(){
    int n, k; cin >> n >> k;
    string s; cin >> s;
    vector<int> lt; //0, 1それぞれの連続区間の左端
    int prv = -1;
    REP(i, n){
        if(s[i] != prv){
            lt.PB(i); prv = s[i];
        }
    }
    int l = SZ(lt);
    REP(i, 2*k + 1) lt.PB(n);
    int ans = 0;
    
    REP(i, l){
        if(s[lt[i]] == '1') ans = max(ans, lt[i + 2*k + 1]-lt[i]);
        else ans = max(ans, lt[i + 2*k]-lt[i]);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul  unsigned long long int
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod
//ll divide(ll a, ll b)  //euler's theorem(a/b)%mod
//{
//   return a*power(b,mod-2)%mod;  //only when mod is prime
//}

ll power(ll x, ll y)
{
    ll res = 1;
   while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
int main()
{
    speed;
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n&1)
    cout<<"No\n";
    else
    {
    	if(s.substr(0,n/2)==s.substr(n/2))
    	cout<<"Yes\n";
    	else
    	cout<<"No\n";
	}


	return 0;
}


Measured memory_bytes: 3488
#include<iostream>
#include<map>
using namespace std;
int main(){
  map<string,int> m;
  string s;
  while(cin>>s){
    int& count = m[s];
    if(count==0) count=1;
    else count++;
  }
  int max_count=0,max_length=0;
  string max_count_s;
  string max_length_s;
  for(auto p:m){
    if(p.second>max_count){
      max_count=p.second;
      max_count_s=p.first;
    }
    if((int)p.first.size()>max_length){
      max_length=(int)p.first.size();
      max_length_s=p.first;
    }
  }
  cout << max_count_s << " " << max_length_s << "\n";
}

Measured memory_bytes: 1180
n = gets.to_i
p = gets.split.map(&:to_i)
i = 2
ans = 0
while i < n
  if p[i - 2] < p[i - 1] && p[i - 1] < p[i]
    ans += 1
  elsif p[i - 2] > p[i - 1] && p[i - 1] > p[i]
    ans += 1
  end
  i += 1
end
puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
class Node{
public:
  int location;
  int p,l,r;
  Node(){}
};
class Point{
public:
  int id,x,y;
  Point(){}
  Point(int id,int x,int y): id(id),x(x),y(y){}
  bool operator < (const Point &p){return id<p.id;}
};
static const int MAX =1000000;
static const int NIL = -1;
int n;
Point P[MAX];
Node T[MAX];
int np;
bool lessX(Point &p1,Point &p2){return p1.x<p2.x;}
bool lessY(Point &p1,Point &p2){return p1.y<p2.y;}
int makeKDTree(int l,int r, int d){
  if(!(l<r))return NIL;
  int mid=(l+r)>>1;
  int t=np++;
  nth_element(P+l,P+mid,P+r,(d&1 ? lessY : lessX));
  T[t].location=mid;
  T[t].l=makeKDTree(l,mid,d+1);
  T[t].r=makeKDTree(mid+1,r,d+1);
  return t;
}
void find(int v,int sx,int tx,int sy,int ty,int d,vector<Point> &ans){
  int x=P[T[v].location].x;
  int y=P[T[v].location].y;
  if(sx<=x&&x<=tx&&sy<=y&&y<=ty)ans.push_back(P[T[v].location]);
  if(d%2==0){
    if(T[v].l!=NIL&&sx<=x)find(T[v].l,sx,tx,sy,ty,d+1,ans);
    if(T[v].r!=NIL&&x<=tx)find(T[v].r,sx,tx,sy,ty,d+1,ans);
  }
  else{
    if(T[v].l!=NIL&&sy<=y)find(T[v].l,sx,tx,sy,ty,d+1,ans);
    if(T[v].r!=NIL&&y<=ty)find(T[v].r,sx,tx,sy,ty,d+1,ans);
  }
}
int main(){
  int x,y;
  cin>>n;
  rep(i,n){
    scanf("%d %d",&x,&y);
    P[i]=Point(i,x,y);
    T[i].l=T[i].r=T[i].p=NIL;
  }
  np=0;
  int root=makeKDTree(0,n,0);
  int q;
  cin>>q;
  int sx,sy,tx,ty;
  vector<Point>ans;
  rep(i,q){
    scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
    ans.clear();
    find(root,sx,tx,sy,ty,0,ans);
    sort(ans.begin(),ans.end());
    rep(j,ans.size())printf("%d\n",ans[j].id);
    cout<<endl;
  }return 0;
}


Measured memory_bytes: 16552
n = int(input())
s = 0
for i in range(n - 1):
  u, v = map(int, input().split())
  if u > v:
    u, v = v, u
  s += u * (n + 1 - v)
print(n * (n + 1) * (n + 2) // 6 - s)


Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

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

	int n;
	cin >> n;
	vector<ll> vals(n);
	for (int i = 0; i < n; ++i) cin >> vals[i];
	sort(vals.begin(), vals.end());

	// Operation flips sign of - subtree -> Can pick any signs as long as + and - appear at least once
	ll res = 0;
	res -= vals[0];
	res += vals[n-1];
	for (int i = 1; i < n-1; ++i) res += abs(vals[i]);
	cout << res << '\n';

	for (int i = 1; i < n-1; ++i) {
		if (vals[i] <= 0) {
			cout << vals[n-1] << ' ' << vals[i] << '\n';
			vals[n-1] -= vals[i];
		} else {
			cout << vals[0] << ' ' << vals[i] << '\n';
			vals[0] -= vals[i];
		}
	}
	cout << vals[n-1] << ' ' << vals[0] << '\n';
}


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

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;
const int N = 1e5;
int n;
ll dp[N+1][3], a[N][3];

int main() {
  scanf("%d ", &n);
  REP(i,n) REP(j,3) scanf("%lld ", &(a[i][j]));
  memset(dp, 0, sizeof(dp));
  REP(i,n) REP(j,3) REP(k,3) {
    if (j == k) continue;
    dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][j]);
  }
  ll res = 0;
  REP(i,3) res = max(res, dp[n][i]);
  printf("%lld\n", res);
  return 0;
}


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

//  2進数ならば baseNumber を  2 とする
// 10進数ならば baseNumber を 10 とする

ll GetDigitsCount(ll targetNumber, ll baseNumber=10) {
	ll digitsCount = 0;
	while (targetNumber != 0) {
		digitsCount++;
		targetNumber /= baseNumber;
	}
	return digitsCount;
}

int main() {

	ll n; cin >> n;
	ll ans = 9223372036854775807LL;
	for (ll i = 1; i * i <= n; i++) {
		ll tmpAns = 0LL;
		if (n % i == 0) {
			ll j = n / i;
			tmpAns = max(GetDigitsCount(i), GetDigitsCount(j));
			ans = min(ans, tmpAns);
		}		
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# %%
N = int(input())
h = [int(hk) for hk in input().split()]


# %%
def step(h):
    if sum(h) == 0:
        return 0

    if 0 in h:
        split = h.index(0)
        return step(h[:split]) + step(h[split + 1:])

    else:
        new_h = [hk - 1 for hk in h]
        return 1 + step(new_h)


# %%
print(step(h))


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

using namespace std;
const int maxn=1000005;
int n,m,dp[maxn],best,path[maxn],root;
vector<pair<int,int>> g[maxn];

int dfs_With_dp(int u)
{
    if(dp[u]) return dp[u];
    dp[u]=1;
    for(auto v:g[u]) {
        int c=v.first;
        if(dp[u]<dfs_With_dp(c)+1) {
            dp[u]=dp[c]+1;
            path[u+1]=c+1;
        }
    }
    return dp[u];
}

int main()
{
    int x,y;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++) {
        scanf("%d%d",&x,&y);
        x-=1;
        y-=1;
        g[x].push_back(make_pair(y,i+1));
    }
    for(int i=0;i<n;i++) {
        int path_len=dfs_With_dp(i);
        if(best<path_len) {
            root=i;
            best=path_len;
        }
    }
    cout<<best-1<<endl;

    return 0;
}

Measured memory_bytes: 32000
#include <stdio.h>

int main(void){
  int D, N;
  scanf("%d %d", &D, &N);
  if(D == 0){
    if(N != 100){
      printf("%d\n", N);
    }else{
      printf("%d\n", 101);
    }
  }else if(D == 1){
    if(N != 100){
      printf("%d\n", N*100);
    }else{
      printf("%d", 10100);
    }
  }else{
    if(N != 100){
      printf("%d\n", N*10000);
    }else{
      printf("%d\n", 1010000);
    }
  }
  return 0;
}


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

int main(){
  string s;
  cin >> s;
  int ans = 0;
  rep(i,s.size(),0){
    if(i % 2 == 0){
      if(s[i] == 'L') ans = 1;
    }
    if(i % 2 == 1){
      if(s[i] == 'R') ans = 1;
    }
  }
  if(ans == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
class Arrow
  attr_reader :source, :sink, :label

  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
  end
end

def push(queue, label)
  index = queue.size
  label = label.dup
  (0...queue.size).each do |i|
    target, nodes = queue[i]
    case target <=> label
    when -1
      return nil unless label.start_with?(target)
      label.slice!(0...target.size)
    when 0
      return nodes
    else
      index = i
      if target.start_with?(label)
        target.slice!(0...label.size)
        queue.insert(i, nil)
      else
        queue.slice!(i..-1)
      end
      break
    end
  end
  new_nodes = {}
  queue[index] = [label, new_nodes]
  new_nodes
end

def calc(n, arrows, start, goal)
  ins = Array.new(n){[]}
  arrows.each do |arrow|
    ins[arrow.sink] << arrow.source
  end

  reachable_from = {}
  stack = [goal]
  until stack.empty?
    node = stack.pop
    reachable_from[node] = true
    ins[node].each do |source|
      stack << source unless reachable_from[source]
    end
  end

  return nil unless reachable_from[start]
  arrows.select!{|arrow| reachable_from[arrow.sink]}

  outs = Array.new(n){[]}
  arrows.each do |arrow|
    outs[arrow.source] << arrow
  end

  limit = n * arrows.map{|arrow| arrow.label.size}.max

  result = ''
  queue = [['', {start => true}]]
  until queue.empty?
    label, nodes = queue.shift
    result << label
    return result if nodes[goal]
    return nil if result.size > limit

    nodes.each do |node, _|
      outs[node].each do |arrow|
        new_nodes = push(queue, arrow.label)
        new_nodes[arrow.sink] = true if new_nodes
      end
    end
  end
  nil
end

loop do
  n, a, s, g = gets.split.map(&:to_i)
  break if n == 0

  arrows = (0...a).map do |i|
    x, y, lab = gets.split
    Arrow.new(x.to_i, y.to_i, lab)
  end

  puts calc(n, arrows, s, g) || 'NO'
end

Measured memory_bytes: 8900
import java.util.Scanner;


public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt(), M = sc.nextInt();

		int[][] g = new int[N+1][];
		for (int i = 0 ; i <= N ; i++) {
			g[i] = new int[i+2];
		}

		while (M-- != 0) {
			int a = Integer.parseInt(sc.next()),
				b = Integer.parseInt(sc.next()),
				x = Integer.parseInt(sc.next());
			g[a][b] = Math.max(g[a][b], x+1);
		}

		int count = 0;
		for (int x = 1 ; x <= N ; x++) {
			for (int y = 1 ; y <= x ; y++) {
				g[x][y] = Math.max(g[x][y], Math.max(g[x-1][y]-1, g[x-1][y-1]-1));
				if (g[x][y] > 0) count++;
			}
		}

		System.out.println(count);
	}

	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 226620
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int n = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        
        if(a * n >= b){
            System.out.println(b);
        }else{
            System.out.println(a * n);
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int k[20],s[20][20],p[20];
  for(int i=0;i<m;i++){
    cin>>k[i];
    for(int j=0;j<k[i];j++){
      cin>>s[i][j];
    }
  }
  for(int i=0;i<m;i++) cin>>p[i];
  
  int ans=0;
  for(int bit=0;bit<(1<<n);bit++){
    int light=0;
    for(int i=0;i<m;i++){
       int cnt=0;
       for(int j=0;j<k[i];j++){
         if(bit&(1<<s[i][j]-1)) cnt++;
       }
       if(p[i]==0&&(cnt%2==0)) light++;
       if(p[i]==1&&(cnt%2!=0)) light++;
    }
    if(light==m) ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,M;
struct edge{
  int to,from,c;
  bool operator < (const edge &e) const {
    return c < e.c;
  }
};

struct uni{
  int d[555];
  void init(){ memset(d,-1,sizeof(d)); }
  int find(int id){ return d[id] < 0 ? id : (d[id] = find(d[id])); }
  void marge(int a,int b){
    a = find(a); b = find(b);
    if( a==b ) return;
    if( d[a] > d[b] ) swap(a,b);
    d[a]+=d[b]; d[b] = a;
  }
  bool same(int a,int b){ return find(a) == find(b); }
};

vector<edge> E;
vector<edge> use;
vector<int> G[501];
uni U;

void dfs(int *A, int id, int from){
  A[id] = 1;
  for(int i=0;i<(int)G[id].size();i++){
    if( G[id][i] == from ) continue;
    dfs(A,G[id][i],id);
  }
}

int main(){
  cin >> N >> M;
  U.init();
  for(int i=0;i<M;i++){
    int a,b,c; cin >> a >> b >> c;
    E.push_back( (edge){a,b,c} );    
  }
  sort(E.begin(),E.end());
  for(int i=0;i<(int)E.size();i++){
    int a = E[i].from, b = E[i].to;
    if( !U.same(a,b) ){
      U.marge(a,b);
      use.push_back( E[i] );
      G[a].push_back( b );
      G[b].push_back( a );
    }
  }

  int res1 = 0, res2 = 0;
  for(int i=0;i<(int)use.size();i++){
    bool flag = true;
    int A[501]={};
    int B[501]={};
    int a = use[i].from, b = use[i].to;
    dfs(A,a,b);
    dfs(B,b,a);
    for(int j=0;j<(int)E.size();j++){
      int t = E[j].to, f = E[j].from, c = E[j].c;
      if( A[t] && B[f] ){
        if( t == a && f == b ) continue;
        if( c == use[i].c ) flag = false;
      }
      if( B[t] && A[f] ){
        if( t == b && f == a ) continue;
        if( c == use[i].c ) flag = false;
      }
      if(!flag) break;
    }
    if( flag ){
      res1++; res2 += use[i].c;
    }
  }
  cout << res1 << " " << res2 << endl;

}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    int N, T;
    cin >> N >> T;

    int ans = 0;
    int st; cin >> st;
    int ed = T;
    for(int i = 1; i < N; i++){
        int t; cin >> t;
        if(ed > t){
            ed = t + T;
        } else {
            ans += ed - st;
            st = t;
            ed = t+T;
        }
    }
    ans += ed-st;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
def srch(u, cnt, Dst, Fst, Lst):
    S = [u]
    Fst[u] = cnt
    while(len(S) > 0):
        cnt += 1
        u = S.pop()
        if Dst[u] is not None and len(Dst[u]) > 0:
            while(len(Dst[u])):
                u1 = Dst[u].pop()
                if Fst[u1] == 0:
                    S.append(u)
                    S.append(u1)
                    Fst[u1] = cnt
                    break
                else:
                    Lst[u] = cnt
        else:
            Lst[u] = cnt
    return cnt + 1

def main():
    num = int(input())
    Dst = [None for i in range(num + 1)]
    Fst = [0] * (num + 1)
    Lst = Fst[:]

    for n in range(1, num+1):
        a = list(map(int,input().split()))
        u = a[0]
        if a[1] > 0:
            Dst[u] = a[2:]
            Dst[u].reverse()

    cnt = 1
    for i in range(1,num):
        if Fst[i] == 0:
            cnt = srch(i, cnt, Dst, Fst, Lst)

    for n in range(1, num+1):
        print("{} {} {}".format(n,Fst[n],Lst[n]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 7808
#include<bits/stdc++.h>
#define XX first
#define YY second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  cin >> N;
  int ans = N/2;
  if (N%2 == 0) ans--;
  cout << ans << endl;
}


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

using namespace std;

int main (void) {
    int N;
    cin >> N;
    vector<int> a(N);
    for ( int i=0; i<N; i++ )
        cin >> a.at(i);

    int a_;
    long long ans = 0;
    for ( int i=0; i<N; i++ ) {
        a_ = a.at(i);
        while ( a_ % 2 == 0 ) {
            a_ /= 2;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
list_ = []
flag = 0
for i in range(n):list_.append(input())
if n == len(set(list_)):
        for i in range(n - 1):
            if list_[i][-1] != list_[i+1][0]:
                flag += 1
                break
        if flag == 0:
            print("Yes")
        else:
            print("No")
else:
    print("No")

Measured memory_bytes: 9188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

char maze[51][51];

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    if (b <= a ) cout << "delicious" << endl;
    else if (b > a && b-a <= x) cout << "safe" << endl;
    else cout << "dangerous" << endl; 
       
    return 0;
}

Measured memory_bytes: 256
n = int(input())
q = [input().split() + [i] for i in range(n)]
for i in range(n):
    q[i][1] = int(q[i][1])
p = sorted(sorted(q, key = lambda x:x[1], reverse = True), key = lambda x:x[0])
for s, t, r in p:
    print(r + 1)


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


using namespace std;


int main(void) {

	int N;
	int X = 0;
	int Y = 0;


	cin >> N;

	vector<int> V(N, 0);
	vector<int> C(N, 0);

	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}

	for (int i = 0; i < N; i++) {
		if (V[i] - C[i] > 0) {
			X += V[i];
			Y += C[i];
		}
	}

	cout << X - Y << endl;

}

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

int main() {
    /* 入力受け取り */
    int n, Q;
    cin >> n >> Q;
    vector<long long> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    /* Q 回分のクエリを処理 */
    for (int j = 0; j < Q; ++j) {
        long long x; cin >> x; // 各クエリ x

        /* 合計値 */
        long long res = 0;

        /* 区間の左端 left で場合分け */
        int right = 0;     // 毎回 right を使い回すようにする
        long long sum = 0; // sum も使い回す
        for (int left = 0; left < n; ++left) {
          for (int i=right; i < n; i++){
				sum += a[i];
				if (sum > x) break;
				right++;
			}
			res += right - left;
			if( right < n) sum -= a[right];
			sum -= a[left];
		}
        

        cout << res << endl;
    }
}


Measured memory_bytes: 3548
n = int(input())
c = 0
max_c = 0
max_num = 1

for i in range(1, n+1):
    if i % 2 == 0:
        j = i
        c = 1
        j /= 2
        while j % 2 == 0:
            c += 1
            j /= 2
    if c > max_c:
        max_c = c
        max_num = i

print(max_num)

Measured memory_bytes: 3060
using System;

namespace ITP1_5_B
{
    class Program
    {
        static void Main()
        {
            for (; ; )
            {
                string[] str = Console.ReadLine().Split(' ');
                int H = int.Parse(str[0]);
                int W = int.Parse(str[1]);
                string line = "";

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

                for (int i = 0; i < W; i++) line += "#";

                Console.WriteLine(line);

                    for (int i = 1; i < H - 1; i++)
                    {
                        Console.Write("#");

                        for (int j = 1; j < W - 1; j++) Console.Write(".");

                        Console.WriteLine("#");
                    }

                Console.WriteLine(line + "\n");
            }
        }
    }
}

Measured memory_bytes: 8908
#include <stdio.h>

int main(void) {
	// your code goes here
	long long int i,a[100000],j,temp,s=0;
	long long int n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		s=s+(a[i]-1);
	}
	printf("%lld\n",s);
	
		
	
	return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<vector<int> > g(N);
  for(int i = 0; i < N; ++i) {
    int t, d;
    cin >> t >> d; --t;
    g[t].push_back(d);
  }
  vector<int> basic, addit;
  for(int i = 0; i < N; ++i) {
    sort(g[i].begin(), g[i].end(), greater<int>());
    if(g[i].size() >= 1) {
      basic.push_back(g[i].front());
    }
    if(g[i].size() >= 2) {
      addit.insert(addit.end(), g[i].begin() + 1, g[i].end());
    }
  }
  sort(basic.begin(), basic.end(), greater<int>());
  sort(addit.begin(), addit.end(), greater<int>());
  int lb = basic.size(), la = addit.size();
  vector<long long> sbasic(lb + 1), saddit(la + 1);
  for(int i = 0; i < lb; ++i) sbasic[i + 1] = sbasic[i] + basic[i];
  for(int i = 0; i < la; ++i) saddit[i + 1] = saddit[i] + addit[i];
  long long ans = 0;
  for(int i = 0; i <= K && i <= lb; ++i) {
    if(K - i <= la) {
      ans = max(ans, (long long)(i) * i + sbasic[i] + saddit[K - i]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7032
lst=input().split(" ")
N=int(lst[0])
M=int(lst[1])
cost=0
drinks=[]
for i in range(N):
    lst=input().split(" ")
    drinks.append([int(lst[0]),int(lst[1])])
drinks.sort(key=lambda x:x[0])
for d in drinks:
    if M>d[1]:
        M -= d[1]
        cost += d[0]*d[1]
    else:
        cost += d[0]*M
        break

    
print(cost) 

Measured memory_bytes: 21156
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define NMAX 1005
#define HMAX 10005

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

const int inf=1000000000;
int h, n;
int A[HMAX], B[HMAX];
int dp[NMAX][HMAX];

int main(){
  cin >> h >> n;
  rep(i, n){
    cin >> A[i] >> B[i];
  }
  rep(i, n){
    repo(j, h){
      dp[i][j]=inf;
    }
  }
  rep(j, h+1){
    dp[0][j]=((j+A[0]-1)/A[0])*B[0];
  }

  repo(i, n-1){
    /*
    rep(l, A[i]){
      dp[i][l]=min(dp[i-1][l],B[i]);
    }
    */
    /*
    for(int j=1; j<=h; j++){
      int k=0;
      while(j-k*A[i]>0){
        dp[i][j]=min(dp[i][j], dp[i-1][j-k*A[i]]+B[i]*k);
        k++;
      }
      dp[i][j]=min(dp[i][j], B[i]*k);
    }
    */
    repo(j, h){
      if(j-A[i]>0){
        dp[i][j]=min(dp[i-1][j], dp[i][j-A[i]]+B[i]);
      } else {
        dp[i][j]=min(dp[i-1][j], B[i]);
      }
    }
  }
  /*
  rep(i, n){
    repo(j, h){
      cout << dp[i][j]  << " ";
    }
    cout << endl;
  }
  */
  cout << dp[n-1][h] << endl;
  return 0;
}


Measured memory_bytes: 39296
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define p(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1e9

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef long long ll;

int dy[8]={1,1,1,0,0,-1,-1,-1};
int dx[8]={-1,0,1,-1,1,-1,0,1};
struct S{
	int a,b,c;
};
bool asc(const S& left,const S& right){
	return left.c > right.c;
}
int n,m,l,r;
vi a;
int dp[100001];
void input(){
	cin>>n;
	int tmp;
	rep(i,n){
		cin>>tmp;
		a.pb(tmp);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	//memset(dp,-1,sizeof(dp));
	int ans=0,tmp=0;
	/*rep(i,n){
		dp[i]=1;
		rep(j,i){
			if(a[i]>a[j]){
				dp[i]=max(dp[i],dp[j]+1);
			}
		}
		ans=max(ans,dp[i]);	
	}*/
	/*rep(i,n)dp[i]=INF;
	dp[0]=a[0];
	REP(i,1,n){
		rep(j,i+1){
			if(dp[j-1]<a[i]){
				dp[j]=min(dp[j],a[i]);
				ans=max(ans,j+1);
			}
		}
	}*/
	rep(i,n)dp[i]=INF;
	rep(i,n){
		*lower_bound(dp,dp+n,a[i])=a[i];
	//	rep(j,n)p(dp[j]);
	//	cout<<endl;
	}
	cout<<(lower_bound(dp,dp+n,INF)-dp)<<endl;
	return 0;
}

Measured memory_bytes: 3680
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
  
  int n, alice = 0, bob = 0;
  
  cin >> n;
  
  int a[n];
  
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  sort(a, a+n, greater<int>());
  
  for(int i = 0; i < n; i=i+2){
    alice += a[i];
  }
  for(int i = 1; i < n; i=i+2){
    bob += a[i];
  }
  
  cout << alice-bob << endl;
  
  return 0;
}

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

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

    int n;
    cin >> n;
    vector<long long> A(n), B(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

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

    for(int i = 0; i < n; i++){
        B[i] = A[i];
        if(i > 0) B[i] += B[i - 1];
    }

    int maxi = n - 1;
    for(int i = n - 2; i >= 0; i--){
        if(B[i] * 2 >= A[i + 1]){
            maxi = i;
        }else{
            break;
        }
    }

    cout << n - maxi << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int N, C;
int dp[2][1<<16];
int a[30], b[30];

int getData() {
	int res = 0;
	REP(i, 16) {
		int a; scanf("%d", &a);
		res |= a<<i;
	}
	
	return res;
}

int pop_cnt(int s) {
	int res = 0;
	REP(i, 16) if (s >> i & 1) res++;
	return res;
}

int rev(int s) {
	int res = 0;
	REP(i, 16) {
		if (!(s >> i & 1)) res |= 1 << i;
	}
	return res;
}

int main() {
	while (cin >> N >> C, N || C) {
		REP(i, N) a[i] = getData();
		REP(i, C) b[i] = getData();
		
		fill(dp[0], dp[2], -1);
		dp[0][0] = 0;
		
		REP(i, N) {
			int now = i % 2;
			int next = !now;
			
			fill(dp[next], dp[next + 1], -1);
			
			REP(s, 1<<16) if (dp[now][s] != -1) {
				int nows = s | a[i];
				
				REP(j, C) {
					int nexts = nows & rev(b[j]);
					int nextc = dp[now][s] + pop_cnt(nows & b[j]);
					chmax(dp[next][nexts], nextc);
				}
			}
		}
		
		int ans = 0;
		REP(i, 1<<16) chmax(ans, dp[N % 2][i]);
		cout << ans << endl;
	}
	return 0;
}

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

int n,ans;
double ave;
vector<double> A;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n,n){
        A.clear();
        ave=0;
        for (int i=0;i<n;++i){
            double a; cin >> a;
            ave+=a;
            A.emplace_back(a);
        }
        ave/=n; ans=0;
        for (int i=0;i<n;++i){
            if (A[i]<=ave) ++ans;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 998244353;


int main() {
    int n;
    cin >> n;
    vector<int> vc(n), vs(n), vf(n);
    rep(i, n-1) {
        cin >> vc[i];
        cin >> vs[i];
        cin >> vf[i];
    } 
    rep(i, n-1) {
        int ans = 0;
        rng(j, i, n-1) {
            if (ans <= vs[j]) ans = vs[j];
            else 
                ans = vs[j] + vf[j]*((ans - vs[j]+vf[j]-1)/vf[j]); 
            ans += vc[j];
        }
        cout << ans << endl;
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int b[][]=new int[4][13];
int i=0;
int j=0;
String str="";
int num=0;
int mar=0;
do {
	b[i][j]=0;
	j++;
	if(j==13) {
		
		j=0;i++;
	if(i==4) {break;}	
	}
	
}while(true);
i=0;
j=0;
do {
	if(a==i) {break;}
	str=scan.next();
	num=scan.nextInt();
	num-=1;
	if(str.equals("S")) {mar=0;}
	if(str.equals("H")) {mar=1;}
	if(str.equals("C")) {mar=2;}
	if(str.equals("D")) {mar=3;}
	i++;
	b[mar][num]=1;
	}while(true);
i=0;
do {
	if(b[i][j]==0) {
		if(i==0) {
			System.out.println("S "+(j+1));
			
		}	if(i==1) {
			System.out.println("H "+(j+1));
			
		}	if(i==2) {
			System.out.println("C "+(j+1));
			
		}	if(i==3) {
			System.out.println("D "+(j+1));
			
		}
		}
	j++;
	if(j==13) {	
		j=0;i++;
	if(i==4) {break;}	
	}
	
}while(true);
}
}



Measured memory_bytes: 26324
#include<stdio.h>
#include<limits.h>


#define DEBUG 0


int buf [5001];

/*
  100kx5k= 500M
  2^20 = 1M
*/

int find_max_sum(int count){
  int i, j;
  int max, s;
  int sum;
  max = INT_MIN;

  for(i = 0; i < count; i++){
    s = 0;
    for(j = i; j < count; j++){
      s += buf[j];
      if(s>=max) max =s ;
    }
  }
  return max;
}


int main(){
  int count;
  int i;
  while((scanf("%i", &count) == 1) && count){
    if(DEBUG)
      printf("count: %d\n", count);
    for(i=0; i<count;i++){
      scanf("%i", buf+i);
      if(DEBUG)
        printf("data: %d\n", *(buf+i));
    }
    printf("%d\n", find_max_sum(count));
  }
  return 0;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int l, r, d;
    cin >> l >> r >> d;
    int x = 0;
    for(int i=l; i<=r; i++)
    {
        x += i%d == 0;
    }
    cout << x;
    return 0;
}


Measured memory_bytes: 3632
N = input()
l = list(map(int, input().split()))
counter = 0

def is_all_even(l):
    le = list(filter(lambda x:x % 2 == 0, l))
    return len(l) == len(le)

while is_all_even(l):
    counter += 1
    l = [i/2 for i in l]

print(counter)


Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
    int n,k,i;
    scanf("%d %d",&n,&k);
    char s[n];
    for(i=0;i<=n;i++){
        scanf("%c",&s[i]);
        if(i==k){
            if(s[i] == 'A') s[i] = 'a';
            else if(s[i] == 'B') s[i] = 'b';
            else s[i] = 'c';
        }
    }
    for(i=1;i<=n;i++){
        printf("%c",s[i]);
    }
}


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

using namespace std;

int main()
{
	int n;
	cin>>n;
	int non =0,a;
	
	for(int i=0; i<n; i++)
	{
		cin>>a;
		if(a != i+1)
		{
			non++;
		}
	}
	
	if(non <= 2) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

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

bool isPrime(long long num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (long long i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(void){
    long long A, B;
    long long ans=0;

    cin >> A >> B;

    vector<long long> factor;
    long long min_ = min(A,B);
    long long max_ = max(A,B);
    for(long long i=1; i<=floor(sqrt(min_)); i++){
        if(min_ % i == 0){
            factor.push_back(i);
            if(i*i != min_){
                factor.push_back(min_/i);
            }
        }
    }


    vector<long long> factor2;
    for(auto itr=factor.begin(); itr<factor.end(); itr++){
        if(max_ % *itr == 0){
            factor2.push_back(*itr);
        }
    }

    for(auto itr=factor2.begin(); itr<factor2.end(); itr++){
        if(isPrime(*itr)){
            ans++;
        }
    }

    cout << ans+1 << endl;
}

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

void solve(){
	int n, k;
	cin >> n >> k;
	
	int a[n]={};
	
	for(int i=0; i<n; i++)
		cin >> a[i];
	
	// we maintain state of game.
	// dp[0]-> loosing state
	// dp[1]-> winning state
	
	// each winning state there is atleast one branch that is lead to loosing state.
	
	int dp[k+1]={};
	memset(dp, 0, sizeof dp);
	
	// here dp[0]=0 menas if K=0 then first loose.
	// for each value of K think current is max val of K.
	// so transition with use each number.
	// and after choosing any number if oponent move to loossing state choose that number.
	
	dp[0]=0;
	for(int i=1; i<=k; i++){
		dp[i]=0;
		for(auto x : a){
			if(i>=x && dp[i-x]==0) {
				// after choose x ooponent is losing means dp[i-x]==0, so current choose this number.
				dp[i]=1;
				break;
			}
		}
	}
	
	if(dp[k]==1)
		cout << "First";
	else
		cout << "Second";
	
}

int main(){
	solve();
}


Measured memory_bytes: 4000
#include <iostream>
#include <set>

int main(int argc, char *argv[]) {
  int q;
  std::cin >> q;
  std::set<long> s;
  for (int i = 0; i < q; ++i) {
    int c, x;
    std::cin >> c >> x;
    switch (c) {
    case 0:
      s.insert(x);
      std::cout << s.size() << std::endl;
      break;
    case 1:
      std::cout << s.count(x) << std::endl;
      break;
    }
  }
}



Measured memory_bytes: 12508
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
char M[9];
int main(){
	int T,P,R,t,p,s,m,i;
	for(;scanf("%d%d%d",&T,&P,&R),R;){
		map<int,map<int,int> >z;
		for(i=0;i<R;i++){
			scanf("%d%d%d%s",&t,&p,&s,M);
			if(*M=='W')z[t][p]-=1;
			else z[t][p]=s-z[t][p]*1200;
		}
		vector<pair<int,pair<int,int> > >v;
		for(i=1;i<=T;i++){
			for(p=s=0,R=1;R<=P;R++)
				if(z[i][R]>0)p++,s+=z[i][R];
			v.push_back(make_pair(99-p,make_pair(s,i)));
		}
		sort(v.begin(),v.end());
		for(i=0;i<T;i++)
			printf("%d %d %d\n",v[i].second.second,99-v[i].first,v[i].second.first);
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef unsigned long long LL;
const int N = 1<<20, mod = 998244353;
template<typename T>
inline void read(T &x){
    int ch = getchar(); x = 0; bool f = false;
    for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
    for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
    if(f) x = -x;
}
void qmo(int &x){x += x >> 31 & mod;}
int ksm(int a, int b){
    int res = 1;
    for(;b;b >>= 1, a = (LL) a * a % mod) if(b & 1) res = (LL) res * a % mod;
    return res;
}
int n, m, lim, rev[N], w[2][N], a[N], b[N];
void calrev(int len){
    int L = -1; lim = 1;
    while(lim <= len){lim <<= 1; ++ L;}
    for(Rint i = 0;i < lim;++ i) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << L);
    for(Rint mid = 1;mid < lim;mid <<= 1){
        w[0][mid] = w[1][mid] = 1; int Wn = ksm(3, (mod - 1) / (mid << 1));
        for(Rint i = 1;i < mid;++ i) w[0][mid+i] = (LL) w[0][mid+i-1] * Wn % mod;
        for(Rint i = 1;i < mid;++ i) w[1][mid+i] = mod - w[0][(mid<<1)-i];
    }
}
void NTT(int *A, int op){
    for(Rint i = 0;i < lim;++ i) if(i < rev[i]) swap(A[i], A[rev[i]]);
    for(Rint mid = 1;mid < lim;mid <<= 1)
        for(Rint i = 0;i < lim;i += mid<<1)
            for(Rint j = 0;j < mid;++ j){
                int tmp = (LL) A[mid + i + j] * w[op][mid + j] % mod;
                qmo(A[i + j + mid] = A[i + j] - tmp); qmo(A[i + j] += tmp - mod);
            }
    if(op){
        int inv = ksm(lim, mod - 2);
        for(Rint i = 0;i < lim;++ i) A[i] = (LL) A[i] * inv % mod;
    }
}
int main(){
    read(n); read(m); calrev(n+m-2);
    for(Rint i = 0;i < n;++ i) read(a[i]);
    for(Rint i = 0;i < m;++ i) read(b[i]);
    NTT(a, 0); NTT(b, 0);
    for(Rint i = 0;i < lim;++ i) a[i] = (LL) a[i] * b[i] % mod;
    NTT(a, 1);
    for(Rint i = 0;i < n+m-1;++ i) printf("%d ", a[i]);
}

Measured memory_bytes: 31376
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	int n; cin>>n;
	string s; cin>>s;
	set<char> iset;
	set<char> ss;
	vi vec(n);
	int cnt=0;
	for(int i=n-1;i>=0;--i){
		if(!ss.count(s[i])){
			cnt++;
			ss.insert(s[i]);
		}
		vec[i]=cnt;
	}
	int ans=0;
	rep(i,0,n-2){
		if(iset.count(s[i]))continue;
		iset.insert(s[i]);
		set<char> jset;
		rep(j,i+1,n-1){
			if(jset.count(s[j]))continue;
			jset.insert(s[j]);
			ans+=vec[j+1];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const double EPS = 1e-9;
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 50;
int n;
P<int, int> p[N];
double ans = LINF;
double f(P<int, int> a, P<int, int> b, P<int, int> c){
  b.fi -= a.fi; b.se -= a.se;
  c.fi -= a.fi; c.se -= a.se;
  double bb = b.fi*b.fi+b.se*b.se;
  double cc = c.fi*c.fi+c.se*c.se;
  double t = double(abs(b.fi*c.se-b.se*c.fi))/sqrt(bb)/sqrt(cc);
  t = asin(t);
  return sin(t*2);
}
P<double, double> e(P<int, int> A, P<int, int> B, P<int, int> C){
  double a=f(A, B, C), b=f(B, C, A), c=f(C, A, B);
  if(!(a+b+c > EPS)) return mp(-1, -1);
  double x = (a*A.fi + b*B.fi + c*C.fi)/(a+b+c);
  double y = (a*A.se + b*B.se + c*C.se)/(a+b+c);
  return mp(x, y);
}
double g(double x, double y){
  double ret = 0.0;
  FOR(i, 0, n) maxs(ret, (x-p[i].fi)*(x-p[i].fi)+(y-p[i].se)*(y-p[i].se));
  return sqrt(ret);
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n) cin >> p[i].fi >> p[i].se;
  FOR(i, 1, n)FOR(j, 0, i) mins(ans, g((p[i].fi+p[j].fi)/2.0, (p[i].se+p[j].se)/2.0));
  FOR(i, 2, n)FOR(j, 1, i)FOR(k, 0, j){
    auto o = e(p[i], p[j], p[k]);
    double x=o.fi, y=o.se;
    if(x < 0) continue;
    mins(ans, g(x, y));
  }
  printf("%.12f\n", ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<climits>
#include<set>
#define ll long long
using namespace std;
int main() {
	ll n,z=0;
	cin >> n;
	vector<ll>a(n),sum(n,0);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		z += a[i];
		sum[i] = z;
	}
	ll sma = LLONG_MAX;
	for (ll i = 0; i < n;i++) {
		ll o = sma;
		sma = min(sma, abs(sum[n - 1] - 2*sum[i]));
	}
	cout << sma << endl;

}

Measured memory_bytes: 3328