akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long t1 = sc.nextLong();
		long t2 = sc.nextLong();
		long a1 = sc.nextLong();
		long a2 = sc.nextLong();
		long b1 = sc.nextLong();
		long b2 = sc.nextLong();

		long sub1 = (a1 - b1) * t1;
		long sub2 = (a2 - b2) * t2;

		if (sub1 + sub2 == 0) {
			System.out.println("infinity");
			return;
		} else if (sub1 > 0 && sub2 > 0) {
			System.out.println(0);
			return;
		} else if (sub1 < 0 && sub2 < 0) {
			System.out.println(0);
			return;
		}

		if (sub1 < 0) {
			sub1 = -sub1;
			sub2 = -sub2;
		}

		long dist = sub1 + sub2;

		if (dist < 0) {
			if ((sub1 % (-dist) == 0)) {
				System.out.println((sub1 / (-dist)) * 2);
				return;
			}
			System.out.println((sub1 / (-dist)) * 2 + 1);
			return;
		}
		System.out.println(0);
	}

}

Measured memory_bytes: 23252
[N,Q] = list(map(int,input().split()))
S = input()

lr = []
for i in range(Q):
    lr.append(list(map(int,input().split())))

#C:1(左がAの場合)
flag=[0]*N
for i in range(1,N):
    if S[i]=='C' and S[i-1]=='A':
        flag[i]=1

#t = 1からiまでのAC出現回数
t=[0]
for i in range(1,N):
    t.append(t[-1] + flag[i])
# print('flag, t:', flag, t)

#Qに答えていく
for i in range(Q):
    print(t[lr[i][1]-1] - t[lr[i][0]-1])


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n, -1);
    for (int i = 0; i < m; ++i) {
        int s, c;
        cin >> s >> c;
        s--;
        if (a[s] != -1 && a[s] != c) {
            cout << -1 << endl;
            return 0;
        }
        a[s] = c;
    }
    if (a[0] == 0 && n != 1) {
        cout << -1 << endl;
        return 0;
    }
    if (a[0] == -1) a[0] = (n == 1) ? 0 : 1;
    for (int i = 1; i < n; ++i) if (a[i] == -1) a[i] = 0;
    for (int i = 0; i < n; ++i) cout << a[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int [] num = new int[n];
        for (int i = 0; i < n; ++i) {
            num[i] = scanner.nextInt();
        }
        Arrays.sort(num);
        int right = num.length / 2;
        int left = right - 1;
        if (num[right] == num[left]) {
           System.out.println(0);
           return;
        }
        System.out.println((num[right] - num[left]));
    }

}


Measured memory_bytes: 51020
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    long[] X = new long[N];
    long[] Y = new long[N];
    long[] Z = new long[N];
    
    for (int i=0; i<N; i++) {
      X[i] = sc.nextLong();
      Y[i] = sc.nextLong();
      Z[i] = sc.nextLong();
    }

    long ans = 0;
    List<Long> list = new ArrayList<>();
    for (int a=-1;a<=1;a+=2) {
      for (int b=-1;b<=1;b+=2) {
        for (int c=-1;c<=1;c+=2) {
          long tmp = 0;
          list.clear();
          for (int i=0; i<N; i++) {
            list.add(a*X[i] + b*Y[i] + c*Z[i]);
          }
          list.sort(Comparator.reverseOrder());
          for (int i=0; i<M; i++) {
            tmp += list.get(i);
          }
          ans = Math.max(ans, tmp);
        }
      }
    }
    System.out.println(ans);
  }

  private static final long MOD = 998244353;
  private static long FACT[];
  private static long IFACT[];

  // Pre-calculate factorial and its mod_inverse for calculate nCr in O(1)
  private static void create_fact(int N) {
    FACT = new long[N+1];
    IFACT = new long[N+1];
    FACT[0] = 1;
    IFACT[0] = 1;
    for (int i=1; i<=N; i++) {
      FACT[i] = FACT[i-1] * i % MOD;
      IFACT[i] = mod_inverse(FACT[i]);
    }
  }

  // Return nCr
  private static long comb(int n, int r) {
    if (n < 0 || r < 0 || n < r) {
      return 0;
    }
    if (r > n/2) {
      r = n - r;
    }
    return FACT[n]*IFACT[n-r]%MOD*IFACT[r]%MOD;
  }

  // Fast mod inverse
  private static long mod_inverse(long a) {
    long b = MOD;
    long p = 1, q = 0;
    while (b > 0) {
      long c = a / b;
      long d;
      d = a;
      a = b;
      b = d % b;
      d = p;
      p = q;
      q = d - c * q;
    }
    return p < 0 ? p + MOD : p;
  }
}


Measured memory_bytes: 26364
#include <iostream>
#include <string>
#include <vector>

