akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A,B;
	while(cin>>A>>B) {
		string ans;
		if(A<=0&&0<=B) ans="Zero";
		else {
			if(0<A) ans="Positive";
			else {
				
				B=min(-1LL, B);
				ans=(-A- -B+1)%2==0 ? "Positive":"Negative";
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


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

int main(){
    int q, op, x;
    vector<int> A;
    
    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> op;
        switch (op)
        {
        case 0:
            cin >> x;
            A.push_back(x);
            break;
        case 1:
            cin >> x;
            cout << A[x] << endl;
            break;
        case 2:
            A.pop_back();
            break;
        default:
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3916
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int sum = 0;
            for (int i = n; i < 600; i += n) {
                sum += n * i * i;
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 26100
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

void print_vector(vector<int> v){
  rep(i, sz(v)){
    cout << v[i] << " ";
  }
  cout << endl;
  return;
}

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

  if(S.size()+1 != T.size()){
    cout << "No" << endl;
    return 0;
  }
  rep(i, S.size()){
    if(S[i] != T[i]){
      cout << "No" << endl;
      return 0;
    }
  }

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


Measured memory_bytes: 3600
A,B,K = map(int,input().split())
turn = "A"
for k in range(K):
    if turn=="A":
        if A%2==0:
            A=A//2
            B+=A
            turn = "B"
        else:
            A=(A-1)//2
            B+=A
            turn="B"
    elif turn=="B":
        if B%2==0:
            B=B//2
            A+=B
            turn="A"
        else:
            B=(B-1)//2
            A+=B
            turn="A"
print(A,B)

Measured memory_bytes: 3064
package main

import "fmt"

func main(){
	var a,b,ans int
	fmt.Scan(&a,&b)
	for yen := 1009; yen > 0 ; yen-- {
		if yen*8/100 == a && yen/10 == b{
			ans = yen
		} else if ans != 0{
			fmt.Println(ans)
			break
		}
	}
	if ans == 0{
		fmt.Println("-1")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	vector<vector<int>> h(n, vector<int>(3)), dp(n, vector<int>(3));
	for(int i = 0; i < n; i++) cin >> h[i][0] >> h[i][1] >> h[i][2];
	dp[0][0] = h[0][0]; dp[0][1] = h[0][1]; dp[0][2] = h[0][2];
	for(int i = 1; i < n; i++){
		for(int j = 0; j < 3; j++) dp[i][j] = h[i][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]);
	}
	int res = 0; for(int i = 0; i < 3; i++) res = max(res, dp[n-1][i]);
	cout << res << endl;
}

Measured memory_bytes: 11136
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i and a[0][0] < c:
        x, y = a[0]
        if i < y:
            a[0]  = x, y - i
            i = 0
        else:
            heapq.heappop(a)
            i -= y
    if i < b:
        heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))


Measured memory_bytes: 22072
#include<bits/stdc++.h>
#include<iostream>
#include<typeinfo>
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BP(n) __builtin_popcount(n)
#define bs(v,x) binary_search(all(v),x)
#define lb(v,x) lower_bound(all(v),x) //first equal to or lower than element
#define ub(v,x) upper_bound(all(v),x) //first greater than element
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(j,n) for (j=i+1;j<n;j++)
#define Unique(v) vector<ll>::iterator it; sort(all(v)); it= unique(all(v)); v.resize(distance(v.begin(),it))
#define M 1000000007
#define PI acos(-1.0)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL) 
using namespace std;
void input(vector<int>& v,int n){ int i,io; rep(i,n) { cin>>io; v.pb(io);} }
void output(vector<int> v) { int i; rep(i,v.size()) cout<<v.at(i)<<" "; }
map<char,int>  frequency(vector<char> v){ int i; map<char,int> m; rep (i,v.size()) {  if (m.find(v[i])==m.end()) m.insert({v.at(i),1}); else m[v.at(i)]++; } return m; }
bool perfsq(ll n){ return (ceil(sqrt(n))==floor(sqrt(n))); }
bool ispower2(int n) { if (n&(n-1)==0) return true; else return false; }
int string_to_int(string s) { stringstream geek(s); int x = 0; geek >> x; return x; }
bool binary_pred(int a,int b){ return a==b; }
int main() {
	fastio;
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	//int T;cin >> T;while(T--) {}
	ld d,t,s;
	cin>>d>>t>>s;
	ld t1 = d/s;
	if (t1 <= t)
		cout<<"Yes"<<endl;
	else 
		cout<<"No"<<endl;	
}
// Check for corner cases
// Check for special case like n = 0 or n = INT_MAX
// Check for Buffer Overflow or use of unsigned variable if any
// Check if problem can be solved mathematically 



Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
int main() {
  int d;
  //int n=0;//
  cin >>d;
  int c[26]; int s[d][26];
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
    //n+=c[i];//
  }
  for (int i = 0; i < d; i++) {
    for (int ii = 0; ii < 26; ii++) {
      cin >> s[i][ii];
    }
  }
  long long int la[d];
  int lad[26];
  for (int i = 0; i < 26; i++) {
    lad[i]=-1;
  }
  int mm,md;
  //long long int m=0;//満足度確認用
  for (int i = 0; i < d; i++) {
    md=0;
    //la[i]=(n-c[0])*(-i-1)+s[i][0];//
    la[i]=s[i][0];
    for(int ii = 1; ii < 26; ii++) {
      la[i]-=(i-lad[ii])*c[ii];
    }
    for (int ii = 1; ii < 26; ii++) {
      //mm=(n-c[ii])*(-i-1)+s[i][ii];//
      mm=s[i][ii];
      for(int iii = 0; iii < 26; iii++) {
        if(ii!=iii) mm-=(i-lad[iii])*c[iii];
      }
      if((la[i]+c[md]<mm+c[ii])||(la[i]==mm&&c[md]<c[ii])){
        la[i]=mm; md=ii;
      }
    }
    lad[md]=i;
    cout<<md+1<<endl;
    //m+=la[i];//満足度確認用
    //cout<<m<<endl;//満足度確認用
  }
  //cout<<m<<endl;//満足度確認用
  //cout<<n<<endl;//
}


Measured memory_bytes: 3668
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long sum = 0;

		if(k%2 == 0) {
			sum += Math.pow(n/k, 3);
			sum += Math.pow((n+k/2)/k, 3);
		}else {
			sum += Math.pow(n/k, 3);
		}

		System.out.println(sum);

	}
}

Measured memory_bytes: 23252
n, m, c = map(int, input().split())
b = list(map(int, input().split()))

ans = 0
for i in range(n):
  a = list(map(int, input().split()))
  t = 0
  for j in range(m):
    t += a[j] * b[j]
  t += c
  if t > 0:
    ans += 1
print(ans)

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

int main(){
	int h1,h2,k1,k2,a,b,c,d;
	cin>>h1>>h2>>k1>>k2>>a>>b>>c>>d;
	if(a*h1 + floor(h1/10)*c +  b*h2 + floor(h2/20)*d > a*k1 + floor(k1/10)*c +  b*k2 + floor(k2/20)*d)cout<<"hiroshi"<<endl;
	else if(a*h1 + floor(h1/10)*c +  b*h2 + floor(h2/20)*d == a*k1 + floor(k1/10)*c +  b*k2 + floor(k2/20)*d)cout<<"even"<<endl;
	else cout<<"kenjiro"<<endl;
	return 0;
}


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend()
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

const ll MAX_H = 400, MAX_W = 400;
ll H, W;
bool grid[MAX_H][MAX_W];
bool is_reached[MAX_H][MAX_W];

bool in_grid(ll x, ll y) {
   return ((0 <= x && x < H) && (0 <= y && y < W));
}

int main(){
   cin >> H >> W;
   REP(i, H){
      string s; cin >> s;
      REP(j, W){
         (s[j] == '#') ? grid[i][j] = 1 : grid[i][j] = 0;
      }
   }
   ll ans = 0;
   ll b = 0, w = 0;
   REP(i, H){
      REP(j, W){
         if(is_reached[i][j]) continue;
         b = 0, w = 0;
         queue<Pii> que;
         que.push(mp(i, j));
         is_reached[i][j] = true;
         while(!que.empty()){
            Pii p = que.front();
            que.pop();
            ll x = p.first, y = p.second;
            (grid[x][y]) ? b++ : w++;
            REP(k, 4){
               ll X = x + dx[k], Y = y + dy[k];
               if(in_grid(X, Y) && (!is_reached[X][Y]) && (grid[x][y] ^ grid[X][Y])){
                  que.push(mp(X, Y));
                  is_reached[X][Y] = true;
               }
            }
         }
         ans += b * w;
//         printf("i = %lld, j = %lld, b = %lld, w = %lld\n", i, j, b, w);
      }
   }
   cout << ans << endl;
}


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

using namespace std;

char tr(char c)
{
  if ( c > 0x40 && c < 0x5b)
    return (c + 0x20);
  else if ( c > 0x60 && c < 0x7b)
    return (c - 0x20);
  else
    return c;
}

int main()
{
  string s;
  getline(cin,s);

  for ( int i = 0; i < (int)s.size(); i++ )
    cout << tr(s[i]);
  cout << endl;
  
  return 0;
}

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

int main() {
  int N ;
   cin >> N;
  vector <int> h(N);
  for ( int i=0 ; i<N ; i++){
    cin >> h.at(i) ;
  }
  sort ( h.begin(),h.end() );
  cout << h.at(N-1) - h.at(0) << endl;
}

Measured memory_bytes: 3592
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int c=sc.nextInt();
		int i,j,k,cc=0;
		int[]a=new int[m];
		int[][]b=new int [n][m]; 
		
		for(k=0;k<m;k++) {
			a[k]=sc.nextInt();
		}
		
		for( i=0;i<n;i++) {
			for(j=0;j<m;j++) {
				b[i][j]=sc.nextInt();
			}
		}
		
		int []ans=new int[n];
		
		for(i=0;i<n;i++) {
			for(j=0;j<m;j++) {
				ans[i]+=b[i][j]*a[j];
			}
			ans[i]+=c;
		}
		
		for(i=0;i<n;i++) {
			if(ans[i]>0) {
				cc++;
			}
		}
		System.out.println(cc);
		
	}

}


