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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

const int MAX_DIGIT = 50;
ll dp[100][2];

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  rep(d, MAX_DIGIT) {
    ll mask = 1LL << (MAX_DIGIT - d - 1);
    int num = 0;
    rep(i, n) if (a[i] & mask) ++num;

    ll cost0 = mask * num;
    ll cost1 = mask * (n - num);

    if (dp[d][1] != -1) {
      dp[d+1][1] = max(dp[d+1][1], dp[d][1] + max(cost0, cost1));
    }

    if (dp[d][0] != -1) {
      if (k & mask) {
	dp[d+1][1] = max(dp[d+1][1], dp[d][0]  + cost0);
      }
    }

    if (dp[d][0] != -1) {
      if (k & mask) dp[d+1][0] = max(dp[d+1][0], dp[d][0] + cost1);
      else dp[d+1][0] = max(dp[d+1][0], dp[d][0] + cost0);
    }
  }
  ll ans = max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int x,y;

 
  while(1){
    cin>>x>>y;  
    if(x==0 && y==0)break;
  
    if(x>y){ 
      cout<<y<<" "<<x<<endl;
    }else{
      cout<<x<<" "<<y<<endl;
    }
  }
  
  return 0;

}

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

int main(){
int n,k;
std::cin >> n >> k;
int a[n];
for(int i=0;i<n;i++) std::cin >> a[i];
std::sort(a,a+n);
int t=0;	
for(int i=0;i<k;i++){
  t+=a[i];	
}	
std::cout << t << std::endl;	
return 0;	
}


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

#define fast_input() {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
#define For(i, l, r) for(int (i) = (l); (i) <= (r); ++(i))
#define For1(i, l, r) for(int (i) = (r); (i) >= (l); --(i))

/*
MIKUNO - 15/02/1999
*/
//	priority_queue <ll, vector<ll>, greater<ll> > q;
#define INF 1e9+5
using ll = long long;
const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
void add_self(int& a, int b) {
	a += b;
	if (a > mod)
		a -= mod;
}

int main() {
	fast_input();
	int n;
	cin >> n;
	vector<double> p(n + 1);
	for (int i = 1; i <= n; ++i) {
		cin >> p[i];
	}
	vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
	//dp[i][j] the probability to get i coins head and j coins tail
	dp[0][0] = 1;
	for (int head = 0; head <= n; ++head) {
		for (int tail = 0; tail <= n; ++tail) {
			if (head + tail >= n) break;
			dp[head + 1][tail] += dp[head][tail] * p[head + tail + 1];
			dp[head][tail + 1] += dp[head][tail] * (1.0 - p[head + tail + 1]);
		}
	}
	/*for (int head = 0; head <= n; ++head) {
		for (int tail = 0; tail <= n; ++tail) {
			cout << dp[head][tail] << " ";
		}
		cout << "\n";
	}*/
	double ans = 0;
	for (int head = 0; head <= n; ++head) {
		for (int tail = 0; tail <= n; ++tail) {
			if (head + tail == n && head > tail) {
				ans += dp[head][tail];
			}
		}
	}
	//cout << ans;
	printf("%.10lf", ans);
}



Measured memory_bytes: 72448
#include <iostream>
#include <map>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
    int N,M,X;cin>>N>>M>>X;
    int C[N];
    int A[N][M];
    for (int i = 0; i < N; i++){
        cin>>C[i];
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }
    vector<int> result;
    for (int bit = 0; bit < (1 << N); bit++) {
        int money = 0;
        bool hit = true;
        for (int j = 0; j < M; j++) {
            int cur = 0;
            for (int i = 0; i < N; i++) {
                if (bit&(1<<i)) {
                    cur+=A[i][j];
                    money += C[i];
                }
            }
            if (cur < X) hit = false;
        }
        if (hit) result.push_back(money);
    }
    if (result.size() == 0) cout << "-1" << endl;
    else {
        sort(result.begin(), result.end());
        cout << result.at(0) / M << endl;
    }
    return 0;
}