int main(void){
    int x,y;
    std::cin >> x >> y;
    int aGroup[4] = {4,6,9,10};
    int bGroup[7] = {1,3,5,7,8,10,12};
    if(x == 2 && y == 2){
        std::cout << "Yes";
        return 0;
    }

    for(int i = 0; i < 4; i++){
        if(aGroup[i] == x){
            for(int j = 0; j < 4; j++){
                if(aGroup[j] == y){
                    std::cout << "Yes";
                    return 0;
                }
            }
        }
    }

    for(int i = 0; i < 7; i++){
        if(bGroup[i] == x){
            for(int j = 0; j < 7; j++){
                if(bGroup[j] == y){
                    std::cout << "Yes";
                    return 0;
                }
            }
        }

    }

    std::cout << "No";
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
p = [0]*m
s = [0]*m
for i in range(m):
  p[i], s[i] = map(str, input().split())
  p[i] = int(p[i])

ng = [0]*n
ok = [0]*n
for i in range(m):
  if ok[p[i]-1] == 0 and s[i] =='AC':
    ok[p[i]-1] += 1
  elif ok[p[i]-1] == 0 and s[i] =='WA':
    ng[p[i]-1] += 1
result = [x * y for (x, y) in zip(ok, ng)]
print(str(sum(ok)) + ' ' + str(sum(result)))

Measured memory_bytes: 15736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			while (n-- != 0)
			{
				var p = new int[81];
				for (int i = 0; i < 9; i++)
				{
					Console.ReadLine().Split(' ')
						.Select(c => c[0] - '0')
						.ToArray().CopyTo(p, i * 9);
				}
				for (int x = 0; x < 9; x++)
				{
					for (int y = 0; y < 9; y++)
					{
						var d = p.Where((v, i) =>
							(i / 9 == x) ||
							(i % 9 == y) ||
							((i / 9 / 3 == x / 3) && (i % 9 / 3 == y / 3)))
							.Where(v => v == p[x * 9 + y]).Count();
						Console.Write("{0}{1}", d>=2 ? "*" : " ", p[x * 9 + y]);
					}
					Console.WriteLine();
				}
				if (n != 0) Console.WriteLine();
			}
		}
	}
}

Measured memory_bytes: 6188
#include<bits/stdc++.h>
using namespace std;
int n,x;
struct task
{
  int b,l,r;
  long long sum;
  bool operator<(const task &q)const{return sum>q.sum;}
}a[110001];
int main()
{
  cin>>n>>x;
  long long o=0;
  for(int i=1;i<=n;i++) {
    cin>>a[i].b>>a[i].l>>a[i].r;
    a[i].sum=1ll*a[i].b*a[i].l+1ll*(x-a[i].b)*a[i].r;
    o+=1ll*a[i].b*a[i].l;
  }
  sort(a+1,a+1+n);
  long long l=0,r=1ll*x*n,ans=r;
  while(l<=r)
  {
    long long m=(l+r)/2,p=m/x,q=m%x,s=0,buf=0;
    for(int i=1;i<=p;i++)s+=a[i].sum;
    buf=s;
    if(q)
    {
      for(int i=1;i<=n;i++)
        if(i<=p)
          buf=max(buf,s+(q>a[i].b?a[i].b*a[i].l+(q-a[i].b)*a[i].r:q*a[i].l)+a[p+1].sum-a[i].sum);
        else
          buf=max(buf,s+(q>a[i].b?a[i].b*a[i].l+(q-a[i].b)*a[i].r:q*a[i].l));
    }
    if(buf>=o)r=m-1,ans=m;
    else l=m+1;
  }
  cout<<ans<<'\n';
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
    int a, b;
    int h, m;
    cin >> a >> b >> h >> m;
    long double theta;

   
    theta = 2.0*M_PI*((long double)h/12.0 + ((long double)m/60.0)/12.0 - (long double)m/60.0);
    
    long double c = sqrtl((long double)(a*a + b*b) - (long double)(2.0*a*b)*cosl(theta));

    printf("%.20Lf\n", c);

    return 0;

}

Measured memory_bytes: 4076
#include<stdio.h>
#include<string.h>
int main(){
    int c[26] = {0};
    char s[30];
    scanf("%s",s);
    int len,flag;
    flag = 0;
    len = strlen(s);
    for(int i = 0;i < len;i++)
        c[s[i]-'a']++;
    for(int i = 0;i < 26;i++){
        if(c[i]>1){
            printf("no\n");
            flag = 1;
            break;
        }
    }
    if(flag==0) printf("yes\n");
    return 0;
}


Measured memory_bytes: 128
N,M = [ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(M) ]
li = [ (a-1,b-1,c) for a,b,c in li ]

dw = [ [] for i in range(N) ]


for a,b,c in li:
  dw[a].append( (b,c) )

NOT = 1e+16 -1 
  
cost = [NOT]*N
cost[0]=0
cosli = []
for i in range(1000):
  chk = [0]*N
  now = 0
  pop=[now]
  for i in range(N):
    if (len(pop)==0):
      break
    now = pop.pop()
    chk[now]=1
    for b,c in dw[now]:
      if ( cost[b] == NOT ):
        cost[b] = cost[now] + c
      else:
        cost[b] = max(cost[now] + c,cost[b])
      if (chk[b]==0):
        pop.append(b)
  cosli.append( cost[N-1] )  

if ( cosli[-1] != cosli[-2] ):
  print ("inf")
else:
  print (cosli[-1])

Measured memory_bytes: 48984
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define drep(i,n) for (int i = n; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
using namespace std;
typedef long long ll;

int gcd(int a, int b)
{
   if (a%b == 0) return(b);
   else          return(gcd(b, a%b));
}
int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}