Measured memory_bytes: 23380
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int n,i,t,x;
		n=stdIn.nextInt();
		for(i=1;i<=n;i++){
			t=0;
			x=i;
			while(x!=0){
				if(x%10==3){
					t++;
					break;
				}
				x/=10;
			}
			if(i%3==0||t!=0)System.out.print(" "+i);
		}
		System.out.println();
	}
}


Measured memory_bytes: 28720
#include <cstdio>
#include <vector>
#include <set>

std::set<int> divisors(int n) {
  std::set<int> res;
  for (int i = 1; i*i <= n; ++i) {
    if (n % i == 0) {
      res.insert(i);
      res.insert(n/i);
    }
  }
  return res;
}

int main() {
  int M = 300000;
  std::vector<int> sieve(M+1);

  sieve[1] = -2;
  for (int i = 2; i*i <= M; ++i) {
    if (!(i % 7 == 1 || i % 7 == 6)) continue;
    if (sieve[i]) continue;
    for (int j = i*i; j <= M; j += i) {
      sieve[j] = i;
    }
  }

  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 1) break;

    auto d = divisors(n);
    printf("%d:", n);
    for (auto i: d) {
      if (!(i % 7 == 1 || i % 7 == 6)) continue;
      if (sieve[i] == 0) printf(" %d", i);
    }
    puts("");
  }
}



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

