akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


int main() {
int N=0;

cin >> N;
vector<string> S(N);
for(int i=0;i<N;i++){
    
    cin >> S.at(i);

}
sort(S.begin(),S.end());
S.erase(unique(S.begin(),S.end()),S.end());
cout <<S.size()<<endl;

}

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

const int INF = 1<<28;

int main() {
  int n;
  while(cin >> n && n) {
    pair<int,int> A(INF,0), B(INF,0), C(-INF,0), D(-INF,0);
    for(int i = 0; i < n; ++i) {
      int id, a, b, c, d, e, f, g, h;
      cin >> id >> a >> b >> c >> d >> e >> f >> g >> h;
      pair<int,int> p(a*60+b + c*60+d + e*60+f + g*60+h, id);
      if(p < A) {
        B = A;
        A = p;
      } else if(p < B) {
        B = p;
      }
      if(p > D) {
        C = D;
        D = p;
      } else if(p > C) {
        C = p;
      }
    }
    cout << A.second << endl;
    cout << B.second << endl;
    cout << C.second << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.awt.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        Point[] list = new Point[m];

        for (int i = 0; i < m; i++) {
            list[i] = new Point(sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(list, Comparator.comparingInt(p -> p.y));

        int ans = 0;
        int index = 0;

        for (int i = 0; i < m; i++) {
            Point p = list[i];
            if (p.x < index && p.y >= index) {
                continue;
            }
            index = p.y;
            ans++;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 90784
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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


   String[] xy = br.readLine().split(" ");
   double a = Double.parseDouble(xy[0]);
   double b = Double.parseDouble(xy[1]) ;
   double c = Double.parseDouble(xy[2]) ;

   double S = 0.5 * a * b * Math.sin( Math.toRadians(c) );
   double L = a + b + Math.sqrt( Math.pow( a , 2 )  + Math.pow( b , 2 ) - 2* a * b * Math.cos( Math.toRadians(c) ) );
   double h = b * Math.sin( Math.toRadians(c) );

   System.out.println(S);
   System.out.println(L);
   System.out.println(h);

  }
}

Measured memory_bytes: 24504
/**
 *    author:  tourist
 *    created: 29.12.2018 15:35:32       
**/
#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long L;
  int n;
  cin >> L >> n;
  vector<long long> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  long long ans = 0;
  for (int outer = 0; outer < 2; outer++) {
    vector<long long> new_x = x;
    new_x.push_back(L);
    for (int i = 0; i < n; i++) {
      new_x.push_back(L + x[i]);
    }
    vector<long long> d(2 * n);
    for (int i = 0; i < 2 * n; i++) {
      d[i] = new_x[i + 1] - new_x[i];
    }
    debug(d);
    vector<long long> pref(2 * n + 1);
    vector<long long> pref_mul(2 * n + 1);
    for (int i = 0; i < 2 * n; i++) {
      pref[i + 1] = pref[i] + d[i];
      pref_mul[i + 1] = pref_mul[i] + d[i] * (2 * i);
    }
    for (int start = 0; start <= n; start++) {
      int left = n - start;
      int right = start;
      int from1 = start;
      int to1 = n - 1;
      int from2 = n;
      int to2 = start + n - 1;
      long long cur = 0;
      if (left > right) {
        int extra = left - right;
        cur += (pref[to1 + 1] - pref[to1 + 1 - extra]) * (2 * right + 1);
        to1 -= extra;
      }
      if (left < right) {
        int extra = right - left;
        cur += (pref[from2 + extra] - pref[from2]) * (2 * left);
        from2 += extra;
      }
      cur += (pref_mul[to1 + 1] - pref_mul[from1]) - (pref[to1 + 1] - pref[from1]) * ((2 * from1) - 1);
      cur += -(pref_mul[to2 + 1] - pref_mul[from2]) + (pref[to2 + 1] - pref[from2]) * (2 + (2 * to2));
      ans = max(ans, cur);
    }
    for (int i = 0; i < n; i++) {
      x[i] = L - x[i];
    }
    reverse(x.begin(), x.end());
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 17876
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	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;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

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

vector<P> p;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int zero = 0;
    map<pair<ll, ll>, P> mp;
    rep(i,n){
        ll x, y;
        cin >> x >> y;
        if(x == 0 && y == 0){
            ++zero;
            continue;
        }
        ll g = gcd(x, y);
        x /= g;
        y /= g;
        if(y < 0) x = -x, y = -y;
        if(y == 0 && x < 0) x = -x, y = -y;
        bool rot90 = (x <= 0);
        if(rot90){
            ll tmp = x;
            x = y; y = -tmp;
        }
        if(rot90) mp[{x, y}].first++;
        else mp[{x, y}].second++;
    }
    mint ans = 1;
    for(auto p : mp){
        int s = p.second.first;
        int t = p.second.second;
        mint now = 1;
        now += mint(2).pow(s) - 1;
        now += mint(2).pow(t) - 1;
        ans *= now;
    }
    ans -= 1;
    ans += zero;
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 16048
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]) = {
      var n = readLine.split(" ").map(_.toInt)
      while( n(0)!= 0 || n(1) != 0) {

          if(n(0)<n(1)) println(n(0)+" "+n(1))
          else println(n(1)+" "+n(0))
          n = readLine.split(" ").map(_.toInt)
      }
  }
}

Measured memory_bytes: 46052
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int A,B,C;
    cin>>A>>B>>C;
    if((A-C)*(B-C)<=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){
    int N, M, K; cin >> N >> M >> K;
    bool jdg = false;
    for (int n = 0; n <= N; n++) {
        for (int m = 0; m <= M; m++) {
            int black = n * (M - m) + m * (N - n);
            if (black == K) jdg = true;
        }
    }
    cout << ((jdg) ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 256
slist=list(map(int,list(input())))
len_s=len(slist)

min_answer=len_s
for i in range(1,len_s):
  if slist[i-1]!=slist[i]:
    min_answer=min(min_answer,max(i,len_s-i))
    #print(i,len(slist)-i)

print(min_answer)

Measured memory_bytes: 4652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

const int INF = 1e9 + 1;
int N, K;
vector<int> h, dp;

int main() {
  cin >> N >> K;
  h.resize(N), dp.resize(N, INF);
  rep(i, N) cin >> h[i];

  dp[0] = 0;

  rep(i, N) {
    rep(j, K) {
      if (i + 1 + j < N)
        dp[i + 1 + j] = min(dp[i + 1 + j], dp[i] + abs(h[i + 1 + j] - h[i]));
    }
  }

  cout << dp[N - 1] << endl;

  return 0;
}


Measured memory_bytes: 1024
/*
 * https://atcoder.jp/contests/abc152/tasks/abc152_e
 * Flatten.
 */

# include<iostream>
# include<vector>
# include<algorithm>

const long long MOD = 1e9+7;
const long long MAX_N = 1e6+5;

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

long long inverse(long long a, long long b, long long& x, long long& y)
{
    if( b == 0)
    {
        x = 1;
        y = 0;

        return a;
    }
    
    long long x1, y1;
    long long d = inverse(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);

    return d;
}


long long modpow(long long a, long long n, long long mod=MOD)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod=MOD)
{
    return modpow(a, mod - 2, mod);
}

std::vector<std::pair<long long, long long>> prime_devisor(long long n)
{
    std::vector<std::pair<long long, long long>> res;
    for(long long p = 2; p * p <= n; p++)
    {
        if(n % p != 0) continue;
        
        long long num = 0;
        while(n % p == 0)
        {
            ++num;
            n /= p;
        }
        res.push_back(std::make_pair(p, num));
    }
    if(n != 1) res.push_back(std::make_pair(n, 1));

    return res;
}

long long solve(std::vector<long long>& a, std::vector<long long>& mem)
{

    for(int i = 0; i < a.size(); i++)
    {
        auto pd = prime_devisor(a[i]);
        for(auto p: pd) mem[p.first] = std::max(mem[p.first], p.second);
    }

    long long lcm = 1;
    for(int i = 2; i < MAX_N; i++) lcm = lcm*modpow(i, mem[i]) % MOD;

    long long ans = 0;
    for(int i = 0; i < a.size(); i++)
    {
        ans += lcm*modinv(a[i])%MOD;
    }

    return ans % MOD;
}

int main()
{
    int n;
    long long num, index = 0;
    std::cin>>n;

    std::vector<long long> a(n), mem(MAX_N, 0);
    while(n--)
    {
        std::cin>>num;
        a[index++] = num;
    }
    std::cout<<solve(a, mem)<<std::endl;
    //std::cout<<MOD<<" "<<MAX_N;

    return 0;
}


Measured memory_bytes: 11188
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function kod(n,d)
	a = Int[]
	r = 0
	while 10^r <= n
		push!(a,div(n,10^r)%10)
		r += 1
	end
	flg = 0
	for i in 1:length(a)
		if a[i] in d
			flg = 1
			break
		end
	end
	flg
end

function main()
	n,k = readline() |> split |> parseMap
	d = readline() |> split |> parseMap
	while kod(n,d) == 1
		n += 1
	end
	println(n)
end

main()


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

int main()
{
    int N, K, p[1000];

    cin >> N >> K;

    for(int i = 0; i < N; ++i)
            cin >> p[i];
    sort(p, p + N);

    int ans = 0;

    for(int i = 0; i < K; ++i)
        ans += p[i];
    cout << ans << endl;


    return 0;
}



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

int n;
vector<int> v;

long long solve(void)
{
	long long sum, i;

	sum = 0;
	i = 0;
	while(i < (n - 2) / 2)
	{
		sum += 2 * v[i];
		i++;
	}
	sum += v[i];
	i++;
	if (n % 2 == 0)
		sum -= v[i];
	else
		sum += v[i];
	i++;
	while(i < n)
	{
		sum -= 2 * v[i];
		i++;
	}
	return abs(sum);
}

signed main(void)
{
	cin >> n;
	long long ans;

	v = vector<int>(n);
	rep(i, n) cin >> v[i];
	sort(v.rbegin(), v.rend());
	ans = solve();
	reverse(v.begin(), v.end());
	ans = max(ans, solve());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
    int n, a, b;
    int t;
    int ans;

    scanf("%d %d %d\n", &n, &a, &b);

    t = n * a;
    ans = b;
    if( t < b ) {
        ans = t;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        CF_Reader in = new CF_Reader();

        char[] word = in.next().toCharArray();
        int ln = word.length;
        int halve = (ln - 1) / 2;
        boolean f = isPalindrome(0, halve-1, word);
        boolean s =  isPalindrome(halve + 1, ln - 1, word);
        boolean l = isPalindrome(0, ln - 1, word);
        System.out.println((f && s && l) ? "Yes": "No");

        out.close();
    }



    static boolean isPalindrome(int start, int end, char[] word) {
        while (start < end) {
            if (word[start] != word[end]) return false;
            start++;
            end--;
        }
        return true;
    }


    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

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

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

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

        char nextCharacter() throws IOException {
            return next().charAt(0);
        }

        String nextLine() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 22612
#include <stdio.h>

int main(void){
  int x[5];
  int i, j;
  
  scanf("%d %d %d %d %d\n", &x[0], &x[1], &x[2], &x[3], &x[4]);
  for(i=0; i<5; i++){
    if(x[i] == 0){
      j = i+1;
    }
  }
  
  printf("%d\n", j);
  
  return 0;
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
    int W,H,N;
    cin >> W >> H >> N;
    vector<tuple<int, int, int>> v(N);
    for(int i = 0; i < N; ++i) cin >> get<0>(v[i]) >> get<1>(v[i]) >> get<2>(v[i]);

    P a(0,0),b(W, H);

    for(auto& t : v){
        switch(get<2>(t)){
        case 1:
            if(get<0>(a) < get<0>(t))
                get<0>(a) = get<0>(t);
            break;
        case 2:
            if(get<0>(b) > get<0>(t))
                get<0>(b) = get<0>(t);
            break;
        case 3:
            if(get<1>(a) < get<1>(t))
                get<1>(a) = get<1>(t);
            break;
        case 4:
            if(get<1>(b) > get<1>(t))
                get<1>(b) = get<1>(t);
            break;
        }
    }
    if(get<0>(b) - get<0>(a) > 0 && get<1>(b) - get<1>(a) > 0)
        cout << (get<0>(b) - get<0>(a)) * (get<1>(b) - get<1>(a)) << endl;
    else
        cout << 0 << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
signed main() {
  string S; cin >> S;
  int st = -1, en = -1;
  for(int i = 0; i + 1 < (int)S.size(); ++i) {
    if(S[i] == S[i + 1]) {
      st = i + 1;
      en = i + 1 + 1;
      break;
    }
    if(i + 2 < (int)S.size() && S[i] == S[i + 2]) {
      st = i + 1;
      en = i + 2 + 1;
    }
  }
  cout << st << ' ' << en << endl;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

const int MAX_N = 1e5;
struct Edge { ll to, cost; };
vector<vector<Edge>> G;
ll dp[MAX_N];

void dfs(int v, int p, ll d)
{
    dp[v] = d;
    for (auto u : G[v]) {
        if (u.to == p) continue;
        dfs(u.to, v, d+u.cost);
    }
}

int main()
{
    ios::sync_with_stdio(false);

    int N; cin >> N;
    G.resize(N);

    rep(i, N-1) {
        int A, B, C;
        cin >> A >> B >> C;
        A--, B--;
        G[A].push_back({B, C});
        G[B].push_back({A, C});
    }

    int Q, K;
    cin >> Q >> K;

    dfs(K-1, -1, 0);

    rep(q, Q) {
        int X, Y; cin >> X >> Y;
        X--, Y--;
        cout << dp[X] + dp[Y] << endl;
    }
}

Measured memory_bytes: 14336
def gcd(a,b):
  if a%b==0:
    return(b)
  else:
    return(gcd(b,a%b))

n=int(input())
t=[int(input()) for i in range(n)]
t.sort(reverse=1)
ans=t[0]
for x in t:
  if ans%x!=0:
    ans=ans*x//gcd(ans,x)
'''
for i in range(n-1):
  u=int(input())
  if ans%u!=0:
    ans=ans*u//gcd(ans,u)
'''


print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    long n;
    cin >> n;
    long a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    vector<long>num(n+1,0);
    for(int i=0;i<n;i++)num[a[i]]++;
    long ans = 0;
    for(int i=0;i<=n;i++){
        ans += (num[i]*(num[i]-1))/2;
    }
    for(int i=0;i<n;i++){
        cout << ans - num[a[i]] + 1 << endl;
    }
}

Measured memory_bytes: 5760
n, m, l = map(int, input().split())
A, B, C = [], [], []

for i in range(n):
    A.append(list(map(int, input().split())))
for i in range(m):
    B.append(list(map(int, input().split())))

for i in range(n):
    row = []
    for j in range(l):
        sigma = 0
        for k in range(m):
            sigma += A[i][k] * B[k][j]
        row.append(sigma)
    C.append(row)

for row in C:
    print(*row)


Measured memory_bytes: 7052
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(a, b) for(int unsafe_cnt=a; unsafe_cnt < b;unsafe_cnt++)
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  int n;
  vector<int> a;
  cin >> n;
  rep(0, n){
    int input;
    cin >> input;
    a.push_back(input);
  }
  sort(a.begin(), a.end());
  int prev = 0;
  int sum = 0;
  for(auto iter = a.begin(); iter != a.end(); iter++){
    sum += *iter - prev;
    prev = *iter;
  }
  sum -= *(a.begin());
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		char[] cr1 = str.toCharArray();
		str = br.readLine();
		char[] cr2 = str.toCharArray();
		String dis = "No";
		int x;
		for(int i=0; i<cr1.length; i++){
			if(dis.equals("Yes")) break;
			if(cr1[i]==cr2[0]){
				dis = "Yes";
				x = i;
				for(int j=1; j<cr2.length; j++){
					x++;
					if(x == cr1.length) x=0;
					if(cr1[x]!=cr2[j]){
						dis = "No";
						break;
					}
				}
			}
		}
		System.out.println(dis);
	}
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> C(N);
    rep(i, N) cin >> C[i];
    map<ll, ll> pos;
    vector<ll> dp(N + 1, 0);
    rep(i, N) {
        pos[C[i]] = -1;
    }
    dp[0] = 1;
    rep(i, N) {
        ll c = C[i];
        ll prev = pos[c];
        if (prev != -1 && i > prev + 1) {
            dp[i + 1] += dp[prev + 1];
            dp[i + 1] %= MOD;
        }
        pos[c] = i;
        dp[i + 1] += dp[i];
        dp[i + 1] %= MOD;
    }
    cout << dp[N] << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main() {
   int n;
   std::cin >> n;
   std::vector<int> a(n);
   int count = 0;
   for (size_t i = 0; i < n; i++) {
      std::cin >> a.at(i);
   }
   for (size_t i = 0; i < n; i++) {
      while (a.at(i) % 2 == 0) {
         a.at(i) /= 2;
         count++;
      }
   }
   std::cout << count << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

//木の関連pair、typedef
typedef pair<int, int> P;

vector<long> counters(2*100000);

int main() {
    int N;
    int Q;
    cin >> N >> Q;

    vector<P> relation(N-1);
    int from =0;
    int to = 0;
    for (int i = 0; i < N-1; i++) {
        cin >> from >> to;
        relation[i] = P(from-1, to-1);
    }

    vector<P> operation(Q);
    int node =0;
    int increVal = 0;
    for (int i = 0; i < Q; i++) {
        cin >> node >> increVal;
        operation[i] = P(node-1, increVal);
    }

    //N番目の親を設定
    vector<int> parent(N);
    for (int i = 0; i < N; i++) {
        int node = relation[i].first;
        int branch = relation[i].second;

        parent[branch] = node;
    }

    // 操作実行（ノードにのみ）
    for (int i = 0; i < Q; i++) {
        int node = operation[i].first;
        int increVal = operation[i].second;        
        
        counters[node] += increVal;
    }
    
    // counter値を伝搬
    for (int i = 1; i < N; i++){
        counters[i] += counters[parent[i]];
    }

    for (int i = 0; i < N; i++) {
        cout << counters[i] << ' ';
    }

    return 0;
}


Measured memory_bytes: 7808
x=int(input())
for _ in range(x):
	num=list(map(int,input().split()))
	b,c=0,0
	flag=True
	for i in num:
		if b<i:
			b=i
		elif c<i:
			c=i
		else:
			print("NO")
			flag=False
			break
	if flag:
		print("YES")


Measured memory_bytes: 5592
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n, = map(int,readline().split())
*a, = map(lambda x:2*int(x),readline().split())
*b, = map(lambda x:2*int(x)+1,readline().split())

c = sorted(a+b)
res = []
aa = []
bb = []
for x,y in zip(c[:n],c[n:]):
    if x%2 == 0:
        if y%2 == 0:
            aa.append((x//2,y//2))
        else:
            res.append((x//2,y//2))
    else:
        if y%2 == 0:
            res.append((y//2,x//2))
        else:
            bb.append((x//2,y//2))

while aa:
    p,q = aa.pop()
    r,s = bb.pop()
    if p != r and q != s:
        res.append((p,r))
        res.append((q,s))
    else:
        res.append((p,s))
        res.append((q,r))

from operator import itemgetter
res.sort(key = itemgetter(0))

for x,y in res:
    if x==y:
        print("No")
        exit()
print("Yes")
ans = [y for x,y in res]
print(*ans)




Measured memory_bytes: 62348
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

constexpr int mod = 1000000007;
struct ModCalc {
    vector<int> fact;
    ModCalc(int N) : fact(N + 1) {
        fact[0] = 1;
        rep(i, N) fact[i + 1] = (long long)(i + 1) * fact[i] % mod;
    }
    int ModPow(int x, int y) {
        if (y == 0) return 1;
        long long a = ModPow(x, y / 2);
        if (y & 1) return a * a % mod * x % mod;
        else return a * a % mod;
    }
    int ModCom(int x, int y) {
        if (x < y) return 0;
        int res = fact[x];
        res = (long long)ModPow(fact[y], mod - 2) * res % mod;
        res = (long long)ModPow(fact[x - y], mod - 2) * res % mod;
        return res;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    
    map<int, int> cnt;
    for (int i = 2; i * i <= M; ++i) {
        while (M % i == 0) {
            M /= i;
            ++cnt[i];
        }
    }
    if (M != 1) ++cnt[M];
    
    ModCalc MC(200000);
    long long ans = 1;
    for (auto p : cnt) {
        ans *= MC.ModCom(N + p.second - 1, p.second);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
/*氏名：保坂優介, 学籍番号：200441141
  概要：約数の数を表示*/

#include<stdio.h>

int main(void)
{
    int i, j, a, b, c,ans=0;        //変数の宣言

    scanf("%d %d %d", &a, &b, &c);      //入力

    for (i = a; i <= b; i++)        //aからbまで繰り返し
    {
        j = c % i;
        if (j == 0)     //割り切れる場合
        {
            ans++;
        }
    }

    printf("%d\n", ans);      //表示
    return 0;
}


Measured memory_bytes: 2100
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			var a = Console.ReadLine ().Split().Select(x=>int.Parse(x)).ToArray();
			int N = a [0];
			int X = a [1];
			var b = Console.ReadLine ().Split().Select(x=>int.Parse(x)).ToArray();
			long time = 0;
			var dp = new int[N,N];
			long min = long.MaxValue;
			dp [0,0] = 0;
			for (int k = 0; k < N; k++) {
				time = k * (long)X;
				for (int i = 0; i < N; i++) {
					dp [i,k] = k==0?b[i]: Math.Min (dp [i,k - 1], b [(i - k + N) % N]);
					time += dp [i,k];
				}
				if (time <= min) {
					min = time;
				}
			}
			Console.WriteLine (min);
		}
	}
}


Measured memory_bytes: 18776
N, Y = map(int, input().split())

ans = [-1,-1,-1]
for x in range(0,N+1):
    for y in range(0,N-x+1):
        z = N - x - y
        if x*10000 + y*5000 + z*1000 == Y:
            ans[0] = x
            ans[1] = y
            ans[2] = z
print(ans[0],ans[1],ans[2])

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

int main() {
  int a, b; cin >> a >> b;
  if (a < 0) {
    if (b < 0) {
      if ((a-b-1) % 2 == 0) {
        cout << "Positive" << endl;
      } else {
        cout << "Negative" << endl;
      }
      return 0;
    }
    cout << "Zero" << endl; return 0;
  }
  if (a == 0) {
    cout << "Zero" << endl; return 0;
  }
  if (a > 0) {
    cout << "Positive" << endl; return 0;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */
int main() {
    long double a, b, c;
    cin >> a >> b >> c;
    if(2 * sqrt(a * b) < c - a - b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
#define ng 100010
typedef pair<ll,ll> pair;

int main(){
    ll n;
    cin >> n;
    ll m = n / 2;
    ll even[ng];
    ll odd[ng];
    ll max1,max2;
    max1 = 0;max2 = 0;
    ll maxeven,maxodd;
    for(ll i = 0; i < ng; i++){
        even[i] = 0;
        odd[i] = 0;
    }
    for(ll i = 0; i < n; i++){
        ll temp;
        cin >> temp;
        if(i % 2 == 0){
            even[temp]++;
            if(max1 < even[temp]){
                max1 = even[temp];
                maxeven = temp;
            }
        }
        else{
             odd[temp]++;
             if(max2 < odd[temp]){
                max2 = odd[temp];
                maxodd = temp;
            }
        }
    }
    sort(even,even+ng,greater<>());
    sort(odd,odd+ng,greater<>());
    ll ans = 0;
    /*for(ll i = 1; i < ng;i++){
        ans += even[i];
        ans += odd[i];
    }*/
    if(maxeven != maxodd){
        ans = n - max1 - max2;
    }
    else{
        ans = n-max(max1+odd[1],max2+even[1]);
    }

    cout << ans << endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vll;

const int MOD = (int)(1e+9) + 7;
int N;
vector<vll> dp;

int main(void) {
	cin >> N;
	dp.resize(2, vll(2, vl(N + 1, 0)));
	dp[0][0][1] = 8;
	dp[0][1][1] = 1;
	dp[1][0][1] = 1;
	dp[1][1][1] = 0;
	for (int k = 2; k <= N; ++k) {
		dp[0][0][k] = (dp[0][0][k - 1] * 8) % MOD;
		dp[0][1][k] = (dp[0][0][k - 1] + ((dp[0][1][k - 1] * 9) % MOD)) % MOD;
		dp[1][0][k] = (dp[0][0][k - 1] + ((dp[1][0][k - 1] * 9) % MOD)) % MOD;
		dp[1][1][k] = (dp[0][1][k - 1] + dp[1][0][k - 1]  + ((dp[1][1][k - 1] * 10) % MOD)) % MOD;
	}
	cout << dp[1][1][N] << '\n';
	return 0;
}


Measured memory_bytes: 57692
def DFS(G):
    ans = [0] + [[0,0,0] for _ in range(len(G))]
    def main(G,i):
        ans[0] += 1
        ans[i] = [i, ans[0], ans[0]]
        for j in sorted(G[i-1][2:]):
            if ans[j][0] == 0: main(G,j)
        ans[0] += 1
        ans[i][2] = ans[0]
    for u in G:
        if ans[u[0]][0] == 0: main(G,u[0])
    return ans[1:]


if __name__=='__main__':
    n = int(input())
    G = [list(map(int,input().split())) for _ in range(n)]
    for out in DFS(G): print(*out)

Measured memory_bytes: 7792
#include <iostream>
using namespace std;
int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    const int dx = tx - sx, dy = ty - sy;
    string ans="";
    // Path 1
    ans += string(dx, 'R') + string(dy, 'U');
    // Path 2
    ans += string(dx, 'L') + string(dy, 'D');
    // Path 3
    ans += 'D' + string(dx+1, 'R') + string(dy+1, 'U') + 'L';
    // Path 4
    ans += 'U' + string(dx+1, 'L') + string(dy+1, 'D') + 'R';
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using pint = pair<int,int>;
const int MAX = 110000;

int main() {
    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    // 偶数番目、奇数番目について
    // どの数がどれだけあるかのヒストグラムを作る
    vector<int> odd_hist(MAX, 0), even_hist(MAX, 0);
    for (int i = 0; i < N; ++i) {
        if (i & 1) odd_hist[a[i]]++;
        else even_hist[a[i]]++;
    }

    // 頻度順にソート
    vector<pint> odd, even;
    for (int i = 0; i < MAX; ++i) {
        odd.push_back(pint(odd_hist[i], i));
        even.push_back(pint(even_hist[i], i));
    }
    sort(odd.begin(), odd.end(), greater<pint>());
    sort(even.begin(), even.end(), greater<pint>());

    // お互いの最大が異なればそれが答え、そうでなかったら 2 番目を持ち出す
    if (odd[0].second != even[0].second) {
        cout << N - (odd[0].first + even[0].first) << endl;
    }
    else {
        cout << N - max(odd[0].first + even[1].first,
                        odd[1].first + even[0].first) << endl;
    }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int n = (int) s.size();
  vector<int> tmp, asw(n, 0);
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'R') {
      tmp.push_back(i);
    } else {
      while (not tmp.empty()) {
        int d = i - tmp.back();
        if (d % 2) {
          ++asw[i - 1];
        } else {
          ++asw[i];
        }
        tmp.pop_back();
      }
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'L') {
      tmp.push_back(i);
    } else {
      while (not tmp.empty()) {
        int d = tmp.back() - i;
        if (d % 2) {
          ++asw[i + 1];
        } else {
          ++asw[i];
        }
        tmp.pop_back();
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i > 0) {
      cout << " ";
    }
    cout << asw[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1480
#include <iostream>
#include <cmath>
#include <queue>
using namespace std;
bool is_integer(double x)
{
    return floor(x) == ceil(x);
}
class Move
{
public:
    int w;
    int h;
    int warp;
};
int main()
{
    int h, w;
    int ch, cw, dh, dw;
    char s[1001][1001] = {'#'};
    cin >> h >> w >> ch >> cw >> dh >> dw;
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            cin >> s[i][j];
        }
    }
    queue<Move> walk_que;
    queue<Move> warp_que;
    Move *p_start = new Move();
    p_start->h = ch;
    p_start->w = cw;
    p_start->warp = 0;
    warp_que.push(*p_start);
    // スタート地点から行けるマス
    while (!warp_que.empty())
    {
        Move warp = warp_que.front();
        warp_que.pop();
        walk_que.push(warp);
        if (s[warp.h][warp.w] == '*')
        {
            continue;
        }
        while (!walk_que.empty())
        {
            Move walk = walk_que.front();
            walk_que.pop();
            int aw = walk.w;
            int ah = walk.h;
            int awarp = walk.warp;
            if (s[ah][aw] == '*')
            {
                continue;
            }
            if (ah == dh && aw == dw)
            {
                cout << awarp << endl;
                return 0;
            }
            s[ah][aw] = '*';
            // cout << aw << ' ' << ah << ' ' << awarp << endl;
            for (int i = -2; i <= 2; i++)
            {
                for (int j = -2; j <= 2; j++)
                {
                    if (i == 0 && j == 0)
                        continue;
                    if (ah + i <= 0 || ah + i > h)
                    {
                        continue;
                    }
                    if (aw + j <= 0 || aw + j > w)
                    {
                        continue;
                    }
                    if (i * i + j * j == 1)
                    {
                        if (s[ah + i][aw + j] == '.')
                        {
                            Move *tmp = new Move();
                            tmp->h = ah + i;
                            tmp->w = aw + j;
                            tmp->warp = awarp;
                            walk_que.push(*tmp);
                        }
                    }
                    else
                    {
                        if (s[ah + i][aw + j] == '.')
                        {
                            Move *tmp = new Move();
                            tmp->h = ah + i;
                            tmp->w = aw + j;
                            tmp->warp = awarp + 1;
                            warp_que.push(*tmp);
                        }
                    }
                }
            }
        }
    }
    cout << -1 << endl;
}

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

#define pow(x) (x)*(x)
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define pb push_back
#define skip continue
#define PI 3.14159265
#define name "input"

typedef unsigned long long ull;
typedef  long long ll;
typedef long double ld;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MAXN = 6e5 + 1;
const ld EPS = 1e-12;

//это приём, позволяющий возводить любое число в n-ую степень за O(logn)
int binPow(int v, int u, int mod) {
    if(!u)  return 1;   
    int res = binPow(v, u / 2, mod);  
    res = (res * 1ll * res) % mod;  
    if(u & 1) 
        res = (res * 1ll * v) % mod;  
    return res; 
} 
//это количество чисел от 1 до n, взаимно простых с n Асимтотика O(sqrt(n))
int phi (int n) {
    int result = n;
    for (int i=2; i*i<=n; ++i)
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    if (n > 1)
        result -= result / n;
    return result;
}
//NOD
int gcd (int a, int b) {
    return b ? gcd (b, a % b) : a; }
int lcm(int a, int b) { 
    return a / gcd (a, b) * b; }

int fib(int n){ int a=0,b=1; for (int i = 0; i < n; ++i){ b=b+a; a=b-a; }return b; }
bool compare(const string &c1,const string &c2){ return c1.size() < c2.size(); }


string alph = "abcdefghijklmnopqrstuvwxyz";

int n;
void solve(){
    cin >> n;
    n%=10;
    if(n==3)
        cout<<"b";
    else if(n==0 || n==1 || n==6 || n==8) cout<<"p";
    else cout<<"h";
    cout<<"on\n";
}

int main(){

    faster();

    int T=1; 
    //cin>>T;

    while(T--){
        solve();
        cout<<"\n";
    }
    return 0;     
}

Measured memory_bytes: 3572
#include <iostream>
#include <cstring>
#include <stack>

using namespace std;

int main() {
    string s;
    cin >> s;
    
    stack<int> istack;
    for(int i = 0; i < s.length(); ++i) {
        int cur = int(s[i] - '0');
        if(istack.empty()) {
            istack.push(cur);
            continue;
        }
        
        int top = istack.top();
        
        if(cur + top == 1) {
            istack.pop();
        } else {
            istack.push(cur);
        }
    }
    
    int result = int(s.size()) - int(istack.size());
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 768
/*
** author:mahmoud magdy
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"

inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m;
    cin>>m;
    return m;
}
void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
string s ;
int dp[1005][1005];
int solve(int i , int j){
if(i>=j)
    return 0;
if(dp[i][j]!=-1)return dp[i][j];
int ch1=solve(i+1,j-1)+(s[i]!=s[j]);
int ch2=solve(i+1,j)+1;
int ch3=solve(i,j-1)+1;
return dp[i][j]=min({ch1,ch2,ch3});
}
int main()
{
    fast();
   char c;
   cin>>c;
   if(c>='A'&&c<='Z')cout<<"A\n";
  else cout<<"a\n";
}

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

int main() {
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= N; ++a) {  // 10000円の枚数を 0 〜 N で調べる
        for (int b = 0; b + a <= N; ++b) {  // 5000円の枚数を 0 〜 N-a で調べる
            int c = N - a - b;  // 1000円の枚数は決まる
            int total = 10000*a + 5000*b + 1000*c;
            if (total == Y) {  // 答えが見つかったら
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
    }

    // 答えを出力 (見つかっていなくても -1 -1 -1 になるので OK です)
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
    return 0;
}

Measured memory_bytes: 3560
function main(lines) {
  const N = n();

  let cnt = 0;
  for (let a = 1; a < N; a++) {
    cnt += Math.floor((N-1) / a);
  }
  
  return cnt;
}



const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");

let lineCount = 0;
const s = () => lines[lineCount++];
const n = () => Number(s());
const b = () => BigInt(s());
const sa = () => s().split(' ');
const na = () => sa().map(Number);
const ba = () => sa().map(BigInt);
const getLines = (n) => lines.slice(lineCount, lineCount += n);

const ans = main(lines);
console.log( ans );

Measured memory_bytes: 32504
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String ans ="No";
    for(int i = 1; i <= 9; i++){
      for(int j = 1; j <= 9; j++){
        if(n == i*j){
          ans = "Yes";
        }
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 23764
import math

n = int(input())

###商及び余りをsとすると、n=m*s+s=s(m+1)、ただし0<s<m
sum_fav = 0
for s in range(1,int(math.sqrt(n))+1):
  if n%s == 0:
    m = n//s-1
    if s < m:
      #print(m)
      sum_fav += m
    else:
      break
  
print(sum_fav)


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


#define long long long int

using namespace std;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef pair<int, int> pi;


int main() {
    std::ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    cout << k + 100 * (max(10 - n, 0));

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; 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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N, M, X;
int A[200];

int main() {
  cin >> N >> M >> X;
  int left = 0, right = 0;
  rep(i, 0, M) {
    int a;
    cin >> a;
    if (a < X)
      ++left;
    else
      ++right;
  }
  cout << min(left, right) << endl;
}


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

using vi = vector<int>;


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


  for(int i=0; i<50000; i++){
    if (i*108>= N*100 && i*108 < (N+1)*100){
      cout << i << endl;
      return 0;
    } 
  }

  cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

int main(){
  int n, d;
  std::cin >> n >> d;
  std::vector<std::vector<double>> x;
  std::vector<double> temp;
  double input;
  for(int i=0; i<n; ++i){
    temp = {};
  	for(int j=0; j<d; ++j){
      std::cin >> input;
  	  temp.push_back(input);
    }
  x.push_back(temp);
  }
  std::vector<double> distance;
  for(int i=0; i<n-1; ++i)
    for(int j=i+1; j<n; ++j){
      double temp = 0.0;
      for(int k=0; k<d; ++k)
        temp += pow(x[i][k]-x[j][k],2);
      distance.push_back(sqrt(temp));
    }
  int cnt = 0;
  for(auto i : distance){
    double err = i-round(i);
    if(-0.0001<err && err<0.0001)
      ++cnt;
  }
  std::cout << cnt << std::endl;
  return 0;
}

Measured memory_bytes: 384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {
	int N,M;
	ArrayList<Integer>[] list;
	@SuppressWarnings("unchecked")
	public void solve() {
		while(true){

			N = nextInt();
			if(N == 0)break;

			list = new ArrayList[30];
			for(int i = 0;i < 30;i++){
				list[i] = new ArrayList<Integer>();
			}

			for(int i = 0;i < N;i++){
				M = nextInt();
				for(int j = 0;j < M;j++){
					int day = nextInt() - 1;
					list[day].add(i);
				}
			}

			long[] max = new long[N];
			for(int i = 0;i < N;i++){
				max[i] = (1L << i);
			}

			boolean find = false;

			for(int i = 0;i < 30;i++){
				long sum = 0L;
				for(int n : list[i]){
					sum |= max[n];
				}
				for(int n : list[i]){
					max[n] |= sum;
				}

				long ans = 0L;

				for(int n : list[i]){
					ans |= max[n];
				}

				if(ans == (1L << N) - 1){
					find = true;
					out.println(i + 1);
					break;
				}
			}
			if(!find){
				out.println(-1);
			}

		}
	}

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

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

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)


const int maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
const int inf = 1e9;

int n, m;

char c[1010][1010];
queue<int> q;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

int f[1010][1010];

int main() {
    __;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> c[i][j];
            if (c[i][j] == '#') {
                q.push(i);
                q.push(j);
            }
        }
    }
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        int y = q.front();
        q.pop();
        for (int k = 0; k < 4; ++k) {
            if (x + dx[k] >= 1 && x + dx[k] <= n && y + dy[k] >= 1 && y + dy[k] <= m &&
                c[x + dx[k]][y + dy[k]] == '.') {
                c[x + dx[k]][y + dy[k]] = '#';
                f[x + dx[k]][y + dy[k]] = f[x][y] + 1;
                q.push(x + dx[k]);
                q.push(y + dy[k]);
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            ans = max(ans, f[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11408