//------------------------------------------------------------
int main() {
  int N, x=-1, y=-1, z=-1, re=0;
  ll Y;
  cin >> N >> Y;

  rep(i, N+1)
  {
    rep(j, N-i+1)
    {
      re = Y-i*10000-j*5000;
      if(re%1000==0 && re>=0 && re/1000+i+j==N)
      {
        x=i; y=j; z=re/1000;
        break;
      }
    }
  }

  cout << x << ' ' << y << ' ' << z << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

int main(){
  ll T;
  cin >> T;
  rep(i,T){
    ll N,M,A,B;
    cin >> N >> M >> A >> B;
    cout << floor_sum(N,M,A,B) << endl;
  }
}

Measured memory_bytes: 3644
#include<stdio.h>

main(){
	int i, n,a[10000], max=-1000000, min=1000000;
	double sum=0;
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	
	for(i=0;i<n;i++){
		if(max<a[i])max=a[i];
		if(min>a[i])min=a[i];
		sum+=a[i];
	}
	
	printf("%d %d %.0f\n",min,max,sum);
	
	return 0;
}

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


int main()
{
	int N,M;
	int a[60], b[60], c[60], d[60];
	long long  min;
	long long dist;
	int point;
	cin	>> N >> M;
	for (int i = 0; i < N; ++i) cin >> a[i] >> b[i];
	for (int i = 0; i < M; ++i) cin >> c[i] >> d[i];

	for (int i = 0; i < N; ++i) {
		min = 1000000000;
		for (int j = 0; j < M; ++j) {
			dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);

			if (dist < min) {
				min = dist;
				point = j+1;
			}


		}
		cout << point << endl;
	}


	
	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)

