akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;
int a[MAXN],cnt[MAXN];

int main() {

    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int ma=-5,ans=-5;
        memset(cnt,0,sizeof(cnt));
        int tmp;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&tmp);
            tmp++;
            cnt[tmp-1]++,cnt[tmp]++,cnt[tmp+1]++;
        }
        for(int i=0;i<=1e5+1;i++)
        {
             if(ma<cnt[i])
             {
             ans=i-1;
             ma=cnt[i];
             }

        }
        printf("%d\n",ma);
    }
    return 0;
}


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

struct rail{
	int c,s,f;
};

signed main(){
	int N; cin>>N;
	vector<rail> sta(N-1);
	for(int i=0;i<N-1;i++)cin>>sta[i].c>>sta[i].s>>sta[i].f;
	
	for(int i=0;i<N;i++){
		int ans=0;
		for(int j=i;j<N-1;j++){
			ans=max(sta[j].s,ans);
			ans+=(sta[j].f-ans%sta[j].f)%sta[j].f;
			ans+=sta[j].c;
		}
		cout<<ans<<endl;
	}
	return 0;

}

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    ll x, a, b;
    cin >> x;
    repeat(i, -1000, 1000) {
        repeat(j, -1000, 1000) {
            if (pow(i, 5) - pow(j, 5) == x) {
                a = i;
                b = j;
            }
        }
    }
    cout << a << ' ' << b << endl;

    return 0;
}


Measured memory_bytes: 4112
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>