Measured memory_bytes: 3208
#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)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> ans(n, vector<bool>(m));
  rep(i, n) {
    int k;
    cin >> k;
    rep(j, k) {
      int a;
      cin >> a;
      ans[i][a-1] = true;
    }
  }
  int sum = m;
  rep(i, m) {
    rep(j, n) {
      if (!ans[j][i]) {
        sum--;
        break;
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e18;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  string s;
  cin >> s;
  ll ans = 0;
  rep(i,sz(s)){
    if(s[i]=='1'){
      ans++;
    }
  }
  print(ans);
}


Measured memory_bytes: 3556
#include<stdio.h>
int main(){
  int a, b, d, r;
  double f;
  scanf ("%d %d", &a, &b);

  d = a / b;
  r = a % b;
  f = (double)a / b;

  printf("%d %d %f", d, r, f);

  return 0;
}


Measured memory_bytes: 2100
while 1:
  n = input()
  if n==0: break
  x = [int(raw_input()) for _ in [0]*n]
  c = 0
  for i in range(n):
    for j in range(i+1,n)[::-1]:
      if x[j] < x[j-1]:
        x[j], x[j-1] = x[j-1], x[j]
        c += 1
  print c

Measured memory_bytes: 4224
n,m,x,y=map(int,input().split())
xs=list(map(int,input().split()))
ys=list(map(int,input().split()))
x_=max(xs)
y_=min(ys)
for z in range(x_+1,y_+1):
    if x<z<=y:
        print('No War')
        exit()
print('War')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int n,m;
      cin>>n>>m;
      vector<vector<int>>dp(n+1,vector<int>(m+1,0));
      dp[1][1]=1;
      for(int i=1;i<=n;i++){
            string s;
            cin>>s;
            for(int j=1;j<=m;j++){
                  if(i==1&&j==1)continue;
                  if(s[j-1]=='.')dp[i][j]=(dp[i][j-1]+dp[i-1][j])%modulo;
            }
      }
      cout<<dp[n][m];
}


Measured memory_bytes: 8064
#include<iostream>
using namespace std;
long long gcd(long long x,long long y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
int main()
{
    long long a,b;
    while(cin>>a>>b)
    {
        long long d=gcd(a,b);
        a/=d;
        b/=d;
        long long l=a*b*d;
        cout<<d<<" "<<l<<endl;
    }
}

Measured memory_bytes: 3092
<?php
list($n) = ints();
$ans = PHP_INT_MAX;
for ($i = 1; $i <= (int) sqrt($n); ++$i) {
    if ($n % $i) continue;
    $f = max(strlen((string) $i), strlen((string) intdiv($n, $i)));
    $ans = min($ans, $f);
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int a) {
  return (a * a + 4) / 8;
}

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

  int n; cin >> n;
  int now = 1;
  while(now * 2 <= n) {
    now *= 2;
  }
  cout << now << endl;
}


Measured memory_bytes: 256
class Plastic
  def initialize
    rect_num = 0
    loze_num = 0

    while input = $stdin.gets do
      @a,@b,@c = input.chomp.split(',').map(&:to_i)
      rect_num += 1 if check_rect
      loze_num += 1 if check_loze
    end

    puts rect_num
    puts loze_num
  end

  def check_rect
    @a*@a + @b*@b == @c*@c
  end

  def check_loze
    @a == @b
  end
end

p = Plastic.new

Measured memory_bytes: 2380
n,m=map(int,input().split())
p=1
q=n
for i in range(m):
  l,r=map(int,input().split())
  if p<l:
    p=l
  if r<q:
    q=r
  if p>q:
    print(0)
    exit()
print(q-p+1)

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

int main()
{
	int sum = 0;
	int n;
	cin >> n;
	int a[50] = {0};
    for(int i = 1; i <= n; i++){
    	int t;
    	cin >> t;
    	if(t == i) sum++;
	}
	if(sum == n || sum == n - 2){
		cout << "YES";
	}else{
	    cout << "NO";	
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
//vvi(n, vector<int>(m, -1))
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(a) (a).begin(), (a).end()
#define out(x) cout << (x) << endl;

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n;

	int v[30], c[30];

	ll sum = 0;
	rep(i, n) cin >> v[i];
	rep(i, n) cin >> c[i];

	rep(i, n){
		if(v[i] - c[i] > 0) sum += v[i] - c[i];
	}

	cout << sum << endl;
}

Measured memory_bytes: 256
N, = map(int, input().split())
Xs = []
for i in range(N):
    X, Y, Z = map(int, input().split())
    Xs.append((X,Y,Z,i))
Xs.sort(key=lambda x : x[0]+x[1])

dp = [0]*(2*(10**4)+1)
for x,y,z,i in Xs:
#    print(i+1,x,y,z)
    for i in range(y+1):
        i = y-i
        dp[i+x] = max(dp[i+x], dp[i]+z)
#    print(dp[:10])
print(max(dp))


Measured memory_bytes: 41988
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<climits>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<set>
#include<stack>
#include<functional>
#include<queue>
using namespace std;

const int d[4] ={-1,-4,1,4};

int main(){
    map<string,int> memo; memo["01234567"] = 0;
    queue<string> q; q.push("01234567");
	string q_c;
	while(!q.empty()){
		q_c = q.front(); q.pop();
		int n = find(q_c.begin(),q_c.end(),'0')-q_c.begin();
		for(int i=0;i<4;i++){
			int nn = n+d[i];
			if((n==3 && nn==4) || (n==4 && nn==3) || nn<0 || 8<=nn) continue;
			string q_d = q_c; swap(q_d[n],q_d[nn]);
			if(memo.find(q_d)==memo.end()){
				q.push(q_d); memo[q_d] = memo[q_c]+1;
			}
		}
	}
    while(true){
        char in[9]={};
        for(int i=0;i<8;i++) if(!(cin>>in[i])) return 0;
        string s = in;
        printf("%d\n",memo[s]);
	}
	return 0;
}

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

const int maxn = 1e3+5;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  int a[maxn][maxn];
  for(int i=0;i<n;i++){
    for(int j=0;j<n-1;j++){
      cin>>a[i][j];
      a[i][j]--;
    }
  }

  int ans = 0;
  int now[10005] = {};
  while(1){
    bool used[10005] = {};
    bool all = true;
    for(int i=0;i<n;i++){
      if(now[i]==n-1 || used[i] || used[a[i][now[i]]]) continue;
      int t = a[i][now[i]];
      if(i == a[t][now[t]]){
	used[i] = true;
	used[t] = true;
	now[i]++;
	now[t]++;
	all = false;
      }
    }
    if(all){
      bool ok = true;
      for(int i=0;i<n;i++){
	if(now[i]!=n-1) ok =false;
      }
      if(ok){
	cout << ans << endl;
	return 0;
      }
    cout << -1 << endl;
    return 0;
    }
    ans++;
  }
  return(0);
}

Measured memory_bytes: 4224
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
using ull = unsigned long long;
using P = pair<int, int>;

static constexpr ull MOD = 1000000007;
static constexpr double pi = 3.14159265359;


int N;
int A, B, C;
vector<int> l;

int dfs(int cur, int a, int b, int c) {
    if (cur == N) {
        if (min(a, min(b, c)) > 0) {
            return abs(A - a) + abs(B - b) + abs(C - c) - 30;
        }
        return 999999999;
    }

    int ret0 = dfs(cur + 1, a, b, c);
    int ret1 = dfs(cur + 1, a + l[cur], b, c) + 10;
    int ret2 = dfs(cur + 1, a, b + l[cur], c) + 10;
    int ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;
    return min(ret0, min(ret1, min(ret2, ret3)));
}

int main() {
    cin >> N;
    cin >> A >> B >> C;
    for (int i = 0; i < N; ++i) {
        int tmp;
        cin >> tmp;
        l.push_back(tmp);
    }
    int ans = dfs(0, 0, 0, 0);
    cout << ans << endl;
}


Measured memory_bytes: 888
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m==-1 or f==-1:
        print("F") 
    elif 80 <= m+f:
        print("A")
    elif 65 <= m + f:
        print("B")
    elif 50 <= m + f:
        print("C")
    elif (30 <= m + f ) and r >= 50:
        print("C")
    elif 30 <= m + f:
        print("D")
    else:
        print("F")



Measured memory_bytes: 5592
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#include <numeric>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int a;
	cin >> a;
	cout << a + a * a + a * a*a << endl;
	return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	// 2-100
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		if (x==0) {
			System.out.println(1);
		}else {
			System.out.println(0);
		}
	}

}