using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
    int k,x;
    cin >> k >> x;
    int r = x-k+1;
    int l = x+k-1;
    for(int i=r; i<=l; ++i) {
        cout << i << " ";
    } 
    cout << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  int x, y;
  cin >> x >> y;
  x--; y--;
  string S, T;
  cin >> S >> T;
  vector<vector<int> > countR(N+1, vector<int>(2));
  vector<vector<int> > countL(N+1, vector<int>(2));
  vector<vector<int> > countU(N+1, vector<int>(2));
  vector<vector<int> > countD(N+1, vector<int>(2));
  bool ans = true;
  for(int i=1; i<N+1; i++) {
    int j = 0;
    countR[i][j] = countR[i-1][j];
    countL[i][j] = countL[i-1][j];
    countU[i][j] = countU[i-1][j];
    countD[i][j] = countD[i-1][j];
    switch(S[i-1]) {
    case 'R':
      countR[i][j]++;
      break;
    case 'L':
      countL[i][j]++;
      break;
    case 'U':
      countU[i][j]++;
      break;
    case 'D':
      countD[i][j]++;
      break;
    }
    j = 1;
    countR[i][j] = countR[i-1][j];
    countL[i][j] = countL[i-1][j];
    countU[i][j] = countU[i-1][j];
    countD[i][j] = countD[i-1][j];
    switch(T[i-1]) {
    case 'R':
      countR[i][j]++;
      break;
    case 'L':
      countL[i][j]++;
      break;
    case 'U':
      countU[i][j]++;
      break;
    case 'D':
      countD[i][j]++;
      break;
    }
    if(y + (countR[i][0] - countL[i-1][1]) >= W ||
       y - (countL[i][0] - countR[i-1][1]) <  0 ||
       x + (countD[i][0] - countU[i-1][1]) >= H ||
       x - (countU[i][0] - countD[i-1][1]) <  0) {
      ans = false;
    }
    if(y + (countR[i][0] - countL[i][1]) <  0)
      countL[i][1] = max(0, y + (countR[i][0] - countL[i][1])) + y + countR[i][0];
    if(y - (countL[i][0] - countR[i][1]) >= W)
      countR[i][1] = min(W-1, y - (countL[i][0] - countR[i][1])) - y + countL[i][0];
    if(x + (countD[i][0] - countU[i][1]) <  0)
      countU[i][1] = max(0, x + (countD[i][0] - countU[i][1])) + x + countD[i][0];
    if(x - (countU[i][0] - countD[i][1]) >= H)
      countD[i][1] = min(H-1, x - (countU[i][0] - countD[i][1])) - x + countU[i][0];
  }
  if(ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 44424
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    deque<int> pile;
    rep(i, N) {
        int a;
        cin >> a;
        if (i == 0)
            pile.push_back(a);
        else {
            int k = lower_bound(all(pile), a) - pile.begin() - 1;
            if (k == -1)
                pile.push_front(a);
            else
                pile[k] = a;
        }
    }

    cout << pile.size() << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	string s; cin>>s;
	if(s=="Sunny") cout<<"Cloudy"<<endl;
	else if(s=="Cloudy") cout<<"Rainy"<<endl;
	else cout<<"Sunny"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll N, Q; cin >> N >> Q;
    string S; cin >> S;
    // prepare
    ll A[N + 1];
    A[0] = 0;
    for (int i = 0; i <= N; ++i) {
        A[i + 1] = A[i];
        if (S[i] == 'A' && S[i + 1] == 'C') A[i + 1]++;
    }

    // query
    for (int i = 0; i < Q; i++) {
        ll l, r; cin >> l >> r;
        cout << A[r-1] - A[l-1] << endl;
    }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  int d_max;
  cin >> A.at(0);
  d_max = A.at(0);
  for (int i = 1; i < N; i++){
    cin >> A.at(i);
    if (A.at(i) - A.at(i - 1) > d_max){
      d_max = A.at(i) - A.at(i - 1);
    }
  }
  if (K - A.at(N - 1) + A.at(0) > d_max){
    d_max = K - A.at(N - 1) + A.at(0);
  }
  cout << K - d_max << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define yes cout<<"YES"<<nl
#define no  cout<<"NO"<<nl
#define nl  '\n'
#define tr ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define tst int t;cin>>t;while(t--)
#define     Max             1000000000000000014
#define     Min             -1000000000000000014
#define     PI              3.1415926535897
#define     Fr               first
#define     Se               second
#define     all(v)          v.begin(),v.end()
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     space            ' '
#define COUT(v) for(auto it:v)cout<<it<<space;cout<<nl;
/*error cheaking method starts from here */
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
/*error cheaking method ebds here */

#define vi    vector<int>
#define    vl    vector<ll>
#define    si    set<int>
#define    sl    set<ll>
#define    msi    multiset<int>
#define    msl    multiset<ll>
#define    pii    pair<int,int>
#define    pil    pair<int,ll>
#define    pli    pair<ll,int>
#define    pll    pair<ll,ll>
#define    mp    make_pair
#define    pb    push_back
int main()
{
    int n;
    cin>>n;
    vl v;
    int i,x;
    for(i=0;i<n;i++)
        cin>>x,v.push_back(x);
    sort(v.begin(),v.end());
    int c=0;
    for(i=0;i<v.size();i++)
    {
        for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==v[i])
                continue;
            for(int k=j+1;k<v.size();k++)
            {
                if(v[k]==v[i]||v[k]==v[j])
                    continue;
                ll x=v[i],y=v[j],z=v[k];
                if(x+y>z&&x+z>y&&y+z>x)
                    c++;
            }
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3632
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O20")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
using ll = int_fast64_t; using namespace std;

#ifndef __GNUC__
string text =
R"X(136)X";
stringstream iss{text};
#endif

ll cnt;
inline bool  oddQ(ll &b) { return (b & 1); }
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	ll N; iss >> N;
	for (ll i = 1; i <= N; ++i) {
		if ((ll(log10(i)) + 1) & 1) ++cnt;
	}
	cout << cnt << "\n";
}


Measured memory_bytes: 3928
#include<stdio.h>
typedef long long ll;
const ll inf=922337203685477580ll;
void fmin(ll&a,ll b){
	if(b<a)a=b;
}
int h[200010],nex[200010],to[200010],v[200010],M,r,c;
void add(int a,int b,int c){
	M++;
	to[M]=b;
	v[M]=c;
	nex[M]=h[a];
	h[a]=M;
}
bool vis[200010];
ll val[200010],m1,m2;
void dfs(int x){
	vis[x]=1;
	fmin(x<=r?m1:m2,val[x]);
	for(int i=h[x];i;i=nex[i]){
		if(!vis[to[i]]){
			val[to[i]]=v[i]-val[x];
			dfs(to[i]);
		}else if(val[x]+val[to[i]]!=v[i])
			throw 1;
	}
}
int main(){
	int n,i,x,y,z;
	scanf("%d%d%d",&r,&c,&n);
	while(n--){
		scanf("%d%d%d",&x,&y,&z);
		add(x,y+r,z);
		add(y+r,x,z);
	}
	try{
		for(i=1;i<=r+c;i++){
			if(!vis[i]){
				m1=m2=inf;
				dfs(i);
				if(m1+m2<0)throw 1;
			}
		}
	}catch(int e){
		puts("No");
		return 0;
	}
	puts("Yes");
}

Measured memory_bytes: 8192
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MAX = 510000;
const int MOD = 1000000007;
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; }
struct Corr {
    int x,y, depth;
};
int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };
int rx[5] = { -2,-1,0,1,2 }, ry[5] = { -2,-1,0,1,2 };
int main(void) {
    int h, w,ch,cw,dw,dh; cin >> h >> w>>ch>>cw>>dh>>dw;
    ch--; cw--; dh--; dw--;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    deque<Corr> dq;
    dq.push_back({ cw,ch,0 });
    vector<vector<bool>> field(h, vector<bool>(w, 0));
    vector<vector<int>> mp(h, vector<int>(w));
    field[ch][cw] = 1; mp[ch][cw] = 0;
    while (!dq.empty()) {
        Corr now = dq.front(); dq.pop_front();
        field[now.y][now.x] = 1;
        if (now.x == dw && now.y == dh) {
            cout << now.depth << endl;
            return 0;
        }
        rep(i, 4) {
            int nx = now.x + dx[i], ny = now.y + dy[i];
            if (nx < 0 || nx >= w || ny < 0 || ny >= h || field[ny][nx])continue;
            if (s[ny][nx] == '#') continue;
            Corr next = { nx,ny,now.depth };
            mp[ny][nx] = now.depth;
            dq.push_front(next);
        }rep(i, 5) {
            rep(j, 5) {
                if (rx[i] == 0 && ry[j] == 0)continue;
                int nx = now.x + rx[i], ny = now.y + ry[j];
                if (nx < 0 || nx >= w || ny < 0 || ny >= h || field[ny][nx])continue;
                if (s[ny][nx] == '#') continue;
                Corr next = { nx,ny,now.depth + 1 };
                mp[ny][nx] = now.depth + 1;
                dq.push_back(next);
            }
        }
    }cout << -1 << endl;
}

Measured memory_bytes: 11676
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[]=new int[N];
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
		}
		double ans;
		double tmp=0;
		for(int i=0;i<N;i++) {
			tmp += (double)1/A[i]; 
		}
		ans=1/tmp;		
		System.out.println(ans);
	}
	
}