int main(){
	int d,m,n;
	scanf("%d%d%d",&n,&m,&d);
	int cnt = 0;
	for(int i=1;i<=n;i++){
		if(i-d>0)cnt++;
		if(d!=0){
			if(i+d<=n)cnt++;
		}
	}
	//cnt *= m-1;
	
	
	double d_cnt = (double)cnt;
	
	d_cnt/=(double)n*n;
	
	d_cnt *= m-1;
	
	printf("%f",d_cnt);
	
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc160_a
{
    class Program
    {
        static void Main(string[] args)
        {

            string S = Console.ReadLine();
            if (S[2] == S[3] && S[4] == S[5])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.Read();

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;
const ll infl = 1e17;

typedef unsigned long long ull;


char getchar(char x,ll k){
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    ll idx = (x - 'a' + k) % 26;
    return alpha[idx];
}

int main()
{
    string s;
    cin >> s;
    ll k;
    cin >> k;
    ll idx = 0;
    string ans = "";
    while (idx<s.size()-1){
        if (s[idx]=='a' || k==0){
            ans += s[idx];
            idx++;
            continue;
        }
        if ('z'-s[idx]+1<=k){
            k -= 'z' - s[idx] + 1;
            ans += 'a';
            idx++;
        }
        else {
            ans += s[idx];
            idx++;
        }
    }
    ans += getchar(s[idx], k);
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
int A,B;
cin>>A>>B;
int coins=0;
for(int i=0; i<2;i++){
     if(A>B) {
coins+=A;
A--;
}else{
   coins+=B;
    B--;
}
}     
          cout<<coins<<endl;
  }
               
            
     




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

int main(void){
  int n;
  int k;
  cin >> n;
  vector<char> s(n);
  for(int i=0; i<n; ++i) cin >> s[i];
  cin >> k;
  char target = s[k-1];
  for(int i=0; i<n; ++i){
    if(s[i]==target) cout << target;
    else cout << "*";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n) {
        vector<string> v(n);
        for (auto & i : v) {
            cin >> i;
        }
        if(n == 1){
            cout << v.front() << "\n";
            continue;
        }
        stack<int> s;
        for (int i = 0; i < n; ++i) {
            int m = (int)v[i].size()-1;
            while(s.size() > 2*m) {
                s.pop();
                int x = s.top(); s.pop();
                int y = s.top(); s.pop();
                int z = s.top(); s.pop();
                if(y == -1) x += z;
                else x *= z;
                s.emplace(x);
                s.emplace(y);
            }
            if(v[i].back() == '+') s.push(0), s.push(-1);
            else if(v[i].back() == '*') s.push(1), s.push(-2);
            else {
                int x = v[i].back()-'0';
                int y = s.top(); s.pop();
                int z = s.top(); s.pop();
                if(y == -1) x += z;
                else x *= z;
                s.emplace(x);
                s.emplace(y);
            }
        }
        while(s.size() > 2) {
            s.pop();
            int x = s.top(); s.pop();
            int y = s.top(); s.pop();
            int z = s.top(); s.pop();
            if(y == -1) x += z;
            else x *= z;
            s.emplace(x);
            s.emplace(y);
        }
        s.pop();
        cout << s.top() << "\n";
    }
    return 0;
}


Measured memory_bytes: 3168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n, y;
		n = sc.nextInt();
		y = sc.nextInt();
		
		sc.close();
		
		y /= 1000;

		int x = -1, z = -1, ans = -1;
		
		for(int i = 0; i <= n; ++i) {
			for(int j = 0; j + i <= n; ++j) {
				int tmp = y - 5 * i - 10 * j;
				if(tmp + i + j == n && tmp >= 0) {
					x = i;
					z = j;
				}
			}
		}
		if(x != -1)ans = y - 5 * x - 10 * z;
		System.out.println(z + " " + x + " " + ans);
	}

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

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

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

const ll N = 1e5 + 10;
ll n, m, ans, adj[N];
bool mark[N];

int main() {
	memset(adj, 127, sizeof adj);
	cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		adj[a] = min(adj[a], b);
	}
	for (ll i = n - 1; i >= 0; i--) {
		if (adj[i] < n && !mark[adj[i]]) {
			ans++;
			for (ll j = i + 1; j < n && !mark[j]; j++)
				mark[j] = 1;
		}
	}
	cout << ans;
}

Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(100000)

N, M = [int(x) for x in input().split()]

# Union Find
# N = 100
PARENT = list(range(N))

def root(n):
    if PARENT[n] == n:
        return n
    else:
        ret = root(PARENT[n])
        PARENT[n] = ret
        return ret

def same(n1, n2):
    return root(n1) == root(n2)

def unite(n1, n2):
    n1 = root(n1)
    n2 = root(n2)
    if n1 == n2:
        return
    PARENT[n1] = n2

used = set()

for i in range(M):
    x, y, z = [int(x) for x in input().split()]
    x -= 1
    y -= 1
    unite(x, y)
    used.add(x)
    used.add(y)

s = {root(u) for u in used}

cnt = len(s) + N - len(used)

print(cnt)


Measured memory_bytes: 34664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;


vector<int> ve[200001];
vector<int> ans;

void dfs(int v, int p = -1) {
  for(int u : ve[v]) {
    if(u == p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    ve[a].push_back(b);
    ve[b].push_back(a);
  }
  ans.resize(n);
  rep(i,q) {
    int p, x;
    cin >> p >> x;
    p--;
    ans[p] += x;
  }
  dfs(0);
  for(int i=0; i<n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    public static int[] color;
    public static Edges[] e;
    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        color = new int[n];//1:black 2:white 0:undecided
        e = new Edges[n];
        for (int i = 0; i < n; i++) e[i] = new Edges();
        for (int i = 0; i < n - 1; i++) {
            int from = in.ni()-1, to = in.ni()-1, cost = in.ni();
            e[from].add(new Edge(to, cost));
            e[to].add(new Edge(from, cost));
        }
        color[0] = 1;
        bfs(0);
        for(int c: color) out.println(c-1);
    }
    public static void bfs(int to){
        for (int i = 0; i < e[to].size(); i++) {
            if(color[e[to].get(i).to]!=0) continue;
            if(e[to].get(i).even){
                color[e[to].get(i).to] = color[to];
            }else{
                color[e[to].get(i).to] = 3-color[to];
            }
            bfs(e[to].get(i).to);
        }
    }
    public static class Edges extends ArrayList<Edge>{}
    public static class Edge{
        int to; boolean even;
        public Edge(int to, int cost){
            this.to = to;
            this.even = cost%2==0;
        }
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

using namespace std;
#define A 0<=a
#define B a<0&&0<b
#define C b<=0
#define D 0<=c
#define E c<0&&0<d
#define F d<=0

int main(void)
{
    long a,b,c,d;
    long ans;

    cin >> a >> b >> c >> d ;

    if(A&&D)
        ans = b*d;
    else if(A&&E)
        ans = b*d;
    else if(A&&F)
        ans = a*d;
    else if(B&&D)
        ans = b*d;
    else if(B&&E)
        ans = max(a*c,b*d);
    else if(B&&F)
        ans =a*c;
    else if(C&&D)
        ans = b*c;
    else if(C&&E)
        ans = a*c;
    else
        ans = a*c;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <iomanip>
#include <iostream>

#include <cmath>

using D = double;

struct Cartesian {
  D x;
  D y;
};

struct Polar {
  D radius;
  D degree;
};

constexpr D PI = std::acos(-1);

constexpr D degree_to_radian(D degree) {
  return degree * PI / 180.0;
}

constexpr D minutes_degree(int H, int M) {
  return std::fmod(5.5 * ((H * 60) + M), 360.0);
}

constexpr Cartesian polar_to_cartesian(Polar const& polar) {
  return {polar.radius * std::cos(degree_to_radian(polar.degree)),
    polar.radius * std::sin(degree_to_radian(polar.degree))};
}

constexpr D distance_2_points(Cartesian p1, Cartesian p2) {
  return std::hypot(p1.x - p2.x, p1.y - p2.y);
}

int main() {
  D A, B, H, M;
  std::cin >> A >> B >> H >> M;

  auto degree = minutes_degree(H, M);
  auto minute = polar_to_cartesian({B, degree});

  std::cout 
      << std::setprecision(std::numeric_limits<D>::digits10 + 1)
      << distance_2_points({A, 0}, minute) << '\n';
}


Measured memory_bytes: 4096
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(long.Parse).ToArray();

        var sum = a.Sum();
        var min = a.Min();
        if (n % 2 == 1)
        {
            Console.WriteLine(sum % 2 == 0 ? "Second" : "First");
            return;
        }
        Console.WriteLine(min % 2 == 1 || sum % 2 == 1 ? "First" : "Second");
    }
}



Measured memory_bytes: 44100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int a, b;

		while(true) {
			a = stdIn.nextInt();
			b = stdIn.nextInt();

			if(a == 0 && b == 0) {
				break;
			}

			if(a < b) {
				System.out.println(a +" "+ b);
			}else {
				System.out.println(b +" "+ a);
			}
		}

	}

}



Measured memory_bytes: 34300
# https://atcoder.jp/contests/agc011/tasks/agc011_a
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


N, C, K = read_ints()
T, = read_col(N)
T.sort()

# 条件が2つのgreedy
# つまりsorted(T)に対して、C人乗ったら出発。K分経ったら出発を繰り返す。
bus = []  # バスの乗客
ans = 0  # なんかいバスが出発したか
for t in T:
    if (len(bus) and bus[0] + K < t) or len(bus) == C:  # これ以上待てないor C人になった
        ans += 1  # バスを出発させる
        # print(bus)
        bus = []
    bus.append(t)
if bus:
    ans += 1
print(ans)


Measured memory_bytes: 93472
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	int A, B;
	cin >> A >> B;

	int ans = A * B;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int n,m;

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		m = sc.nextInt();

		int max = 1;
		int min = n;
		int ans = 0;

		for (int i = 0; i < m; i++) {

			int maxTmp,minTmp;

			maxTmp = sc.nextInt();
			minTmp = sc.nextInt();

			max = Math.max(max, maxTmp);
			min = Math.min(min, minTmp);

		}

		ans = min - max + 1;

		if (ans < 1) {
			System.out.println(0);
		} else {
			System.out.println(ans);
		}

	}
}