Measured memory_bytes: 26980
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

h, w = MAP()

# a = [[0] * (w + 2)] * (h + 2)
s = [list(input()) for _ in range(h)]

dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
            # スルー
        num = 0
        for d in range(8):
            ni = i + dy[d]
            nj = j + dx[d]
            # niとnjで有効なのはsの定義域．
            # ni w 0 <= ni <= w - 1
            # nj h 0 <= nj <= h - 1
            
            if ni < 0 or h <= ni:
                continue
                # スルー
            if nj < 0 or w <= nj:
                continue
                # スールー
            if s[ni][nj] == "#":
                num += 1
        s[i][j] = str(num)
            # (num + "0")

for i in range(h):
    print("".join(s[i]))


Measured memory_bytes: 5524
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;

    int r=0, b=0;
    for(int i=0; i<n; i++){
        if(s[i] == 'R') r++;
        if(s[i] == 'B') b++;
    }
    if(r>b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

#define COUT(x) cout << #x << " = " << (x) << ", "
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
typedef long long ll;
const int MOD = 1000000007;

int main(){
  string s;
  cin >> s;
  if(s.size() == 2){
    if(s[0] == s[1]){
      cout << "1 2" << endl;
    }else{
      cout << "-1 -1" << endl;
    }
    return 0;
  }
  for(int i = 2; i < s.size(); i++){
    if(s[i] == s[i-1] || s[i] == s[i-2] || s[i-1] == s[i-2]){
      cout << i-1 << " " << i+1 << endl;
      return 0;
    }
  }
  cout << "-1 -1" << endl;
}


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

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

		int[] intArray = new int[3];
		intArray[0] = A;
		intArray[1] = B;
		intArray[2] = C;

		Arrays.sort(intArray);
	//	for(int i = 0; i < intArray.length; i++) {
	//		System.out.print(intArray[i]);
	//	}
		System.out.println(intArray[0]+" "+intArray[1]+" "+intArray[2]);

	}
}

Measured memory_bytes: 26256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner num = new Scanner(System.in);
        int[] list = new int[3];
        list[0] = num.nextInt();
        list[1] = num.nextInt();
        list[2] = num.nextInt();
        num.close();
        Arrays.sort(list);

        System.out.printf("%d %d %d\n", list[0], list[1], list[2]);
    }
}


Measured memory_bytes: 26300
// https://atcoder.jp/contests/abc009/tasks/abc009_3
// 未解決
#include <bits/stdc++.h>
#include <string>
using namespace std;

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素


