akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 400009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 1e9 + 7;
class {
   public:
    i64 fac[maxn], invfac[maxn];
    void solve() {
        i64 n, k;
        fac[0] = 1;
        for (int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % MOD;
        invfac[maxn - 1] = pw(fac[maxn - 1], MOD - 2);
        for (int i = maxn - 2; i >= 0; --i) {
            invfac[i] = invfac[i + 1] * (i + 1) % MOD;
        }
        cin >> n >> k;
        i64 ans = 0;
        for (int i = 0; i <= min(n - 1, k); ++i) {
            (ans += C(n - 1, n - 1 - i) * C(n, n - i) % MOD) %= MOD;
        }
        cout << ans << '\n';
    }
    i64 C(i64 a, i64 b) {
        if (b < 0)
            return 0;
        assert(a >= b);
        return fac[a] * invfac[b] % MOD * invfac[a - b] % MOD;
    }
    i64 pw(i64 a, i64 b) {
        i64 c = 1;
        while (b) {
            if (b & 1ll)
                c = c * a % MOD;
            a = a * a % MOD;
            b >>= 1;
        }
        return c;
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
int main() {
	double w,h,x,y;
	cin>>w>>h>>x>>y;
	printf("%.9lf %d\n",w*h/2,(x==w/2&&y==h/2));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define INF 0x7FFFFFFF//or 0x3f3f3f3f ? -Wall
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	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();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 150000 + 5;

struct node {
	LL a, b;
	node(LL _a = 0, LL _b = 0) {a = _a, b = _b;}
	bool operator < (const node &T) {
		if (a == T.a) return b < T.b;
		return a < T.a;
	}
};

int n; LL V;
std::vector<LL> w[N];
std::vector<int> v[N];
std::vector<node> S[N], zkx;

void dfs(int x) {
	S[x].clear();
	if (!v[x].size()) {S[x].push_back(node(0, 0)); return;}
	int k = v[x][0], l = v[x][1];
	LL vk = w[x][0], vl = w[x][1];
	dfs(k); dfs(l);
	if (S[k].size() > S[l].size()) swap(k, l), swap(vk, vl);
	if (!S[k].size()) return;
	for (int i = 0, j = 0; i < S[k].size(); i++) {
		LL a = S[k][i].a, b = S[k][i].b;
		while (j + 1 < S[l].size() && b + S[l][j + 1].a + vk + vl <= V) j++;
		if (j < S[l].size() && b + S[l][j].a + vk + vl <= V) S[x].push_back(node(a + vk, S[l][j].b + vl));
	}
	for (int i = 0, j = 0; i < S[k].size(); i++) {
		LL a = S[k][i].a, b = S[k][i].b;
		while (j < S[l].size() && a + S[l][j].b + vk + vl > V) j++;
		if (j < S[l].size() && a + S[l][j].b + vk + vl <= V) S[x].push_back(node(S[l][j].a + vl, b + vk));
	}
	sort(S[x].begin(), S[x].end());
	zkx.clear();
	for (int i = 0; i < S[x].size(); i++) {
		int flag = 1;
		if (zkx.size() && zkx[zkx.size() - 1].a <= S[x][i].a && zkx[zkx.size() - 1].b <= S[x][i].b) flag = 0;
		if (flag) zkx.push_back(S[x][i]);
	}
	S[x].clear();
	for (int i = 0; i < zkx.size(); i++) S[x].push_back(zkx[i]);
}

int check(LL val) {
	V = val; dfs(1);
	return S[1].size() ? 1 : 0;
}

int main() {
	read(n);
	LL l = 0, r = 0, ans;
	LL x, y;
	for (int i = 2; i <= n; i++) {
		read(x), read(y);
		v[x].push_back(i);
		w[x].push_back(y);
		r += y;
	}
	while (l <= r) {
		LL m = (l + r) >> 1;
		if (check(m)) {
			ans = m;
			r = m - 1;
		} else l = m + 1;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 38500
from collections import deque
n,m=map(int,input().split())
A=[[] for i in range(n)]
for i in range(m) :
    a,b=map(int,input().split())
    A[b-1].append(a-1)
    A[a-1].append(b-1)
depth=[-1]*n
visit=deque([0])

while True :
    if len(visit)==0 :
        break
    x=visit.popleft()
    for i in A[x] :
        if depth[i]==-1 :
            depth[i]=x+1
            visit.append(i)

print("Yes")
[print(i) for i in depth[1:]]


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

int main()
{
  int cnt[100000] = {};
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i)
  {
    int a;
    cin >> a;
    ++cnt[a];
  }
  auto _sum = cnt[0] + cnt[1] + cnt[2];
  int max = _sum;
  for (int i = 2; i < 99999; ++i)
  {
    _sum += (cnt[i + 1] - cnt[i - 2]);
    if (max < _sum)
      max = _sum;
  }
  cout << max;
  return 0;
}


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

template<class T> class CumulativeSum2 {
private:
  vector<vector<T>> data;
public:
  CumulativeSum2(int W, int H) : data(W + 1, vector<int>(H + 1, 0)) {}
  void add(int x, int y, T z) {
    x++, y++;
    if (x >= data.size() || y >= data.at(0).size()) return;
    data.at(x).at(y) += z;
  }
  void build() {
    for (int i = 1; i < data.size(); i++) {
      for (int j = 1; j < data.at(i).size(); j++) {
        data.at(i).at(j) += data.at(i).at(j - 1) + data.at(i - 1).at(j) - data.at(i - 1).at(j - 1);
      }
    }
  }
  T query(int sx, int sy, int gx, int gy) const {
    return (data.at(gx).at(gy) - data.at(sx).at(gy) - data.at(gx).at(sy) + data.at(sx).at(sy));
  }
};

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  CumulativeSum2<int> CS2(N, N);
  for (int i = 0; i < M; i++) {
    int L, R;
    cin >> L >> R;
    CS2.add(--L, --R, 1);
  }
  CS2.build();
  for (int i = 0; i < Q; i++) {
    int p, q;
    cin >> p >> q;
    --p;
    cout <<  CS2.query(p, p, q, q) << "\n";
  }
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

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 <iostream>
#include <map>

using namespace std;

int main()
{
	//cout << "Hello cmake!" << endl;
	std::map<string, int> dictionary{
		{"RRR", 3},
		{"SSS", 0},
		{"RRS", 2},
		{"SRR", 2},
		{"SSR", 1},
		{"RSR", 1},
		{"RSS", 1},
		{"SRS", 1}
	};
	string s;
	cin >> s;
	cout << dictionary[s];
	return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long N;
  cin >> N;
  vector<long long> A(N);
  long long S = 0;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    S += A[i];
  }

  long long minx = S, sum = 0;
  for (int i = 0; i < N; i++) {
    sum += A[i];
    minx = min(minx, abs(sum - (S - sum)));
  }
  cout << minx << endl;

  return 0;
}


Measured memory_bytes: 4752
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
#define MAX_T (105)
int K;
int T;
int a[MAX_T];
int main()
{
    scanf("%d %d", &K, &T);
    int max_n = 0;

    for ( int i = 0; i < T; i++ ) {
	scanf("%d", &a[i]);
	if ( max_n < a[i] ) max_n = a[i];
    }

    int remain = K - max_n;
    if ( remain >= max_n - 1 ) {
	printf("0\n");
    }
    else {
	printf("%d\n", max_n - 1 - remain);
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int A,B,C,D;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    if(A+B>C+D){
        printf("Left\n");
    }else if(A+B<C+D){
        printf("Right\n");
    }else{
        printf("Balanced\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
	int n,k;
	int num = 1;
	cin >> n >> k;
	int i,j;
	for(i=0;num<k&&i<n;++i)num*=2;
	for(j=i;j<n;++j)num += k;
	cout << num << endl;
}

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


int main(void)
{
	int N = 0, M = 0;
	cin >> N >> M;

	vector<pair<int, int>> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i].first;
		cin >> A[i].second;
	}
	sort(A.begin(), A.end());

	long long ans = 0;
	int j = 0;
	priority_queue<int> B;

	for (int i = 0; i < M; i++)
	{
		while (A[j].first <= i + 1 && j < N)
		{
			B.push(A[j].second);
			j++;
		}
		if (!B.empty())
		{
			ans += B.top();
			B.pop();
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 1660
n = int(input())
x = input()
x10 = int(x, 2)
lenx = len(x)

maxbit = x.count("1")
xc0 = x10 % (maxbit + 1)
xc1 = x10 % (maxbit - 1) if maxbit > 1 else 0

def f(ii):
  cnt = 0
  while ii > 0:
    ii %= bin(ii).count("1")
    cnt += 1
  return cnt

for i in range(lenx):
  if x[i] == "0":
    t = xc0 + pow(2, (lenx - 1 - i), maxbit + 1)
    ans = f(t % (maxbit + 1)) + 1
  else:
    if maxbit - 1 == 0:
      ans = 0
    else:
      t = xc1 - pow(2, (lenx - 1 - i), maxbit - 1)
      ans = f(t % (maxbit - 1)) + 1
  print(ans)
  
  


Measured memory_bytes: 9408
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		boolean flag = false;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		if (n <= 100) {
			int ai[] = new int[n];
			for (int i = 0; i < ai.length; i++) {
				ai[i] = sc.nextInt();
				if (ai[i] >= 0 && ai[i] <= 1000) {
					flag = true;
				} else {
					flag = false;
					break;
				}

			}

			if (flag == true) {
				int length = ai.length - 1;
				for (int j = length; j >= 0; j--) {
					if (j == 0) {
						System.out.println(ai[j]);
					} else {

						System.out.print(ai[j] + " ");
					}

				}
			}

		}

	}

}

Measured memory_bytes: 26236
main :: IO ()
main = do
  [n, a, b] <- map read . words <$> getLine :: IO [Int]
  print $ solve n a b

solve n a b = sum $ filter f [1..n]
  where
    f x = let y = sum $ map (\a -> fromEnum a - fromEnum '0') (show x)
          in a <= y && y <= b


Measured memory_bytes: 892
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <bitset>
#include <complex>
#include <limits>
#include <random>


using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

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

	int A;
	cin >> A;

	if (A == 0)cout << 1 << endl;
	else cout << 0 << endl;

	return 0;
}


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

void solve() 
{
    int d,t,s;cin>>d>>t>>s;
    cout<<(t*s>=d?"Yes":"No")<<endl;
}

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

Measured memory_bytes: 3660
def calc(ind, width):
    from_x = (ind // width) + 1
    y_kari = ind % (width * 2)
    if y_kari >= width:
        from_y = width * 2 - y_kari
    else:
        from_y = y_kari + 1
    return from_x, from_y

def main():
    high, width = map(int, input().split())
    data = []
    for i in range(high):
        now_data = list(map(int, input().split()))
        if i % 2 == 1:
            now_data = reversed(now_data)
        data += now_data

    i = 0
    ans_list = []
    while i < high * width - 1:
        if data[i] % 2 == 0:
            i += 1
            continue

        next_ind = i + 1
        data[next_ind] += 1

        from_x, from_y = calc(i, width)
        next_x, next_y = calc(next_ind, width)

        ans_list.append([from_x, from_y, next_x, next_y])

        i += 1

    print(len(ans_list))
    for ele in ans_list:
        print(' '.join(map(str, ele)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 29592
import java.util.*;

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

    int n = sc.nextInt();
    int l = sc.nextInt();
    int ans = 0;

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

    System.out.println(ans);
  }
}


Measured memory_bytes: 23636
import java.util.Arrays;
//Java8(OpenJDK 1.8.0)
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Solve s= new Solve();
		s.solve();
	}

}
class Solve{
	 Scanner sc = new Scanner(System.in) ;
	 void solve() {
		
		 int N =sc.nextInt();
		 int[] A = new int[N];
		 int[] A_sort = new int[N];
		 
		 for(int i = 0;i<N;i++) {
			 int temp = sc.nextInt();
			 A[i] = temp;
			 A_sort[i] = temp;
		 }
		 
		 Arrays.sort(A_sort);
		 
		 for(int i = 0; i<N;i++) {
			 boolean jufuku = false;
			 
			 for(int j=N-1;j>=0;j--) {
				 if(A[i]!=A_sort[j]) {
					 System.out.println(A_sort[j]);
					 break;
				 }else if(A[i]==A_sort[j]&&jufuku==true){
					 System.out.println(A_sort[j]);
					 break;
				 }else {
					 jufuku = true;
				 }
			 }
		 }
	 }
}

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

function main()
	m,d = readline() |> split |> parseMap
	k = 0
	for i in 1:m
		for j in 1:d
			x = j%10
			y = div(j,10)
			if x>=2&&y>=2 && x*y==i
				k += 1
			end
		end
	end
	println(k)
end

main()

Measured memory_bytes: 117984
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

vector<vector<vector<int>>> dp(50, vector<vector<int>>(500, vector<int>(500, INF)));

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

    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; ++i)  cin >> a[i] >> b[i] >> c[i];
    
    dp[0][0][0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= 400; ++j){
            for(int k = 0; k <= 400; ++k){
                if(dp[i][j][k] == INF)  continue;
                chmin(dp[i + 1][j][k], dp[i][j][k]);
                chmin(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
            }
        }
    }

    int ans = INF;
    for(int i = 1; max(ma, mb) * i <= 405; ++i){
        if(dp[n][ma * i][mb * i] == INF)    continue;
        chmin(ans, dp[n][ma * i][mb * i]);
    }
    if(ans == INF)  ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 51072
n = int(input())
station = [list(map(int, input().split())) for i in range(n - 1)]

for j in range(n-1):
    ans = 0
    for i in range(j, n - 1):
        if station[i][1] <= ans and ans % station[i][2] == 0:
            ans += station[i][0]
        elif station[i][1] > ans:
            ans = station[i][1] + station[i][0]
        else:
            ans += station[i][2] - (ans % station[i][2]) + station[i][0]
    print(ans)

print("0")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,l,m,n,k,x;
    	cin>>n;
    	string s;
    	cin>>s;
    	k=0;
    	rep(i,0,n-2)
    	{
    		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
    		k++;
		}
    	cout<<k;
    	
    }
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in();
	vector<int> F(N,0);
	
	ll X=0,K=1;
	while(true){
		if(!((10ll*X+7ll)%N)){
			out(K);
			return 0;
		}
		X = (10ll*X+7ll)%N;
		if(F[X]){
			out(-1);
			return 0;
		}
		F[X]=1;
		K++;
	}

	return 0;
}


Measured memory_bytes: 7032
import java.util.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer N = Integer.parseInt(scanner.next());
        String[] str  = new String[N];
        List<String> list = new ArrayList<String>();
        Arrays.setAll(str, i ->  scanner.next());

