akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
vector<int> h(N);
const int INF=1e9+5;
vector<int> dp(N,-1);
int n;
int f(int i){
    if(dp[i]!=-1) return dp[i];
    if(i>n) return INF;
    if(i==n) return 0;
    return dp[i]=min(abs(h[i]-h[i+1])+f(i+1),abs(h[i]-h[i+2])+f(i+2));
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",&h[i]);
    }
    cout<<f(1)<<'\n';
    //while(1);
    return 0;
}

Measured memory_bytes: 3328
/*
                ******
		
        Author: Nguyen Phuc Chuong

                ******
*/

#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> graph;
int n, m;
bool vis[200007];

int dfs(int x)
{	
	vis[x] = true;
	int cnt = 1;
	for (int i = 0; i < (int)graph[x].size(); i++)
	{
		if (!vis[graph[x][i]])
			cnt += dfs(graph[x][i]);		
	}
	return cnt;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	graph = vector<vector<int>>(n, vector<int>(0));
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	int ans = 1;
	for (int i = 0; i < n; i++)
	{
		if (!vis[i])
			ans = max(ans, dfs(i));
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 23772
/*
      author  : nishi5451
      created : 14.08.2020 19:39:42
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    string s;
    cin >> s;
    int cnt = 0;
    rep(i,int(s.size())){
        if(i==0){
            if(s[i]!='A'){
                cout << "WA" << endl;
                return 0;
            }
        }
        else if(i==1 || i==s.size()-1){
            if(!(s[i]>='a' && s[i]<='z')){
                cout << "WA" << endl;
                return 0;
            }
        }
        else{
            if( !(s[i]>='a' && s[i]<='z') ){
                if(s[i]!='C'){
                    cout << "WA" << endl;
                    return 0;
                }
                cnt++;
            }
        }
    }
    if(cnt!=1) cout << "WA" << endl;
    else cout << "AC" << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, k;
    cin >> a >> b >> k;
    set<int> s;
    for(int i = 0; i < k; i++) if(a + i <= b) s.insert(a + i);
    for(int i = 0; i < k; i++) if(b - i >= a) s.insert(b - i);
    for(auto p : s) cout << p << endl;
}

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

using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 2; i <= n; i++){
        int num;
        cin >> num;
        a[num]++;
    }
    for(int i = 1; i <= n; i++){
        cout << a[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>

//#define PI 3.141592653589

using namespace std;


int ans;
int n, s;


/*
iはこれまでに足し合わせた数字の数

*/
void dfs(int i, int kazu, int sum)
{
	if (i == n && sum == s)
	{
		ans++;
		return;
	} else if (i == n) {
		return;
	} else if (kazu == 10) {
		return;
	}
	
	dfs(i, kazu+1, sum);
	dfs(i+1, kazu+1, sum+kazu);
}


int main()
{
	while (1)
	{
		cin >> n >> s;
		if (n == 0 && s == 0) break;
		ans = 0;
		dfs(0, 0, 0);
		cout << ans << endl;
	}
	
	return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;


int N, M;
ll A[100000];
priority_queue<int, vector<int>, less<int>> que;

signed main(){
    cin >> N >> M;
    ll a = 0, sum = 0;
    REP(i, N){
        cin >> a;
        que.push(a);
        sum += a;
    }
    ll t;
    REP(i, M){
        t = que.top();
        que.pop();
        sum -= (t + 1) / 2;
        t /= 2;
        que.push(t);
    }
    PRINT(sum);
    return 0;
}

Measured memory_bytes: 892
import Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  [d, x] <- (map read . words) <$> getLine :: IO [Int]
  as <- replicateM n readLn :: IO [Int]
  print $ x + sum (map (\i -> chocolatesFor i as d) [0..n-1])

chocolatesFor :: Int -> [Int] -> Int -> Int
chocolatesFor i as d =
  let a = as !! i
      t = (d - 1) `div` a
  in t + 1


Measured memory_bytes: 1020
#include <stdio.h>
int main()
{
    int a[1000];
    int n, j;
    scanf("%d", &n);
    for(j=0; j<n; j++)
    {
        scanf("%d", &a[j]);
    }
    for(j = n-1; j>=0; j--)
    {
      printf("%d", a[j]);
      if(j  > 0)
            printf(" ");
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v;
    int a; cin >> a;
    v.emplace_back(a);    
    REP(i,n-1) {
        int x; cin >> x;
        if (v.back() >= x ) {
            v.emplace_back(x);
        } else {
            auto it = upper_bound(ALL(v),x,greater<int>());
            *it = x;
        }
    }
    
    cout << v.size() << endl;

    return 0;
}

Measured memory_bytes: 892
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

ll n,m,a,b,c,x,y,aa[100010],ba[100010];
bool r,br,ar;
string s;
char ca,cb;


int main(){
    cin>>n>>m;
    a=0;
    
    a+=(n/m)*(n/m)*(n/m);
    if(!(m%2) and n*3>=m)a+=((n-m/2)/m+1)*((n-m/2)/m+1)*((n-m/2)/m+1);
    

    printf("%lld\n",a);
    
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print(max(a + b, a - b, a * b))
    return

#B
def B():
    n = II()
    s = S()
    ans = 0
    for i in range(n + 1):
        s1 = list(set(s[i:]))
        s2 = list(set(s[:i]))
        b = 0
        for si in s1:
            b += si in s2
        ans = max(ans, b)
    print(ans)
    return

#C
def C():
    n = II()
    s = S()
    dp = [0 for i in range(n)]
    for num,si in enumerate(s):
        if si == "E":
            dp[num] = dp[num-1]+1
        else:
            dp[num] = dp[num - 1]
    ans = float("INF")
    a = max(dp)
    for i in range(n):
        ans = min(ans,  a - dp[i] + i - dp[i] + (s[i] == "E"))
    
    print(ans)
    return

#D
def D():
    n = II()
    a = LI()
    bitlength = len(bin(max(a))) - 2
    a = list(map(lambda x: bin(x)[:1:-1], a))
    cumulativebit = [[0] * bitlength for i in range(n)]
    for i in range(n):
        for bi in range(bitlength):
            cumulativebit[i][bi] += cumulativebit[i - 1][bi] + (0 if len(a[i]) <= bi else 1 if int(a[i][bi]) else 0)
    r = 0
    ans = 0
    for l in range(n):
        f = False
        for r in range(r, n):
            for bi in range(bitlength):
                if cumulativebit[r][bi] - cumulativebit[l][bi] >= 2 or (l != r and len(a[r]) > bi and len(a[l]) > bi and int(a[r][bi]) and int(a[l][bi])):
                    f = True
                    break
            if f:
                break
        if f:
            ans += r - l
        else:
            ans += r - l + 1
    print(ans)
    return



#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 131588
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
using namespace std;

int main(){
  int q; cin>>q;
  set<int>s;
  while(q--){
    int x,y;
    cin>>x>>y;
    if(x==1)cout<<s.count(y)<<endl;
    else if(x==0){
      s.insert(y);
      cout<<s.size()<<endl;
    }
    else if(x==2){
      s.erase(y);
    }
  }
}


Measured memory_bytes: 12372
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
 
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};
 

ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
  
   

ll lcm(ll a, ll b)  {
  
   return (a*b)/gcd(a, b);  
} 


int main()
{
	ll a, b; cin>>  a >> b;
	cout<<  lcm(a, b); 
	return 0;
}


Measured memory_bytes: 256
import Data.Bool
import Control.Monad
import qualified Data.Vector as V
main=putStrLn.solve.lines=<<getContents
solve(nm:ab)=bool"No""Yes"$any f$replicateM 2[0..n-m]where
  [n,m]=map read.words$nm
  (as,bs)=V.splitAt n.V.fromList.map V.fromList$ab
  f[i,j]=and.V.zipWith(==)bs$V.map(V.slice j m).V.slice i m$as

Measured memory_bytes: 4880
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}
int main(){
  int N;cin>>N;
  vs W(N);
  rep(i,N)cin>>W[i];
  bool ok=true;
  f(i,0,N-1){
    if(W[i][W[i].size()-1] !=W[i+1][0]){
      ok=false;break;
    }
  }
  sort(all(W));
  f(i,0,N-1){
    if(W[i]==W[i+1]){
      ok=false;
      break;
    }
  }
  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int x;
    scanf("%d", &x);
    for(int i=1; i<=x; i++){
        for(int l=i; l>0; l/=10){
            if(!(i%3) || l%10==3){
                printf(" %d", i);
                break;
            }
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2076
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1e9+10)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main() {
	int A, B, M;
	int ans;
	cin >> A >> B >> M;
	vector<int> as = {};
	vector<int> bs = {};
	int am;
	int bm;
	rep(i, A){
		int a;
		cin >> a;
		as.push_back(a);
		if (i == 0){
			am = a;
		}else if(am > a){
			am = a;
		};
	}
	rep(i, B){
		int b;
		cin >> b;
		bs.push_back(b);
		if (i == 0){
			bm = b;
		}else if(bm > b){
			bm = b;
		}
	}
	ans = am + bm;
	rep(i, M){
		int x, y, c;
		cin >> x >> y >> c;
		if ((as.at(x-1) + bs.at(y-1) - c) < ans){
			ans = as.at(x-1) + bs.at(y-1) - c;
		}
	}

	cout << ans << endl;

	return 0;
}






Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;
map<int, int> ct;
map<int, int> ct2;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define AFOR(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n, m, l;
int a, b, c;
string s[MN];
string str;
string ans;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

/*
int N;
cin >> N;
vi vect(N);
FOR(i,N) cin >> vec.at(i);*/
//sort(vec.begin(),vec.end());
//vvi data(N,vi(4));


/*	int bfs(int x, int y,vvi &A,vvi flag) {
		queue<pii> que;
		que.push(pii(x, y));
		while (que.size()) {
			pii p = que.front(); que.pop();
			AFOR(i, 4) {
				int nx = p.first + dx[i]; int ny = p.second + dy[i];
				if (0 <= nx && nx < N && 0 <= ny && ny < N) {
					if (A.at(p.first).at(p.second) + flag.at(p.first).at(p.second) < A.at(nx).at(ny)) {
						A.at(nx).at(ny) = A.at(p.first).at(p.second) + flag.at(p.first).at(p.second);
						que.push(pii(nx, ny));
					}
				}
			}
		}
		return 0;
	}
	*/
	/*int gcd(int p, int q){
		while(q != 0){
		int r = p % q;
		p = q;
		q = r;
		}
	return p;
	}*/
int N;
int A[200100];
int L[200100];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string T;
	string ans;
	cin >> T;
	int count = 0;

	AFOR(i, T.size()) {
		if (i == T.size() - 1) {
			if (T.at(i) == '?') T.at(i) = 'D';
		}
		else if (T.at(i) == '?') {
				T.at(i) = 'D';
		}
	}
	

	cout << T << endl;


	return 0;
}

Measured memory_bytes: 6908
import sys

n, W = map(int, sys.stdin.readline().split())

val = []
for i in range(n):
    val.append(list(map(int, sys.stdin.readline().split())))

total=0
for vv in sorted(val, key=lambda x:x[0]/x[1], reverse=True):
    if W>=vv[1]: #   50 > 10
        W -= vv[1]
        total += vv[0]
    else:
        total += W*vv[0]/vv[1]
        break

print(total)



Measured memory_bytes: 27112
import sys

h,w,k=map(int,next(sys.stdin).split())
a=list(sys.stdin)

ans=0
for y in range(1<<h):
    for x in range(1<<w):
        ct=0
        for i in range(h):
            if y&(1<<i): continue
            for j in range(w):
                if x&(1<<j): continue
                ct+=a[i][j]=='#'
        ans+=ct==k

print(ans)


Measured memory_bytes: 9160
def main():
    N = int(input())
    a = list(map(int, input().split()))

    s = [0] * N
    s[0] = a[0]
    sr = [0] * N
    sr[0] = a[-1]

    for i in range(1, N):
        s[i] = s[i-1] + a[i]
        sr[i] = sr[i-1] + a[N-i-1]

    ans = 10 ** 18
    for i in range(N-1):
        tmp = abs(s[i] - sr[N-i-2])
        if tmp < ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 28664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
//#include <function>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {

  long N;
  cin >> N;
  vector<long> array(N);
  long sum_a = 0;
  long max_a = 0;
  long ans = 1;
  const long MOD = 998244353;
  REP(i, N) {
    cin >> array[i];
    sum_a += array[i];
    max_a = max_a > array[i]? max_a : array[i];
    ans = (ans * 3) % MOD;
  }

  //long dp[300][(300 * 300) + 1] = {0};
  //long dp1[300][(300 * 300) + 1] = {0};

  vector<vector<long>> dp(300, vector<long>(300 * 310 + 1L, 0L));
  vector<vector<long>> dp1(300, vector<long>(300 * 310 + 1L, 0L));

  dp[0][array[0]] = 1;
  dp[0][0] = 2;
  dp1[0][array[0]] = 1;
  dp1[0][0] = 1;

  REP(i, N - 1){
    REP(j, (N * max_a) + 1) {
      dp[i + 1][j] = (dp[i + 1][j] + 2 * dp[i][j]) % MOD;
      dp[i + 1][j + array[i + 1]] = (dp[i + 1][j + array[i + 1]] + dp[i][j]) % MOD;
      dp1[i + 1][j] = (dp1[i + 1][j] + dp1[i][j]) % MOD;
      dp1[i + 1][j + array[i + 1]] = (dp1[i + 1][j + array[i + 1]] + dp1[i][j]) % MOD;
    }
  }

  long tmp1 = 0;
  long tmp2 = 0;
  if (sum_a % 2 == 0){
    for(long i = sum_a / 2; i < N * max_a + 1; i++){
      tmp1 = (tmp1 + dp[N - 1][i]) % MOD;
      //tmp2 = (tmp2 + dp1[N - 1][i]) % MOD;
    }
    tmp2 = dp1[N - 1][sum_a / 2] % MOD;
  }else{
    for(long i = (sum_a + 1) / 2; i < N * max_a + 1; i++){
      tmp1 = (tmp1 + dp[N - 1][i]) % MOD;
    }
  }
  //cout << ans << endl;
  //cout << tmp1 << endl;
  //cout << tmp2 << endl;


  tmp1 = (tmp1 * 3) % MOD;
  tmp2 = (tmp2 * 3) % MOD;
  ans = (ans - tmp1) % MOD;
  if (ans < 0) ans += MOD;
  ans = (ans + tmp2) % MOD;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 437416
line = input().split()
line2 = []
zenin = int(line[0])
snack = int(line[1])

for i in range(zenin):
  line2.append(i+1)

for i in range(snack):
  person = int(input())
  line3 = input().split()
 
  for i in range(person):
    if int(line3[i]) in line2:
      line2.remove(int(line3[i]))
      
print(len(line2))

Measured memory_bytes: 9228
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>
#include <numeric>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

static const ll MAX = 200000;

#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define rpt(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int main()
{
    IO;

    ll a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;

}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
vi dp(222222,llINF);
vi nxt(222222,-1);
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  string s;
  cin>>s;
  reverse(ALL(s));
  dp[0]=0;
  for(int i=0;i<n;i++){
    if(dp[i] == llINF)continue;
    if(i+m>=n){
      dp[n]=dp[i]+1;
      nxt[n]=i;
      break;
    }
    for(int j=i+m;j>=i;j--){
      if(s[j] == '0'){
	if(dp[j]>dp[i]+1){
	  dp[j] = dp[i]+1;
	  nxt[j]=i;
	  break;
	}
      }
    }
  }
  ll now=n;
  ll num=0;
  /*for(int i=0;i<=n;i++)cout<<dp[i]<<" ";
    cout<<endl;*/
  vi ans;
  if(dp[n]==llINF){cout<<-1<<endl;return 0;}
  for(int i=0;i<dp[n];i++){
    // cout<<nxt[now]<<" ";
    ans.pb(now-nxt[now]);
    //cout<<now-nxt[now]<<" ";
    num=now;
    now=nxt[now];
  }
  //cout<<endl;
  // reverse(ALL(ans));
  for(auto a:ans)cout<<a<<" ";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 5064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N), v(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
    iota(v.begin(), v.end(), 0);
    double sum = 0;
    int cnt = 0;
    do {
        double d = 0;
        for (int i = 1; i < N; i++) {
            auto dx = x[v[i]] - x[v[i - 1]], dy = y[v[i]] - y[v[i - 1]];
            d += sqrt(dx * dx + dy * dy);
        }
        sum += d;
        cnt++;
    } while (next_permutation(v.begin(), v.end()));
    cout << fixed << setprecision(10) << sum / cnt << endl;
}

Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}'; return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

template<typename T>
class Dijkstra {
 public:
  Dijkstra(const int& node_size) : node_size_(node_size) { Initialize(); }
  void Add_Edge(const int& from, const int& to, const T& cost);
  void Solve(const int& source);
  T operator[](const int& to) const;

 private:
  struct edge {
   int to;
   T cost;
  };
  int node_size_;
  std::vector<T> distance_;
  std::vector<std::vector<edge>> graph_;
  void Initialize();
};

template<typename T>
void Dijkstra<T>::Add_Edge(const int& from, const int& to, const T& cost) {
  graph_[from].push_back({to, cost});
}

template<typename T>
void Dijkstra<T>::Solve(const int& source) {
  std::priority_queue<std::pair<T, int>,
                      std::vector<std::pair<T, int>>,
                      std::greater<std::pair<T, int>>> pq;
  distance_[source] = 0;
  pq.push({0, source});

  while (!pq.empty()){
    std::pair<T, int> top = pq.top(); pq.pop();
    int v = top.second;
    if (distance_[v] < top.first) continue;
    for (const auto& e : graph_[v]) {
      if (distance_[e.to] > distance_[v] + e.cost){
        distance_[e.to] = distance_[v] + e.cost;
        pq.push({distance_[e.to], e.to});
      }
    }
  }
}

template<typename T>
void Dijkstra<T>::Initialize() {
  distance_.assign(node_size_, std::numeric_limits<T>::max() / 2);
  graph_.resize(node_size_);
}

template<typename T>
T Dijkstra<T>::operator[](const int& to) const {
  return distance_[to];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  Dijkstra<int64> dijkstra(n);
  for (int i = 0; i < m; ++i) {
    int l, r; int64 c; cin >> l >> r >> c;
    dijkstra.Add_Edge(l - 1, r - 1, c);
  }
  for (int i = 1; i < n; ++i) {
    dijkstra.Add_Edge(i, i - 1, 0);
  }

  dijkstra.Solve(0);
  if (dijkstra[n - 1] == numeric_limits<int64>::max() / 2) {
    cout << -1 << endl;
  } else {
    cout << dijkstra[n - 1] << endl;
  }

  return 0;
}

Measured memory_bytes: 9336
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	// ?????????????????°??????????????????
	int a = 0;
	cin >> a;
	a = a*a*a;
	cout << a << endl;
	// ???????????§
}


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

int dp[101][4][4][4];
const int MOD=1e9+7;

int main(){
    int n;
    cin>>n;
    dp[0][3][3][3]=1;
    rep(len,n){
        rep(i,4){
            rep(j,4){
                rep(k,4){
                    if(dp[len][i][j][k]==0) continue;
                    rep(a,4){
                        if(j==0&&k==2&&a==1) continue;
                        if(j==0&&k==1&&a==2) continue;
                        if(j==2&&k==0&&a==1) continue;
                        if(i==0&&k==2&&a==1) continue;
                        if(i==0&&j==2&&a==1) continue;
                        dp[len+1][j][k][a]+=dp[len][i][j][k];
                        dp[len+1][j][k][a]%=MOD;
                    }
                }
            }
        }
    }
    int ans=0;
    rep(i,4){
        rep(j,4){
            rep(k,4){
                ans+=dp[n][i][j][k];
                ans%=MOD;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    string a, b;
    cin >> a >> b;
    int len = a.length();
    int cnt = 0;
    for(int i = 0;i < len;i ++) {
        if(a[i] != b[i])
            cnt ++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3920
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 2 * b)cout << 0 << endl;
	else cout << a-2*b<< endl;
	return 0;
}

Measured memory_bytes: 256
fun abs(x:Int): Int {
    if(x > 0)
        return x
    else
        return -x
}

fun max(x: Int, y: Int): Int {
    return if(x > y) x else y
}


fun isValidAns(xyh: List<List<Int>>, cx: Int, cy: Int, H: Int): Boolean {
    for ((x,y,h) in xyh) {
        val hh = H - abs(cx-x) - abs(cy-y)
        if (h != max(hh, 0))
            return false
    }
    return true
}

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val xyh = (1..N).map { readLine()!!.split(" ").map { it.toInt() } }

    var found = false
    for (cx in 0..100) {
        for (cy in 0..100) {
            val H = mutableSetOf<Int>()

            for ((x,y,h) in xyh) {
                if (h == 0)
                    continue
                val hh = h + abs(x - cx) + abs(y - cy)
                H.add(hh)
            }
            if(H.size == 1 && isValidAns(xyh, cx, cy, H.min()!!)) {
                // check validity

                val ans = H.min()
                println("${cx} ${cy} ${ans}")
                found = true
            }
            if (found)
                break
        }
        if (found)
            break
    }
}

Measured memory_bytes: 45180
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      long a = sc.nextLong();
      long b = sc.nextLong();
      long c = sc.nextLong();
      boolean ans = true;
      if((c - a - b <= 0) || 4*a*b >= (c - a - b)*(c - a - b)){
        ans = false;
      }
      
	  System.out.println(ans?"Yes":"No");
    }
}


Measured memory_bytes: 23892
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <utility>
using namespace std;
#define INF 100000005
#define MAX 200005

int a[55];
int main(){
	int n, p, s, num, ans, flag;
	while(cin >> n >> p, n){
		fill(a, a+55, 0);
		s = p;
		flag = 1;
		while(flag){
			num = 0;
			for(int i = 0;flag && i < n;i++){
				if(!s && a[i]){
					s = a[i];a[i] = 0;
				}else if(s){
					a[i]++;s--;
					if(a[i] == p){
						ans = i;
						flag = 0;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3052
#include <stdio.h>
int solve(int i, int m);
int n,A[100];

int main(void){
	int q,m,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	scanf("%d",&q);
	
	for(i=0;i<q;i++){
		scanf("%d",&m);
		if(solve(0,m)){
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}
	return 0;
}

int solve(int i, int m){
	if(m==0){
		return 1;
	}
	if(i>=n){
		return 0;
	}
	
	int res= solve(i+1,m) || solve(i+1,m-A[i]);
	return res;
}


Measured memory_bytes: 2076
#include <stdio.h>

int main(void)
{
    int n;
    scanf("%d", &n);

    int p1, p2, i;
    scanf("%d", &p1);

    printf("%d", p1);

    for (i = 1; i < n; i++) {
        scanf("%d", &p2);
        if (p1 != p2) printf(" %d", p2);
        p1 = p2;
    }

    printf("\n");

    return 0;
}


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

int a[100010];
int main()
{
	memset(a,0,sizeof(a));
	int n,x;
	cin>> n;
	for(int i=0;i<n;i++){
		cin>> x;
		a[x]++;
		a[x+1]++;
		if(x-1>=0)	a[x-1]++;
	}
	sort(a,a+100010,greater<>());
	cout<<a[0]<<'\n';
	return 0;
} 

Measured memory_bytes: 640
module DoublyLinkedList = struct

  type t = {
    mutable data : int;
    mutable next : t;
    mutable prev : t;
  }

  let make () =
    let rec head = { data = 0; next = head; prev = head } in
    head

  let insert data head =
    let x = { data = data; next = head.next; prev = head } in
    head.next.prev <- x;
    head.next <- x

  let delete x =
    x.next.prev <- x.prev;
    x.prev.next <- x.next

  let delete_first head = delete head.next

  let delete_last head = delete head.prev

  let delete_node data head =
    let rec doit ite =
      if ite == head then None
      else if ite.data = data then Some ite
      else doit ite.next in
    match doit head.next with
    | None -> ()
    | Some ite -> delete ite

  let print_elements head =
    print_int head.next.data;
    let rec doit ite =
      if ite == head then ()
      else begin
        print_string " ";
        print_int ite.data;
        doit ite.next
      end in
    doit head.next.next

end

module L = DoublyLinkedList

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let head = L.make () in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["insert"; n] -> L.insert (int_of_string n) head
    | ["delete"; n] -> L.delete_node (int_of_string n) head
    | ["deleteFirst"] -> L.delete_first head
    | _ -> L.delete_last head
  done;
  L.print_elements head;
  print_newline ()

Measured memory_bytes: 41100
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(int n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
    fac[0] = fac[1] = 1;
    for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
    finv[MAX-1]=fac[MAX-1].inv();
    for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
    for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*finv[k];
}
// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
template<typename T>
map<T,ll> factorize(T x){
	map<T,ll> res;
	for(ll i=2;i*i<=x;i++){
		while(x%i==0){
			x/=i;
			res[i]++;
		}
	}
	if(x!=1) res[x]++;
	return res;
}
int main(){
    ll n,m;
    cin>>n>>m;
    mint ans=1;
    init();
    map<ll,ll> mp=factorize(m);
    for(auto p: mp){
        ans*=COM(n+p.se-1,p.se);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 47104
# 20/5/28
import sys
sys.setrecursionlimit(3 * 10 ** 5)
input = sys.stdin.readline

def bfs(root, parent):
    global AL, cnt
    for v in AL[root]:
        if v != parent:
            cnt[v] += cnt[root]
            bfs(v, root)

N, Q = [int(x) for x in input().split()]
AL = [[] for _ in range(N + 1)]
for i in range(1, N):
    a, b = [int(x) for x in input().split()]
    AL[a].append(b)
    AL[b].append(a)

cnt = [0] * (N + 1)
for j in range(Q):
    p, x = [int(x) for x in input().split()]
    cnt[p] += x

bfs(1, -1)
print(*cnt[1:])

Measured memory_bytes: 230932
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    
    n = I()
    a = LI()
    lst = [0 for _ in range(n)]
    mod = 10**9+7
    for x in a:
        lst[x] += 1

    if n%2 == 0:
        for x in lst[1::2]:
            if x!=2:
                print(0)
                exit(0)
        print(pow(2,n//2,mod))
    else:
        if lst[0]!=1:
            print(0)
        else:
            for x in lst[2::2]:
                if x != 2:
                    print(0)
                    exit(0)
            print(pow(2,(n-1)//2,mod))

    
main()


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

int main(){
    int X, N;
    cin >> X >> N;
    
    int p[N];
    for(int i=0; i<N; i++){
        cin >> p[i];
    }
    
    int flag = 0;
    
    for(int i=0; i<N; i++){
        if(X == p[i]){
            flag = 1;
        }
    }
    if(flag == 0){
        cout << X << endl;
    }
    
    if(flag == 1){
        int i=1;
        while(1){
            flag = 0;
            for(int n=0; n<N; n++){
                if((X-i)==p[n]){
                    flag = 1;
                }
            }
            if(flag == 0){
                cout << X-i << endl;
                break;
            }
            flag = 0;
            for(int n=0; n<N; n++){
                if((X+i)==p[n]){
                    flag = 1;
                }
            }
            if(flag == 0){
                cout << X+i << endl;
                break;
            }
            i++;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3628
n = gets.chomp.to_i
a = gets.split("\s").map{|i| i.to_i }
average = a.inject(:+).to_f / n
a.reverse!
min = 100
ans = n
a.each_with_index do |item, idx| 
  abs = (item - average).abs
  if min >= abs
    min = abs
    ans = n - idx - 1
  end
end

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define int int long long
#define MdataX 200005
#define FdataST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
int n;
void GO()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans = max(a*c,a*d);
    ans = max(ans,max(b*c,b*d));
    cout<<ans<<endl;
}

int32_t main()
{
    FdataST
    #ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
    #endif
    int testCase;
    // cin>>testCase;
    testCase=1;
    std::vector<int> tc;
    for (int i = 0; i < testCase; ++i)
    {
        tc.push_back(i);
    }
    for(auto test : tc)
    {
        GO(); // let's solve this case :)
    }
    
    return 0;
}

Measured memory_bytes: 3652
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
if V<=W:
    print('NO')
    exit()

sa = abs(B-A)
ss = (V-W)
if T*ss>=sa:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9196
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(a, b):
    if a + b == 15:
        return '+'
    if a * b == 15:
        return '*'
    
    return 'x'


def main():
    a, b = read_int_n()

    
    print(slv(a, b))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5840
//
//  main.cpp
//  ervb
//
//  Created by Kanak Gautam on 21/04/20.
//  Copyright © 2020 Kanak Gautam. All rights reserved.
//
 
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#define pb push_back
#define mk make_pair
#define endl "\n"
#define mod 1000000007
using namespace std;
typedef long long int lli;
typedef long double ld;
priority_queue <lli, vector<lli>, greater<lli> > ti;
vector <lli> p[300005],f(200005,0),b(200005,0),a(200005,0);
map <pair<lli,lli>,lli> mp;
set<pair<lli, lli> > s;
set<lli> st;
map<lli,lli> np,v;
queue<lli> q;
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
lli bpow(lli a, lli b) {
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}
lli fact(lli i)
{
    f[0]=1;
    for(lli k=1;k<=i;k++)
    {
        (f[k]=f[k-1]*k)%=mod;
    }
    return f[i];
}
lli isprime(lli n)
{
    if(n==1)
        return 0;
    for(lli i=2;i<=sqrt(n);i++)
        if(n%i==0)
            return 0;
    return 1;
}
bool cmp(lli i,lli j)
{
    return p[i].size()<p[j].size();
}
 
/*void sieve()
{
    for(lli i=2;i<=5000000;i++)
    {
        if(b[i]==0)
        {
        for(lli j=2;i*j<=5000000;j++)
        {
            b[i*j]=1;
        }
        }
    }
}*/
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    lli n,d;cin>>n>>d;
    lli x,y,ans=0;
    for(lli i=1;i<=n;i++)
    {
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d)
            ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 15056
#include<stdio.h>
int main() {
	long long a, b;
	int i, j;
	long long n, k,m,memo,result=0;
	scanf("%lld%lld", &n, &k);

	for (b = k + 1; b <= n; b++) {
		m = n;
		memo = n%b;
		m = (m - memo) / b;
		result = result + m*(b - k);
		if (memo >= k&&k!=0) {
			result = result + memo - k + 1;
		}
		else if (memo >= k&&k == 0) {
			result = result + memo - k;
		}
	}
	printf("%lld", result);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
struct node {
  const node *left, *right;
  const int val;
  node(node *left, int val, node *right) : val(val), left(left), right(right) {}
};
node *parse(const char*p)
{
  int i = 0;
  function<node*()> rec = [&rec,&i,&p]() -> node* {
    if(p[i] != '(') return NULL;
    i++; // '('
    node *left = rec();
    i++; // ')'
    i++; // '['
    int k = 0;
    while(p[i] != ']') {
      k = k * 10 + p[i] - '0';
      i++;
    }
    i++; // ']'
    i++; // '('
    node *right = rec();
    i++; // ')'
    return new node(left, k, right);
  };
  return rec();
}

ostream &operator<<(ostream &os, const node*t)
{
  os << "(";
  if(t->left != NULL) os << t->left;
  os << ")";
  os << "[" << t->val << "]";
  os << "(";
  if(t->right != NULL) os << t->right;
  os << ")";
}

node *merge(const node *ta, const node *tb)
{
  if(ta == NULL) return NULL;
  if(tb == NULL) return NULL;
  node *left = merge(ta->left, tb->left);
  node *right = merge(ta->right, tb->right);
  return new node(left, ta->val + tb->val, right);
}

int main(int argc, char *argv[])
{
  for(;;) {
    string ta, tb;
    getline(cin, ta);
    getline(cin, tb);
    
    node *na = parse(ta.c_str());
    node *nb = parse(tb.c_str());
    node *nab = merge(na, nb);
    cout << nab << endl;
    break;
  } 
  return 0;
}

Measured memory_bytes: 3180