int main(){
    ll x,y;
    cin>>x>>y;
    ll a=x;
    ll ans=1;
    while(1){
        a*=2;
        if(a<=y)ans++;
        else break;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int rain = 0;
    int ans = 0;
    for(int i=0; i<3; i++){
        if(s[i] == 'R') { rain++; ans = rain;}
        else rain = 0;
    }

    cout << ans << endl;

    return 0;
}

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

int n, h[100005], f[100005];
std ::stack<int> st;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &h[i]);
	int lst = 0;
	for (int i = 1; i <= n; ++i)
		if (h[i + 1] > h[i] || i == n) {
			for (int j = lst + 1; j <= i; ++j)
				f[j] = (i - j);
			lst = i, f[i] = 0;
			//printf("%d ", i);
		}
	//printf("\n");
	f[n] = 0;
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (f[i] > ans) 
			ans = f[i];
		//printf("%d ", f[i]);
	}
	//printf("\n");
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1024
use proconio::{
    input, 
    fastout,
};

#[fastout]
fn main() {
    input! {
        k: usize,
    }

    if k % 2 == 0 || k % 5 == 0 {
        println!("-1");
        return;
    }

    let div = if k % 7 == 0 {
        9 * k / 7
    } else {
        9 * k
    };

    let mut rem = 10 % div;
    let mut count = 1;

    loop {
        if rem % div == 1 {
            break;
        }

        rem *= 10;
        rem %= div;
        count += 1;
    }

    println!("{}", count);
}


Measured memory_bytes: 2180
n,a,b=map(int, input().split())
MAX_NUM = 3*10**5
pr = 10**9+7
fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]
fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % pr
    inv[i] = pr - inv[pr%i] * (pr // i) % pr
    finv[i] = finv[i-1] * inv[i] % pr
g=pow(2,n,pr)-1
t=1
for i in range(n,n-a,-1):
    t=t*i%pr
g-=t*finv[a]
t=1
for i in range(n,n-b,-1):
    t=t*i%pr
g-=t*finv[b]
print(g%pr)

Measured memory_bytes: 39972
import java.util.*;


class Main
{
    public static void main(String[] args)
    {
            Scanner sc = new Scanner(System.in);
            int n =  sc.nextInt();
            int [] arr = new int [n];
            int ctn=0;
            for(int i = 0; i<n; i++)arr[i] = sc.nextInt();
            for(int i = n; i>0; i--)
            {
                for(int j = 0; j<n-1;j++)
                {
                    if(arr[j]>arr[j+1])
                    {
                        int temp = arr[j+1];
                        arr[j+1] = arr[j];
                        arr[j] = temp;
                        ctn++;      
                    }
                }
            }     
            for(int i = 0; i<n; i++)
            {
                 if(i==n-1)
                {
                    System.out.printf("%d\n",arr[i]);
                    System.out.println(ctn);
                    break;
                }
                System.out.printf("%d ",arr[i]);            
            }
    }
}
       





Measured memory_bytes: 26312
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const ll mod = 1e9+7;

int main(){
    string K;   cin>>K;
    int d;  cin>>d;
    int n = K.size();
    vector<vector<vector<ll>>>dp(n+1, vector<vector<ll>>(2, vector<ll>(d)));
    dp[0][0][0] = 1;
    rep(i, n)   rep(j, 2)   rep(k, d){
        int l = j?9:K[i]-'0';
        rep(x, l+1){
            (dp[i+1][j || x < l][(k+x)%d] += dp[i][j][k]) %= mod;
        }
    }
    ll ans = 0;
    rep(j, 2)   (ans += dp[n][j][0]) %= mod;
    cout << (ans+mod-1)%mod << endl;
}


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


int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}

//int ()
/*
int triangle(int a, int b, int c){
  if(a<b+c){
    if(b<c+a){
      if(c<a+b){
        printf("1\n");
        return 1;
      }
    }
  }
  printf("1\n");
  return 0;
}
*/

