akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(void) {
  string s; long long k;
  cin >> s >> k;

  if (s.length() == 1) {
    cout << k/2 << "\n";
    return 0;
  }

  bool allsame = true;
  for (int i = 1; i < s.length(); i++) if (s[i] != s[i-1]) { allsame = false; break; }
  if (allsame) {
    cout << (s.length() * k) / 2 << "\n";
    return 0;
  }

  long long d = 0;
  for (long long i = 1; i < s.length(); i++) {
    int p = 1;
    while (s[i] == s[i-1]) {
      p++;
      i++;
      if (i == s.length()) break;
    }
    d += p/2;
  }

  long long change = d * k;
  long long n = s.length();

  if (s[0] == s[n-1]) {
    int i = n-1;
    int p = 1;

    while (i >= 1 && s[i] == s[i-1]) {
      p++;
      i--;
    }

    int j = 1;
    while (j < i && s[j] == s[j-1]) {
      p++;
      j++;
    }

    if (p % 2 == 1) change += k-1;
  }
  cout << change << "\n";
}

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

int main() {
  string N;
  cin >> N;
  char a, b, c, d;
  a = N.at(0);
  b = N.at(1);
  c = N.at(2);
  d = N.at(3);
  if (a == b && b == c) {
  cout << "Yes" << endl;
  }
  else if (c == d && b == c) {
  cout << "Yes" << endl;
  }
  else {
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
open Printf
open Scanf

let solve n =
  let aa = Array.init n @@ fun _ -> scanf "%d " @@ fun x -> x in
  let f (tc, mh) a = if mh <= a then (tc, a) else (tc + mh - a, mh) in
  fst @@ Array.fold_left f (0, 0) aa

let () =
  scanf "%d " solve |> printf "%d\n"


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

int main()
{   char s[105][105];
    int n,m,i,j;
    scanf("%d%d",&n,&m);
    getchar();
    for(i=0;i<n;i++)
        {for(j=0;j<m;j++)
        scanf("%c",&s[i][j]);
        getchar();
        }
    for(i=0;i<n;i++)
        {for(j=0;j<m;j++)
            printf("%c",s[i][j]);
            printf("\n");
           for(j=0;j<m;j++)
            printf("%c",s[i][j]);
            printf("\n");
        }

    return 0;
}


Measured memory_bytes: 3652
/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MAX = 1024;

int n;
int a[MAX];

int main(void) {
	// in = fopen("B.in", "rt");
	
	fscanf(in, "%d", &n);
	for (int i = 0; i < n; i++)
	    fscanf(in, "%d", &a[i]);
	sort(a, a + n);
	a[n - 1] /= 2;
	int sum = 0;
	for (int i = 0; i < n; i++)
	    sum += a[i];
	fprintf(out, "%d\n", sum);
	
	return 0;
}

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

double a,b,h,m;

int main(void){
    double pi = 3.141592653589793;
    cin>>a>>b>>h>>m;
    double c=(h*60+m)*0.5;
    double d=6*m;
    double pi1=abs(c-d)/180;
    double ans=sqrt(a*a+b*b-2*a*b*cos(pi*pi1));
    cout<<setprecision(25)<<ans<<endl;

}


Measured memory_bytes: 4164
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    if(B%A == 0){
      cout << A+B << endl;
    }else{
      cout << B-A << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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

vector<long long> enum_divisors(long long N)
{
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i)
    {
        if (N % i == 0)
        {
            res.push_back(i);
            if (N / i != i)
                res.push_back(N / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}
int main()
{
    ll N, M;
    cin >> N >> M;
    ll ans = 1;
    auto div = enum_divisors(M);

    for (int i = M / N; i >= 1;i--)
    {
        for (int j = 0; j < div.size();j++)
        {
            if(div[j] == i){
                ans = i;
                break;
            }
            //cout << i << " " <<div[j] << endl;
        }
        if (ans != 1)
        {
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <set>
#include <unordered_set>
#include <map>
#include <cmath>
#include <deque>
#include <queue>
#include <string>
#include <cstring>
#include <stack>


using namespace std;
typedef long long ll;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define V vector

int A, B, C, K;
void solve(int a, int b, int c, int k) {
    int res = 0;
    if(k<= a) {
        cout << k; return;
    }
    else {
        res += a;
        k -= a;
    }
    if(k <= b) {
        cout << res; return;
    } else {
        k -= b;
    }
    res -= k;
    cout << res; return;
}

int main() {
    cin >> A >> B >> C >> K;
    solve(A, B, C, K);
    return 0;
}



Measured memory_bytes: 3192
#include<stdio.h>
int main(){
  int i=0,j=0,k,N,a,v;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(k=0;k<N;k++){
    if(k==N-1) printf("%d",A[k]);
    else printf("%d ",A[k]);
  }
  printf("\n");
  for(i=1;i<=N-1;i++){ 
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
      A[j+1]=v;
    }
    for(j=0;j<N;j++){
      if(j==N-1) printf("%d",A[j]);
      else printf("%d ",A[j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2056
#include <iostream>

using namespace std;

bool list[31]={false};

int main(void){
	for(int i=0;i<28;i++){
		int a;
		cin >> a;
		list[a]=true;
	}
	for(int i=1;i<=30;i++)
		if(!list[i])
			cout << i << endl;
	return 0;
}

Measured memory_bytes: 1160
H,W=map(int,input().split())
#H×Wのマス目入力の周りに"."を付け加える関数
def pixel_input(H,W,border="#"):
    pixel = \
    [[border]*(W+2)] + \
    [[border] + list(input()) + [border] for _ in range(H)] + \
    [[border]*(W+2)]
    return pixel
p=pixel_input(H,W)
s=sum([p[i].count("#")-2 for i in range(1,H+1)])

que=[(1,1)]
cnt=1

while(1):
    que2=[]
    for x,y in que:
        if p[x-1][y]==".":
            que2.append((x-1,y))
            p[x-1][y]="#"
        if p[x+1][y]==".":
            que2.append((x+1,y))
            p[x+1][y]="#"
        if p[x][y-1]==".":
            que2.append((x,y-1))
            p[x][y-1]="#"
        if p[x][y+1]==".":
            que2.append((x,y+1))
            p[x][y+1]="#"
    cnt+=1
    if (H,W) in que2:
        break
    elif que2==[]:
        cnt=-1
        break
    else:
        que=que2

if cnt>=0:
    print(H*W-s-cnt)
else:
    print(-1)

Measured memory_bytes: 3188
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
ll const INF = 1LL << 60;

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

    int a[N];
    rep(i, N) cin >> a[i];


    ll ans = INF;
    for (int i = -100; i <= 100; i++) {
        ll c = 0;
        for (int j = 0; j < N; j++) {
            c += pow((a[j] - i), 2);
        }
        ans = min(ans, c);
    }

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

Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val V = nextIntList()
    val A = IntArray(N / 2 + 1)
    val B = IntArray(N / 2 + 1)
    for (i in 0 until N / 2) {
        A[i] = V[i * 2]
        B[i] = V[i * 2 + 1]
    }
    A[N / 2] = 0
    B[N / 2] = 0
    val C = A.toCountMap().toList().sortedByDescending { it.second }
    val D = B.toCountMap().toList().sortedByDescending { it.second }
    val (i, j) = when {
        C[0].first != D[0].first -> Pair(0, 0)
        C[0].second + D[1].second > C[1].second + D[0].second -> Pair(0, 1)
        else -> Pair(1, 0)
    }
    println(C.map { it.second }.sum() + D.map { it.second }.sum() - C[i].second - D[j].second)
}

fun IntArray.toCountMap(): Map<Int, Long> {
    return this.groupBy { it }.mapValues { if (it.key != 0) it.value.size.toLong() else 0 }
}

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

namespace AtCoder.Beginner141
{
    public static class C
    {
        public static void Main()
        {
            string[] split = Console.ReadLine().Split(' ');
            int playersCount = int.Parse(split[0]);
            int beginningScore = int.Parse(split[1]);
            int qualifiesCount = int.Parse(split[2]);
            int scoreIfNoAns = beginningScore - qualifiesCount;
            int[] answers = new int[playersCount];
            for (int i = 0; i < qualifiesCount; ++i)
            {
                int playerNo = int.Parse(Console.ReadLine()) - 1;
                ++answers[playerNo];
            }
            for (int i = 0; i < playersCount; ++i)
            {
                Console.WriteLine(scoreIfNoAns + answers[i] > 0 ? "Yes" : "No");
            }
        }

    }
}


Measured memory_bytes: 15708
def gcd(a, b):
    c = a % b
    if c == 0:
        return b
    return gcd(b, c)

N = int(input())
a = list(map(int, input().split()))
lcm = a[0]

for i in range(1,N):
    lcm = lcm * a[i] // gcd(lcm, a[i])

ans = 0

for i in a:
    ans += (lcm-1) % i
print(ans)

Measured memory_bytes: 3316
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long cnt = Long.MAX_VALUE;
		for (long i = 1; i * i <= n; i++) {
			if (n % i == 0) {
				cnt = (i - 1) + (n / i - 1);
			}
		}
		System.out.println(cnt);
		sc.close();
	}

}


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




int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif*/
    float t;
    cin>>t;
    int total=(t+1)/2;
    float num=total/t;
    cout<<fixed<<setprecision(10)<<num<<endl;

    return 0;
    
}

Measured memory_bytes: 3808
// Problem : D - Replacing
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <iostream>
using namespace std;
int t[100005];
int main()
{
 int n;
 long long sum=0;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
  int x;
  cin>>x;
  t[x]++;
  sum+=x;
 }
 int q;
 cin>>q;
 while(q--)
 {
  int x,y;
  cin>>x>>y;
  sum+=t[x]*(y-x);
  cout<<sum<<endl;
  t[y]+=t[x],t[x]=0;
 }
 return 0;
}

Measured memory_bytes: 3944
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
int main() 
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a * c, max(a * d, max(b * c, b * d)));
    return 0;
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

N = int(input())
S = input().rstrip()
ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    idx1 = S.find(i[0])
    if idx1 < 0:
        continue
    idx2 = S.find(i[1], idx1 + 1)
    if idx2 < 0:
        continue
    idx3 = S.find(i[2], idx2 + 1)
    if idx3 < 0:
        continue
    ans += 1
print(ans)

Measured memory_bytes: 38256
s=input()
n=len(s)
t=input()
m=len(t)

ANS=[]
for i in range(n-m+1):
    for j in range(m):
        #print(s[i+j],t[j])
        if s[i+j] != "?" and s[i+j] != t[j]:
            break
    else:
        ans = list(s)
        ans[i:i+j+1] = list(t)
        ans="".join(ans)
        ans = ans.replace('?','a')
        ANS.append(ans)
if len(ANS) == 0:
    print("UNRESTORABLE")
else:
    ANS.sort()
    print(ANS[0])

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

int main(){
  int N;
  cin >> N;
  int a=N;
  string vec;
  cin >> vec;
    for(int i=0;i<N-1;i++){
      if(vec.at(i)==vec.at(i+1)){
      a -= 1;
      }
    }
    cout << a <<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int H,W;
  cin>>H>>W;
  VS S(H);
  rep(i,H) cin>>S[i];
  int ans=0;
  rep(i,H) rep(j,W){
    if(S[i][j]=='#') continue;
    VVI X(H,VI(W,-1));
    PII st=mp(i,j);
    X[i][j]=0;
    queue<PII> Q;
    Q.push(st);
    while(!Q.empty()){
      PII now=Q.front();
      int x=now.first;
      int y=now.second;
      Q.pop();
      auto add=[&](int A,int B,int C,int D){
        if(A+C<0 or A+C>H-1 or B+D<0 or B+D>W-1) return;
        if(S[A+C][B+D]=='#') return;
        if(X[A+C][B+D]!=-1) return;
        X[A+C][B+D]=X[A][B]+1;
        Q.push(mp(A+C,B+D));
      };
      add(x,y,0,1);
      add(x,y,0,-1);
      add(x,y,1,0);
      add(x,y,-1,0);
    }
    int tmp=0;
    rep(i,H) rep(j,W) tmp=max(tmp,X[i][j]);
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1
# print(d)
ans = 0
for key in d:
    ans += d[key]*(d[key]-1)//2

for i in range(N):
    print(ans - (d[A[i]] - 1))


Measured memory_bytes: 87884
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 10 22:22:57 2019

@author: YudNK
"""

N, M = map(int, input().split())
list = [[int(i) for i in input().split()] for j in range(M)]
p = input().split()
p = [int(i) for i in p]

def binaly(n):
    d = n
    binaly = [0 for i in range(N)]
    m = 0
    while d >= 1:
        binaly[m] = d % 2
        d = d // 2
        m += 1
    return binaly

pattern = 0
for i in range(2**N):
    sample = binaly(i)
    count = 0
    for j in range(M):
        sum = 0
        for k in range(list[j][0]):
            sum += sample[list[j][k + 1] - 1]
        if sum%2 == p[j]:
            count += 1
    if count == M:
        pattern += 1
print(pattern)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };

VI pm;
int n;

int main() {
	pm.push_back( 2 );
	for ( int i = 3; i < 1000000; i += 2 ) {
		bool can_add = true;
		for ( int j = 0; j < pm.size() && sq(pm[j]) <= i; j++ ) {
			if ( i % pm[ j ] == 0 ) {
				can_add = false;
				break;
			}
		}
		if ( can_add ) {
			pm.push_back( i );
		}
	}
	while ( ~scanf("%d", &n) && n ) {
		int ans = 0;
		for ( int i = 0; i < pm.size() && pm[i] <= n / 2; i++ ) {
			ans += binary_search( pm.begin(), pm.end(), n - pm[ i ] );
		}
		printf( "%d\n", ans );
	}
	return 0;
}

Measured memory_bytes: 1588
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
ll arr[MAXN];
int main()
{
    ll n,k,s;
    while(cin>>n>>k>>s)
    {
        memset(arr,0,sizeof(arr));
        for(int i=1;i<=k;i++)
        {
            arr[i]=s;
        }
        for(int i=k+1;i<=n;i++)
        {
            arr[i]=s/2+7;
        }
        for(int i=1;i<=n;i++)
        {
            cout<<arr[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int main(){
int X;
cin>>X;
int arr[3][X];
for(int i=0;i<3;i++)
{
    for(int t=0;t<X;t++)
    {
        if(i==2 && t==X-1)
        break;
            cin>>arr[i][t];

    }
}
int sam=0;

for(int i=0;i<X;i++)
{
    sam+=arr[1][i];
    if(i+1<X && arr[0][i+1]==arr[0][i]+1)
        sam+=arr[2][arr[0][i]-1];
}

cout<<sam;

return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 200003
#define pb push_back
using namespace std;

int n,m,ans,cnt;
bool mark[maxn];
vector<int> adj[maxn];

void dfs(int u) {
	cnt++;
	mark[u] = true;
	int deg = adj[u].size();
	for( int i = 0 ; i < deg ; i++ ) {
		int v = adj[u][i];
		if(mark[v])
			continue;
		dfs(v);
	}
}

int main() {
	scanf("%d%d",&n,&m);
	for( int i = 0 , x,y ; i < m ; i++ ) {
		scanf("%d%d",&x,&y);
		adj[x].pb(y);
		adj[y].pb(x);
	}
	for( int i = 1 ; i <= n ; i++ )
		if(!mark[i]) {
			cnt = 0;
			dfs(i);
			ans = max(ans,cnt);
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 24248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#ifdef MY_DEBUG_FLAG
template<typename T> void debug(T a) { cerr << a << ' '; }
template<typename T, typename U> void debug(pair<T, U> a) { cerr << a.first << ' ' << a.second << ' '; }
template<typename T> void debug(vector<T> a) { for(auto it : a) debug(it);}
template<typename T> void debug(set<T> a) { for(auto it : a) debug(it);}
#define db(a) cerr << "DEBUG ( " << #a << " == "; debug(a); cerr << ")\n"
#else
#define db(...)
#endif

#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr)
#define sz(a) ((int)(a).size())
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define dec(i,n,a) for(int i=(n); i>=(a); i--)
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()

constexpr int inf = 0x3f3f3f3f;
constexpr int MAXN = 310;
constexpr int mod = 1000000007;

// p-blty of reaching the state p[a][b][c] with a plates with 1, b w/ 2, c w/ 3
double p[MAXN][MAXN][MAXN], EV[MAXN][MAXN][MAXN];

int main() {
	int n; scanf("%d", &n);
	vi cnt(4);
	rep(i,0,n) {
		int t;
		scanf("%d", &t);
		cnt[t]++;
	}
	p[cnt[1]][cnt[2]][cnt[3]] = 1;

	for(int c = n ; c >= 0; c--) {
		for(int b = n; b >= 0; b--) {
			for(int a = n; a >= 0; a--) {
				if(a+b+c > n || !(a+b+c)) continue;
				double p_waste = (double) (n - a - b - c) / n;
				// pw + pw² + pw³ + ...
				double ev_waste = p_waste / (1 - p_waste);
				EV[a][b][c] += (ev_waste+1)*p[a][b][c];
				if(c) {
					double p_go = (double) c / (a+b+c);
					p[a][b+1][c-1] += p[a][b][c]*p_go;
					EV[a][b+1][c-1] += (EV[a][b][c])*p_go;
				}
				if(b) {
					double p_go = (double) b / (a+b+c);
					p[a+1][b-1][c] += p[a][b][c]*p_go;
					EV[a+1][b-1][c] += (EV[a][b][c])*p_go;
				}
				if(a) {
					double p_go = (double) a / (a+b+c);
					p[a-1][b][c] += p[a][b][c]*p_go;
					EV[a-1][b][c] += (EV[a][b][c])*p_go;
				}
			}
		}
	}
	printf("%.10lf\n", EV[0][0][0]);
}


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

#define PI 3.14159265359
//2の累乗数かどうか
bool hantei(int N) {
	bool flag = false;
	while (1) {
		if (N % 2 == 0) N /= 2;
	}
	if (N == 1) flag = true;

	return flag;
}
vector<ll> divisor(ll n){
	vector<ll> res;//約数を格納する列
	for(ll i= 1;i*i <= n;i++){
		if(n % i == 0){
		   res.push_back(i);
		   if(i != n/i) res.push_back(n/i);
		 }
	}
	return res;
}
vector<ll> v;//753数を格納する列

//引数aのケツに3or5or7を追加し準753数を作る
void dfs(ll a, int N) {
	if (a> N) return;

	if (10 * a + 3 <= N) v.push_back(10 * a + 3);
	dfs(10 * a + 3, N);

	if (10 * a + 5 <= N) v.push_back(10 * a + 5);
	dfs(10 * a + 5, N);

	if (10 * a + 7 <= N) v.push_back(10 * a + 7);
	dfs(10 * a + 7, N);
}
//aが753数かどうか判定
bool check(ll a) {
	bool flag3 = false;
	bool flag5 = false;
	bool flag7 = false;
	string s = to_string(a);
	int n = s.size();

	for (int i = 0; i < n; i++) {
		if (s[i] == '3') flag3 = true;
		if (s[i] == '5') flag5 = true;
		if (s[i] == '7') flag7 = true;
	}

	if (flag3 && flag5 && flag7) return true;
	else return false;
}

int main() {
	int N;
	cin >> N;
	dfs(3, N);
	dfs(5, N);
	dfs(7, N);

	int ans = 0;
	for (int i = 0; i < v.size(); i++) {
		if (check(v[i])) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <cmath>
    #include <cstdio>
    #include <vector>
    #include<bits/stdc++.h>
    #include <iostream>
    #include <algorithm>
    #define ll long long int
    using namespace std;
     
     
    int main() {
        int n,m;
        cin>>n>>m;
        int a[n][m];
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)a[i][j]=0;
        int k;
        cin>>k;
        int b[k+1];
        b[0]=0;
        for(int i=1;i<=k;i++)cin>>b[i];
        int r=1;
        int sum=0;
        int u=0,w=0,l=0;
        
        while(sum!=(n*m)){
            
            a[u][w]=r;
            if(u==n-1&&l==0){l=1;w++;}
            else
                if(u==0&&l==1){l=0;w++;}
            else
            if(l==0)u++;
            else
            if(l==1)u--;
            sum++;
            --b[r];
            if(b[r]<=0)++r;
           
                
            
        }
        
       for(int i=0;i<n;i++){
            for(int j=0;j<m;j++)
            {
                cout<<a[i][j]<<" ";
            }
            cout<<endl;
        }
        
    }

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


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

    i64 v = (i64)floor(sqrt(N));
    cout << v * v << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  long long a, b; cin >> a >> b;
  cout << (bitset<32>(a&b)) << endl;
  cout << (bitset<32>(a|b)) << endl;
  cout << (bitset<32>(a^b)) << endl;
}


Measured memory_bytes: 3124
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {

	public static void main(String[] args) throws IOException {
		//Scanner in = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));		
		char s[] = br.readLine().toCharArray();
		char t[] = br.readLine().toCharArray();
		br.close();
		// in.close();

		int row = t.length;
		int col = s.length;
		int tb[][] = new int[row + 1][col + 1];

		for ( int r = 0; r < row; r++ ) {
			for ( int c = 0; c < col; c++ ) {
				if ( t[r] == s[c] ) {
					tb[r + 1][c + 1] = tb[r][c] + 1;
				} else {
					tb[r + 1][c + 1] = Math.max(tb[r + 1][c], tb[r][c + 1]);
				}
			}
		}

		int r = row;
		int c = col;
		ArrayDeque<Character> stack = new ArrayDeque<Character>();
		stack.add(' ');
		while ( tb[r][c] != 0 ) {

			// 左上に行けるとき
			if ( tb[r - 1][c - 1] == tb[r][c] ) {
				r -= 1;
				c -= 1;
			} else
			// 上にだけ行けるとき
			if ( tb[r - 1][c] == tb[r][c] ) {
				r -= 1;
			} else
			// 左にだけ行けるとき
			if ( tb[r][c - 1] == tb[r][c] ) {
				c -= 1;
			} else
			// 行き止まり
			{
				stack.add((Character) s[c - 1]);
				r -= 1;
				c -= 1;
			}
		}

		while ( stack.size() > 0 ) {
			System.out.print(stack.pollLast());
		}
	}
}


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

using namespace std;

int main()
{
    string s,t;
    cin >> s;
    cin >> t;
    
    int cnt=0;
    if(s[0]==t[0]) cnt++;
    if(s[1]==t[1]) cnt++;
    if(s[2]==t[2]) cnt++;

    cout << cnt << endl;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
fund = 1/n
ans = 0
for i in range(1,n+1):
    if i >= k:
        ans += fund
    else:
        ii = i
        cond = 1
        temp = 0
        while cond:
            ii *= 2
            temp += 1
            if ii >= k:
                cond = 0
        ans += fund * ((1/2) ** temp)
print(ans)

Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
q=int(input())
s=sum(a)
data=[0]*10**5
for i in a:
  data[i-1]+=1
for i in range(q):
  b,c=map(int,input().split())
  s+=(c-b)*data[b-1]
  print(s)
  data[c-1]+=data[b-1]
  data[b-1]=0


Measured memory_bytes: 84852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 10010;

struct edge {
    int v;
    ll w;
    edge() {}
    edge(int v, ll w) : v(v), w(w) {};
};

vector<pii> dijkstra(int n, vector<vector<edge> >& G, int s) {
    vector<pii> d(n, pii(MAXN, MAXN)); d[s] = pii(0, s);
    priority_queue<pair<pii, int>, vector<pair<pii, int> >, greater<pair<pii, int> > > que;
    que.push(make_pair(d[s], s));
    while (!que.empty()) {
        auto p = que.top(); que.pop();
        int u = p.second;
        pii dist = p.first;
        if (dist > d[u]) continue;
        for (edge e : G[u]) {
            if (d[e.v] > pii(d[u].first+e.w, min(d[u].second, e.v))) {
                d[e.v] = pii(d[u].first+e.w, min(d[u].second, e.v));
                que.push(make_pair(d[e.v], e.v));
            }
        }
    }
    return d;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<vector<edge> > G(N+3);
    for (int i = 0; i < A; i++) {
        int a;
        cin >> a;
        a--;
        G[a].emplace_back(N, 0);
        G[N].emplace_back(a, 0);
    }
    for (int i = 0; i < B; i++) {
        int a;
        cin >> a;
        a--;
        G[a].emplace_back(N+1, 0);
        G[N+1].emplace_back(a, 0);
    }
    for (int i = 0; i < C; i++) {
        int a;
        cin >> a;
        a--;
        G[a].emplace_back(N+2, 0);
        G[N+2].emplace_back(a, 0);
    }
    int M;
    cin >> M;
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        G[x].emplace_back(y, 1);
        G[y].emplace_back(x, 1);
    }
    vector<vector<pii> > d(3);
    for (int i = 0; i < 3; i++) d[i] = dijkstra(N+3, G, N+i);
    pii ans(MAXN, MAXN);
    for (int i = 0; i < N; i++) {
        pii tmp;
        tmp.second = MAXN;
        for (int j = 0; j < 3; j++) {
            tmp.first += d[j][i].first;
            tmp.second = min(tmp.second, d[j][i].second);
        }
        ans = min(ans, tmp);
    }
    cout << ans.first << " " << ans.second+1 << endl;
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
ll H[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N) cin>>H[i];
	sort(H,H+N);
	
	ll mi=1LL<<30;
	FOR(i,N) {
		if(i+K-1<N) mi=min(mi,H[i+K-1]-H[i]);
	}
	cout<<mi<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>

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


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

    map<string, int> mp;
    rep(i,n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for (auto p : mp) mx = max(mx, p.second);
    for (auto p : mp) {
        if (p.second != mx) continue;
        cout << p.first << endl;
    }
    return 0;
}


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


int main(){
    int n;cin >> n;
    vector<long long int> a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    int cnt=0;
    while(1){
        int flag=1;
        for(int i=0;i<n;i++){
            if(a.at(i)%2==1) flag=0;
        }
        if(flag==0) break;
        else{
            for(int i=0;i<n;i++){
                a.at(i)/=2;
            } 
        }
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> h(n);
    REP(i,n){
        cin >> h[i];
    }
    ll ans = 0;
    sort(h.begin(),h.end());
    REP(i,n-k){
        ans += h[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
n,m=map(int,input().split())

P=[-1]*n

def find(x):
  if P[x]<0:
    return x
  P[x]=find(P[x])
  return P[x]

def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return

  if P[x]>P[y]:
    P[y]+=P[x]
    P[x]=y
  else:
    P[x]+=P[y]
    P[y]=x

def size(x):
  return -P[find(x)]

for i in range(m):
  a,b=map(int,input().split())
  unite(~-a,~-b)

print(-min(P))


Measured memory_bytes: 14528
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

enum {NONE, SQ, RD}; //last bracket (square or round)
bool solve(char *l){
  int idx=0;
  stack<int> st;
  while(true){
    switch(l[idx]){
    case '(':
      st.push(RD);
      break;
    case '[':
      st.push(SQ);
      break;
    case ')':
      if(st.empty() || st.top()!=RD) return false;
      else st.pop();
      break;
    case ']':
      if(st.empty() || st.top()!=SQ) return false;
      else st.pop();
      break;
    case '.':
      if(st.empty()) return true;
      else return false;
      break;
    }
    idx++;      
  }


}

int main(){
  while(true){
    char l[128];
    scanf("%[^\n]", l);
    if(l[0]=='.') break;
    getchar(); // read \n

    if(solve(l)) cout << "yes" << endl;
    else cout << "no" << endl;

  }

}

Measured memory_bytes: 1180
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include<fstream>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define f(n) for(int i=0;i<n;++i)
#define REP(i,n) for(long long i = 0;i < n;++i)
map<int, int> geko;
int main() {
	int n, m;
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		if (a > b) swap(a, b);
		if (a == 1) {
			geko[b] = (geko[b]|1);
		}
		if (b == n) {
			geko[a] = (geko[a] | 2);
		}
	}
	for (int i = 1;i <= n;++i) {
		if (geko[i] == 3) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>>g(n);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int>dist(n,-1);
    dist[0] = 0;
    queue<int>q;
    q.push(0);
    while(!q.empty()) {
        int v = q.front();q.pop();
        for(auto nv : g[v]) {
            if(dist[nv] == -1) {
                dist[nv] = dist[v]+1;
                q.push(nv);
            }
        }
    }
    if(dist[n-1] == 2) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 15964
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 
const int MAXN = 1e5 + 10 ; 
int n ;
vector<int> A(MAXN), B(MAXN), C(MAXN) ; 
int dp[MAXN][4] ; 
int dfs(int idx,int last){
	if ( idx == n ){
		return 0 ; 
	}
	int &res = dp[idx][last] ; 
	if ( res != -1 ) return res ; 
	int ans = 0 ; 
	if ( last != 1 ){
		ans = max(ans,A[idx] + dfs(idx+1,1) );  
	}
	if ( last != 2 ){
		ans = max(ans,B[idx] + dfs(idx+1,2) );  
	}
	if ( last != 3 ){
		ans = max(ans,C[idx] + dfs(idx+1,3) );  
	}
	return res = ans ; 
}
int main(){
    fastio
    memset(dp,-1,sizeof dp) ; 
    cin >> n ; 
    for(int i=0;i<n;i++){
    	cin >> A[i] >> B[i] >> C[i] ; 
    }
    cout << dfs(0,0) << endl;
    return 0 ;
}


Measured memory_bytes: 7680
using System;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] d = new int[n];

        string[] input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            d[i] = int.Parse(input[i]);
        }

        int sum = 0;
        for(int i = 0; i < n - 1; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                sum += d[i] * d[j];
            }
        }
        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
int n,k,a[111111],b[111111];
int ok=0,ng=LLONG_MAX;
bool solve(int x){
	int cnt=0;
	rep(i,n){
		if(x-a[i]>=0)cnt+=(x-a[i])/b[i]+1;
		if(cnt>=k)return false;
	}
	return true;
}
signed main(){
	cin>>n>>k;
	rep(i,n)cin>>a[i]>>b[i];
	while(ng-ok>1){
		int mid=ok+(ng-ok)/2;
		if(solve(mid))ok=mid;
		else ng=mid;
	}
	if(solve(ok-1)&&!solve(ok))cout<<ok<<endl;
	else if(solve(ok)&&!solve(ng))cout<<ng<<endl;
	else cout<<ng+1<<endl;
}


Measured memory_bytes: 1792
#include <cstdio>

int n,m,k;
int S[2000001],T[2000001],stk[2000001],top,tem[2000001],t;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=n;i;i--)scanf("%1d",S+i);
	for(int i=m;i;i--)scanf("%1d",T+i);
	if(n<m)n=m;
	stk[0]=0x7f7f7f7f;
	for(int i=n;i;i--){
		if(!(S[i]&&T[i])){
			if(S[i]||T[i])stk[++top]=i;
			continue; 
		}
		else{
			S[i]=T[i]=0;
			for(int j=k,pos=i+1;;){
				if(stk[top]>j+pos-1){
					stk[++top]=pos+j-1;
					S[pos+j-1]=T[pos+j-1]=1;
					break;
				}
				j-=(stk[top]-pos)+1;
				pos=stk[top];
				bool bb1=0,bb2=0;
				for(;!bb1||!bb2;++pos){
					if(S[pos]||T[pos])--top;
					if(!S[pos]&&!bb1)S[pos]=bb1=1;
					else if(!bb1)S[pos]=0;
					if(!T[pos]&&!bb2)T[pos]=bb2=1;
					else if(!bb2)T[pos]=0;
					if(S[pos]||T[pos])tem[++t]=pos;
				}
				if(!(S[pos-1]&&T[pos-1]))break;
				S[pos-1]=T[pos-1]=0;--t;
			}
			while(t)stk[++top]=tem[t--];
		}
	}
	int p=1;
	while(!S[stk[p]]&&p<=top)++p;
	for(int i=stk[p];i;i--)putchar(S[i]+'0');putchar('\n');
	p=1;
	while(!T[stk[p]]&&p<=top)++p;
	for(int i=stk[p];i;i--)putchar(T[i]+'0');putchar('\n');
}

Measured memory_bytes: 22528
#include <cstdio>
const int N = 2e5 + 5;
int n, m, k;
char s[N];
int a1[N], a2[N], cnt1, cnt2;
int main () {
	scanf ("%d%d%d%s", &n, &m, &k, s + 1);
	for (int i = 1; i <= n; i ++) {
		if (s[i] == 'o') {
			a1[++ cnt1] = i;
			i += k;
		}
	}
	cnt2 = m;
	for (int i = n; i >= 1; i --) {
		if (s[i] == 'o') {
			a2[cnt2 --] = i;
			i -= k;
			if (cnt2 == 0) break;
		}
	}
	for (int i = 1; i <= m; i ++)
		if (a1[i] == a2[i]) printf("%d\n", a1[i]);
}

Measured memory_bytes: 4956
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC159C - Maximum Volume

        Scanner sc = new Scanner(System.in);

        int l = sc.nextInt();

        double d1 = l / 3.0;

        System.out.println(d1 * d1 * d1);
    }
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
const int N=100001;
int main(){
  int n;
  pair<int,int>p[N];
  cin>>n;
  for(int i=0;i<n;i++)cin>>p[i].second>>p[i].first;
  sort(p,p+n);
  int ans=0,t=0;
  for(int i=0;i<n;i++){
    if(t<p[i].second){
      ans++;
      t=p[i].first;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3904
#include <stdio.h>
#include <string.h>

int main() {
    char N[3];
    scanf("%s", N);

    int flag=0;
    for (int i=0; i<=2; i++) {
        if(N[i]=='7') {
            flag=1;
            break;
        }
    }
    flag 
        ? printf("Yes\n") 
        : printf("No\n");
    return 0;
}

Measured memory_bytes: 1604
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

D = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for _ in range (D)]
M = 26
INF = 10**20

ans = [0]*D
lasts = [0]*(M+1)

for i in range(D):
    score = -INF
    contest = 0
    for m in range(1,M+1):
        cur = S[i][m-1]
        cur += C[m-1]*(i+1-lasts[m])
        if cur>score:
            score = cur
            contest = m
    ans[i] = contest
    lasts[contest] = i

for a in ans:
    print(a)

Measured memory_bytes: 68448
inputText1 = input()
# inputText1 = "8 3 4"
inputText1List = inputText1.split()
n = int(inputText1List[0])
b = int(inputText1List[1])
r = int(inputText1List[2])
count = 10 **100
if b == 0:
    print(b)
else:
    # i = (count // (b + r)) + 1 # 最大繰り返し数
    baseTextCount = b + r # 7
    i = n // baseTextCount
    mod = n % baseTextCount
    # print(i * b) # あまりを除いた青のボール数
    if mod < b:
        print(i * b + mod)
    else:
        print(i * b + b)


Measured memory_bytes: 3060
#include<iostream>  
#include<cstdio>  
using namespace std;  
  
int gcd(int a,int b)  
{  
    if(b==0) return a;  
    return gcd(b,a%b);  
}   
  
int lcm(int a,int b)  
{  
    return a/gcd(a,b)*b;  
}  
  
int main()  
{  
    int a,b;  
    while(cin>>a>>b) {  
        cout<<gcd(a,b)<<" "<<lcm(a,b)<<endl;  
    }  
    return 0;  
}  

Measured memory_bytes: 2980
a=input()
n=input()
C=[]
dic={}
for i in n:
    if i not in dic:
        dic[i]=1
    else:
        dic[i]+=1
c=A=0;
for i in n:
    if dic[i]>1:
        dic[i]-=1
        if i not in C:
            C.append(i)
            c+=1
            if c>A:A=c
    else:
        if i in C:
            c-=1
print(A)

Measured memory_bytes: 3064
use std::io;


/// https://beta.atcoder.jp/contests/agc003/tasks/agc003_a
fn main() {
    let s = read_one::<String>();
    let mut flg = true;
    if s.contains(&"N") { if !s.contains(&"S") { flg = false; }}
    if s.contains(&"S") { if !s.contains(&"N") { flg = false; }}
    if s.contains(&"W") { if !s.contains(&"E") { flg = false; }}
    if s.contains(&"E") { if !s.contains(&"W") { flg = false; }}
    if flg { println!("Yes"); }
    else { println!("No"); }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 4352
/* include {{{ */
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cinttypes>
#include <cfloat>

#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include <numeric>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <queue>
#include <utility>
#include <vector>
#include <tuple>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
/* }}} */
/* macro {{{ */
// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (i64 i = (a); i < (i64)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (i64 i = (a); i >= (i64)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
/* }}} */
/* using {{{ */
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using ui32 = std::uint_fast32_t;
using ui64 = std::uint_fast64_t;
using f32 = std::float_t;
using f64 = std::double_t;
template <class T> using vec = std::vector<T>;
template <class T> using heap = std::priority_queue<T>;
template <class T> using minheap = std::priority_queue<T, vec<T>, std::greater<T>>;
using vi = vec<i32>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = std::pair<i32, i32>;
/* }}} */
/* constexpr {{{ */
i32 constexpr INF = 1001001001;
i64 constexpr LINF = 1001001001001001001ll;
i32 constexpr MOD = (i32)1e9 + 7;
f64 constexpr EPS = 1e-9;
f64 constexpr PI = M_PI;
i32 constexpr dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* }}} */
/* function {{{ */
inline bool inside(i32 y, i32 x, i32 h, i32 w) { return y >= 0 && x >= 0 && y < h && x < w; }
template <class T> inline void pr(T const& x) { std::cout << x << '\n'; }
template <class T> inline void pr(vec<T> const& v, std::string d = "\n") { rep(i, v.size()) std::cout << v[i] << (i == (i64)(v.size() - 1) ? "\n" : d); }
template <class T, class... Args> inline void pr(T const& x, Args const&... trail) {
  std::cout << x << " ";
  print(trail...);
}
struct IO_PRE_ { IO_PRE_() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(12); } } pre__;
// clang-format on
/* }}} */

int main() {
  i32 a, b;
  std::cin >> a >> b;
  if (a + b == 15) {
    pr("+");
  } else if (a * b == 15) {
    pr("*");
  } else {
    pr("x");
  }
}


Measured memory_bytes: 256