Measured memory_bytes: 21716
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def bfs_grid(H, W, grid):

    d = [[False for _ in range(W)] for _ in range(H)]
    move = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    ans = 0

    for sy in range(H):
        for sx in range(W):
            if d[sy][sx]:
                continue

            q = deque()
            q.append((sx, sy))
            d[sy][sx] = True
            black = 0
            white = 0
            while q:
                x, y = q.popleft()
                now_color = grid[y][x]
                if now_color:
                    white += 1
                else:
                    black += 1
                for m in move:
                    nx, ny = x + m[0], y + m[1]
                    if 0 <= nx < W and 0 <= ny < H:
                        if not d[ny][nx] and grid[ny][nx] != now_color:
                            d[ny][nx] = True
                            q.append((nx, ny))

            ans += black * white

    return ans


def main():
    H, W = in_nn()
    grid = in_map2(H)

    print(bfs_grid(H, W, grid))


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
    int n ,m;double total=0;int count =0;double sum;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        total+=a[i];
    }sum=total/(4*m);
    for(int i=0;i<n;i++){
        if(a[i]>=sum)count++;
    }if(count>=m)cout<<"Yes";
    else cout<<"No";


    return 0;
}

Measured memory_bytes: 256
W, H, x, y, r = map(int, input().split())
if (x - r) < 0 or (x + r) > W or (y - r) < 0 or (y + r) > H:
  print("No")
if (x - r) >= 0 and (x + r) <= W and (y - r) >= 0 and (y + r) <= H:
  print("Yes") 


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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

ll mod=1000000007;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}


int main() {
  int n,k;cin>>n>>k;
  vector<int> p(n);
  rep(i,n)cin>>p[i];
  sort(ALL(p));
  int ans=0;
  rep(i,k)ans+=p[i];
  cout<<ans;
}

Measured memory_bytes: 3632
P[];M(int*a){return*1[&a]-*a;}main(n,i,d,S){for(;~scanf(S="%d\n",&n);printf(S,~i)){for(i=n;d=i--;)scanf(S,P+i);for(qsort(P,n,4,M);n--;)i-=d+=P[n];}}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>

using namespace std;

int N;
long long int Z, W, a[2005], X[2005],Y[2005];