int main()
{
  int  a ,b, c, d, e, X, Y ,r;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  int  A[100003]={};
  int  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
//  char s[101][101]={};
  char s[100001]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
//  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans=0;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  long long  tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
  scanf("%d", &a);
  
  for(i=0;i<a;i++){
    scanf("%d", &A[i]);
  }
  
  qsort(A, a, sizeof(int), compare_int);
//  for(i=0;i<a;i++){
//    printf("%d ", A[i]);
//  }
 
  for(i=0;i<a-2;i++){
    for(j=i+1;j<a-1;j++){
      for(k=j+1;k<a;k++){
//        sum++;
//        printf("%d\n", sum);

        if(A[i]<A[j]+A[k]){
          if(A[j]<A[k]+A[i]){
            if(A[k]<A[i]+A[j]){
              cnt++;
//              printf("1:i=%d i=%d i=%d\n", A[i], A[j], A[k]);
            }
            else break;
          }
          else break;
        }
        else break;
      }
    }
  }

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


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;

const int MAX_X = 5050;
const int MAX_N = 1010;

vector<vector<int>> edge(MAX_N);
vector<int> xs;

pair<int, int> dfs(int n){
    int total = xs[n];
    if((int)edge[n].size() == 0){
        return pair<int, int>{0, total};
    }
    vector<int> dp(MAX_X, 0);
    int child_sum = 0;
    for(int i=0; i<(int)edge[n].size(); i++){
        pair<int, int> ret = dfs(edge[n][i]);
        if(ret.first == -1){
            return pair<int, int>{-1, -1};
        }
        child_sum += ret.first + ret.second;
        if(i == 0){
            if(ret.first <= total){
                dp[ret.first] = 1;
            }
            if(ret.second <= total){
                dp[ret.second] = 1;
            }
            continue;
        }
        // Search possible values 
        for(int j=total; j>-1; j--){
            if(dp[j] == 1){
                dp[j] = 0;
                if(j + ret.second <= total){dp[j + ret.second] = 1;}
                if(j + ret.first <= total){dp[j + ret.first] = 1;}
            }
        }
    }
    for(int i=total; i>-1; i--){
        if(dp[i] == 1){
            int a = total;
            int b = child_sum - i;
            if(a > b){swap(a, b);}
            return pair<int, int>{a, b};
        }
    }
    return pair<int, int>{-1, -1};
}

int main() {
    int n; cin >> n;
    for(int i=0; i<n-1; i++){
        int p; cin >> p; p--;
        edge[p].push_back(i+1);
    }
    for(int i=0; i<n; i++){
        int x; cin >> x;
        xs.push_back(x);
    }
    pair<int, int> ret = dfs(0);
    // cout << ret.first << " " << ret.second << endl;
    if(ret.first == -1){
        cout << "IMPOSSIBLE" << endl;
    }
    else{
        cout << "POSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 8748
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int a,b,n;
    cin>>a>>b>>n;
    ll int x;
    if(n < b){
        x = n;
    }
    else if(n >= b){
        x = b-1;
    }
    cout<<floor(((ll)x*a)/(double)b);
    return 0;
}


Measured memory_bytes: 3776
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>

using namespace std ;

#define MAXN 1000005
#define rep( i , x ) for ( int i = 0 ; i < x ; i ++ )

struct cmp {
    bool operator(  )( int x , int y ) {
        return x < y ;
    }
};

priority_queue< long long , vector< long long > , cmp > Q ;

struct node {
    int t1 , t2 ;
    bool operator < ( const node &a ) const {
        return t2 < a.t2 ;
    }
} a[ MAXN ] ;

int n ;
long long Time = 0 ;

int main(  ) {
    scanf( "%d" , &n ) ; rep( i , n ) scanf( "%d%d" , &a[ i ].t1 , &a[ i ].t2 ) ;
    sort( a , a + n ) ;
    while ( ! Q.empty(  ) ) Q.pop(  ) ;
    rep( i , n ) {
        if ( Time + a[ i ].t1 <= a[ i ].t2 ) {
            Time += a[ i ].t1 ; Q.push( a[ i ].t1 ) ;
        } else {
            while ( ! Q.empty(  ) && a[ i ].t1 < Q.top(  ) && Time + a[ i ].t1 > a[ i ].t2 ) Time -= Q.top(  ) , Q.pop(  ) ;
            if ( Time + a[ i ].t1 <= a[ i ].t2 ) Time += a[ i ].t1 , Q.push( a[ i ].t1 ) ;
        }
    }
    puts(Q.size(  )==n?"Yes":"No") ;
    return 0 ;
}

Measured memory_bytes: 3956
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

unsigned long long dp[301][301];
const int cm = 1 << 12;
char cn[cm], * ci = cn, ct;

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


	fread(cn, 1, cm, stdin);
	int N = 0, M = 0;
	while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';
	while ((ct = *ci++) >= '0') M = M * 10 + ct - '0';

	int xm[301][4], xM[301][4];
	rep1(i, N) {
		xm[i][1] = N;
		xm[i][2] = N;
		xM[i][2] = -1;
		xM[i][3] = -1;
	}
	rep(i, M) {
		int l = 0, r = 0;
		while ((ct = *ci++) >= '0') l = l * 10 + ct - '0';
		while ((ct = *ci++) >= '0') r = r * 10 + ct - '0';
		int x = *ci++ - '0';
		+ci++;
		chmin(xm[r][x], l);
		chmax(xM[r][x], l);
	}

	const int mod = 1e9 + 7;
	dp[0][0] = 1;
	int mj = 0;
	int mk = 0;
	unsigned long long yabai = 1;
	rep1(i, N) {
		for (int j = i - 1; j >= mj; j--) {
			auto dpj = dp[j];
			for (int k = i - 1; k >= max(j, mk); k--) {
				dpj[i] += dpj[k];
				dp[k][i] += dpj[k];
			}
		}
		yabai *= i + 1;
		bool yaba = (yabai > 18446744073709551615 / (i + 1));
		for (int j = i; j > xm[i][2]; j--) {
			for (int k = i; k >= max(j, mk); k--) dp[j][k] = 0;
		}
		for (int j = xm[i][2]; j > max(xM[i][3], mj - 1); j--) {
			for (int k = i; k > max(max(xm[i][1], mk - 1), j - 1); k--) dp[j][k] = 0;
			if (yaba) {
				for (int k = xm[i][1]; k > max(max(xM[i][2], mk - 1), j - 1); k--) {
					dp[j][k] %= mod;
				}
			}
			for (int k = xM[i][2]; k >= max(j, mk); k--) dp[j][k] = 0;
		}
		for (int j = xM[i][3]; j >= mj; j--) {
			for (int k = i; k >= max(j, mk); k--) dp[j][k] = 0;
		}
		if (yaba) yabai = mod;
		if (mj <= xM[i][3]) mj = xM[i][3] + 1;
		if (mk <= xM[i][2]) mk = xM[i][2] + 1;
	}

	ll kotae = 0;
	for (int j = mj; j <= N; j++) for (int k = max(mk, j); k <= N; k++) {
		kotae += dp[j][k] % mod;
	}
	printf("%lld", kotae% mod);

	Would you please return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int s,w;
    cin >> s >>w;
    if(s>w)cout<<"safe"<<endl;
    else cout << "unsafe" <<endl;

    return 0;
}


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

int main() {
	
	string S;
	cin >>S;
	
	if(S.at(5)=='1'){
		
		cout <<"TBD" <<endl;
		
	}
	else if(S.at(6)=='4'||S.at(6)=='3'||S.at(6)=='2'||S.at(6)=='1'){
		
		cout <<"Heisei" <<endl;
		
	}
	else{
		
		cout <<"TBD" <<endl;
		
	}
	
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        List<Integer> list = new ArrayList<>();
        if (s.charAt(0) == '0') {
            list.add(0);
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (i == 0 || s.charAt(i) == s.charAt(i - 1)) {
                cnt++;
            } else {
                list.add(cnt);
                cnt = 1;
            }
        }
        list.add(cnt);
        if (list.size() % 2 == 0) {
            list.add(0);
        }
        int ans = 0;
        int num = 0;
        int left = 0;
        int right = 0;
        for (int i = 0; i < list.size(); i += 2) {
            int nextLeft = i;
            int nextRight = Math.min(i + k * 2 + 1, list.size());
            while (nextLeft > left) {
                num -= list.get(left);
                left++;
            }
            while (nextRight > right) {
                num += list.get(right);
                right++;
            }
            ans = Math.max(ans, num);
        }

        System.out.println(ans);
    }
}


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