        char ar[][] = new char[N][];
        for(int i =0; i < N; i++) {
            ar[i] = str[i].toCharArray();
            Arrays.sort(ar[i]);
            list.add(String.valueOf(ar[i]));
        }

        Map<String, Long> map = new HashMap<String, Long>();
        Long count = 0L;
        for (String temp : list) {
            if (map.containsKey(temp)) {
                count += map.get(temp);
                map.put(temp, map.get(temp) + 1L);
            } else {
                map.put(temp, 1L);
            }
        }
        System.out.println(count);
    }
}


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

int keta(int x){
    int sum=0;
    while(x>0){
        sum+=x%10;
        x/=10;
    }
    return sum;
}

int main(){
    int n,a,b;
    int ans=0;
    cin >> n >> a >> b;
    for(int i=1;i<=n;i++){
        int wa=keta(i);
        if(a<=wa&&wa<=b) ans+=i;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e5+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(ll i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()

#define sqr(a) ((a) * (a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define mem(a,b) memset(a,b,sizeof(a))

#define yes cout<<"YES"<<nl;
#define no cout<<"NO"<<nl;

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu ()
{
    cerr << endl;
}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

int dp[mx],n,a[mx];

int solve (int i)
{
    if ( i >= n )
        return 0;
    if ( dp[i]!= -1 )
        return dp[i];

    int ret1 = INT_MAX, ret2 = INT_MAX;

    if (i+1<=n )
        ret1 = abs(a[i]-a[i+1])+ solve (i+1);

    if(i+2<=n)
        ret2 = abs(a[i]-a[i+2])+solve (i+2);
    ///dbg(i);
    dp[i]= min ( ret1, ret2 );

    return dp[i];
}

int main()
{
    su;

    mem ( dp, -1 );

    cin>>n;

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

    cout << solve( 1 )<< nl;


    return 0;
}


Measured memory_bytes: 10620
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n, k;
  cin >> n >> k;
  int r, s, p;
  cin >> r >> s >> p;
  string t;
  cin >> t;

  int score = 0;
  vector<bool> skipped(n);
  for (int i = 0; i < n; i++) {
    if (i >= k) {
      if (t[i] == t[i-k] && !skipped[i-k]) {
        skipped[i] = true;
        continue;
      }
    }
    if (t[i] == 'r') score += p;
    else if (t[i] == 's') score += r;
    else if (t[i] == 'p') score += s;
  }

  cout << score << endl;

  return 0;
}


Measured memory_bytes: 512
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main() {
    int N;
    cin >> N;
    ll ans = 0;
    vector<vector<ll>> res(10,vector<ll>(10,0));
    for(int i = 1; i <= N; i++) {
        int n = to_string(i).size();
        char s = to_string(i)[0];
        char e = to_string(i)[n-1];
        res[ctoi(s)][ctoi(e)]++;

    }
    for(int i = 1; i <= 9; i++) for(int j = 1; j <= 9; j++) ans += res[i][j]*res[j][i];
    cout << ans << endl;
}


Measured memory_bytes: 256
def read():
	return [int(i) for i in input().split(" ")]
N = int(input())
T = read()
A = read()
t = [(i != j, i) for i, j in zip(T, [None] + T)]
a = [(i != j, i) for i, j in zip(A, (A + [None])[1:])]
P = 1
for p, q in zip(t, a):
	if(p[0]):
		if(q[0]):
			if(p[1] != q[1]):
				print(0)
				exit()
		else:
			if(q[1] < p[1]):
				print(0)
				exit()
	elif(q[0]):
		if(p[1] < q[1]):
			print(0)
			exit()
	else:
		P = P * min(p[1], q[1]) % (10 ** 9 + 7)
print(P) 


Measured memory_bytes: 27100
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=2020000000;
 
 
int n,A[110000],B[110000],C[110000];
ll a[110000],b[110000];
 
 
int bs(int X[],int key){
	int left=0;
	int right=n;
	int mid;
	while(left<right){
		mid=(left+right)/2;
		if(key<X[mid]) right=mid;
		if(key>=X[mid]) left=mid+1;
	}
	return right;
}
 
 
 
int main() {
	cin>>n;
	Rep(i,n) cin>>A[i];
	Rep(i,n) cin>>B[i];
	Rep(i,n) cin>>C[i];
	sort(A,A+n);
	sort(B,B+n);
	sort(C,C+n);
	ll sum[n+1];
	ll ans=0;
	Rep(i,n){
		b[i]=n-bs(C,B[i]);
	}
	sum[0]=0;
	Rep(i,n) sum[i+1]=sum[i]+b[i];
	Rep(i,n){
			ans = ans + sum[n] - sum[bs(B,A[i])];
	}
	
	cout<<ans<<endl;
 
	return 0;
}


Measured memory_bytes: 2944
import sys
from collections import Counter
import random

random.seed(1)

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


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


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


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


def read_str():
    return input()


def gen():
    n = 301
    m = 300
    a = [[-1] * m for i in range(n)]
    for i in range(n):
        for j in range(m):
            a[i][j] = 1 + (i + j) % m
    return n, m, a


def gen2(n, m):
    a = [list(range(1, m + 1)) for i in range(n)]
    for i in range(n):
        random.shuffle(a[i])
    return a


def is_possible(l, n, m, a):
    s = set(range(1, m + 1))
    choice = [0] * n
    c = Counter()
    for i in range(n):
        c[a[i][0]] += 1
    while len(s) > 0:
        update = False
        for i in range(n):
            j = choice[i]
            x = a[i][j]
            if x not in s:
                c[x] -= 1
                while a[i][j] not in s:
                    j += 1
                choice[i] = j
                x = a[i][j]
                c[x] += 1
            if c[x] > l:
                s.remove(x)
                update = True
                break
        if not update:
            return True
    return False


def solve(n, m, a):
    left, right = 1, n
    if is_possible(left, n, m, a):
        return left
    while right - left > 1:
        mid = (left + right) // 2
        if is_possible(mid, n, m, a):
            right = mid
        else:
            left = mid
    return right


def solve2(n, m, a):
    pass

    pinf = float("inf")
    best = pinf
    roop = 0
    while True:
        if roop == m:
            break

        firstlist = []
        for r in a:
            tmp = r[0]
            firstlist.append(tmp)
        mode = -1
        count = -1
        for i in range(1, m + 1):
            tmp_c = firstlist.count(i)
            if tmp_c > count:
                mode = i
                count = tmp_c
        if mode == -1:
            break
        elif count <= best:
            best = count
        for r in a:
            r.remove(mode)
        roop += 1
    return best


def check():
    n_steps = 10000
    M = 10
    n_max = 10
    m_max = 10
    for i in range(n_steps):
        n = random.randint(1, n_max)
        m = random.randint(1, m_max)

        a = gen2(n, m)
        aa = [row[:] for row in a]
        r = solve(n, m, a)
        r2 = solve2(n, m, aa)
        if r != r2:
            print('expected:', r2, 'got:', r, )
            print(n, m)
            for row in a:
                print(*row)
            print()
            # return n, m, a
            n_max -= 1
            m_max -= 1


def main():
    # check()
    solve_it()


def solve_it():
    debug = False
    if debug:
        n, m, a = gen()
    else:
        n, m = read_int_list()
        a = [read_int_list() for _ in range(n)]
    res = solve(n, m, a)
    print(res)


if __name__ == '__main__':
    main()


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

long long N, K;
int BIT[1<<20];
long long A[1<<20];
long long B[1<<20];

long long query(int idx) {
	long long ans = 0;
	while(idx) {
		ans += BIT[idx];
		idx -= (idx & -idx);
	}
	return ans;
}

void update(int idx) {
	while(idx <= N+1) {
		BIT[idx] += 1;
		idx += (idx & -idx);
	}
}

int main() {
	cin>>N>>K;
	for(int i = 1;i <= N;i++) {
		cin>>A[i];
		A[i] += A[i-1];
	}
	for(int i = 1;i <= N;i++) {
		A[i] -= i*K;
		B[i] = A[i];
	}
	
	sort(B, B+N+1);
	int sz = unique(B, B+N+1) - B;
	
	long long ans = 0;
	for(int i = 0;i <= N;i++) {
		int x = lower_bound(B, B + sz, A[i]) - B + 1;
		ans += query(x);
		update(x);
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 5888
#!/usr/bin/env python3
import sys


def input(): return sys.stdin.readline()[:-1]


sys.setrecursionlimit(10**8)
INF = 1001001001001
n, m, l = map(int, input().split())
D = [[INF]*n for i in range(n)]

for i in range(m):
    a, b, c = map(int, input().split())
    D[a-1][b-1] = c
    D[b-1][a-1] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            D[i][j] = min(D[i][j], D[i][k]+D[k][j])


for i in range(n):
    for j in range(n):
        D[i][j] = 1 if D[i][j] <= l else INF

for k in range(n):
    for i in range(n):
        for j in range(n):
            D[i][j] = min(D[i][j], D[i][k]+D[k][j])
# for i in D:
#     print(i)

q = int(input())
for i in range(q):
    s, g = map(int, input().split())
    s -= 1
    g -= 1
    print(D[s][g]-1 if D[s][g] != INF else -1)


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

int N,X;
int B[111111],L[111111],U[111111];


signed main(){
    cin>>N>>X;
    rep(i,N)cin>>B[i]>>L[i]>>U[i];


    int base=0;
    rep(i,N)base+=-B[i]*L[i];

    vint val(N);
    rep(i,N)val[i]=B[i]*(L[i]-U[i])+X*U[i];

    vint ord(N);iota(all(ord),0);
    sort(all(ord),[&](int i,int j){
        return val[i]>val[j];
    });

    int sum=0;
    int num=0;
    rep(i,N){
        sum+=val[ord[i]];
        if(base+sum>=0){
            num=i;
            break;
        }
    }
    sum=0;
    rep(i,num)sum+=val[ord[i]];

    vint ei(N);
    rep(i,num)ei[ord[i]]=1;
    int ans=N*X;
    rep(i,N){
        int score=base+sum;
        if(ei[i]){
            score-=val[i];
            score+=val[ord[num]];
        }
        score+=B[i]*L[i];
        int lb=-1,ub=X+1;
        while(ub-lb>1){
            int mid=(ub+lb)/2;
            int tmp;
            if(mid<=B[i])tmp=score+(mid-B[i])*L[i];
            else tmp=score+(mid-B[i])*U[i];
            if(tmp>=0)ub=mid;
            else lb=mid;
        }
        if(lb==X)continue;
        chmin(ans,num*X+ub);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var K = cin.ReadInt;

            var h = new List<long>();
            for(var i=0; i<N; i++)
            {
                h.Add(cin.ReadLong);
            }

            h.Sort();

            var ans = Math.Pow(10,9);
            for(var i=0; i<=N-K; i++)
            {
                ans = Math.Min(ans, h[i + K - 1] - h[i]);
            }
            WriteLine(ans);
        }

        static long GcdArray(long[] array)
        {
            var ans = array[0];
            for(var i=1; i<array.Length; i++)
            {
                ans = Gcd(ans, array[i]);
            }
            return ans;
        }

        static long Gcd(long a, long b)
        {
            var v = new[] { a, b };
            while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
            return v[0];
        }

        static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

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

int main()
{
   int ans[] ={0,1,3,1,2,1,2,1,1,2,1,2,1};
   int x,y; cin>>x>>y;
   cout<<(ans[x]==ans[y]? "Yes":"No")<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    long K = sc.nextLong();
    
    if(A >= K){
      A = A - K;
    } else {
      B = B - (K - A);
      A = 0;
      B = B > 0 ? B : 0;
    }
    
    System.out.println(A + " " + B);
  }
}


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

typedef string::iterator S;

int main(){
    string s;
    while( getline(cin, s), s != "END OF INPUT" ){
        for(S it = s.begin();;it++){
            int count = 0;
            while( it != s.end() && *it != ' ' ){
                it++; count++;
            }
            cout << count;
            if( it == s.end() ) break;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1184
a,b,h,m=map(int,input().split())
import math
acos=a*math.cos((h+m/60)*math.pi/6)
asin=a*math.sin((h+m/60)*math.pi/6)
bcos=b*math.cos(m*math.pi/30)
bsin=b*math.sin(m*math.pi/30)
print(((acos-bcos)**2+(asin-bsin)**2)**0.5)


Measured memory_bytes: 62552
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <bitset>
#include <string>
#include <array>
#include <queue>

using namespace std;

int main()
{
    int h, w;
    const int INF = 10000;
    cin >> h >> w;
    vector<string> s(h);
    vector<vector<int>> d(h);
    for (int i=0; i<h; ++i){
        cin >> s[i];
        d[i].resize(w);
        for(int j=0; j<w; ++j){
            d[i][j] = INF;
        }
    }
    int dw[4] = {1, 0, -1, 0};
    int dh[4] = {0, 1, 0, -1};
    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    d[0][0] = 0;
    while(!q.empty()){
        pair<int, int> p = q.front();
        q.pop();
        for(int i=0; i<4; ++i){
            int nh = p.first + dh[i];
            int nw = p.second + dw[i];
            if(0 <= nh && nh < h && 0 <= nw && nw < w && s[nh][nw] == '.' && d[nh][nw] == INF){
                q.push(make_pair(nh, nw));
                d[nh][nw] = d[p.first][p.second] + 1;
            }
        }
    }
    int ans = 0;
    if(d[h-1][w-1] == INF){
        ans = -1;
    }
    else {
    vector<bool> check(d[h-1][w-1]+1, false);
        for (int i=0; i<h; ++i){
            for (int j=0; j<w; ++j){
                if(s[i][j] == '.'){
                    ans++;
                }
            }
        }
        ans -= d[h-1][w-1] + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 105;
const int mod = 1000000007;

int a[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i];
  int ret = mod;
  for(int i=1;i<=100;i++){
    int tt = 0;
    for(int j=1;j<=n;j++)tt+=(a[j] - i)*(a[j] -i);
    ret =min(ret, tt);
  }
  cout<<ret<<endl;
  return 0;
}

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

int main()
{
    int i,j;
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {
            printf("%dx%d=%d\n",i,j,i*j);
        }
    }

    return 0;
}

Measured memory_bytes: 524
#include <stdio.h>
#include <stack>
#include <math.h>
#include<iostream>

using namespace std;


int main(){
    int n,a,c[1000000],count=1;
    cin>>n;
    cin>>c[1];
    for(int i=1;i<n;i++){
        
        cin>>a;
        if(a>c[count]){count++; c[count]=a;}
        else{
            for(int t=1;t<=count;t++){
                if(c[t]>=a){c[t]=a; break;}
            }
        }
        
    }
    
    cout<<count<<endl;
    
    return 0;
}




Measured memory_bytes: 3392
n, m = map(int, input().split())
d = []
for i in range(1, m + 1):
  if i * i > m:
    break
  if m % i == 0:
    d.append(i)
    d.append(m // i)
ans = 1
for i in d:
  if i * n <= m:
    ans = max(ans, i)
print(ans)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int num = Integer.parseInt(line);
        int sum;
        
        sum = num * num * num;
        
        System.out.println(sum);
    }
}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (n == 2) {
    cout << s << "\n";
  } else {
    cout << s[2] << s[1] << s[0] << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll maxn = 1e5 + 10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head
int main(){
	ll a, b, c, d;
	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
	while(a > 0){
		c -= b;
		a -= d;
		if(c <= 0){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}


Measured memory_bytes: 3748
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProCon
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            List<int> list = new List<int>();
            for (int i=0; i < num; ++i)
            {
                list.Add(int.Parse(Console.ReadLine()));
            }
            int temp = 1;
            for(int i = 0; i < num; ++i)
            {
                temp = list[temp-1];
                if(temp == 2)
                {
                    Console.WriteLine(i+1);
                    return;
                }
            }
            Console.WriteLine("-1");
        }
    }
}

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

int main(){
  int N; cin >> N;
  vector<pair<int,int>> task(N);
  for(int i=0; i<N; i++){
    int a,b; cin >> a >> b;
    task[i]=make_pair(b,a);
  }
  sort(task.begin(),task.end());
  int sum=0;
  for(int i=0; i<N; i++){
    sum+=task[i].second;
    if(sum>task[i].first){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1792
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var answer []int
	for i := 0; ; i++ {

		var firstNumber, operator, secondNumber string
		fmt.Scan(&firstNumber, &operator, &secondNumber)
		num1, _ := strconv.Atoi(firstNumber)
		num2, _ := strconv.Atoi(secondNumber)

		switch operator {
		case "+":
			answer = append(answer, num1+num2)
		case "-":
			answer = append(answer, num1-num2)
		case "*":
			answer = append(answer, num1*num2)
		case "/":
			answer = append(answer, num1/num2)
		case "?":
			goto LABEL
		}
	}
LABEL:
	for i := 0; i < len(answer); i++ {
		fmt.Println(answer[i])
	}
}



Measured memory_bytes: 1128
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
const int MOD = 1e9+7;
 
 
int main() {
	string A,B,C;
  	cin >> A >> B >>C;
  	if(A.at(A.size()-1) == B.at(0) && B.at(B.size()-1) == C.at(0)) cout << "YES" << endl;
  	else cout << "NO" << endl;
}

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

int main(void){
   int N,K;
   cin>>N>>K;
   vector<int> A(N);
   for(int i=0;i<N;i++){
      cin>>A[i];
   }
   vector<int> result(N+1,0);
   for(int i=0;i<N;i++){
      result[A[i]]++;
   }
   int ans=0;
   sort(result.begin(),result.end());
   for(int i=0;i<N+1;i++){
      if(result[i]>=1) ans++;
   }
   if(ans<=K){
      cout<<0<<endl;
   }else{
      int count=0;
      for(int i=0;i<N+1;i++){
         if(result[i]>=1){
            count+=result[i];
            ans=ans-1;
         }
         if(ans<=K) break;
      }
      cout<<count<<endl;
   }
   return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    ll n, wt; // n = No. of items #### wt = Total capacity
    cin >> n >> wt;
    pair<ll, ll> items[n];
    for (int i = 0; i < n; i++) {
        cin >> items[i].first; // Weight
        cin >> items[i].second; // Value
    }

    ll val[n + 1][wt + 1];
    for (int i = 0; i <= n; i++) { // Item number
        for (int w = 0; w <= wt; w++) { // Weight number
            if (i == 0 || w == 0) val[i][w] = 0; // If item number is 0 or weight is 0 then value is also 0.
            else if (items[i - 1].first <= w) {
                ll CurWt = items[i - 1].first;
                ll CurVal = items[i - 1].second;
                val[i][w] = max(val[i - 1][w], val[i - 1][w - CurWt] + CurVal);
            } else val[i][w] = val[i - 1][w];
        }
    }
    cout << val[n][wt];
}


Measured memory_bytes: 79104
import sys
n,m=map(int,input().split())
if n==1:
    print(m)
    sys.exit()
ans=[]
i=int(1)
while i<=m/i:
    if m%i!=0:
        i+=1
    elif m%i==0:
        j=int(m/i)
        if j>=n:
            ans.append(i)
        if i>=n:
            ans.append(j)
        i+=1
ans.sort()
print(ans[len(ans)-1])

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n; cin >> n;
    string s; cin >> s;
    int cnt = 0;
    for(int i = 0; i < s.size()-2; i++){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import collections

n = int(input())  # even
v = list(map(int, input().split()))
e = v[0::2]
o = v[1::2]
e_cnt = collections.Counter(e)
o_cnt = collections.Counter(o)
e_most = e_cnt.most_common() + ([(0, 0)])
e_most1 = e_most[0][1]
e_most2 = e_most[1][1]
o_most = o_cnt.most_common() + ([(0, 0)])
o_most1 = o_most[0][1]
o_most2 = o_most[1][1]
if e_most[0][0] != o_most[0][0]:
    print(n - e_most1 - o_most1)
else:
    print(min(n - e_most1 - o_most2, n - e_most2 - o_most1))

Measured memory_bytes: 21952
def resolve():
    n = int(input())
    t = list(map(int, input().split()))
    m = int(input())
    px = list(list(map(int, input().split())) for _ in range(m))
    s = sum(t)
    for p, x in px:
        print(s - t[p - 1] + x)


if __name__ == "__main__":
    resolve()


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

int n , m, player1 , player2;
int cards[100];

int main() {

    cin >> n ;
    for(int i=0;i<n;++i)
        cin >> cards[i];

    sort(cards,cards+n);

    for(int i=n-1;i>=0;--i)
    {
        if(m%2==0)
        player1+=cards[i];
        else
        player2+=cards[i];
        ++m;
    }

    cout << player1 - player2 << endl;

	return 0;
}


Measured memory_bytes: 256