int main(void) {

	cin >> N >> Z >> W;

	long long int tmp;
	for (int i = 1; i <= N; i++) {
		cin >> tmp; a[i] = tmp;
	}

	if (N == 1) { cout << abs(a[1] - W) << endl; return 0; }

	a[0] = W;

	for (int i = 0; i <= N; i++) {
		X[i] = 0; Y[i] = 0;
	}

	for (int i = N - 1; i >= 0; i--) {
		X[i] = abs(a[i] - a[N]);
		for (int j = N - 1; j >= i + 1; j--) {
			X[i] = min(X[i], Y[j]);
		}
		Y[i] = abs(a[i] - a[N]);
		for (int j = N - 1; j >= i + 1; j--) {
			Y[i] = max(Y[i], X[j]);
		 }
	}


/*	for (int i = 1; i <= N; i++) {
		cout << "X[" << i << "]= " << X[i] << endl;
		cout << "Y[" << i << "]= " << Y[i] << endl;
	}*/

	cout << Y[0] << endl;

	/*long long int ans;

	ans = abs(a[N] - W);
	for (int i = 1; i <= N - 1; i++) {
		ans = max(ans, X[i]);
	}
	cout << ans << endl;
	*/
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    bool takahashi_win = false;
    while(true){
        c -= b;
        if (c <= 0){
            takahashi_win = true;
            break;
        }
        a -= d;
        if(a <= 0){
            break;
        }
    }
    if(takahashi_win){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int main() {
    ll k;
    cin >> k;

    ll tmpk = k, rank = 0;

    while (tmpk) {
        tmpk /= 10;
        rank++;
    }

    ll ans = 1;
    if (k%2 == 0 && k/2 > 0) {
        ans = -1;
    } else {
        ll sevens = 7;
        for (int i=1; i<rank; i++) {
            sevens *= 10;
            sevens += 7;
            ans++;
        }
        ll amari = sevens%k;
        while (amari) {
            amari %= k;
            if (amari == 0) break;
            ans++;
            amari *= 10;
            amari += 7;
            if (ans >= 100000000) {
                ans = -1;
                break;
            }
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 3616
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		int sx = input[0];
		int sy = input[1];
		int tx = input[2];
		int ty = input[3];
		var ans = new StringBuilder();

		for(var i = 0; i < 4; i++)
		{
			int difx = tx - sx;
			int dify = ty - sy;
			if (i == 0 || i == 1)
			{
                for(int j = 0; j < difx; j++)
				{
					if (i == 0)
					{
						ans.Append("R");
					}
					else
					{
						ans.Append("L");
					}
				}
                for(int j = 0; j < dify; j++)
				{
					if (i == 0) { ans.Append("U"); }
					else { ans.Append("D"); }
				}
			}
			else
			{
				if (i == 2)
				{
					ans.Append("DR");
				}
				else
				{
					ans.Append("UL");
				}
				for (int j = 0; j < difx; j++)
				{
					if (i == 2)
					{
						ans.Append("R");
					}
					else
					{
						ans.Append("L");
					}
				}
				for (int j = 0; j < dify; j++)
				{
					if (i == 2) { ans.Append("U"); }
					else { ans.Append("D"); }
				}

				if (i == 2)
				{
					ans.Append("UL");
				}
				else
				{
					ans.Append("DR");
				}

			}



		}
		Console.WriteLine(ans);

	}
}


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

int main(){
   int n;cin>>n;
   int a[n+1];for(int i=1;i<=n;i++)cin>>a[i];
   int cnt=0;
   int next=a[1];
   int flag=0;cnt++;
   for(int i=0;i<n;i++){
       //printf("next=%d\n",next);
       if(next==2){flag=1;break;}
       next=a[next];cnt++;
   }
   cout<<((flag)?cnt:-1)<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int N = 1e5;
int a[N+5];

int main()

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

    int n, k;

    cin >> n >> k;

    if (k > (n+1)/2) cout << "NO";
    else cout << "YES";

    return 0;
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

constexpr ll MAX = 8100;
bool dp[MAX*2][MAX*2];

int main(int argc, char **argv)
{
	string s;
	ll x, y;
	cin >> s >> x >> y;
	ll N = s.size();

	vector<ll> ho, ve;
	ll right{0};
	ll cnt{0};

	for (ll i = 0; i < N;)
	{
		ll j = i + 1;
		if (s[i] == 'T')
		{
			++cnt;
		}
		else
		{
			while (j < N && s[j] == 'F') {++j;}
			if (cnt & 1)
				ve.push_back(j-i);
			else if (cnt == 0)
				right = j - i;
			else
				ho.push_back(j-i);
		}
		i = j;
	}

	bool ok{true};
	memset(dp, 0, sizeof dp);
	dp[1][right+MAX] = true;
	N = 1 + ho.size();
	for (ll n = 1; n < N; ++n)
	{
		for (ll w = 0; w < MAX*2; ++w)
		{
			if (w-ho[n-1] >= 0)
				dp[n+1][w] |= dp[n][w-ho[n-1]];
			if (w+ho[n-1] < MAX*2)
				dp[n+1][w] |= dp[n][w+ho[n-1]];
		}
	}
	ok &= dp[N][MAX+x];
	
	memset(dp, 0, sizeof dp);
	dp[0][MAX] = true;
	N = ve.size();
	for (ll n = 0; n < N; ++n)
	{
		for (ll w = 0; w < MAX*2; ++w)
		{
			if (w-ve[n] >= 0)
				dp[n+1][w] |= dp[n][w-ve[n]];
			if (w+ve[n] < MAX*2)
				dp[n+1][w] |= dp[n][w+ve[n]];	
		}
	}
	ok &= dp[N][MAX+y];

	std::cout << (ok ? "Yes" : "No") << std::endl;
}


Measured memory_bytes: 256640
dish = [int(input()) for _ in range(5)]
dish = sorted(dish,key = lambda x: x%10)
ans = []
flag = False
for d in dish:
    ans.append(d)
    if flag:
        ans.append(10-(d%10))
    if d % 10 != 0:
        flag = True
print(sum(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    int c[3][3];

    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> c[i][j];
        }
    }

    set<int> i01, i12, j01, j12;

    for(int i=0; i<3; i++){
        j01.insert(c[i][0] - c[i][1]);
        j12.insert(c[i][1] - c[i][2]);
    }
    for(int j=0; j<3; j++){
        i01.insert(c[0][j] - c[1][j]);
        i12.insert(c[1][j] - c[2][j]);
    }

    if(j01.size() == 1 && j12.size() == 1 && i01.size() == 1 && i12.size() == 1){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
def main():
  import itertools
  n,m=map(int,input().split())
  li=[list(map(int,input().split()))[1:] for _ in range(m)]
  p=tuple(map(int,input().split()))
  
  q=set(sum(li,[]))
  
  r=set(range(1,n+1))
  v=r-q
  
  ans=0
  
  for i in range(0,len(q)+1):
    for s in itertools.combinations(q,i):
      s=set(s)
      for j,t in enumerate(li):
        u=s&set(t)
        if len(u)%2==p[j]:
          continue
        else:
          break
      else:
        ans+=2**(len(v))
   
  print(ans)
  
  
if __name__=="__main__":
  main()

Measured memory_bytes: 3064
N,A,B = map(int,input().split())
S = input()
f = []
ok = 0
for i,s in enumerate(S):
    if s == "a":
        if ok < A + B:
            print("Yes")
            ok += 1
        else:
            print("No")
    elif s == "b":
        if ok < A + B and len(f) + 1 <= B:
            print("Yes")
            ok += 1
            f.append(i)
        else:
            print("No")
    else:
        print("No")

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  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;
  }

  // for prime mod
  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;
  }
};



int main()
{
  int n, m; cin >> n >> m;
  vector<P> vec(n);
  rep(i, n) cin >> vec[i].first >> vec[i].second;
  sort(ALL(vec));
  priority_queue<int> pq;
  int ans = 0;
  for(int day = 1; day <= m; ++day) {
    auto s = lower_bound(ALL(vec), make_pair(day, 0));
    auto g = upper_bound(ALL(vec), make_pair(day, INF));
    for(auto it = s; it != g; ++it) pq.push((*it).second);
    if(!pq.empty()) {
      ans += pq.top(); pq.pop();
    }
  }
  cout << ans << endl;
}


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

int main()
{
	int a,b,c,a2,b2,c2,t=0;
	cin>>a>>b>>c;
	while(a%2==0&&b%2==0&&c%2==0){
		a2=b/2+c/2;
		b2=a/2+c/2;
		c2=b/2+a/2;
		a=a2;b=b2;c=c2;
		t++;
		if(t>1000000){
			t=-1;
			break;
		}
	}
	cout<<t<<endl;
	return 0;
}

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

double h[1005];

int main() {
  int n;
  cin >> n;
  double t, a;
  cin >> t >> a;
  int ans = 0;
  double ansd = 1e9;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    double d = abs(t - h[i] * 0.006 - a);
    if (d < ansd)
      ansd = d, ans = i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
const ll ms=1e9+7;
int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct Nod{
	int x,y;
}a[N];
bool cmp(Nod a,Nod b){
	if (a.x==b.x) return a.y>b.y;
	else return a.x<b.x;
}
int b[N],tmpx[N],tmpy[N],tot,c1,c2;
queue<int>q;
struct BIT{
	int s[N];
	int lowbit(int x){
		return x&(-x);
	}
	void modify(int x,int y){
		for (int i=x;i<=c2;i+=lowbit(i))
		(s[i]+=y)%=ms;
	}
	int query(int x){
		int ans=0;
		for (int i=x;i;i-=lowbit(i))
		ans=(ans+s[i])%ms;
		return ans;
	}
}tree;
int main(){
	int n=read(),m=read();
	for (int i=1;i<=n;i++){
		int x=read(); q.push(x);
	}
	for (int i=1;i<=m;i++) b[i]=read(); tot=0,c1=0,c2=0;
	while (!q.empty()){
		int k=q.front(); q.pop(); int pos=lower_bound(b+1,b+1+m,k)-b;
		if (k<=b[1]||k>=b[m]||k==b[pos]) continue;
		a[++tot].x=b[pos]-k,a[tot].y=k-b[pos-1];
		tmpx[++c1]=a[tot].x,tmpy[++c2]=a[tot].y;
	}
	sort(tmpx+1,tmpx+1+c1); sort(tmpy+1,tmpy+1+c2);
	c1=unique(tmpx+1,tmpx+1+c1)-tmpx-1; c2=unique(tmpy+1,tmpy+c2+1)-tmpy-1;
	for (int i=1;i<=tot;i++){
		a[i].x=lower_bound(tmpx+1,tmpx+1+c1,a[i].x)-tmpx;
		a[i].y=lower_bound(tmpy+1,tmpy+1+c2,a[i].y)-tmpy;
	}
	sort(a+1,a+1+tot,cmp);
	ll ans=1;
	for (int i=1;i<=tot;i++){
		if (a[i].x==a[i-1].x&&a[i].y==a[i-1].y) continue;
		int x=(tree.query(a[i].y-1)+1)%ms;
		ans=(ans+x)%ms;
		tree.modify(a[i].y,x);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2688
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n,i;
  cin >> n;
  if(n%1000==0){
    cout << 0 << endl;
    return 0;
  }
  cout << (n/1000*1000+1000)-n << endl;
  return 0;
}

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

int n;
int a[100];
int cnt[9];

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] >= 3200) a[i] = 3200;
		cnt[a[i]/400]++;
	}
	
	int ans1 = 0;
	for (i = 0; i < 8; i++) {
		ans1 += (cnt[i] > 0);
	}
	
	int ans2 = ans1 + cnt[8];
	
	if (ans1 == 0 && cnt[8] > 0) ans1 = 1;
	
	cout << ans1 << " " << ans2 << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
X.sort()

ans = 100 ** 2 * 100
for i in range(X[0], X[-1] + 1):
    work = 0
    for x in X:
        work += (x - i) ** 2
    ans = min(ans, work)

print(ans)

Measured memory_bytes: 3060
# 部分点解法

def main():
    from functools import reduce

    MOD = 10 ** 9 + 7

    n = int(input())
    *x, = map(int, input().split())

    fact = [1]
    for i in range(1, n + 1):
        fact.append(fact[-1] * i % MOD)  # %MODをつけた以外はTLEのコードのまま

    dist_to_r_edge = [x[-1] - x_ for x_ in x[:-1]]

    ret = reduce(
        lambda a, b: (a + b) % MOD,
        (
            d * pow(i, MOD - 2, MOD)
            for i, d in enumerate(dist_to_r_edge, 1)
        )
    )
    print(ret * fact[n - 1] % MOD)


if __name__ == '__main__':
    main()

# ret = 0
# for i, d in enumerate(dist_to_r_edge, 1):
#     ret = (ret + d * pow(i, MOD - 2, MOD)) % MOD
# print(ret * fact[n - 1] % MOD)


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

int main()
{
	string s,t;
	cin >> s >> t;
	int a,b;
	cin >> a >> b;
	string u;
	cin >> u;
	if(u==s)a--;
	if(u==t)b--;
	cout<<a<<' '<<b<<endl;
	return 0;
}

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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m, a, b;
	cin >> n >> m >> a >> b;
	if (a > m/2 || b > n/2) {
		cout << -1;
		return 0;
	}
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++) {
			if (i <= b && j <= a) {
				cout << '1';
			} else if (i > b && j > a) {
				cout << '1';
			} else {
				cout << '0';
			}
		}
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 1280
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>