class Program
{
 
    public static void Main( )
    {
        var NM = Console.ReadLine( ).Split( ).Select( int.Parse ).ToArray( );

        bool[] isAC = Enumerable.Repeat( false, NM[ 0 ] + 1 ).ToArray( );
        int[] penalty = new int[ NM[ 0 ] + 1 ];
        int totalP = 0;

        for ( int i = 1; i <= NM[ 1 ]; i++ )
        {
            var input = Console.ReadLine( ).Split( );
            int q = int.Parse( input[ 0 ] );
            string s = input[ 1 ];

            if ( isAC[ q ] ) continue;

            switch ( s )
            {
                case "WA":
                    penalty[ q ] += 1;
                    break;
                case "AC":
                    isAC[ q ] = true;
                    totalP += penalty[ q ];
                    break;
            }
        }

        Console.WriteLine( $"{isAC.Count( x => x == true )} {totalP}" );
    }
}




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

int main(){
  int64_t A ;
  double B ; 
  cin >> A >> B ; 
  int64_t C = B*100+0.01 ; //切り捨てされないため
  
  
  cout <<  (int64_t)(A * C)/100 << endl ; 
  
  
}

Measured memory_bytes: 3740
#include<cstdio>
#include<algorithm>
using namespace std;
typedef pair<int,int> PA;
int main(){
  int m,n;
  PA seiza[200],hosi[1001];
  while(scanf("%d",&m),m){
    for(int i=0;i<m;i++)
      scanf("%d %d",&seiza[i].first,&seiza[i].second);
    scanf("%d",&n);
    for(int i=0;i<n;i++)
      scanf("%d %d",&hosi[i].first,&hosi[i].second);
    sort(hosi,hosi+n);
    for(int i=0;i<n;i++){
      int x = hosi[i].first - seiza[0].first;
      int y = hosi[i].second - seiza[0].second;
      for(int j=1;j<m;j++){
	if(binary_search(hosi,hosi+n,PA(seiza[j].first+x,seiza[j].second+y))){
	  if(j == m-1) printf("%d %d\n",x,y);
	} else break;
      }
    }
  }
  return (0);
}

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

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0; }
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0; }

using pii=pair<int,int>;

inline pii vmerge(pii s,pii t){
	pii r;
	r.first=min(s.first,t.first);
	r.second=max(s.second,t.second);
	return r;
}
const int LIMIT=200000+10;
pii a[LIMIT];

int main(){
	int n,m; 
	cin >> n >> m;
	vector<pii> xy(m);
	rep(i,m) cin >> xy[i].first >> xy[i].second;
	sort(xy.begin(), xy.end());


	rep(i,LIMIT){
		a[i].first=i;		
		a[i].second=i;
	}

	rep(i,m) {
		int y = xy[i].second-1;
		pii ret=vmerge(a[y],a[y+1]);
		a[y] = a[y+1]= ret;
	}
	
	rep(i,n) cout << (i?" ":"") << a[i].second-a[i].first+1;
	cout << endl;
	return 0;
}