int main(){
  ll n,u,v;
  cin>>n;
  ll ans=n*(n+1)*(n+2)/6;
  for(int i=1;i<n;i++){
    cin>>u>>v;
    ans-=min(u,v)*(n+1-max(u,v));
  }
  cout<<ans<<endl;
}


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

int dp[4005][4005];
int tot[2005][2];
const int mod=998244353;


signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    string a;
    cin>>a;
    int n=a.length();
    dp[0][0]=1;
    a="#"+a;
    for(int i=1;i<=n;i++)
    {
        tot[i][0]=tot[i-1][0];
        tot[i][1]=tot[i-1][1];
        if(a[i]=='0')
            tot[i][0]+=2;
        else if(a[i]=='1')
        {
            tot[i][0]++;
            tot[i][1]++;
        }
        else
        {
            tot[i][1]+=2;
        }        
    }

    for(int i=0;i<=tot[n][0];i++)
    {
        for(int j=0;j<=tot[n][1];j++)
        {
            if(i+j==0)
                continue;
            if(i>0)
            {
                int z=i+j;
                z=min(z,n);
                if(tot[z][0]>=i)
                {
                    dp[i][j]+=dp[i-1][j];
                }
            }
            if(j>0)
            {
                int z=i+j;
                z=min(z,n);
                if(tot[z][1]>=j)
                {
                    dp[i][j]+=dp[i][j-1];
                }
            }
            dp[i][j]%=mod;
        }
    }
    cout<<dp[tot[n][0]][tot[n][1]];


}

Measured memory_bytes: 42968
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

/*
 貪欲
 ①決定問題 必ず解に含まれる(含むように変換できる)ものから決めていく みんプロ本選B
 ②最適化問題 任意の解から評価を落とさず解に含められるようなものから決めていく 区間スケジューリングとか
 ③
 */

/*
 DP
 ①DPはある程度決め打ちをするべき
 */

class union_find {
public:
	union_find(int n)
	: par_(n, -1)
	{}
	void init(int n) {
		par_.assign(n, -1);
	}

	int root(int x) {
		return par_[x] < 0 ? x : par_[x] = root(par_[x]);
	}

	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if(x == y) {
			return false;
		} else {
			if(par_[x] < par_[y]) {
				par_[x] += par_[y];
				par_[y] = x;
			} else {
				par_[y] += par_[x];
				par_[x] = y;
			}
			return true;
		}
	}

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

	int size(int x) {
		return -par_[root(x)];
	}

private:
	std::vector<int> par_;
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin>>n>>m;
	union_find uf(n);
	vector<vector<ll>> li(m);
	REP(i,n) {
		ll k;
		cin>>k;
		REP(j,k) {
			ll l;
			cin>>l;
			l--;
			li[l].pb(i);
		}
	}
	REP(i,m) {
		REP(j,(ll)li[i].size()) {
			uf.unite(li[i][j],li[i][0]);
		}
	}
	if(uf.size(0)==n) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


Measured memory_bytes: 4736
N, = map(int, input().split())
M = 10**9+7
d = [set() for _ in range(N+1)]
from collections import deque
for _ in range(N-1):
    a, b = map(int, input().split())
    d[a].add(b)
    d[b].add(a)