const long long INF = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

llong dfs(llong x, llong y, vector<vector<llong> > &A){
    if(x<0 || x>=A[0].size() || y<0 || y>=A.size()){
        return 0;
    }
    llong ans;

    ans = max(dfs(x-1,y,A)+A[y][x], dfs(x,y-1,A)+A[y][x]);
    return ans;
}

int main(){
    llong N;
    cin >> N;
    vector<vector<llong> > A(2, vector<llong>(N, 0));
    for(int y=0; y<A.size(); y++){
        for(int x=0; x<A[0].size(); x++){
            cin >> A[y][x];
        }
    }
    cout << dfs(N-1, 1, A) << endl;
    return 0;
}


Measured memory_bytes: 3168
#include<iostream>
#include<cstdio>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<deque>
#include<utility>
#include<cctype>
#include<bitset>
#include<stdio.h>
#include<time.h>
#define ll long long
#define mp make_pair
using namespace std;
const ll INF=1e9;
/*--------main part---------*/
inline ll read(){
    ll X = 0,w = 0 ;
	char ch = 0;
    while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
    while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
    return w ? -X : X;
}


int main()
{
	ll k,a,b;
	cin>>k>>a>>b;
	if(b-a<=2)
	{
		cout<<k+1<<endl;
		return 0;
	}
	if(a>b)
	{
		cout<<k+1<<endl;
	}
	else
	{
		if(k<=a)
		{
			cout<<k+1;
			return 0;
		}
		k-=(a+1);
		bool ok=false;
		if(k%2)
		{
			ok=1;
			k--;
		}
		cout<<b+(k/2)*(b-a)+ok;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int n,k,q;
    cin >> n >> k >> q;
    int a[n]={0};
    REP(i,q){
        int x;
        cin >> x;
        --x;
        a[x]++;
    }
    int border=q-k+1;
    REP(i,n){
        if(a[i]>=border)cout << "Yes";
        else cout << "No";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3940
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=1e5+9;
vector<int>v[N];
bool visited[N];
int f[N];
int main()
{
    FASTINOUT;
    int x,m,l,r;
    cin>>x>>m;
    for (int i=0;i<m;i++){
        cin>>l>>r;
        v[l].push_back(r);
        v[r].push_back(l);
    }
    queue<int>q;
    q.push(1);
    while (!q.empty()){
        int l=q.front();
        q.pop();
        if (visited[l])
            continue;
        visited[l]=1;
        for (int i=0;i<v[l].size();i++){
            if (!f[v[l][i]]){
                f[v[l][i]]=l;
                q.push(v[l][i]);
            }
        }
    }
    bool t=1;
    for (int i=1;i<=x;i++){
        if (!visited[i]){
            t=0;
            break;
        }
    }
    if (!t)
        cout<<"No\n";
    else{
        cout<<"Yes\n";
        for (int i=2;i<=x;i++)
            cout<<f[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 10640
#n = int(input())
h1,m1,h2,m2,k = map(str,input().split())
#a_L = list(map(int,input().split()))

import datetime
h1 = h1.zfill(2)
h2 = h2.zfill(2)
m1 = m1.zfill(2)
m2 = m2.zfill(2)

o1 = h1+":"+m1+":00"
o2 = h2+":"+m2+":00"

dt1 = datetime.datetime.strptime(o1, '%H:%M:%S')
input_time1 = dt1.time()
dt2 = datetime.datetime.strptime(o2, '%H:%M:%S')
input_time2 = dt2.time()

total =int((dt2-dt1).total_seconds())/60

ans = int(total-int(k))
if ans >=0:
    print(ans)
else:
    print(0)

Measured memory_bytes: 10392
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		long fact = 1;
		
		n = sc.nextInt();
		
		for(int i = n; i > 0; i--){
			fact *= i;
		}
		
		System.out.println(fact);
	}
}

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

using namespace std;

#define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define single_test

void solve() {
    string s;
    cin >> s;
    if (s.back() == 's') {
        s += "es";
    }
    else {
        s += 's';
    }
    cout << s << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 3668
n = int(input())

c = [int(x) for x in input().split()]

even = [[int(x),0] for x in range(10**5+1)]

odd = [[int(x),0] for x in range(10**5+1)]

for i in range(len(c)):
    if i % 2 == 0:
        even[c[i]][1] += 1
    else:
        odd[c[i]][1] += 1

even = sorted(even,key = lambda x:-x[1])
odd = sorted(odd,key = lambda x:-x[1])

if even[0][0] == odd[0][0]:
    print(min(n-even[0][1]-odd[1][1],n-even[1][1]-odd[0][1]))
else:
    print(n-even[0][1]-odd[0][1])


Measured memory_bytes: 35940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define speed ios::sync_with_stdio(false)
#define pb push_back
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define all(x) (x).begin(), (x).end()
#define uint usigned int
typedef vector <long long> vi;
const int N=3e5+10;
int main() {
    ll i,n,m,k,len,sum=0,l=0,r=0,flag=0;
    cin>>n>>m>>k;
    sum=min(n,m);
    for(i=sum;i>0;i--){
        if(n%i==0 && m%i==0) flag++;
        if(flag==k){
            cout<<i;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
S = input()
lenS = len(S)
ans = 0
def f(SUM,TMP,N):
    n = int(S[N])
    if N == lenS-1:
        SUM += TMP + n
        return SUM
    else:
        ret = f(SUM,(TMP+n)*10,N+1) + f(SUM+TMP+n,0,N+1)
        return ret

print(f(0,0,0))


Measured memory_bytes: 38256