Measured memory_bytes: 5200
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}

int main() {
  int n; cin>>n;
  ll d; cin>>d;
  int an = 0;
  for(int i=0;i<n;i++) {
    ll x,y; cin>>x>>y;
    if (x*x + y*y <= d*d) an++;
  }
  cout<<an<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 3632
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

LL dp[5010][5010];

int main() {
	int n;
	string s;
	cin >> n >> s;
	dp[0][0] = 1;
	for (int i = 0; i <= n; i++) {
		if (i != 0) {
			dp[i][0] += dp[i - 1][0];
		}
		for (int j = 1; j <= i; j++) {
			dp[i][j] += (dp[i - 1][j - 1] * 2) % MOD;
			dp[i + 1][j - 1] = (dp[i][j] + dp[i + 1][j - 1]) % MOD;
		}
	}
	LL ans = dp[n][s.size()];
	for (int i = 0; i < s.size(); i++) {
		ans = (ans * 500000004) % MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 194176
# include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const long long linf = 1e18 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;

typedef long long ll;

string s;
int k, dp[301][301][301], u[301][301][301];

int calc(int l, int r, int k){
      if(k < 0) return -inf;
      if(l > r) return 0;
      if(l == r) return 1;
      if(u[l][r][k]) return dp[l][r][k];
      u[l][r][k] = 1;
      int &res = dp[l][r][k];
      res = max(calc(l + 1, r, k), calc(l, r - 1, k));
      if(s[l] == s[r])
            res = max(res, calc(l + 1, r - 1, k) + 2);
      else
            res = max(res, calc(l + 1, r - 1, k - 1) + 2);
      return res;
}

int main(){
      cin >> s >> k;
      s = ' ' + s;
      cout << calc(1, s.size() - 1, k) << endl;
}


Measured memory_bytes: 212864
N, K = map(int,input().split())
max_edge = (N-1)*(N-2)//2
all_edges = [[i,j] for i in range(N) for j in range(i+1,N)]

if 0 <= K <= max_edge:
    minus = max_edge - K
    count = 0
    answer = []
    for edge in all_edges:
        if edge[0] == 0:
            answer.append(edge)
        elif count < minus:
            answer.append(edge)
            count+=1
    print(len(answer))
    for i in range(len(answer)):
        print((" ").join(str(j+1) for j in answer[i]))
else:
    print(-1)

Measured memory_bytes: 9560
using System;

class Program {
    static int Main(string[] args) {
        string v = Console.ReadLine();
        int a = int.Parse(v.Split(' ')[0]);
        int b = int.Parse(v.Split(' ')[1]);
        int c = int.Parse(v.Split(' ')[2]);

        string msg = "No";
        if (a < b && b < c) { msg = "Yes"; }

        Console.WriteLine(msg);
        return 0;
    }
}

Measured memory_bytes: 8892
#include<iostream>
using namespace std;
int main()
{
	double a, b, c;
	cin >> a;
	b = (int)((int)a / 1.08);
	c = b + 1;
	if ((int)(b*1.08) == a)
		cout << (int)b << endl;
	else
		if ((int)(c * 1.08) == a)
			cout << (int)c << endl;
		else
			cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      if(m == 0)
        System.out.println(0+" "+0);
      else
      {
          int correct=0;
          int penalty=0;
          int a[]=new int[n];
          int b[]=new int[n];
          int c[]=new int[n];
          
          for(int i=0;i<m;i++)
            {
                int x = sc.nextInt();
                b[x-1]=1;
                String xx = sc.next();
                if(a[x-1] == 0)
                {
                    if(xx.equals("WA"))
                    {
                         penalty++;
                         c[x-1]++;
                    }
                       
                    else
                    {
                        correct++;
                        a[x-1]=1;
                        
                    }
                        
                }
              
                
            }
            for(int i=0;i<n;i++)
            {
                if(b[i] == 1)
                {
                    if(a[i] == 0)
                         penalty = penalty-c[i];
                }
                   
            }
            System.out.println(correct+" "+penalty);
           
      }
     
     
        
      
  }
}

Measured memory_bytes: 63956
#include <bits/stdc++.h>
using namespace std;
#define fore(i, init, n) for(long long i = init; i <= n; i++)
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;

const int MAXN = 205;
const int MAXV = 1e5+5;
ll N, W, w[MAXN], v[MAXN], dp[MAXN][MAXV], sum, r;

int main() {
    FIN;
    cin >> N >> W;
    
    fore(i,1,N) {
        cin >> w[i] >> v[i];
        sum += v[i];
    }

    fore(j,1,sum) dp[0][j] = 1e15;
    
    fore(i,1,N) {
        fore(j,1,sum) {
            dp[i][j] = dp[i-1][j];
            if (j >= v[i]) dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i]);
        }
    }

    fore(j, 0, sum)
        if (dp[N][j] <= W)
            r = max(r, j);
        
    cout << r << endl;
    
}