stack = deque([1])
leafs = set()
p = [0 for _ in range(N+1)]
vs = set([1])
vv = list()
while stack:
    v = stack.popleft()
    vv.append(v)
    for u in d[v]:
        if u in vs:
            continue
        p[u] = v
        vs.add(u)
        stack.append(u)

dp1 = [-1 for _ in range(N+1)]
dp2 = [-1 for _ in range(N+1)]
for v in vv[::-1]:
    if len(d[v]) == 1 and v != 1:
        dp1[v] = 1
        dp2[v] = 1
        continue
    xx=yy=1
    for u in d[v]:
        if p[v] == u:
            continue
        xx = (xx * dp2[u])%M
        yy = (yy * (dp1[u] + dp2[u]))%M
    dp1[v] = xx
    dp2[v] = yy
print((dp1[1]+dp2[1])%M)


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define en '\n'
#define fs first
#define sd second

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, m;
    cin >> n >> m;
    vector<ll> h(n);
    for(auto& el : h){
        cin >> el;
    }
    vector< vector<int>> g(n);
    ll l, r;
    for(int i = 0; i < m; ++i){
        cin >> l >> r;
        --l; --r;
        g[l].push_back(r);
        g[r].push_back(l);
    }
    ll res = 0;
    for(int i = 0; i < n; ++i){
        bool r = true;
        for(const auto& el : g[i]){
            if(h[i] <= h[el]){
                r = false;
                break;
            }
        }
        res += r;
    }
    cout << res << en;
}

Measured memory_bytes: 9272
import numpy as np
import fractions

a,b,m=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
ans=min(A)+min(B)
for k in range(m):
    i,j,x=map(int, input().split())
    ans=min(ans,A[i-1]+B[j-1]-x)
if(ans<0):ans=0
print(ans)

Measured memory_bytes: 28672
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
 
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
   
using namespace std;
   
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
   
static const double EPS = 1e-8;
   
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  string text;
  const char dict[] = {'A','Z'};
  while(cin >> text){
      int index = 0;
      bool hasAZ = false;
      for(int i = 0; i < text.size(); i++){
        if(dict[index] == text[i]){
          index++;
          if(index % 2 == 0){
            cout << "AZ";
            index = 0;
            hasAZ = true;
          }
        }
      }
      if(!hasAZ){
        cout << "-1";
      }
      cout << "\n";
  }
}

Measured memory_bytes: 1156
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