Measured memory_bytes: 65036
a,b,c,d,e,f=map(int,input().split())
dp=[0]*(f+1)
w=[]
s=[]
for i in range(f+1):
  if i%(a*100)==0:dp[i]=i
  if i%(b*100)==0:dp[i]=i
  if i>a*100 and dp[i-a*100]:dp[i]=i
  if i>a*100 and dp[i-b*100]:dp[i]=i
for i in dp:
  if i:w.append(i)
m=w[-1]*e//100+1
dp=[0]*(m)
for i in range(m):
  if i%c==0:dp[i]=i
  if i%d==0:dp[i]=i
  if i>c and dp[i-c]:dp[i]=i
  if i>d and dp[i-d]:dp[i]=i
for i in dp:
  if i: s.append(i)
g=0
ans=(w[0],0)
for i in w:
  for j in s:
    if i+j<=f and g<j/(i+j)<=e/(100+e):
      g=j/(i+j)
      ans=(i+j,j)
print(*ans)

Measured memory_bytes: 9200
#include<iostream>
#include<algorithm>
using namespace std;
using LL =long long;

int main() {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	LL ans = 1e10;
	for (int z = 0; z <= 2 * max(X, Y); z += 2) {
		LL sum = A * max(X - z / 2, 0) + B * max(Y - z / 2, 0) + C * z;
		ans = min(sum, ans);

	}


	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
N=int(input())
String=input().replace("W","1").replace("R","2")
c=[0]*N
for i in range (N):
    c[i]=int(String[i])
s=sorted(c)
import bisect
a=bisect.bisect_right(s,1)
cnt=0
for j in range(N-a):
    if c[j]==1:
        cnt+=1
print(cnt)

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

using namespace std;

#define MAX 100010

int main(){
  int Tc,N,K,x[MAX],a[MAX];
  cin >> Tc;
  while(Tc--){
    cin >> N >> K;
    for(int i = 0 ; i < N ; i++){
      cin >> x[i];
    }
    for(int i = 1 ; i < N ; i++){
      a[i-1] = x[i]-x[i-1];
    }
    sort(a,a+N-1);
    int res = 0;
    for(int i = 0 ; i < N-K ; i++){
      res += a[i];
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1956
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin>>n;
  VI a(3*n);
  forn(i,3*n)
    cin>>a[i];
  sort(all(a));
  reverse(all(a));
  in sm=0;
  forn(i,n)
    sm+=a[2*i+1];
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>
#include <sstream>
#include <iomanip>

using namespace std;

using Graph = vector<vector<int> >;

vector<int> seen;



int main()
{
	int N;
	string S;

	cin >> N >> S;

	int ans = 1;
	for (int ni = 1; ni < N; ni++) {
		if (S[ni - 1] != S[ni]) {
			ans++;
		}
	}


	//printf("%d %d %lld", xi, yi, H + gap);

	cout << ans;
	

	return 0;
}



Measured memory_bytes: 512
// I SELL YOU...! 
#include<iostream>
#include<chrono>
#include<random>
using namespace std;
chrono::system_clock::time_point now,start;
int n,a,b,c,l[8]={},v[4],x[4],t,ta,tb,tc,ans=1000000000;
double ti;
signed main(){
  random_device seed_gen;
  mt19937 engine(seed_gen());
  uniform_int_distribution<> r(0,3);
  start = chrono::system_clock::now();
  scanf("%d%d%d%d",&n,&a,&b,&c);
  for(int i=0;i<n;i++) scanf("%d",l+i);
  while(true){
    now = chrono::system_clock::now();
    ti = chrono::duration_cast<chrono::milliseconds>(now-start).count();
    if(ti>=1950) break;
    v[0] = v[1] = v[2] = v[3] = 0;
    x[0] = x[1] = x[2] = x[3] = 0;
    for(int i=0;i<8;i++){
      t = r(engine);
      v[t] += l[i];
      x[t] ++;
    }
    if(v[0]&&v[1]&&v[2]){
      t = (x[0]-1)*10 + (x[1]-1)*10 + (x[2]-1)*10;
      ta = a-v[0]; if(ta<0) ta = -ta;
      tb = b-v[1]; if(tb<0) tb = -tb;
      tc = c-v[2]; if(tc<0) tc = -tc;
      t += ta+tb+tc;
      if(ans>t) ans = t;
    }
  }
  printf("%d\n",ans);
}


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

int main()
{
    int n;
    cin >> n;
    int ans;
    ans = n / 2;
    if(n%2!=0){
        ans += 1;
    }
    cout << ans << endl;
    return 0;
}

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

typedef struct{
	vector<pair<int, int>> edge;
	bool checked = false;
	int color;
}Node;

int main(void){
	int n, u, v, w;
	cin >> n;
	Node node[n];
	for(int i = 0; i < n-1; ++i){
		cin >> u >> v >> w;
		u--; v--;
		node[u].edge.push_back(make_pair(v,w));
		node[v].edge.push_back(make_pair(u,w));
	}
	queue<int> q;
	q.push(0);
	node[0].checked = true;
	node[0].color = 0;
	while(!q.empty()){
		int now = q.front();
		q.pop();
		for(auto x : node[now].edge){
			if(!node[x.first].checked){
				node[x.first].checked = true;
				node[x.first].color = (x.second%2==0) ? node[now].color : !node[now].color;
				q.push(x.first);
			}
		}
	}
	for(int i = 0; i < n; ++i){
		cout << node[i].color << endl;
	}
	return 0;
}

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int takahashi = a / d;
    if (a % d > 0)
    {
        takahashi++;
    }
    int aoki = c / b;
    if (c % b > 0)
    {
        aoki++;
    }

    if (takahashi >= aoki)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int h, w; cin >> h >> w;
    vector<string> grid(h); rep(i, h) cin >> grid[i];
    rep(i, h){
        bool all_w = true;
        rep(j, w)if(grid[i][j]!='.')all_w = false;
        if(all_w){
            rep(j, w)grid[i][j] = 'x';
        }
    }
    rep(j, w){
        bool all_w = true;
        rep(i, h)if(grid[i][j]=='#')all_w = false;
        if(all_w){
            rep(i, h)grid[i][j] = 'x';
        }
    }
    rep(i, h){
        bool fg = false;
        rep(j, w){
            if(grid[i][j] != 'x'){cout << grid[i][j]; fg = true;}
        }if(fg)cout << ln;
    }
}


Measured memory_bytes: 3652
use std::io;
fn main() {
    let mut x = String::new();
    io::stdin().read_line(&mut x).unwrap();
    let mut iter = x.trim().split_whitespace();

    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();
    let ans = if a < b && b < c {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


Measured memory_bytes: 5020
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

def func(arr):
    if len(arr) == 0:
        return 0
    if len(arr) == 1:
        return arr[0]
    tmp = min(arr)
    for i in range(len(arr)):
        arr[i] -= tmp
    n_arr = []
    strt = 0
    flag = True if arr[0] != 0 else False
    for i in range(len(arr)):
        if arr[i] == 0 and flag:
            n_arr.append(arr[strt:i])
            flag = False
        if arr[i] != 0 and not flag:
            flag = True
            strt = i
    if flag:
        n_arr.append(arr[strt:])
    s = tmp
    for i in n_arr:
        s += func(i)
    return s

n = INT()
h = LIST()
ans = func(h)
print(ans)

Measured memory_bytes: 60012
#include <iostream>
#include <cstdio>
#include <algorithm>

#define MAX_N 100000 

long long A_len[MAX_N]={};
long long N;
using namespace std;

int main() {
    long long l1 = 0;
    long long l2 = 0;
    bool flg1=false;
    bool flg2=false;
    scanf("%lld", &N) ;
    for(long long i=0; i< N; i++){
        scanf("%lld", &A_len[i]);
    }
    sort(A_len, A_len+N, greater<long long>());
    for(int i = 1; i<N; i++){
        if(A_len[i]==A_len[i-1]){
            if(!flg1){
                l1=A_len[i];
                flg1=true;
                i++;
            }else{
                l2=A_len[i];
                flg2=true;
            }
        }
        if(flg2)
        break;
    }
    cout << l1*l2 <<endl;
    return 0;
}

Measured memory_bytes: 1024
N,K=gets.split.map(&:to_i)
S=N.times.map{gets.split.map(&:to_i)}

num=Hash.new{|h,k|h[k]=0}
ans=x=sum=k=0
stack=[]
S.sort{|l,r|r[1]<=>l[1]}.each do |t, d|
  if k<K
    k += 1
    stack << [t,d]
    sum += d
    sum -= x*x
    x += 1 if num[t].zero?
    sum += x*x
    num[t] += 1
  else
    if x != k
      until stack.empty?
        low = stack.pop
        next if num[low[0]] == 1
        if low[0] == t
          stack << low
          break
        end
        num[low[0]] -= 1
        sum -= low[1]
        stack << [t,d]
        sum += d
        sum -= x*x
        x += 1 if num[t].zero?
        sum += x*x
        num[t] += 1
        break
      end
    end
  end
  ans = [ans, sum].max
end
p ans

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

int main(){
  int r,D,x;
  cin >> r >> D >> x;
  rep(i,10) {
    x = r*x-D;
    cout << x << endl;
  }
}

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

int main(){
    int N;
    cin >> N;
    int v[N];
    for(int i =0; i < N ; i++){
        cin >> v[i];
    }
    sort(v, v + N);
    double av = v[0];
    for(int i = 1; i < N; i++){
        av = (av + v[i])/2.0;
    }
    cout << av << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

ll N, Z, W;
vector<ll> A(2001, 0); 

int main(void){
    
    scanf("%lld %lld %lld", &N, &Z, &W);
    for(int i = 0; i < N; ++i) scanf("%lld", &A[i]);
    
    ll ans = 0;
    for(int i = 0; i < N; ++i){
        if(i == N - 2) ans = max(ans, abs(A[N - 2] - A[N - 1]));
        else if(i == N - 1) ans = max(ans, abs(A[N - 1] - W));
        else ans = max(ans, min(abs(A[N - 2] - A[N - 1]), abs(A[N - 1] - A[i])));
    }
    printf("%lld\n", ans);
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x,int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/


int main()
{
	int n;
	int p[25];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
	}

	int ans = 0;
	for (int i = 1; i < n-1; i++)
	{
		if (p[i - 1] < p[i] && p[i] < p[i + 1]) ans++;
		else if (p[i - 1] > p[i] && p[i] > p[i + 1]) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//using ll=long long;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//dp注意点
//問題の種類	 初期化する値	 備考
//最小化問題 	INF	
//最大化問題	    -INF	 テーブル全体で 00 以上の値しかとらないことがわかっていれば −1−1 でもいいですし、00 でもいい場合もあります
//数え上げ問題	00	
//確率問題	      00	
//Yes/No 判定問題	False
/*-------------ここまで---------------------------------------------*/

/*signed*/int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
int32_t main() {
  int n, d;
  scanf("%lld%lld", &n, &d);
  int ans = 0;
  d *= d;
  for (int i = 0; i < n; i++) {
	int x, y;
    scanf("%lld%lld", &x,&y);
    if (x*x + y*y <= d)
      ans++;
  }
  printf("%lld\n", ans);
}

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

using namespace std;

// when range [l, r), has property notP~P, want first P.
// when return r, means not found.
template <typename T>
T bs_first(T l, T r, function<bool (T)> f) {
    assert(l < r);
    T mid;
    while (l != r) {
        mid = l + (r-l)/2;
        if (f(mid)) {
            r = mid;
        }else {
            l = mid + 1;
        }
    }
    return r;
}
using ll=long long ;
void solve() {
    int n, A,B;
    cin >> n >> A >> B;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x;
    }
    sort(a.begin(), a.end());
    const ll LIM = 1e9; 
    int res = bs_first<ll>(0, LIM+1, [&](ll t){
            ll rem = t;
            ll base = 1ll*B*t;
            ll ex = A-B;
            for (auto& x: a) {
                if (base >= x) continue;
                ll need = (x-base+ex-1)/ex;
                rem -= need;
                if (rem < 0) return false;
            }
            return true;
            });
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define maxn 3005
int n,a[maxn],f[maxn],u,v;
std::vector<int>conj[maxn];
int dfs(int u){
	if (f[u]!=-1)return f[u];
	f[u]=0;
	for(int i=0;i<conj[u].size();++i)
		if(a[conj[u][i]]<a[u]&&!dfs(conj[u][i]))f[u]=1;
	return f[u];
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=1;i<n;++i){
		scanf("%d%d",&u,&v);
		conj[u].push_back(v);
		conj[v].push_back(u);
	}std::memset(f,-1,sizeof(f));
	for(int i=1;i<=n;++i)
		if (dfs(i))printf("%d ",i);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string ans;
  cin >> N;
  for(int i=0;i<26;i++){
    for(int j=0;j<15;j++){
      if(4*i+7*j == N){
        cout <<"Yes" << endl;;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))
r_list = [0]*9
for a in a_list:
	if a < 400:
		r_list[0] += 1
	elif a < 800:
		r_list[1] += 1
	elif a < 1200:
		r_list[2] += 1
	elif a < 1600:
		r_list[3] += 1
	elif a < 2000:
		r_list[4] += 1
	elif a < 2400:
		r_list[5] += 1
	elif a < 2800:
		r_list[6] += 1
	elif a < 3200:
		r_list[7] += 1
	else:
		r_list[8] += 1
min_count = 0
super_r = r_list.pop(-1)
for r in r_list:
	if r > 0:
		min_count += 1
max_count = super_r + min_count
if min_count == 0 and super_r > 0:
	min_count = 1
print(min_count, max_count)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,n,m,i,j,p,q,sum=0,cnt1=0,cnt,cnt2=0,cnt3=0,flag=0;
    long long int it,st,ct,qt;
    string str,ptr;
    vector<long long int> veci;
    vector<char>vecc;
    vector<string>vecs;
    queue<long long int>vecq;
    set<long long int>si;
    cin>>n;
    vector<long long int> count(n+1,0);
    for(i=1; i<n; i++)
    {
        cin>>a;
        //veci.push_back(a);
        count[a]++;
    }
    for(i=1;i<=n;i++)
        cout<<count[i]<<endl;




    return 0;
}



Measured memory_bytes: 4792
import sys
input = sys.stdin.readline
 
t = int(input())
po = []
 
for _ in range(t):
  x,y = list(map(int,input().split()))
  po.append((x,y))
  
po.sort()
 
dp1 = [+(10**99) for _ in range(t)]
 
for i in range(t):
  x,y = po[i][0], po[i][1]
  value = x+y
  dp1[i] = min(dp1[i-1], value)
  
dp2 = [+(10**99) for _ in range(t)]
 
for i in range(t):
  x,y = po[i][0], po[i][1]
  value = x-y
  dp2[i] = min(dp2[i-1], value)
  
best = -9999999999999999999999999999
#print(dp)
 
for i in range(1,t):
  dist = po[i][0] + po[i][1] - dp1[i-1]
  best = max(best, dist)
  
  dist = po[i][0] - po[i][1] - dp2[i-1]
  best = max(best, dist)
  
print(best)

Measured memory_bytes: 117864
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll K, A, B;
  cin >> K >> A >> B;
  string ans = "NG";
  for (int i = A; i <= B; i++) {
    if (i % K == 0) ans = "OK";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


using namespace std;



int main(){
	int n;
	cin>>n;
	vector<int> v;
	int s=0, ma;
	for (int i=1;;i++){
		s+=i;
		if (s >= n){
			ma = i;
			break;
		}
	}
	int er = -1;
	if (s>n){
		er=s-n;
	}
	for (int i=1;i<=ma;i++){
		if (er!=i)cout<<i<<endl;
	}



	return 0;
}

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

void fnInput(vector<int>& rvnCandy, int& rnCandySiz)
{
  int nChildSiz;
  cin >> nChildSiz >> rnCandySiz;
  rvnCandy.resize(nChildSiz);

  for (int& rnCandy : rvnCandy)
    cin >> rnCandy;

  sort(begin(rvnCandy), end(rvnCandy));
}

int fnCandyDist(const vector<int>& cnrvnCandy, int nCandySiz)
{
  int nFullyChld = 0;
  for (int nCandy : cnrvnCandy)
  {
    nCandySiz -= nCandy;
    if (nCandySiz >= 0)
      nFullyChld++;
    else
      break;
  }
  if (nCandySiz > 0)  nFullyChld--;

  return nFullyChld;
}

int main()
{
  int nCandySiz;
  vector<int> vnCandy;

  fnInput(vnCandy, nCandySiz);
  cout << fnCandyDist(vnCandy, nCandySiz) << endl;

  return 0;
}

Measured memory_bytes: 256
//距離が1以下なら？：葉から塗るよりも、深さ0から幅優先の要領で塗った方が簡単！
//距離が2以下でも？：深さ0から幅優先の要領で塗った方が簡単！もうちょい詰めると、実装は深さ優先が簡単！
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int mod = 1000000007;
int n, k;
vector<int> et[100000];
int cnt[100000];

void dfs(int p, int v, int depth, int iter) {
	if (depth == 0) { cnt[v] = 0; }
	else if (depth == 1) { cnt[v] = 1 + iter; }
	else { cnt[v] = 2 + iter; }
	
	int i;
	int chcnt = 0;
	rep(i, et[v].size()) {
		int nv = et[v][i];
		if (nv == p) continue;
		dfs(v, nv, depth + 1, chcnt);
		chcnt++;
	}
}

signed main() {
	int i;
	
	cin >> n >> k;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		et[a].push_back(b);
		et[b].push_back(a);
	}
	dfs(-1, 0, 0, 0);
	
	int ans = 1;
	rep(i, n) {
		int mul = max(0LL, k - cnt[i]);
		ans *= mul;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x, y,z;
  bool operator < (const P &a )const{
    //if(x!=a.x)
    return y<a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[1012];
int l[1];
int j[1];


long long x,y,z,mod=1000000007;
//string r;
char r[22];

P u[2221];
queue<int> q;
stack<int> s;
//set<P> s;
map<int,int> p;

vector<int> v;

bool as(P a,P b)
{
  //if(a.x!=b.x)
  //return a.x<b.x;
  return a.z<b.z;
}

int f(int n)
{
  if(o[n]==n) return n;
  return o[n]=f(o[n]);
}

int main()
{
  scanf("%d %d %lld",&a,&b,&x);
  for(int t=1;t<=b;t++)
  {
    scanf("%d %d %d",&n,&m,&k);
    u[t]={n,m,k};
  }
  sort(u+1,u+b+1,as);
  for(int t=1;t<=b;t++)
  {
    iota(o+1,o+a+1,1);
    y=u[t].z;
    o[u[t].x]=u[t].y;
    for(int t=1;t<=b;t++)
    if(f(u[t].x)!=f(u[t].y))
    {
      y+=u[t].z;
      o[f(u[t].x)]=f(u[t].y);
    }
    if(y==x) c++;
    else if(y>x) d++;
    else e=1;
  }
  if(!c)
  {
    puts("0");
    return 0;
  }
  z=1;
  for(int t=1;t<=c;t++)
    z*=2,z%=mod;
  z=(z+mod-1)%mod;
  if(e) z*=2,z%=mod;
  else z=(z+mod-1)%mod;
  for(int t=1;t<=d;t++)
    z*=2,z%=mod;
  
  printf("%lld",z);
}
//0
//13
//19



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

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

    rep(i, 3){
        if(S[i] == '1') cout << 9;
        else if (S[i] == '9') cout << 1;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,m;
  cin >>n>>m;
  vector<pair<int,int>> a(m);
  vector<bool> ans(n,false);
  rep(i,m){
    int c,d;
    cin >>c>>d;
    a.at(i)=make_pair(c,d);
    if(c==1){
      ans.at(d-1)=true;
    }
  }
  sort(a.begin(),a.end());
  for( auto p:a){
    int d=p.first;
    int e=p.second;
    if(ans.at(d-1)==true && e==n){
      cout <<"POSSIBLE";
      return 0;
    }
  }
  cout << "IMPOSSIBLE";
}
  

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
#define int long long int

void solve(long long N, long long Q, std::vector<long long> S,
           std::vector<long long> T, std::vector<long long> X,
           std::vector<long long> D)
{
  vector<tuple<lli, lli, lli>> v;
  rep(i, N) v.emplace_back(S[i] - X[i], T[i] - X[i], X[i]);
  using p = tuple<lli, lli, lli>;
  priority_queue<p, vector<p>, greater<p>> que_l;
  priority_queue<p, vector<p>, greater<p>> que_r;
  rep(i, N)
  {
    que_l.push(v[i]);
  }
  lli a, b, c;
  multiset<lli> Xs;
  rep(i, Q)
  {
    while (!que_l.empty() && std::get<0>(que_l.top()) <= D[i])
    {
      tie(a, b, c) = que_l.top();
      Xs.insert(c);
      que_r.push(make_tuple(b, a, c));
      que_l.pop();
    }
    //cout << que_l.size() << " " << que_r.size() << endl;
    while (!que_r.empty() && std::get<0>(que_r.top()) <= D[i])
    {
      tie(a, b, c) = que_r.top();
      Xs.erase(Xs.find(c));
      que_r.pop();
    }
    //cout << "# " << i << endl;
    // for (auto s : Xs)
    //   cout << s << " ";
    // cout << endl;
    cout << (Xs.size() ? *Xs.begin() : -1) << endl;
  }
}

signed main()
{
  long long N;
  scanf("%lld", &N);
  long long Q;
  scanf("%lld", &Q);
  std::vector<long long> S(N);
  std::vector<long long> T(N);
  std::vector<long long> X(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &S[i]);
    scanf("%lld", &T[i]);
    scanf("%lld", &X[i]);
  }
  std::vector<long long> D(Q);
  for (int i = 0; i < Q; i++)
  {
    scanf("%lld", &D[i]);
  }
  solve(N, Q, std::move(S), std::move(T), std::move(X), std::move(D));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


Measured memory_bytes: 30956
#include<stdio.h>
#include<math.h>
int main()
{
  int n, num, sum = 0, i, j;
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%d", &num);
      if(num % 2 == 0 && num > 2)
	{
	  sum++;
	}
      else
	{
	  for(j = 3; j <= sqrt(num); j+=2)
	    {
	      if(num % j == 0)
		{
		  sum++;
		  break;
		}
	    }
	}
    }
  printf("%d\n", n - sum);
  return 0;
}



Measured memory_bytes: 2064
import java.io.*;

class Main
{
	public static void main(String args[]) throws IOException
	{
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		String str1 = br.readLine();

		int num = Integer.parseInt(str1);
		num = num * num * num;

		System.out.println(num);
	}
}

Measured memory_bytes: 24432
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace Standart_Deviation
{
    class Program
    {
        static void Main(string[] args)
        {
            String str;
            while ((str = Console.ReadLine()) != "0")
            {
                var input = Console.ReadLine().Split(' ');
                int[] ngo = new int[int.Parse(str)];
                for (int i = 0; i < input.Length; ++i) ngo[i] = int.Parse(input[i]);
                double average = ngo.Sum() / (double)ngo.Length;
                //Console.WriteLine("average = {0}", average);
                double bunsun = 0;
                for (int i = 0; i < input.Length; ++i)
                {
                    bunsun += Math.Pow(ngo[i] - average, 2);
                }
                //Console.WriteLine("bunsun = {0}", bunsun / input.Length);
                double sd = Math.Sqrt(bunsun / input.Length);
                Console.WriteLine(sd);
            }
        }
    }
}


Measured memory_bytes: 9784
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

int n, m, x, y, ans, a[N], b[N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d",&n ,&m);
	a[1] = 1;
	for(int i = 1; i <= n; i++)
		b[i] = 1;
	for(int i = 1; i <= m; i++){
		scanf("%d %d",&x ,&y);
		if(a[x])
			a[y] = 1;
		if(b[x] == 1 and a[x] == 1)
			a[x] = 0;
		b[x]--;
		b[y]++;
	}
	for(int i = 1; i <= n; i++)
		ans += a[i];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4736