Measured memory_bytes: 80128
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a = LI()
s = sum(a)
if s >= 22:
    print('bust')
else:
    print('win')

Measured memory_bytes: 65552
n = int(input())
s = list(input())
count_L = [0] * 26
count_R = [0] * 26
ans = []
for i in range(n-1):
    count_L = [0] * 26
    count_R = [0] * 26
    c = 0
    for j in range(0,i+1):
        count_L[ord(s[j])-97] += 1
    for j in range(i+1,n):
        count_R[ord(s[j])-97] += 1
    #print(count_L,count_R)

    for j in range(26):
        if count_L[j] > 0 and count_R[j] > 0:
            c += 1
    ans.append(c)
print(max(ans))

Measured memory_bytes: 3064
#include <stdio.h>
 
int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  
  int s;
  
  s=b/a;
  s=s*100;
  
  if(s==(b*100)/a){
    printf("%d",a+b);
  }else{
    printf("%d",b-a);
  }

return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdint.h>

int
main(void)
{
	int n, i, a, min, max;
	uint64_t sum;

	scanf("%d", &n);
	sum = 0;
	min = 1 << 30;
	max = -(1 << 30);

	for (i = 0; i < n; i++) {
		scanf("%d", &a);

		if (a < min)
			min = a;
		if (max < a)
			max = a;
		sum += a;
	}

	printf("%d %d %ld\n", min, max, sum);

	return 0;
}



Measured memory_bytes: 2092
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

int gcd3(int A, int B) {
	if (B == 0) return A;
	else return gcd3(B, A % B);
}
ll gcd2(ll A, ll B) {
	if (B == 0) return A;
	ll k = A - ll(double(A) / B) * B;
	if (B < 2e9) return gcd3(B, k);
	else return gcd2(B, k);
}
const ll f80 = 23416728348467685;
const ll f81 = 37889062373143906;
ll gcd(ll A, ll B) {
	if (B == 0) return A;
	if (B < 2e9) return gcd3(B, A % B);
	if (B < 2e15) return gcd2(B, A % B);

	if (A % f81 == 0 && B % f80 == 0) return A / f81;
	else return gcd(B, A % B);
}

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


	int N;
	cin >> N;
	pair<ll, ll> AB[200001];
	int a0 = 0, b0 = 0;
	int ab00 = 0;
	int ka = 0, kb = N - 1;
	rep(i, N) {
		ll a, b;
		cin >> a >> b;

		if (a == 0 && b == 0) {
			ab00++;
			continue;
		}
		if (a == 0) {
			a0++;
			continue;
		}
		if (b == 0) {
			b0++;
			continue;
		}

		ll G = gcd(abs(a), abs(b));
		a /= G;
		b /= G;
		if (a < 0) {
			a = -a;
			b = -b;
		}
		if (b > 0) AB[ka++] = { a,b };
		else AB[kb--] = { -b,a };
	}
	auto BA = AB + kb + 1;
	kb = N - 1 - kb;
	ll kotae = 1;
	sort(AB, AB + ka);
	sort(BA, BA + kb);
	BA[kb] = { 2e18, 2e18 };

	pair<ll, ll> mae = AB[0];
	int p = 0;
	int kA = 0;
	rep(i, ka) {
		if (mae != AB[i]) {
			int tmp = 0;

			pair<ll, ll> mae2 = BA[p];
			int kB = 0;
			while (p < kb && BA[p] <= mae) {
				if (mae2 != BA[p]) {
					kotae = kotae * modpow(2, kB) % mod;
					mae2 = BA[p];
					kB = 1;
				}
				else kB++;
				p++;
			}

			if (mae == mae2) {
				tmp = kB;
			}
			else {
				kotae = kotae * modpow(2, kB) % mod;
			}

			if (tmp) {
				kotae = kotae * (modpow(2, kA) + modpow(2, kB) - 1) % mod;
			}
			else {
				kotae = kotae * modpow(2, kA) % mod;
			}

			mae = AB[i];
			kA = 1;
		}
		else kA++;
	}

	int tmp = 0;
	pair<ll, ll> mae2 = BA[p];
	int kB = 0;
	while (p < kb) {
		if (mae2 != BA[p]) {
			if (AB[ka - 1] == mae2) {
				tmp = kB;
			}
			else {
				kotae = kotae * modpow(2, kB) % mod;
			}
			mae2 = BA[p];
			kB = 1;
		}
		else kB++;
		p++;
	}

	if (AB[ka - 1] == mae2) {
		tmp = kB;
	}
	else {
		kotae = kotae * modpow(2, kB) % mod;
	}

	if (tmp) {
		kotae = kotae * (modpow(2, kA) + modpow(2, kB) - 1) % mod;
	}
	else {
		kotae = kotae * modpow(2, kA) % mod;
	}

	kotae = kotae * (modpow(2, a0) + modpow(2, b0) - 1) % mod;

	co((kotae - 1 + ab00 + 2 * mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 6780