int main(){
	
	int N, M;
	
	cin >> N >> M;
	
	string F[100];
	
	for(int i = 0; i < N; i++){
		cin >> F[i];
	}
	
	int count_W[100];
	int count_B[100];
	int count_R[100];
	
	count_W[0] = 0;
	count_B[0] = 0;
	count_R[0] = 0;
	
	for(int i = 0; i < N; i++){
		int w = 0;
		int b = 0;
		int r = 0;
		for(int j = 0; j < M; j++){
			if(F[i][j] == 'W'){
				w++;
			}else if(F[i][j] == 'B'){
				b++;
			}else{
				r++;
			}
		}
		count_W[i + 1] = b + r;
		count_B[i + 1] = w + r;
		count_R[i + 1] = w + b;
	}
	
	for(int i = 1; i <= N; i++){
		count_W[i] += count_W[i - 1];
		count_B[i] += count_B[i - 1];
		count_R[i] += count_R[i - 1];
	}
	
	int ans = 100000000;
	
	for(int i = 1; i < N; i++){
		for(int j = i + 1; j < N; j++){
			ans = min(ans, count_R[N] - count_R[j] + count_B[j] - count_B[i] + count_W[i]);
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3224
S = input().split(" ")
H = int(S[0])
W = int(S[1])


def calculate(h, w):
    result = []
    for i in range(1, h):
        s1 = w * i
        s2 = (h - i) * (w // 2)
        s3 = (h - i) * w - s2

        minValue = min(min(s1, s2), s3)
        maxValue = max(max(s1, s2), s3)

        result.append(maxValue - minValue)

        if i <= h - 1:
            s1 = w * i
            s2 = ((h - i) // 2) * w
            s3 = (h - i) * w - s2
            minValue = min(min(s1,s2),s3)
            maxValue = max(max(s1,s2),s3)
            result.append(maxValue - minValue)

    for i in range(1, w):
        if i <= w - 1:
            s1 = i * h
            s2 = ((w - i) // 2) * h
            s3 = (w - i) * h - s2

            minValue = min(min(s1, s2), s3)
            maxValue = max(max(s1, s2), s3)
            result.append(maxValue - minValue)

        s1 = i * h
        s2 = (w - i) * (h //2)
        s3 = (w - i) * h - s2
        minValue = min(min(s1, s2), s3)
        maxValue = max(max(s1, s2), s3)
        result.append(maxValue - minValue)

    print(min(result))

calculate(H, W)


Measured memory_bytes: 18928
#include <iostream>
#include <stdlib.h>
#include <vector>

using namespace std;

int main(){
  int n, k;
  vector<int> x;
  cin >> n >> k;
  int in;
  int i;
  for(i=0; i<n; i++){
    cin >> in;
    x.push_back(in);
  }
  int sum = 0;
  for(i=0; i<n; i++){
    sum += min(abs(x[i]-0), abs(x[i]-k));
  }
  cout << sum*2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

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

typedef long long ll;

int main() {
	//入力;
	int H, W;
	cin >> H >> W;
	vector<string> maze(H);
	REP(i, H) { cin >> maze[i]; }

	queue<int> qy, qx;
	vector<vector<int>> v(H, vector<int>(W, -1));

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


	REP(i, H) {
		REP(j, W) {
			if (maze[i][j] == '#') {
				qy.push(i);
				qx.push(j);
			}
		}
	}

	int ans = 0;

	do {
		queue<int> tmpy, tmpx;
		int nuri=0;

		while (!qy.empty()) {
			int y = qy.front();
			int x = qx.front();
			qy.pop();
			qx.pop();

			REP(i, 4) {
				int ny = y + dy[i];
				int nx = x + dx[i];
				if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
				if (maze[ny][nx] == '#') continue;
				else {
					maze[ny][nx] = '#';
					tmpy.push(ny);
					tmpx.push(nx);
					++nuri;
				}

			}

		}

		if(nuri> 0) ++ans;

		while (!tmpy.empty()) {
			qy.push(tmpy.front());
			qx.push(tmpx.front());
			tmpy.pop();
			tmpx.pop();
		}
		
	} while (!qy.empty());

	cout << ans << endl;

	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);

	return 0;
}

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

int main(){
    long double a,b,c;
    cin >> a >> b >> c;
    long double sahen = a + b + 2*(long double)(sqrt(a))*(long double)(sqrt(b));
    long double uhen = c;
    if(sahen < uhen) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;
typedef long long SI;
typedef unsigned long long UI;

using namespace std;

int main() {

  UI N,M;
  cin >> N >> M;

  SI lmax = 0;
  SI rmin = N;
  for(UI i=0; i<M; i++) {
    SI l, r;
    cin >> l >> r;
    lmax = max(lmax, l);
    rmin = min(rmin, r);
  }
  cout << max(rmin - lmax + 1, 0LL) << endl;

  return 0;
}



Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            
            int[] counts  = new int[128];
            while(sc.hasNext()){
                String str = sc.nextLine().toLowerCase();
                for(int i=0;i<str.length();i++){
                    counts[str.charAt(i)]++;
                }
            }
            for(char ch='a';ch<='z';ch++){
                System.out.println(ch+" : "+counts[ch]);
            }
            return;
        }
        
    }
}


Measured memory_bytes: 26112
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Yes()       printf("Yes\n")
#define No()        printf("No\n")

int main(){
	char s[200001]={0}, t[200001]={0}, db[27]={0};
	scanf("%s%s",s,t);
	for(int i=0; i<strlen(s); i++){
		if	   ( db[s[i]-'a']==t[i] ){ continue; }
		else if( db[s[i]-'a']==0	){ db[s[i]-'a'] = t[i]; }
		else						 { printf("No\n"); return 0; }
	}
	qsort( db, 26, sizeof(char), strcmp );
	for(int i=0; i<26; i++){
		if( db[i]!=0 && db[i]==db[i+1] ){ printf("No\n"); return 0; }
	}
	printf("Yes\n");
  	return 0;
}

Measured memory_bytes: 2032
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

ll N;
ll A[300001];
ll ans[300001];
ll one;

int main(){
	cin.tie(0);
	cout.tie(0);

	ios::sync_with_stdio(false);

	cin >> N;
	FOR(i, 0, N) {
		cin >> A[i+1];
	}

	ll mid = N / 2+1;
	
	FOR(i, mid, N + 1) {
		ans[i] = A[i];
		if (A[i] == 1)one++;

	}
	for (int i = mid - 1; i >= 1; i--) {
		int cur = i*2;
		int cnt = 0;
		while (cur <= N) {
			cnt += ans[cur];
			cur += i;
		}
		if (A[i] != cnt%2) {
			ans[i] = 1;
			one++;
		}
	}

	cout << one << endl;
	FOR(i, 1, N + 1) {

		if (ans[i] == 1) {
			cout << i << " ";
		}
	}
	cout << endl;


	return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
//const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	const int mod = 2019;
	int l, r;
	cin >> l >> r;
	if (r - l >= 2019) {
		cout << 0 << endl;
		return 0;
	}
	l %= mod;
	r %= mod;
	int ans = inf;
	for (int i = l; i < r; ++i) {
		for (int j = i + 1; j <= r; ++j) {
			ans = min(ans, (i * j) % mod);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

ll mod(ll x){
    ll res=x%MOD;
    return res+(res<0?MOD:0);
}
ll inv(ll x){
    ll b=MOD,u=1,v=0;
    while(b){
        ll t=x/b;
        x-=t*b;swap(x,b);
        u-=t*v;swap(u,v);
    }
    return mod(u);
}
vector<ll> prods(int x){
    vector<ll> res(x+1);
    res[0]=1;
    for(int i=1; i<=x; i++)res[i]=mod(i*res[i-1]);
    return res;
}
vector<ll> p;//p=prods(MAX_n)
ll comb(ll a, ll b){
    if(b<0||b>a)return 0;
    return mod(mod(p[a]*inv(p[b]))*inv(p[a-b]));
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x,y;cin>>x>>y;
    if((-x+2*y)%3!=0||(-2*x+y)%3!=0){cout<<0<<endl;return 0;}
    ll n1 = (-x+2*y)/3;
    ll n2 = (2*x-y)/3;
    if(n1<0||n2<0){cout<<0<<endl;return 0;}
    p = prods(2000001);
    cout<<comb(n1+n2,n1)<<endl;
    return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
#include <iomanip>
#include<numeric>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define rep(i, k) for (i = 0; i < k; i++) 
typedef long long ll;
typedef pair<ll, ll> l_l;
int i, j;

ll b, k, n = 0, z = 0, x, y, p[1010] = {};
	vector<ll> v,vec;
	string s;
int main() {
	cin >> s;
	b = 700;

	rep(i,s.length()) {
		if (s[i] == 'o') {
			b += 100;
		}

	}

	cout << b;
	return 0;

}


Measured memory_bytes: 3620
/*input
8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int m,n,x;
    cin>>n>>m>>x;
    int c[n];
    int A[n][m];
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        for(int j=0;j<m;j++)
            cin>>A[i][j];
    }
    int ans=INT_MAX;
    for(int i=0;i<pow(2,n);i++)
    {
        bitset<12> num(i);
        int cost=0;
        int arr[m]={0};
        for(int j=11;j>=0;j--)
        {
            if(num[j]==1)
            {
                cost+=c[j];
                for(int k=0;k<m;k++)
                {
                    arr[k]+=A[j][k];
                }
            }
            int flag=0;
            for(int j=0;j<m;j++)
            {
                if(arr[j]<x)
                    flag=1;
            }
            if(flag==0)
                ans=min(ans,cost);
        }
    }
    if(ans==INT_MAX)
            ans=-1;
    cout<<ans<<'\n';
}

Measured memory_bytes: 4060
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int n = sc.nextInt();


        if (n == 0) {
            System.out.println(x);
            return;
        }

        Set<Integer> p = new HashSet<>();
        for (int i = 0; i < n ; i++) {
            p.add(sc.nextInt());
        }

        if (!p.contains(x)) {
            System.out.println(x);
            return;
        }


        int result = Integer.MAX_VALUE;
        int i = 0;
        while (i <= n) {
            if (!p.contains(x - i)) {
                result = x - i;
                break;
            }

            if (!p.contains(x + i)) {
                result = x + i;
                break;
            }

            i++;
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 35888
#include<bits/stdc++.h>
#define debug(x) cerr<<"\tDEBUG: "<<#x<<" = "<<(x)<<endl
#define debug2(a,b) cerr<<#a<<"\t"<<#b<<" = "<<(b)<<endl
using namespace std;
const int maxn=105;
bool cur1;
int n,m;

bool cur2;
int main(){
//	double sz=&cur1-&cur2;
//	cout<<sz/1024/1024<<endl;
	int a,b;
	cin>>a>>b;
	b=b*2+1;
	cout<<(a-1)/b+1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 1e15;
const double eps = 1e-6;
typedef tuple<ll, ll, ll> T;


int main() {
	vector<ll> prime(100500, 1);
	prime[0] = 0;
	prime[1] = 0;
	for (int step = 2; step <= 2000; step++) {
		for (int mult = 2;mult*step < 100500; mult++) {
			prime[step*mult] = 0;
		}
	}
	vector<ll> imos(100499);
	for (int i = 1;i < imos.size();i++) {
		if (i % 2 && prime[i] && prime[(i + 1) / 2])
			imos[i]++;
		imos[i] += imos[i - 1];
	}
	ll Q;
	cin >> Q;
	for (int i = 0;i < Q;i++) {
		ll l, r;
		cin >> l >> r;
		cout << imos[r] - imos[l - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 2176
using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace _0815
{
    class Program
    {
        static long x, k, d;
        static void Main(string[] args)
        {
            var xkd = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            x = xkd[0];
            k = xkd[1];
            d = xkd[2];

            long result = Solution();
            Console.WriteLine(result);
        }

        static long Solution()
        {
            x = Math.Abs(x);
            long res = 0;
            if (x/d >= k)
            {
                res = x - k * d;
            }
            else
            {
                while (x >= d)
                {
                    x -= d;
                    k--;
                }
                k = k % 2;
                res = x - d * k;
            }
            res = Math.Abs(res);
            return res;
        }
    }
}


Measured memory_bytes: 28132
#include<stdio.h>
#include<math.h>
int N,X[105],Y[105],i;
double D;
 
double d(int p)
{
    int i;
    for(D=0.0,i=0;i<N;i++)
    {
        if(p==4)D=D>abs(X[i]-Y[i])?D:abs(X[i]-Y[i]);
        else D+=pow(1.0*abs(X[i]-Y[i]),p);
    }
    return p==4?D:pow(D,1.0/p);
}
 
int main()
{
    scanf("%d",&N);
    for(i=0;i<N;i++)scanf("%d",X+i);
    for(i=0;i<N;i++)scanf("%d",Y+i);
    for(i=1;i<5;i++)printf("%lf\n",d(i));
    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
int x,n;
vector<bool>a(201); 

bool check(int y){
	if(y<0||!a[y]){
		cout<<y;
		return 1;
	}
	return 0;
}
int main(){
	cin>>x>>n;
	int v;
	for(int i=0;i<n;i++){
		cin>>v;
		a[v]=1;
	}
	if(check(x))return 0;
	for(int i=1;i<=100;i++){
		int c=x-i;
		if(check(c))return 0;
		c=x+i;
		if(check(c))return 0;
	}
	return 0;
}


Measured memory_bytes: 3620
import java.io.*;
import java.util.*;

 class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }

    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
//        int t = ri();
        int t=1;
        while (t-- > 0)
        {
            String str=rs();
            if(str.equals("ABC"))
            {
                ans.append("ARC\n");
            }
            else
            {
                ans.append("ABC\n");
            }

        }
        out.print(ans.toString());
        out.flush();

    }
}


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

using namespace std;

typedef long long int ll;

#define FOR(i,l,r) for(i=l;i<r;i++)

#define REP(i,n) FOR(i,0,n)

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

#define P pair<ll,ll>

#define F first

#define S second

signed main(){

  ll N,t=1,B;cin>>N;
  while(1){
    if(N%t==0){
      REP(B,121)
      if(5*B*B*B*B-10*B*B*B*t+10*B*B*t*t-5*B*t*t*t+t*t*t*t==N/t)break;
    }
    if(B!=121)break;
    t++;
  }
  cout<<B<<" "<<B-t<<endl;

  return 0;

}

Measured memory_bytes: 3644
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 998244353;

struct SegmentTree{
    const int INF = 1e9;
    int n, width;
    VI dat;

    void init(int x){
        n = x;
        width = 1;
        while (width < n) width *= 2;
        dat.resize(2*width-1);
        REP(i,2*width-1) dat[i] = INF;
    }

    void update(int i, int x){
        i += width - 1;
        dat[i] = x;
        while (i > 0){
            i = (i - 1) / 2;
            dat[i] = min(dat[i*2+1], dat[i*2+2]);
        }
    }

    int query(int a, int b, int k, int l, int r){
        if (r <= a || b <= l) return INF;
        if (a <= l && r <= b) return dat[k];
        int vl = query(a, b, k*2+1, l, (l+r)/2);
        int vr = query(a, b, k*2+2, (l+r)/2, r);
        return min(vl, vr);
    }

    // [l, r)
    int query(int l, int r){
        return query(l, r, 0, 0, width);
    }
};

int main(void){
    int n;
    cin >> n;
    vector<PL> p(n);
    REP(i,n){
        p[i].first = in();
        p[i].second = in();
    }
    sort(ALL(p));
    VL x(n), d(n);
    REP(i,n){
        x[i] = p[i].first;
        d[i] = p[i].second;
    }
    VI r(n);
    SegmentTree seg;
    seg.init(n);
    FORR(i,n-1,0){
        int j = lower_bound(ALL(x), x[i] + d[i]) - x.begin();
        j--;
        if (j > i) j = -seg.query(i + 1, j + 1);
        r[i] = j;
        seg.update(i, -r[i]);
    }
    // REP(i,n) cout << x[i] << " " << d[i] << "  " << r[i] << endl;
    VL dp(n + 1);
    dp[0] = 1;
    REP(i,n){
        (dp[i + 1] += dp[i]) %= mod;
        (dp[r[i] + 1] += dp[i]) %= mod;
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 10880
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x,y,z,n,m,i;
char o;
cin>>n;
char a[n];
for(i=0;i<n;i++)
{
    a[i]='p';
}
cin>>m;
for(i=1;i<=m;i++)
{
    cin>>x>>o;
    if(a[x-1]!='p')
    {
        if(a[x-1]!=o)
        {
            cout<<"-1";
            return 0;
        }
        else
        {
            a[x-1]=o;

        }
    }
    else{

        a[x-1]=o;
    }
}
if(a[0]=='p')
{

     if(n==1)
    {
         a[0]='0';
    }
    else
    {
          a[0]='1';
    }
}

for(i=1;i<n;i++)
{
    if(a[i]=='p')
    {
       a[i]='0';
    }
}
if(a[0]=='0' && n!=1)
{
    cout<<"-1";
    return 0;
}
else
{
    for(i=0;i<n;i++)
{
    cout<<a[i];
}
}

  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	ar := make([]int, 3)
	fmt.Scan(&ar[0], &ar[1], &ar[2])
	sum := 0
	if ar[0] == ar[1] && ar[1] == ar[2] {
		fmt.Println(sum)
		return
	}
	for {
		sort.Ints(ar)
		if ar[2]-ar[0] >= 2 {
			sum++
			ar[0] += 2
		} else {
			sum++
			ar[0]++
			ar[1]++
		}
		if ar[0] == ar[1] && ar[1] == ar[2] {
			fmt.Println(sum)
			return
		}
	}
}


Measured memory_bytes: 512
#include <iostream>
#include "stdio.h"

int BinarySearchArray(int *A, int arraySize, int key) {
	int left = 0;
	int right = arraySize;
	int mid;

	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		if (key < A[mid]) right = mid;
	}

	return 0;
}



int main() {
	int arraySize, *A, searchKeysSize, key, foundSum = 0;

	scanf("%d", &arraySize);
	A = new int[arraySize + 1];
	for (int i = 0; i < arraySize; i++) {
		scanf("%d", &A[i]);
	}

	scanf("%d", &searchKeysSize);
	for (int i = 0; i < searchKeysSize; i++) {
		scanf("%d", &key);
		foundSum += BinarySearchArray(A, arraySize, key);
	}

	printf("%d\n", foundSum);

	return 0;
}


Measured memory_bytes: 3488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    double n;cin>>n;
    int c1 = floor(n/1.08);
    int c2 = ceil(n/1.08);
    if(int(c1*1.08)==int(n)){co(c1);return 0;}
    if(int(c2*1.08)==int(n)){co(c2);return 0;}
    co(":(");
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int a[200005]={0};
int cmp(int x,int y)
{
	return x>y;
}
int main()
{
	int n,k;
	int nub=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		int w;
		scanf("%d",&w);
		if(a[w]==0)
		{
			nub++;
		}
		a[w]++;
	}
	//printf("%d\n",nub);
	sort(a,a+200005,cmp);
	//printf("%d %d %d",a[0],a[1],a[2]);
	long long sum=0;
	for(int i=nub-1;i>k-1;i--)
	{
		sum=sum+a[i];
	}
	printf("%lld\n",sum);
	
	
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n, m;
    ll l;
    cin >> n >> m >> l;
    vector<vector<ll>> d(n, vector<ll>(n, inf));
    for (int i = 0; i < n; ++i) {
        d[i][i] = 0;
    }
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        d[a][b] = d[b][a] = c;
    }
    // わーしゃるふろいど
    for (int k = 0; k < n; k++) {         // 経由する頂点
        for (int i = 0; i < n; i++) {     // 始点
            for (int j = 0; j < n; j++) { // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    //
    vector<vector<ll>> d2(n, vector<ll>(n, inf));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (d[i][j] <= l) {
                d2[i][j] = 1;
            }
        }
    }

    for (int k = 0; k < n; k++) {         // 経由する頂点
        for (int i = 0; i < n; i++) {     // 始点
            for (int j = 0; j < n; j++) { // 終点
                d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
            }
        }
    }

    int q;
    cin >> q;
    vector<ll> ans;
    for (int i = 0; i < q; ++i) {
        int s, t;
        cin >> s >> t;
        ans.push_back(d2[s - 1][t - 1]);
    }

    for (auto k : ans) {
        if (k != inf)
            cout << k - 1 << endl;
        else
            cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int ans[100010];
vector <int> v[100010];
int main(){
  int n;
  while(cin>>n){
    ll tmp=1;
    memset(ans, -1, sizeof ans);
    ans[1]=2;
    for(int i=3; tmp<100010; ++i){
        tmp+=i-1;
        ans[tmp]=i;
    }
    int cnt=1;
    if(ans[n]!=-1){
        cout<<"Yes"<<endl;
        printf("%d\n",ans[n]);
        for(int i=1; i<=ans[n]; ++i){
            for(int j=i+1; j<=ans[n]; ++j){
                v[i].push_back(cnt);
                v[j].push_back(cnt);
                ++cnt;
            }
        }
        for(int i=1; i<=ans[n] ;++i){
            cout<<v[i].size()<<" ";
            for(int j=0; j<v[i].size(); ++j){
                printf("%d ",v[i][j]);
            }
            printf("\n");
        }
    }
    else{
        cout<<"No"<<endl;
    }
  }
  return 0;
}




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

int main()
{
  int H, N;
  cin >> H >> N;
  for (int i = 0; i < N; ++i)
  {
    int A;
    cin >> A;
    H -= A;
  }
  cout << ((H <= 0) ? "Yes" : "No");
  return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	long long a,b,x,y,total=0;
	
	cin >> a >> b;
	
	while(a--){
		cin >> x >> y;
		if(sqrt(x*x + y*y)<=b){
			total++;
		}
	}
	cout << total << endl;
}

Measured memory_bytes: 3668