akhauriyash/Code-Regression huggingface dataset:
#pragma optimize GCC("Ofast")
#pragma comment(linker, "/STACK:1073741824")

#include<iostream>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<deque>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<fstream>
#include<iterator>
#include<functional>
#include<bitset>
#include<memory>
#include<sstream>
#include<new>
#include<cassert>
#include<iomanip>

using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<bool, bool> pbb;
typedef pair<ld, ld> pdd;

const int inf = (int)1e9 + 9;
const ll linf = (ll) 1e18;
const ld eps = 1e-7;
const int mod = (int) 1e9 + 7;

#define it(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define scn second
#define sgn(x) (x > 0 ? 1 : (x == 0 ? 0 : -1))

signed main()
{
	ios_base::sync_with_stdio(false);
	srand(time(0));
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	ll res = 0;
	for (int b = k + 1; b < n + 1; b++)
	{
		int mul = 0;
		while (mul * b + k <= n)
		{
			res += min(n, (mul + 1) * b - 1) - mul * b - k + 1;
			if (mul * b + k == 0)
			{
				res--;
			}
			mul++;
		}
	}
	cout << res;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;

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

        int ans = 0;
        int cnt = 1;
        while(cnt<B){
            cnt-=1;
            cnt+=A;
            ans++;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
import sys
from collections import Counter

# sys.stdin = open('c1.in')


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


def read_str_list():
    return input().split()


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


def read_str():
    return input()


n, m = read_int_list()
c = Counter()

for i in range(m):
    a, b = read_int_list()
    if a == 1:
        c[b] += 1
    if b == n:
        c[a] += 1

res = 'IMPOSSIBLE'
if 2 in c.values():
    res = 'POSSIBLE'
print(res)


Measured memory_bytes: 27464
#include <bits/stdc++.h>
using namespace std;
const int MOD=1000000007;
int d,a,b,i2,pos;
long long dp[102],res,tmp[102];
char k[10002];
int main()
{
    scanf("%s",&k);
    for(; k[pos]!=0; ++pos) a+=k[pos]-'0';
    scanf("%d",&d);
    dp[0]=1;
    if(a%d==0) ++res;
    while(--pos>=0)
    {
        if(k[pos]!='0')
        {
            b=k[pos]-'0';
            a-=b;
            i2=a%d;
            if(i2) i2=d-i2;
            for(int i=0; i<b; ++i)
            {
                res+=dp[i2--];
                if(i2<0) i2+=d;
            }
            res%=MOD;
        }
        tmp[0]=0;
        i2=d-1;
        for(int i=0; i<9; ++i)
        {
            tmp[0]+=dp[i2--];
            if(i2<0) i2+=d;
        }
        for(int i=1; i<d; ++i) tmp[i]=tmp[i-1]+dp[i-1]-dp[++i2%d];
        for(int i=0; i<d; ++i) dp[i]=(dp[i]+tmp[i])%MOD;
    }
    if(--res<0) res+=MOD;
    printf("%lld",res);
    return 0;
}


Measured memory_bytes: 256
import copy
from itertools import combinations

H, W, K = map(int, input().split())
table = []
total = 0

def check(tb):
    black = 0
    for t in tb:
        for m in t:
            if m == '#':
                black += 1
    if black == K:
        return True
    else:
        return False

for n in range(H):
    table.append([i for i in input()])

if check(table):
    total += 1

for n in range(H+1):
    for rows in combinations(range(H), n):
        new_table = copy.deepcopy(table)
        for r in rows:
            new_table[r] = ['r']*W
        if check(new_table) and n != 0:
            total += 1
        for k in range(1, W+1):
            for cols in combinations(range(W), k):
                new_new_table = copy.deepcopy(new_table)
                for c in cols:
                    for row in new_new_table:
                        row[c] = 'r'
                if check(new_new_table):
                    total += 1
print(total)

Measured memory_bytes: 9356
#include <bits/stdc++.h>
using namespace std;
int main(){
    int input = 0;

    double animalSum, feetSum, turtle, crane = 0.0;
    cin >> animalSum >> feetSum;
    turtle = (feetSum - 2 * animalSum) / 2;
    crane = animalSum - turtle;

    if(crane >= 0 && std::floor(crane) == crane &&
        turtle >=0 && std::floor(turtle) == turtle){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  cout<<1-N<<endl;
  
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <algorithm>
#include <limits>
#include <cmath> 
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    int c;
    if(b/100>=1)c=1000*a+b;
    else if(b/10>=1)c=100*a+b;
    else c=10*a+b;
    int m=sqrt(c);
    bool s=false;
    
    if(c==m*m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;

    auto mem = new long[][](N, N);
    auto used = new bool[][](N, N);

    long dfs(int t, int a, int b) {
        if (a > b) return 0;
        if (used[a][b]) return mem[a][b];
        if (t == 0) {
            mem[a][b] = max(dfs(t^1, a+1, b) + A[a], dfs(t^1, a, b-1) + A[b]);
        } else {
            mem[a][b] = min(dfs(t^1, a+1, b) - A[a], dfs(t^1, a, b-1) - A[b]);
        }
        used[a][b] = true;
        return mem[a][b];
    }

    dfs(0, 0, N-1).writeln;
}


Measured memory_bytes: 86652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int N;
    cin >> N;
    vector<int> hi(N);
    vector<int> cost(N,INF);
    rep(i,N) cin >> hi[i];
    cost[0] = 0;
    rep(i,N-2){
        cost[i+1] = min(cost[i + 1],abs(hi[i+1] - hi[i])+cost[i]);
        cost[i + 2] = min(cost[i + 2],abs(hi[i + 2] - hi[i]) + cost[i]);
    }
    cost[N - 1] = min(cost[N - 1],abs(hi[N - 1] - hi[N - 2])+cost[N - 2]);

    cout << cost[N - 1] << endl;
}

Measured memory_bytes: 1024
K, N = map(int, input().split())
MOD = 998244353

P = N+K
fact = [1]*(P+1)
rfact = [1]*(P+1)
for i in range(P):
    fact[i+1] = r = ((i+1) * fact[i]) % MOD
    rfact[i+1] = pow(r, MOD-2, MOD)

def comb(n, k):
    return fact[n] * rfact[k] * rfact[n-k] % MOD

def h(n, k):
    if n < 0 or k < 0:
        return 0
    return comb(n+k, k)

def calc(A):
    M = A//2
    r = 0
    if A % 2:
        p = K - 2*M + N - 2
        for m in range(M+1):
            if K-2*M-2+m < 0 or N-m < 0:
                continue
            r += pow(2, m, MOD) * comb(M, m) * (h(K-2*M-2+m, N-m) + h(K-2*M-2+m, N-m-1)) % MOD
    else:
        p = K - 2*M + N - 1
        for m in range(M+1):
            if K-2*M-1+m < 0 or N-m < 0:
                continue
            r += pow(2, m, MOD) * comb(M, m) * h(K-2*M-1+m, N-m) % MOD
    return r % MOD
ans = []
for i in range(2, 2*K+1):
    if i <= K:
        ans.append(calc(i - 1))
    else:
        ans.append(calc(2*K - i + 1))
print(*ans, sep='\n')

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

void solve() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> L(N);
    for (int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for (int j = 0; j < K; j++) {
            int l;
            cin >> l;
            l--;
            L[i].push_back(l);
        }
    } 
    UnionFind uf(N);
    vector<int> first(M, -1);

    for(int i = 0; i < N; i++) {
        for (int j = 0; j < L[i].size(); j++) {
            if (first[L[i][j]] == -1) {
                first[L[i][j]] = i;
            } else {
                uf.unionSet(i, first[L[i][j]]);
            }
        }
    }
    set<int> id;
    for(int i = 0; i < N; i++) {
        id.insert(uf.root(i));
    }
    if (id.size() == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,h,ans[100005],arr[100005],sto[100005];
ll solve(int ind)
{
    if(ind>=n)
        return 2e9;
    if(ind == n-1)
        return 0;
    if(~sto[ind])
        return sto[ind];
    ll ans = 2e9;
    for(int i = 1;i<=min(n-ind,h);i++)
        ans = min(ans,abs(arr[ind]-arr[ind+i])+solve(ind+i));
    sto[ind] = ans;
    return  ans;
}
int main()
{
    cin >> n >> h;
    memset(sto,-1,sizeof sto);
    for(int i = 0;i<n;cin >> arr[i++]);
    cout << solve(0);
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>

#include <string>

#include <cstring>

using std::cin;
using std::cout;
using std::endl;

using std::string;

using std::strcpy;

static char mat[52][52];

static char const *
solve(int W, int H)
{
  for (int y = 1; y <= H; y++)
  {
    for (int x = 1; x <= W; x++)
    {
      if (mat[y][x] == '#'
          && mat[y - 1][x] != '#' && mat[y + 1][x] != '#'
          && mat[y][x - 1] != '#' && mat[y][x + 1] != '#')
      {
        return "No";
      }
    }
  }
  return "Yes";
}

int
main()
{
  int H, W;
  cin >> H >> W;
  string s;
  for (int y = 0; y < H; y++)
  {
    cin >> s;
    strcpy(&mat[y + 1][1], s.c_str());
  }
  cout << solve(H, W) << endl;
  return 0;
}


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

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        long[] val = new long[n];
        long[] prefix = new long[n + 1];
        for (int i = 0; i < n; i++) {
            val[i] = in.nextInt();
            prefix[i + 1] += prefix[i] + val[i];
        }

        long[][] dp = new long[n][n];
        for (int gap = 1; gap < n; gap++) {
            for (int i = 0; i < n; i++) {
                if (i + gap < n) {
                    if (gap == 1) {
                        dp[i][i + gap] = val[i] + val[i + gap];
                    } else {
                        long min = Long.MAX_VALUE;
                        for (int p = i; p < i + gap; p++) {
                            if (p + 1 <= i + gap) {
                                min = Math.min(min, dp[i][p] + dp[p + 1][i + gap]);
                            }
                        }
                        dp[i][i + gap] = min + prefix[i + gap + 1] - prefix[i];
                    }
                }
            }
        }

        out.println(dp[0][n - 1]);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
	a += b; c += d;
	
	if(a > c) printf("Left\n");
	else if(a < c) printf("Right\n");
	else printf("Balanced\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
#define MOD 1000000007
#define INF 1e18
#include <ctime>
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define rev(i, n, x) for (ll i = n; i > x; i--)
#define all(c) (c).begin(), (c).end()
#define int long long int
#define endl "\n"
#ifdef mishra
#define debug(x) cout << " >> " << #x << ": " << x;
#define debugend() cout << endl;
#define print_time() cout << setprecision(6) << "time: " << (clock() - start) / (double)CLOCKS_PER_SEC << '\n';
#else
#define debug(x) ;
#define debugend() ;
#define print_time() ;
#endif

clock_t start;
void FAST(ll argc)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    start = clock();
    if (argc == 2)
    {
        freopen("std2.txt", "r", stdin);
        freopen("std3.txt", "w", stdout);
    }
}

/*vector<ll> v;
void seive()
{
    v.pb(2);
    for (int i = 3; i < 100000; i += 2)
    {
        for (int j = 0; j < v.size(); j++)
        {
            if (i % v[j] == 0)
                break;
            if (v[j] * v[j] > i)
            {
                v.pb(i);
                break;
            }
        }
    }
}
/*
void prime_factor(ll x, vector<ll> &r)
{
    ll sqrt_x = sqrt(x);

    for (ll i : v)
    {
        if (i > sqrt_x)
            break;

        if (x % i == 0)
            r.pb(i);

        while (x % i == 0)
        {
            x /= i;
        }
    }

    if (x >= 2)
        r.pb(x);
}
*/
/*
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % MOD;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % MOD;
        y = y >> 1;
        x = (x * x) % MOD;
    }
    return res;
}
*/
/*
inline void dfs(ll curr, ll prev)
{

    for (ll i : a[curr])
        if (i != prev)
            dfs(i, curr);
}
*/
/*
ll multi(ll a, ll b)
{
    return ((a * b) % MOD);
}
*/
//---------------------CODE STARTS HERE---------------------

signed main(char argc, char *argv[])
{
    FAST(argc);

    ll testcase = 1;
    // cin >> testcase;

    while (testcase--)
    {
        int n;
        cin >> n;
        double p[n + 1];
        rep(i, 1, n + 1)
                cin >>
            p[i];

        double dp[n + 1][n + 1];
        rep(j, 0, n + 1)
            dp[0][j] = 0;

        dp[0][0] = 1.0;
        rep(i, 1, n + 1)
        {
            dp[i][0] = dp[i - 1][0] * (1 - p[i]);
            rep(j, 1, n + 1)
                dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
        }
        // rep(i, 0, n + 1)
        // {
        //     rep(j, 0, n + 1)
        //             cout
        //         << (dp[i][j]) << " ";
        //     cout << endl;
        // }
        double ans = 0;
        rep(i, n / 2 + 1, n + 1)
            ans += dp[n][i];
        printf("%0.10f\n", ans);

        //--------??--------CLEAR VECTORS--------??--------
    }

    //v.clear();
    print_time();
    return 0;
}

Measured memory_bytes: 70656
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>

#define ff first
#define ss second

using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long ll;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef vector<VP> VVP;


int main() {
	int n;
	cin >> n;
	VI A(n);
	for (auto& x : A) cin >> x;
	VP B(n);
	for (int i = 0; i < n; ++i) {
		B[i].ff = A[i];
		B[i].ss = i+1;
	}
	sort(B.begin(), B.end());
	vector<ll> sol(n+1, 0);
	int minid = n;
	for (int i = n-1; i >= 0; --i) {
		minid = min(minid, B[i].ss);
		while (i > 0 && B[i-1].ff == B[i].ff) {
			--i;
			minid = min(minid, B[i].ss);
		}
		sol[minid] += (B[i].ff - (i > 0 ? B[i-1].ff : 0)) * (ll)(n-i);
	}
	for (int i = 1; i <= n; ++i) cout << sol[i] << '\n';
}

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

using namespace std;

int main()
{
	int K,A,B,n;
	cin>>K;
	cin>>A>>B;
	if(A%K==0)
		cout<<"OK";
	else
	{
		n=A/K;
		n+=1;
		n*=K;
		if(n>=A && n<=B)
		{
			cout<<"OK";
		}
		else
		{
			cout<<"NG";
		}
	}
	return 0;
}

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

int main()
{
	int a, b;
	int i, max;
	vector<int> vertex(101);
	bool f;

	max = 0;
	while (cin>>a>>b) {
		vertex[a]++;
		vertex[b]++;
		if (a>max) max = a;
		if (b>max) max = b;
		if (a||b) continue;

		f = true;
		if ( !(vertex[1]&1) ) f = false;
		for (i = 3; i <= max; i++)
 			if (vertex[i]&1) f = false;
		if (f) cout<<"OK"<<endl;
		else cout<<"NG"<<endl;

		max = 0;
		vertex.clear();
		vertex.resize(101);
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n;
    long long sum,ans,res;
    long long a[200010];
    cin>>n;sum=0;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        sum+=a[i];
    }
    ans=1e18;res=0;
    for(i=1;i<=n-1;i++)
    {
        res+=a[i];sum-=a[i];
        ans=min(ans,abs(res-sum));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

int main() {
  long long N, S, N_tmp;

  std::cin >> N;

  S = 0;
  N_tmp = N;

  while (N_tmp>0) {
    S += N_tmp % 10;
    N_tmp /= 10;
  }

  if (N%S == 0) {
    std::cout << "Yes";
  } else {
    std::cout << "No";
  }

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
const int mod = 1e9 + 7;

inline ll pw(ll a,int b)
{
	ll res=1;
	while(b)
	{
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}

ll fac[MAXN],inv[MAXN];

inline ll c(int n,int m)
{
	if(n<0||m<0||n<m) return 0;
	return fac[n]*inv[m]%mod * inv[n-m] %mod;
}

int main(void)
{
	fac[0]=1;
	for(int i=1; i<MAXN; ++i) fac[i] = fac[i-1]*i %mod;
	inv[MAXN-1]=pw(fac[MAXN-1],mod-2);
	for(int i=MAXN-2; i>=0; --i) inv[i] = inv[i+1]*(i+1) %mod;
	
	int n,d;
	scanf("%d%d",&n,&d);
	if(d>n) d=n;
	
	int ans=0;
	for(int i=0; i<=d; ++i)
	{
		ans += c(n,i) * c(n-1,n-i-1) %mod;
		if(ans>=mod) ans-=mod;
	}
	printf("%d",ans);
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll count = 0;
    vector<ll> H;
    cin >> N;
    H.resize(N);
    rep(i, N) cin >> H[i];
    while(true) {
        ll i;
        for(i = 0;i < N;i++) {
            if(H[i] != 0) break;
        }
        if(i == N) break;
        rep2(j, i, N) {
            if(H[j] == 0) break;
            H[j]--;
        }
        count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
using P = pair<int, int>;
struct edge{int f,t,c;};
const int mx = 2505;
const int inf = 1e9;
int n, m, p, a, b, c, d[10005];
vector<P> G[mx];
int main(){
	scanf("%d%d%d", &n, &m, &p);
	rep(i,m){
		scanf("%d%d%d", &a, &b, &c);
		a--; b--; c -= p;
		G[a].push_back(P(b,-c));
	}
	fill(d,d+m*2,inf);
	d[0] = 0;
	rep(i,n*2+10){
		rep(j,n) for(auto t: G[j]){
			if(d[j] != inf && d[t.first] > d[j] + t.second){
				d[t.first] = d[j] + t.second;
				if(i >= n-1 && t.first == n-1) return 0*puts("-1");
			}
		}
	}
	printf("%d\n", max(0,-d[n-1]));
}

Measured memory_bytes: 892
H,W = [int(i.strip()) for i in input().split(' ')]

MAP = [list(input())for _ in range(H)]

F = [[0] * 10] * 10

arrive = {}
if MAP[0][0] == '#':
    arrive[(0,0)] = 1
else:
    arrive[(0,0)] = 0

while True:
    A = {}
    for p , v in arrive.items():
        if p[0]+1 < H:
            if MAP[p[0]+1][p[1]] == '.':
                if not (p[0]+1 , p[1]) in A:
                    A[(p[0]+1 , p[1])] = v 
                else:
                    t = A[(p[0]+1 , p[1])]
                    A[(p[0]+1 , p[1])] = v if v < t else t
            else:
                if MAP[p[0]][p[1]] == '#':
                    v2 = v
                else:
                    v2 = v + 1
                if not (p[0]+1 , p[1]) in A:
                    A[(p[0]+1, p[1])] = v2
                else:
                    t = A[(p[0]+1 , p[1])]
                    A[(p[0]+1 , p[1])] = v2 if v2 < t else t

        if p[1] + 1 < W:
            if MAP[p[0]][p[1] + 1] == '.':
                if not ( p[0] , p[1] + 1) in A:
                    A[( p[0] , p[1] + 1)] = v 
                else:
                    t = A[( p[0] , p[1] + 1)]
                    A[( p[0] , p[1] + 1)] = v if v < t else t
            else:
                if MAP[p[0]][p[1]] == '#':
                    v2 = v
                else:
                    v2 = v + 1
                if not ( p[0] , p[1] + 1) in A:
                    A[( p[0] , p[1] + 1)] = v2
                else:
                    t = A[( p[0] , p[1] + 1)]
                    A[( p[0] , p[1] + 1)] = v2 if v2 < t else t

    if (H-1,W-1) in A:
        print(A[(H-1,W-1)])
        exit()

    else:
        arrive = A.copy()


Measured memory_bytes: 3316
n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
idx=a.index(1)
q,r=idx.divmod(k-1)
ans=q
if r>0
  ans+=1
  idx+=(k-1-r)
end
q,r=(n-idx-1).divmod(k-1)
ans+=q
ans+=1 if r>0

puts ans

Measured memory_bytes: 8068
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll MOD=(ll)1e9+7;
//}}}

int main(){
  string s;
  cin >> s;
  bool f1 = false;
  bool f2 = false;
  foreach(c, s){
    if(c == 'C')f1=true;
    if(f1 && c == 'F')f2=true;
  }
  bool ans = f1 && f2;
  puts(ans ? "Yes" : "No");
  return 0;
}


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

int main(void){
    int N,D,X;
    cin>>N>>D>>X;
    vector<int> A(N);
    for (int i=0;i<N;i++) cin>>A[i];
    int ans=X;
    for (int i=0;i<N;i++) {
        for (int j=1;j<=D;j++) {
            if ((j-1)%A[i]==0) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    long long n;
    cin >> n;
    vector<long long> v(5);
    for(int i=0; i<5; ++i)
        cin >> v[i];

    long long x = *min_element(v.begin(), v.end());
    long long ans = (n + x - 1) / x + 4;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    vector<int> a(n),b(n);

    rep(i,n){
        cin >> a[i];
    } 
    copy(a.begin(),a.end(),back_inserter(b));
    sort(b.rbegin(),b.rend());
    rep(i,n){
        if(a[i]==b[0]){
            cout << b[1] << "\n";
        }else{
            cout << b[0] << "\n";
        }
    }
    return 0;  
}

Measured memory_bytes: 3952
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)

	sc.Scan()
	a := strings.Split(sc.Text(), " ")
	D, _ := strconv.Atoi(a[0])
	T, _ := strconv.Atoi(a[1])
	S, _ := strconv.Atoi(a[2])

	if S*T >= D {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1772
import sys
sys.setrecursionlimit(10**6)
N,K=map(int,input().split())
A=[int(i)-1 for i in input().split()]
ans=0
if A[0]!=0:
  ans+=1
  A[0]=0
Graph=[[] for i in range(N)]
for i,a in enumerate(A[1:]):
  Graph[a].append(i+1)
#print(Graph)
def dfs(x):
  global ans
  height=0
  for a in Graph[x]:
    height=max(height,dfs(a)+1)
  #print(x,height,A[x])
  if height==K-1:
    if A[x]!=0:
      ans+=1
      return -1
  return height


dfs(0)
print(ans)


Measured memory_bytes: 187760
import sys
from collections import deque


def bfs(G, v, p, counter):
    queue = deque([(v, p)])
    while queue:
        v, p = queue.popleft()
        for c in G[v]:
            if c == p:
                continue
            counter[c] += counter[v]
            queue.append((c, v))


def main():
    input = sys.stdin.readline

    N, Q = map(int, input().split())

    G = [[] for _ in range(N + 1)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        G[a].append(b)
        G[b].append(a)

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

    bfs(G, 1, -1, counter)

    print(" ".join(map(str, counter[1:])))


if __name__ == "__main__":
    main()


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

void findDivisors(int n) 
{ 

	int div[n + 1]; 
	memset(div, 0, sizeof div); 

	for (int i = 1; i <= n; i++) 
	{ 
		for (int j = 1; j * i <= n; j++)
		{
			div[i * j]++;
		}
	} 
	long long ans = 0;
	for (int i = 1; i <= n; i++) 
	{
		ans = ans + 1LL * i * div[i];
	}
	cout << ans << "\n";
} 

int main() 
{ 
	int n;
	cin >> n;
	findDivisors(n);
	return 0; 
} 


Measured memory_bytes: 42692
#include <iostream>

using namespace std;

int countFive, countSeven;

void check(int input) {
	if (input == 5) {
		countFive++;
	}
	else if (input == 7) {
		countSeven++;
	}
}

int main() {
	int input = 0;
	cin >> input;
	check(input);
	cin >> input;
	check(input);
	cin >> input;
	check(input);

	if (countFive == 2 && countSeven == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

}

Measured memory_bytes: 256
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   : combinatorics NCR
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define rep(i,a) lp(i,0,a-1)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 2e3 + 3, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
ll dp[N][N] = { };
ll solve(int num, int g) {
	if (!g || !num)
		return !(g | num);
	ll &ret = dp[num][g];
	if (ret != -1)
		return (ret % mod);
	ret = 0;
	ret += solve(num - 1, g);
	if (ret >= mod)
		ret %= mod;
	ret += solve(num - 1, g - 1);
	if (ret >= mod)
		ret %= mod;
	return ret;
}
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	int n, k;
	cin >> n >> k;
	clr(dp, -1);
	lp(i,1,k)
	{
		ll b = solve(k, i);
		ll akbr = solve(n - k, i + 1);
		ll eqr = solve(n - k, i);
		eqr *= 2;
		if (eqr >= mod)
			eqr %= mod;
		ll as8r = solve(n - k, i - 1);
		ll sum = akbr + as8r + eqr;
		if (sum >= mod)
			sum %= mod;
		cout << (sum * b) % mod << "\n";
	}
	return 0;
}

Measured memory_bytes: 31744
#include <bits/stdc++.h>
typedef long long int ll;
#define vaibhavv06               \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(0);
#define int long long
#define MM(a,b) memset(a,b,sizeof(a))
const ll MOD = 1000000007;
using namespace std;

const int nax = 1e5+5;
vector<int> edges[nax];
int d1[nax],d2[nax];

void dfs(int u, int p,int d[]){
	d[u]=d[p]+1;
	for(auto x:edges[u]){
		if(x!=p) dfs(x,u,d);
	}
}

int32_t main(){
    vaibhavv06;
    
	int n; cin>>n;
	int t,a; cin>>t>>a;
	for(int i=1;i<n;i++){
		int a,b; cin>>a>>b;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	d1[0]=-1;
	d2[0]=-1;
	dfs(t,0,d1);
	dfs(a,0,d2);
	int ans=0;
	for(int i=1;i<=n;i++){
		if(d1[i]<d2[i]){
			ans=max(ans,d2[i]-1);
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 11264
a = int(input())
b = int(input())
c = int(input())
x = int(input())
t = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if x - 500*i - 100*j - 50*k == 0:
                t += 1

print(t)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

  int n;
  cin>>n;
  if(n%2==1){
    cout<<n*2<<endl;
  }else{
    cout<<n<<endl;
  }


  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int n,s,i,x=0,ave,sum,max=0,min=10000;
		int[] aves=new int[100];
		while(true){
			sum = 0;
			max=0;
			min=10000;
			n=sc.nextInt();
			if(n==0){
				break;
			}
			int[] score=new int[n];
			for(i=0;i<n;i++){
				score[i]=sc.nextInt();
				sum = sum + score[i];
				if(score[i]>max){
					max=score[i];
				}
				if(score[i]<min){
					min=score[i];
				}
			}
			ave=(sum-max-min)/(n-2);
			aves[x]=ave;
			x++;
		}
		for(i=0;i<aves.length;i++){
			if(aves[i]==0){
				System.out.printf("");
			}
			else{
				System.out.printf("%d\n",aves[i]);
			}
		}
	}
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  
  int temp;
  for (int i = 0; i < N-1; i++) {
    for (int j = i+1; j < N; j++) {
      if (d.at(i) < d.at(j)) {
        temp = d.at(i);
        d.at(i) = d.at(j);
        d.at(j) = temp;
      }
    }
  }
  
  int counter = 1;
  for (int i = 0; i < N-1; i++) {
    if (d.at(i) > d.at(i+1)) counter++;
  }
  
  cout << counter << endl;
}

Measured memory_bytes: 256
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]



sort_ab = sorted(ab, key=lambda x:(x[1], x[0]))
#print(sort_ab)
count=0
for i in range(n):
    count+=sort_ab[i][0]
    if sort_ab[i][1]<count:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 91412
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize, m: usize
    };

    let res = if n == m { "Yes" } else { "No" };
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2248
/*--ILRS-- sr4saurabh  */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define popb pop_back
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define sz size 
#define len length 
#define se second 
const ll mod=998244353;
//const ll mod = 1000000000+7;
const ll N=10000000+6;
#define M_PI           3.14159265358979323846
//--------------------------------------------



//--------------------------------------------





//============================================
int main() {
    ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
    #ifndef ONLINE_JUDGE
       freopen ("INPUT.txt" , "r" , stdin);
       freopen ("OUTPUT.txt", "w" , stdout);
    #endif

	//THE WATER WAS DEEP, I DROWNED AND THEN CAME FLOATING UP,DEAD!!

       
     int n;
     cin>>n;

     int k;
     cin>>k;

     ll count[2*n+1]={0};
   		count[1] = 1;
   		count[2] = -1;
     pii s[k+1];
     s[0].fi = s[0].se = 1;
     for(int i = 1 ; i <= k ; i++)
     {

     	cin>>s[i].fi>>s[i].se;
     }

     for(int i = 1 ; i <= n ; i++)
     {
     	count[i] = (count[i]+count[i-1])%mod;

     	for(int j = 1 ; j <= k ; j++)
     	{
     		count[i+s[j].fi] = (count[i+s[j].fi] + count[i])%mod;
     		count[i+s[j].se+1] = (count[i+s[j].se+1] - count[i] + mod ) %mod;
     	}
     }

     

     cout<<count[n];




return 0;
} 

Measured memory_bytes: 6756
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,X;
    cin >> N >> X;
    vector<int> m(N);
    int sum = 0;
    for (int i=0;i<N;i++) {
        cin >> m.at(i);
        sum += m.at(i);
    }
    X -= sum;
    sort(m.begin(),m.end());
    int cnt = 0;
    cnt = X / m.at(0);
    cout << N+cnt << endl;
}

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

int main() {
  int N,K;cin>>N>>K;
  vector<bool> B(N,false);
  for(int i=0;i<K;i++){
    int d;cin>>d;
    for(int j=0;j<d;j++){
      int A;cin>>A;
      B[A-1]=true;
    }
  }
  int cnt=0;
  for(int i=0;i<N;i++){
    if(!B[i])cnt++;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int MOD = 1e9+7;
// 0b10000100000010000 = {5, 7, 5}
// 0b10100100010010100 = {2, 3, 4, 3, 2, 3}
int main()
{
    int N, X, Y, Z; cin >> N >> X >> Y >> Z;
    vector<Int> A(1 << (X+Y+Z)), B(A);
    int mask = (1 << (X+Y+Z)) - 1;
    int okay = (1 << (X+Y+Z-1)) | (1 << (X+Y-1)) | (1 << (X-1));
    A[0] = 1;
    Int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < A.size(); j++) {
            for (int k = 1; k <= 10; k++) {
                B[mask & ((j << k) | (1 << (k-1)))] += A[j];
            }
        }
        (ans *= 10) %= MOD;
        for (int j = 0; j < A.size(); j++) {
            B[j] %= MOD;
            if ((j & okay) == okay) {
                (ans += B[j]) %= MOD;
                B[j] = 0;
            }
        }
        swap(A, B);
        fill(begin(B), end(B), 0);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
long long P=1000000007,a[500010][62],ans[500010][62],anss=0;
int n;

int main()
{	cin>>n;
	for(int i=1;i<=n;++i)
	{
		long long x;
		int cnt=61;
		cin>>x;
		while(x)
		{
			a[i][cnt]=x%2;
			ans[i][cnt]=ans[i-1][cnt]+a[i][cnt];
			x/=2;
			--cnt;
		}
		for(;cnt>=1;--cnt)
			ans[i][cnt]=ans[i-1][cnt];
	}
	for(int i=61;i>=1;--i)
	{
		long long t=1ll<<(61-i);
		t%=P;
		for(int j=1;j<n;++j)
			if(a[j][i]==1)
			{
				long long num=n-j-ans[n][i]+ans[j][i];
				anss+=num*t;
				anss%=P;
			}
			else
			{
				long long num=ans[n][i]-ans[j][i];
				anss+=num*t;
				anss%=P;
			}
	}
	cout<<anss<<endl;
	return 0;
} 

Measured memory_bytes: 293120
#include <algorithm>
#include <stdio.h>
#include <iostream>
using namespace std;
using ll = long long;

int main(){
    ll N,t=0;
    cin >> N;
    ll C[N-1], S[N-1],F[N-1];
    for(int i=0; i<N-1; i++){
        cin >> C[i] >> S[i] >> F[i];
    }
    for (int j=0;j<N-1;j++){
    for(int i=j; i<N-1; i++){
        if(t<S[i]){
            t=S[i] + C[i];
        }else if(t%F[i]==0){
            t= t + C[i];
        }else{
            t= t + F[i] -(t%F[i])+C[i];
        }
    }
    cout << t << endl;
    t=0;
    }
    cout << 0 << endl;
    return 0;
}

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

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int a,b; cin >> a >> b;
    if(b>=a) cout << "unsafe\n";
    else cout << "safe\n";
    return 0;
}

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

int main()
{
    int n;
    string s;
    cin >> n >> s;
    if( n % 2 != 0 ){
        cout << "No" << endl;
    }
    else{
        string t;
        int a = int(n/2);
        for(int i = 0; i < a; ++i )
        {
            t.push_back(s.at(i));
        }
        string g;
        for( int i = a; i < s.size(); i++ )
        {
            g.push_back(s.at(i));
        }
        if( t == g ){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 256
ARGF.each_line do |line|
  h, w = line.split.map(&:to_i)
  i = 0
 while (h >= 3 && w <= 300) do
  i += 1
  break if [h, w].eql? [0, 0]
    case i
    when 1, h
      puts '#' * w
    when h + 1
      puts
      break
    else
      print "#", ("." * (w - 2)), "#\n"
    end
  end
end

Measured memory_bytes: 6100
#include<stdio.h>

int main(void){
	int S,h,m,s;
	scanf("%d",&S);
	h=S/3600;
	S=S%3600;
	m=S/60;
	S=S%60;
	s=S;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int[] a = new int[n/2];
  int[] b = new int[n/2];
  int[] ac = new int[100001];
  int[] bc = new int[100001];
  for(int i = 0;i < n/2;i++){
    int p = sc.nextInt();
    a[i] = p;
    ac[p]++;
    int q = sc.nextInt();
    b[i] = q;
    bc[q]++;
  }
  int fa = 0;
  int sa = 0;
  int fb = 0;
  int sb = 0;
  int afk = 0;
  int ask = 0;
  int bfk = 0;
  int bsk = 0;
  for(int i = 1;i < 100001;i++) {
	  if(fa <= ac[i]) {
		  sa = fa;
		  fa = ac[i];
		  ask = afk;
		  afk = i;
	  }
     else if(sa <= ac[i]){
       sa = ac[i];
       ask = i;
     }
	 if(fb <= bc[i]) {
         sb = fb;
		  fb = bc[i];
		  bsk = bfk;
		  bfk = i;
	  }
    else if(sb <= bc[i]){
       sb = bc[i];
       bsk = i;
     }
  }
  if(afk != bfk) {
	  System.out.println(n - fa - fb);
  }
  else {
	  int s = n - fa - sb;
	  int t = n - sa - fb;
	  System.out.println(s >= t ? t:s);

  }
}}

Measured memory_bytes: 64684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (ll i = 0; i < ll(n); i++)

const ll mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }

    // nPk - permutation
    mint p(int n, int k) {
        return fact[n] * ifact[n - k];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<pll> s;
    for (ll i = 1; i * i <= n; i++) {
        s.pb(mp(i, 0));
        s.pb(mp(n / i, 0));
    }
    sort(all(s));
    s.erase(unique(all(s)), s.end());
    rep(i, s.size() - 1) {
        ll l = n / s[i + 1].first;
        ll r = n / s[i].first;
        s[i].second = r - l;
    }
    s.back().second = 1;
    int m = s.size();

    map<ll, ll> mp;
    rep(i, m) mp[s[i].first] = i;

    vector<vector<mint>> dp(k + 1, vector<mint>(m));
    dp[0][mp[n]] = 1;
    rep(i, k) {
        for (int j = m - 2; j >= 0; --j) {
            dp[i][j] += dp[i][j + 1];
        }
        rep(j, m) {
            int nj = mp[n / s[j].first];
            dp[i + 1][j] += dp[i][nj] * s[j].second;
        }
    }
    mint ans;
    rep(j, m) ans += dp[k][j];
    cout << ans.x << endl;
}

Measured memory_bytes: 58484
#include<stdio.h>
#include<stdlib.h>

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

int main()
{
  int n; 
  int a[100001];
  int i;
  int ans=0;
  int s=0,t=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  qsort(a,n,sizeof(int),compare_int);
  for(i=0;i<n;i++){
    if(s==a[i]){
      if(t==0){
        t=1;
        ans++;
      }
      else if(t==1){
        ans--;
        t=0;
      }
    }
    else if(s!=a[i]){
      s=a[i];
      t=1;
      ans++;
    }
  }
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 2292