akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int u = sc.nextInt() - 1;
		int v = sc.nextInt() - 1;
		ArrayList<Edge>[] g  = new ArrayList[n];
		for(int i = 0; i < n; i++){
		    g[i] = new ArrayList<Edge>();
		}
		for(int i = 0; i < n-1; i++){
		    int a = sc.nextInt() - 1;
		    int b = sc.nextInt() - 1;
		    g[a].add(new Edge(a, b, 1));
		    g[b].add(new Edge(b, a, 1));
		}
		
		// 計算
		int result = 0;
		if(u == v){
		    System.out.println(result);
		    return;
		}
		if(g[u].size() == 1 && g[u].get(0).to == v){
		    System.out.println(result);
		    return;
		}
		PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
		int[] distV = new int[n];
		int[] visitedV = new int[n];
		pq.add(v);
		visitedV[v] = 1;
		while(!pq.isEmpty()){
		    int from = pq.poll();
		    for(Edge e : g[from]){
		        int to = e.to;
		        if(visitedV[to] == 1) continue;
		        visitedV[to] = 1;
		        distV[to] =  distV[from] + 1;
		        pq.add(to);
		    }
		}
		int[] distU = new int[n];
		Arrays.fill(distU, -1);
		distU[u] = 0;
		int[] visitedU = new int[n];
		pq.add(u);
		visitedU[u] = 1;
		while(!pq.isEmpty()){
		    int from = pq.poll();
		    for(Edge e : g[from]){
		        int to = e.to;
		        if(visitedU[to] == 1) continue;
		        visitedU[to] = 1;
		        if(to != v){
		            distU[to] =  distU[from] + 1;
		            pq.add(to);
		        }
		    }
		}
		int max = 0;
		for(int i = 0; i < n; i++){
		    if(distU[i] != -1 && distU[i] < distV[i]){
		        max = max(max, distV[i]);
		    }
		}
		result = max - 1;
		
		// 出力
		System.out.println(result);
	}
}

class Edge {
    int from;
    int to;
    int weight;
    
    Edge(int from, int to, int weight){
        this.from = from;
        this.to = to;
        this.weight = weight;
    }

    public String toString(){
        return "from:" + from + " to:" + to + " weight:" + weight;
    }   
}



Measured memory_bytes: 104716
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,m,i,j,a[5005],b[5005][205],l[5005],r[5005],top,zhan[5005],cf[5005][5005],max1;
void cz(long long u,long long v,long long x,long long y,long long z){
	cf[u][x]+=z;
	cf[u][y+1]-=z;
	cf[v+1][x]-=z;
	cf[v+1][y+1]+=z;
	return;
}
long long maxx(long long u,long long v){
	return u>v?u:v;
}
int main(){
	n=read();m=read();
	for(i=2;i<=n;i++)
		a[i]=a[i-1]+read();
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			b[i][j]=read();
	for(j=1;j<=m;j++){
		top=0;
		zhan[top]=0;
		for(i=1;i<=n;i++){
			while(b[i][j]>b[zhan[top]][j]&&top!=0)
				top--;
			l[i]=zhan[top]+1;
			top++;
			zhan[top]=i;
		}
		top=0;
		zhan[top]=n+1;
		for(i=n;i>=1;i--){
			while(b[i][j]>=b[zhan[top]][j]&&top!=0)
				top--;
			r[i]=zhan[top]-1;
			top++;
			zhan[top]=i;
		}
		for(i=1;i<=n;i++)
			cz(l[i],i,i,r[i],b[i][j]);
	}
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			cf[i][j]+=cf[i-1][j]+cf[i][j-1]-cf[i-1][j-1];
    for(i=1;i<=n;i++)
    	for(j=i;j<=n;j++)
    		max1=maxx(max1,cf[i][j]-(a[j]-a[i]));
    pus(max1,2);
    return 0;
}

Measured memory_bytes: 204032
#include <iostream>

using namespace std;

int main(void){

  int W,H;

  while(1){
   
  cin >> H >> W;

  if(H == 0) break;

  for(int i=0; i<H; i++){
     for(int j=0; j<W; j++){
        if(!(i == 0 || i == (H -1) || j == 0 || j == (W -1)))
          cout <<  ".";
        else 
          cout << "#";
     }
     cout << endl;
   }
   cout << endl;

  }
  

  return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int cnt = 0;
    int ans = S.length();
    rep(i, S.length()) {
        if (S[i] == 'S') cnt++;
        else if (cnt > 0) {
            cnt--;
            ans -= 2;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

int main(){
	int n;
	cin >> n;
	int sum = 0;
	int max = 0;
	REP(i,n){
		int l;
		cin >> l;
		if(max<l) max = l;
		sum+=l;
	}
	if(sum>2*max){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
def solve(a, b, c):
    if (b - a + 1 < c):
        c = b - a + 1
    d = list(range(a, a+c))
    e = list(range(b-c+1,b+1))
    f = d+e
    g = list(set(f))
    g.sort()
    h = list(map(str, g))
    return h

a, b, c = map(int, input().split())

ans = solve(a, b, c)

print("\n".join(ans) + "\n")


Measured memory_bytes: 3060
function Main(input: string) {
  const lines = input.split('\n');
  const length = lines[0].length;
  let result = length != 0;
  let i = 0;
  while (i < length) {
    if (lines[0].charAt(i) !== 'h' || lines[0].charAt(i + 1) !== 'i') {
      result = false;
      break;
    }
    i += 2;
  }
  console.log(result ? 'Yes' : 'No')
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
n = gets.to_i
a = gets.split.map(&:to_i)
money = 1000
stock = 0
n.times do |idx|
  current = a[idx]
  if idx.zero?
    if a[idx+1] > current
      stock, money = money.divmod(current)
    end
  elsif idx == n - 1
    money += stock * current
    stock = 0
  else
    if a[idx+1] < current
      money += stock * current
      stock = 0
    elsif a[idx+1] > current && money >= current
      stock, money = money.divmod(current)
    end
  end
end
puts money

Measured memory_bytes: 14272
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int, int>;

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  string ans="No";
  if (abs(a-c)<=d) {ans="Yes";}
  if (abs(a-b)<=d && abs(b-c)<=d) {ans="Yes";}
  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i=0; i<n; i++) {
    cin >> p[i];
  }

  int max = 0;
  int sum = 0;
  for (int i=0; i<n; i++) {
    if (p[i] > max) {
      max = p[i];
    }
    sum += p[i];
  }

  sum = sum - max / 2;

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
from itertools import accumulate

N = int(input())
As = list(map(int, input().split()))
acc = list(accumulate(As))

# 偶数が正
ans = 0
cnt = 0 #累積カウント
parity = [1,-1]
for i,a in enumerate(acc):
    a += cnt
    p = parity[i%2]
    if p * a > 0:
        continue
    else:
        ans += abs(a)+1
        cnt += p*(abs(a)+1)

# 偶数が負
ans2 = 0
cnt = 0 #累積カウント
parity = [-1,1]
for i,a in enumerate(acc):
    a += cnt
    p = parity[i%2]
    if p * a > 0:
        continue
    else:
        ans2 += abs(a)+1
        cnt += p*(abs(a)+1)

print(min(ans,ans2))


Measured memory_bytes: 14212
// Choose Integers
#include <cmath>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int s = -1;
    bool can = A % B == C;
    for (int i = 1; (A * i) % B != s; i++) {
        if (i == 1) {
            s = A % B;
            continue;
        }
        if ((A * i) % B == C) can = true;
    }
    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<i64>();
    let h = (0..n).map(|_| input()).collect::<Vec<i64>>();

    let mut ans = 0;
    let mut hh = vec![0; n as usize];
    loop {
        let mut l = -1;
        let mut r = -1;
        for i in 0..n {
            if l < 0 && hh[i as usize] < h[i as usize] {
                l = i;
                r = i;
            } else if l < 0 {
                continue;
            } else if l >= 0 && hh[i as usize] < h[i as usize] {
                r += 1;
            } else {
                break;
            }
        }

        if l == -1 {
            break;
        }

        if r >= n {
            r = r - 1;
        }
        ans += 1;
        for i in l..r + 1 {
            hh[i as usize] += 1;
        }
    }

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


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

const string name = "JOI";
char field[1010][1010];
char mark[2][2];
int N, M;

bool check(int sx, int sy){
  for(int i = 0 ; i < 2 ; i++){
    for(int j = 0 ; j < 2 ; j++){
      if(field[sy+i][sx+j] != mark[i][j]) return false;
    }
  }
  return true;
}

int diff(int x, int y, char c){
  int curr = 0, nex = 0;
  for(int i = y-1 ; i <= y ; i++){
    for(int j = x-1 ; j <= x ; j++){
      if(check(j, i)) curr++;
    }
  }
  
  char org = field[y][x];
  field[y][x] = c;
  
  for(int i = y-1 ; i <= y ; i++){
    for(int j = x-1 ; j <= x ; j++){
      if(check(j, i)) nex++;
    }
  }
  
  field[y][x] = org;
  
  return nex - curr;
}

int solve(){
 int ini = 0;
  
  for(int y = 0 ; y < N-1 ; y++)
    for(int x = 0 ; x < M-1 ; x++) if(check(x, y)) ini++;      
  
  int ans = ini;
  
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < M ; j++){
      for(int k = 0 ; k < 3 ; k++){
	if(field[i][j] == name[k]) continue;
	
	int d = diff(j, i, name[k]);
	if(d == 4) return ini + d;
	ans = max(ans, ini + d);	
      }
    }
  }
  return ans;
}

int main(){
  
  cin >> N >> M;
  
  for(int i = 0 ; i < N ; i++)
    for(int j = 0 ; j < M ; j++) cin >> field[i][j];
  
  for(int i = 0 ; i < 2 ; i++)
    for(int j = 0 ; j < 2 ; j++) cin >> mark[i][j];
  
  cout << solve() << endl;
  
  return 0;
}

Measured memory_bytes: 2188
#include <cstdio>
#include <cmath>


int main()
{
    int A, B, X;

    scanf("%d %d %d", &A, &B, &X);

    const double a = (double)A;
    const double b = (double)B;
    const double axb = a * b;

    double diff = 10000;

    double m = (double)X / A;
    double min = 0.0f;
    double max = a;

    bool moveB = false;
    double mid;
    if ((axb / 2.0) < m)
    {
        moveB = true;
        // b を移動(空き部分を計算)
        max = b;
        mid = max / 2.0;

        while (diff >= 0.00000000001)
        {
            double preMid = mid;
            if (m < (axb - a * (b - mid) / 2.0))
            {
                // 溢れる
                max = mid;
                mid = mid - (max - min) / 2.0;
            }
            else {
                // 溢れない bに近づける
                min = mid;
                mid = mid + (max - min) / 2.0;
            }
            diff = std::abs(mid - preMid);
        }
    }
    else
    {
        mid = max / 2.0;
        while (diff >= 0.00000000001)
        {
            double preMid = mid;
            if (m > (b * (a - mid) / 2.0))
            {
                // 溢れる
                max = mid;
                mid = mid - (max - min) / 2.0;
            }
            else {
                // 溢れない bに近づける
                min = mid;
                mid = mid + (max - min) / 2.0;
            }
            diff = std::abs(mid - preMid);
        }
    }

    printf("%f\n", std::atan((moveB ? (b - mid) / a : b / (a - mid))) / (3.141592653589) * 180);

    return 0;
}


Measured memory_bytes: 256
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	ll l, r;
	cin >> l >> r;
	if (r - l >= 2018){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 2019;
	for (int i = l; i <= r; i++){
		for (int j = l; j < i; j++){
			ll a = i % 2019;
			ll b = j % 2019;
			ll c = a * b;
			c %= 2019;
			ans = min(ans, c);
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int hp0, hpMax;
	int w, h;
	char[][] map;
	int nDamages;
	HashMap<Character, Integer> damages;
	int nDirections;
	LinkedList<P> directions;
	int nPostions;
	int[] potions;

	class P{
		int x, y;

		P(int x, int y){
			this.x=x;
			this.y=y;
		}
	}

	void run(){
		for(;;){
			hp0=sc.nextInt();
			hpMax=sc.nextInt();
			if((hp0|hpMax)==0){
				break;
			}
			h=sc.nextInt();
			w=sc.nextInt();
			map=new char[h][w];
			for(int j=0; j<h; j++){
				String s=sc.next();
				for(int i=0; i<w; i++){
					map[j][i]=s.charAt(i);
				}
			}
			nDamages=sc.nextInt();
			damages=new HashMap<Character, Integer>();
			for(int i=0; i<nDamages; i++){
				char c=sc.next().charAt(0);
				int d=sc.nextInt();
				damages.put(c, d);
			}
			nDirections=sc.nextInt();
			directions=new LinkedList<P>();
			for(int i=0; i<nDirections; i++){
				char c=sc.next().charAt(0);
				int dx=0, dy=0;
				switch(c){
				case 'U':
					dy=-1;
					break;
				case 'D':
					dy=1;
					break;
				case 'L':
					dx=-1;
					break;
				case 'R':
					dx=1;
					break;
				}
				for(int k=sc.nextInt(); k>0; k--){
					directions.addLast(new P(dx, dy));
				}
			}
			nDirections=directions.size();
			nPostions=sc.nextInt();
			potions=new int[nPostions];
			for(int i=0; i<nPostions; i++){
				potions[i]=sc.nextInt();
			}
			solve();
		}
	}

	void solve(){
		int x=0, y=0;
		// dir, S
		// 0:ツ使ツづづつ「ツづ按つ「
		// 1:ツ使ツづつス
		int[][] dp;
		dp=new int[nDirections+1][1<<nPostions];
		dp[0][0]=hp0;

		debug(dp[0]);

		for(int i=0; i<=nDirections; i++){
			int damage=damages.get(map[y][x]);
			for(int s=0; s<1<<nPostions; s++){
				if(dp[i][s]<=0){
					continue;
				}
				for(int t=0; t<nPostions; t++){
					// s|tツづーツ更ツ新
					if((s>>t&1)==0){
						int hp=Math.min(hpMax, dp[i][s]+potions[t]);
						int u=1<<t;
						dp[i][s|u]=Math.max(dp[i][s|u], hp);
					}
				}
			}
			for(int s=0; s<1<<nPostions; s++){
				dp[i][s]-=damage;
			}
			if(i==nDirections){
				break;
			}

			debug("i", i, dp[i]);
			debug("");
			System.arraycopy(dp[i], 0, dp[i+1], 0, 1<<nPostions);

			P p=directions.get(i);
			x+=p.x;
			y+=p.y;
		}
		boolean f=false;
		for(int i=0; i<1<<nPostions; i++){
			if(dp[nDirections][i]>0){
				f=true;
			}
		}
		println(f?"YES":"NO");
	}

	void debug(Object... os){
	// System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		try{
			// System.setIn(new FileInputStream("in.txt"));
		}catch(Throwable e){
			e.printStackTrace();
		}
		new Main().run();
	}
}

Measured memory_bytes: 36000
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
typedef pair<int,int> pii;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

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

void solve(){

    int n;
    cin >> n;

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

    int a[n+1];
    if(n>1)a[n] = b[n-1];
    else a[n] = b[1];
    a[1] = b[1]; 

    for(int i = 1;i<n-1;i++){
        a[i+1] = min(b[i],b[i+1]);
    }
    int ans = 0;
    for(int i = 1;i<=n;i++)ans+=a[i];

        cout << ans << endl;
} 

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 256
s = input()
n = len(s)
ans = n // 2
if n % 2 == 0:
    ans = n // 2
    for i in range(n // 2):
        if s[n // 2 - (i + 1)] != s[n // 2 + i]:
            break
        else:
            if s[n // 2 + i] == s[n // 2 + (i - 1)]:
                ans += 1
            else:
                break
else:
    ans += 1
    k = s[n // 2]
    for i in range(n // 2):
        if s[n // 2 - (i + 1)] != s[n // 2 + (i + 1)]:
            break
        else:
            if s[n // 2 + (i + 1)] == s[n // 2 + i]:
                ans += 1
            else:
                break
print(ans)

Measured memory_bytes: 3188
N = int(input())
A = [int(_) for _ in input().split()]


class BIT:
    # index 1~
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


M = N * (N + 1) // 2  # (N+1)C2
sorted_A = sorted(A)

inf = 0
sup = max(A) + 1
while sup - inf > 1:
    x = (sup + inf) // 2

    S = [0] * (N + 1)
    for i in range(N):
        if A[i] >= x:
            S[i + 1] = S[i] + 1
        else:
            S[i + 1] = S[i] - 1

    min_value = min(S)
    for i in range(N + 1):
        S[i] += abs(min_value) + 1

    forward = 0
    bit = BIT(max(S))
    for s in S:
        forward += bit.sum(s)
        bit.add(s, 1)

    if forward >= (M + 1) // 2:
        inf = x
    else:
        sup = x

for a in reversed(sorted_A):
    if inf >= a:
        print(a)
        break


Measured memory_bytes: 108388
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int n,x[200001],y[200001]; cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i];
        y[i]=x[i];
    }
    sort(x,x+n);
    int a=x[n/2-1],b=x[n/2]; //a<b
    for(int i=0;i<n;i++){
        if(y[i]>a){
            cout<<a<<endl;
        }else{
            cout<<b<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;

	int x = a + b;

	if (x % 2 == 0) {
		cout << x / 2;
	}
	else {
		cout << x / 2 + 1;
	}
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define Mod 1000000007
typedef long long int ll;
int main()
{
  string s,t;
  cin>>s>>t;
  map<int,vector<int> > cnt;
  int i,j;
  for(i=0;i<s.length();i++)
  {
      cnt[s[i]-'a'].push_back(i);
  }
  ll ans=0;

  int y;
  if(cnt[t[0]-'a'].size()==0)
  {
      cout<<"-1";
  }
  else
  {
      y=cnt[t[0]-'a'][0];
      ans+=(y+1);

  int u=0;
  int n=s.length();
  for(i=1;i<t.length();i++)
  {
      int ok=-1;
      if(cnt[t[i]-'a'].size()==0)
      {
          u=1;
          break;
      }
      else
      {
      int lo=0,hi=cnt[t[i]-'a'].size()-1;

      while(lo<=hi)
      {
          int mid=(lo+hi)/2;
          if(cnt[t[i]-'a'][mid]>y)
          {
              ok=cnt[t[i]-'a'][mid];
              hi=mid-1;
          }
          else
          {
              lo=mid+1;
          }
      }

      if(ok==-1)
      {
          ans-=(y+1);
          ans+=n;
          ans+=(cnt[t[i]-'a'][0]+1);
          y=cnt[t[i]-'a'][0];
      }
      else
      {
          ans-=(y+1);
          ans+=(ok+1);
          y=ok;
      }
      }
  }
  if(u==1)
    cout<<"-1";
  else
    cout<<ans;
    }
}


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

int main() {
    string S;
    int K;

    cin >> S;
    cin >> K;

    string ans;

    int flg = 1;
    int cnt = 0;
    for (int i = 0; i < K; i++){
        if (flg) {
            if (S[i] != '1'){
                flg = 0;
            }
            cnt += 1;
        }
    }

    if (flg){
        ans = S[0];
    } else {
        ans = S[cnt - 1];
    }

    if (K==1){
        ans = S[0];
    } 
    else if (S.size() == 1){
        ans = S[0];
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int INF=0x3f3f3f3f;
ll a[200050];
void solve(int T){
	int n;
	ll ans=0,now=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	now=a[1];
	for(int i=2;i<=n;i++){
		if(a[i]<now)ans+=now-a[i];
		else now=a[i];
	}
	printf("%lld",ans);
}
signed main(){
	int t=1;
	//scanf("%d",&t);
	for(int i=1;i<=t;i++){
		solve(i);
	}
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

ll mod = 1000000007;

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

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}

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

  string s;
  int sum = 0;
  cin >> s;
  rep(i,s.length()){
    sum += s[i] - '0';
  }
  if(sum % 9 == 0)cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
  ll n,ans=0;
  cin>>n;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    while(a[i]%2==0){
      a[i]/=2;
      ans++;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

const int VMAX = 5000;
const int INF = 1e7;

int V;
vector<int> G[VMAX];
int match[VMAX];
bool used[VMAX];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  for (auto u : G[v]) {
    int w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  REP (v, V) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) {
        res++;
      }
    }
  }
  return res;
}

int gcd(int a, int b) {
  return (b == 0 ? a : gcd(b, a % b));
}

bool pickable(int b, int r) {
  return gcd(b, r) > 1;
}

const int MMAX = 600, NMAX = 600;

int m, n;
int blues[MMAX], reds[NMAX];

int blue_idx(int i) {
  return i;
}

int red_idx(int i) {
  return m + i + 10;
}

void init(int v) {
  REP(i, v) {
    G[i].clear();
  }

  memset(match, -1, sizeof(match));
  memset(used, 0, sizeof(used));
}

int main() {
  while (cin >> m >> n and m) {
    init(m + n + 100);
    REP(i, m) {
      cin >> blues[i];
    }

    REP(i, n) {
      cin >> reds[i];
    }

    REP(b, m) REP(r, n) {
      if (pickable(blues[b], reds[r])) {
        add_edge(blue_idx(b), red_idx(r));
      }
    }

    V = m + n + 100;

    cout << bipartite_matching() << endl;
  }
}

Measured memory_bytes: 3368
import std.stdio, std.container, std.typecons;

struct User {
  int id;
  int value;
  int opCmp(ref User u) {
    if (this.value == u.value) return (u.id - this.id);
    return this.value - u.value;
  }
}

void main() {
  User[int] sum;
  int users, events;
  auto h = heapify(Array!User());
  readf("%d %d\n", &users, &events);
  foreach(t; 0..events) {
    int id, event;
    readf("%d %d\n", &id, &event);
    if (!(id in sum)) {sum[id] = User(id, 0);}
    sum[id].value += event;
    h.insert(sum[id]);
    
    while(true) {
      User u = h.front;
      if (sum[u.id].value == u.value) break;
      h.removeFront;
    }
  writeln(h.front.id, " ", h.front.value);
  }
}

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

#define ll long long
#define vecint vector<int>
#define listint list<int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define MOD 1000000007;


int main(){
  char c;
  char list[]={'a','i','u','e','o'};
  cin >> c;
  string ans="consonant";
  rep(i,5){
    if(list[i]==c) ans="vowel";
  }
  print(ans);
  return 0;
}


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

int main()
{
	int n,m;
	cin>>n>>m;
	int num=0;
	if(n%2==0) n--;	//可以都转变成奇数构造，因为m <= (n-1)/2;
	for(int i=1;i<=n/4&&num<m;i++){		//前一半
		cout<<i<<" "<<n/2-i+1<<"\n";
		num++;
	}
	for(int i=n/2+1,j=0;num<m;i++,j++){		//后一半，题目保证m是合法的，所以可以直接num < m
		cout<<i<<" "<<n-j<<"\n";
		num++;
	}
	return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  string S,T,U;
  cin>>S>>T>>U;
  char x='A'-'a';
  char s=S[0]+x;
  char t=T[0]+x;
  char u=U[0]+x;
  
  cout<<s<<t<<u;
return 0;}

Measured memory_bytes: 3600
import java.util.Scanner

object Main {
  def solve(N: Int, T: Array[Long], A: Array[Long]): Long = {
    // leastFeasibleMultiple
    def lfm(factor: Long, n: Long): Long = {
      if (n % factor == 0) n / factor
      else n / factor + 1
    }

    def step(i: Int, dT: Long, dA: Long): Long = i match {
      case N => dT + dA
      case _ =>
        // dT(i + 1) >= dT(i) && dA(i + 1) >= dA(i) && dT(i + 1) が T(i) の倍数 && dA(i + 1) が A(i)　の倍数
        // これらの条件を満たすには・・・・・説明むずい
        val multiple = math.max(lfm(T(i), dT), lfm(A(i), dA))
        step(i + 1, T(i) * multiple, A(i) * multiple)
    }

    step(0, 1, 1)
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val T = Array.ofDim[Long](N)
    val A = Array.ofDim[Long](N)
    (0 until N) foreach { i =>
      T(i) = sc.nextLong()
      A(i) = sc.nextLong()
    }
    System.out.println(solve(N, T, A))
  }
}


Measured memory_bytes: 28756
#include <stdio.h>

int main(){
	int i;
	double s[10],sum;
	while(scanf("%lf",&s[0]) != EOF){
		sum = s[0];
		for(i = 1;i < 10;i++){
			if(i % 2) s[i] = s[i - 1] * 2;
			else s[i] = s[i - 1] / 3;
			sum += s[i];
		}
		printf("%f\n",sum);
	}
	return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
	int n;
	int count[114514]={0};
	cin >> n;

	int t;
	for(int i=0; i<n; i++){
		cin >> t;
		count[t]++;
	}

	bool f=true;
	if(n%2){
		if(count[0] != 1){
			f=false;
		}
		for(int i=2; i<=n-1; i+=2){
			if(count[i] != 2){
				f=false;
			}
		}
	}

	else{
		for(int i=1; i<n; i+=2){
			if(count[i] != 2){
				f=false;
			}
		}
	}


	if(f == false){
		cout << "0" << endl;
	}
	else{
		int res=1;
		for(int i=0; i<n/2; i++){
			res = (res*2)%1000000007;
		}
		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 1e7+5;
int prime[maxn]={0};
int temp[maxn]={0};
void getprim(int n){
    prime[1]=1;
    long long num = 0;
    for(long long i=2;i<=n;i++){
        if(!prime[i]){
            num = i;
            while(num<=n){
                for(long long j=num;j<=n;j+=num){
                    ++temp[j];
                    //cout << j <<endl;
                }
                num = num*i;
            }
            for(long long j=i;j<=n;j+=i){
                if(prime[j]==0)
                    prime[j]=temp[j]+1;
                else
                    prime[j]*=(temp[j]+1);
                temp[j]=0;
            }

        }
    }
}
int main()
{
    int n;
    cin >> n;
    getprim(n);
    /*
    for(int i=1;i<=n;i++){
        int num = 0;
        int num2 = i;
        int num3;
        for(int j=1;j*j<=num2;j++){
            if(num2%j==0){
                num+=2;
                if(num2/j==j)
                    num--;
            }
        }
        if(num!=prime[i]){
            cout << i << " " << num << " " << prime[i] << endl;
        }
    }*/
    long long sum = 0 ;
    for(int i=1;i<=n;++i)
        sum = sum + 1ll*i*(prime[i]);
    cout << sum <<endl;
    return 0;
}


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


int main() {
  int A, B, C;
  int64_t K;
  cin >> A >> B >> C >> K;
  if (K % 2 == 1){
    cout << B - A << endl;
  }
  else{
    cout << A - B << endl;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
# include <bits/stdc++.h>
using namespace std;
long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define scl(x)         ll x;       scanf("%lld", &x);
#define scll(x, y)     ll x, y;    scanf("%lld %lld", &x, &y);
#define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
int main()
{
  
  int flag=1;
  ll sum=0;
  int flag1=0;
  ll tot=0;
  
  map<int,int>m;
  vector<string>v;
  vector<string>v1;

  multiset<string>st;
  multiset<string>st2;
  string s;
  cin>>s;
 
  int b=0;
  rep(i,0,s.size()-1)
  {
    if(s[i]=='B') b++;
    else {
     
      tot+=b;
  }
}

  cout<<tot;
    return 0;
  
  
}

Measured memory_bytes: 640
def array_integer(a)
	0.upto(a.count) {|x|
		a[x] = a[x].to_i
	}
	return a
end

length = STDIN.gets.chomp.to_i
array = array_integer(STDIN.gets.chomp.split(' '))
array = array[0..length-1]

0.upto(length - 2) {|i|
	print array[i], " "
}
print array[length-1], "\n"
	
1.upto(length - 1) {|i|
	v = array[i]
	j = i - 1
	while j >= 0 && array[j] > v do
		array[j+1] = array[j]
		j -= 1
	end
	array[j+1] = v
	0.upto(length - 2) {|i|
		print array[i], " "
	}
	print array[length-1], "\n"
}


Measured memory_bytes: 8892
/*
 * FileName:     D_model
 * CreatedDate:  2020-06-28 10:07:57 +0900
 * LastModified: 2020-06-28 10:08:08 +0900
 */


#include<stdio.h>
int main(){
	long long n;
	scanf("%lld\n",&n);
	int ans=0;
	for(long long i=2;i*i<=n;i++)if(n%i==0){
		int cnt=0;
		while(n%i==0)n/=i,cnt++;
		for(int j=1;j<=cnt;j++){
			cnt-=j;
			ans++;
		}
	}
	if(n!=1)ans++;
	printf("%d\n",ans);
}


Measured memory_bytes: 1728
use std::io;

fn main() {
    let input_n = input();
    let input_a = input();
    let n: i32 = input_n.parse().unwrap();
    let a: i32 = input_a.parse().unwrap();

    let modulo = n % 500;
    if modulo <= a {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn input() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input.as_str().split_whitespace().collect()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	double d,t,s;
	cin>>d>>t>>s;
	if(d/s>t)
	{
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	
}


Measured memory_bytes: 3712
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    if (n<=1){
        cout << "Are You Joking !!!";
        return 0;
    }
    int num[n];
    for (int i=0;i<n;i++){
        cin>> num[i];
    }
    int swaps=0;
    for (int i=0;i<n;i++){
        if (num[i]==i+1){
            int temp;
            temp=num[i];
            num[i]=num[i+1];
            num[i+1]=temp;
            swaps++;
        }
    }
    cout << swaps;
}

Measured memory_bytes: 640
// mitsui_sumitomo_2019_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int X;
    cin >> X;

    int n = 100000;
    vector<int> s{100, 101, 102, 103, 104, 105};

    vector<bool> dp(n+1);
    dp[0] = true;
    REP(i, 6){
        REPN(j, s[i], n+1){
            dp[j] = dp[j] | dp[j-s[i]];
        }
    }

    if (dp[X]){
        print("1");
    } else {
        print("0");
    }


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;

const int maxn = 1e5 + 10;
const long long inf = 0x7fffffffffffffff;

struct Edge {
	int to;
	long long len;
	Edge(int to, long long len) : to(to), len(len) {}
	bool operator < (const Edge &r) const
	{
		return len > r.len;
	}
};

vector<Edge> edge[maxn];
int n;
long long dist[maxn];

void dij(int k)
{
	bool vis[maxn] = {};
	for (int i = 0; i <= n; i++)
		dist[i] = inf;
	priority_queue<Edge> que;
	
	dist[k] = 0;
	que.push(Edge(k, 0));

	while (!que.empty()) {
		Edge tmp = que.top();
		que.pop();
		int u = tmp.to;
		if (vis[u])
			continue;
		vis[u] = true;
		for (int i = 0; i < edge[u].size(); i++) {
			int to = edge[u][i].to;
			long long len = edge[u][i].len;
			if (!vis[to] && dist[to] > dist[u] + len) {
				dist[to] = dist[u] + len;
				que.push(Edge(to, dist[to]));
			}
		}
	}

}

int main(void)
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		edge[a].push_back(Edge(b, c));
		edge[b].push_back(Edge(a, c));
	}
	int q, k;
	scanf("%d %d", &q, &k);
	dij(k);
	for (int i = 0; i < q; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		printf("%lld\n", dist[a] + dist[b]);
	}
	return 0;
}

Measured memory_bytes: 11248
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 998244353;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
const int biggg = 2000000000;
const long long bigggest = 1000000000000000000LL;
const double eps = .0000000001; 

int main ()
{
  prep();
  int a, b;
  cin >> a >> b;
  for (int i=0; i<=3000; i++){
      if ((i*8)/100 == a && (i*10)/100 == b){
          cout << i;
          return 0;
      }
  }
  cout << -1;
  return 0;
}

Measured memory_bytes: 256
# ハッシュで数えてキーでソートして+-1を全探索
# と思ったけど登場してないやつでもいける 3 5 なら4が2個になるのでN個から全探索

n = int(input())
arr = list(map(int, input().split()))
lis = [0 for _ in range(10**5+1)]
hash = dict()
for a in arr:
    lis[a] += 1

ans = 1
for i in range(1, 10**5):
    ans = max(ans, lis[i-1]+lis[i]+lis[i+1])

print(ans)


Measured memory_bytes: 56132
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  int ans_w = 1, ans_s = 0;
  for (int i = 0; i <= f/(100*a); ++i) {
    for (int j = 0; j <= (f-100*a*i)/(100*b); ++j) {
      if (i == 0 && j == 0) continue;
      int water = 100*a*i + 100*b*j;
      int fr = f - water;
      int a_sugar = min(water / 100 * e, fr);
      for (int k = 0; k <= a_sugar/c; ++k) {
        int sugar = k*c;
        sugar += (a_sugar - sugar) / d * d;
        if (ans_s * 1.0 / (ans_s + ans_w) <= sugar * 1.0 / (sugar + water)) {
          ans_s = sugar;
          ans_w = water;
        }
      }
    }
  }
  cout << ans_w + ans_s << " " << ans_s << endl;
  return 0;
}


Measured memory_bytes: 256
#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 Would
#define you
#define please

int main() {

	int N, K;
	cin >> N >> K;

	int A[200000] = {};
	int kosuu = 0;
	
	rep(i, N) {
		int a;
		cin >> a;
		if (A[a] == 0) kosuu++;
		A[a]++;
	}
	sort(A, A + 200000);

	int kotae = 0;
	for (int i = 200000 - kosuu; i < 200000 - K; i++) {
		kotae += A[i];
	}
	
	co(kotae);

	Would you please return 0;
}

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

int main()
{
int i;
int A;
int B;
int C;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> A;
	cin >> B;
	cin >> C;

	B /= A;
	if( B > C ) B = C;

	cout << B << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;

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

//--------------------

ll N;
vector<ll> A;
map<ll, ll> M;

int main() {

  cin >> N;
  A.resize(N);
  rep(i, N) {
    cin >> A[i];
    ++M[A[i]];
  }

  ll res = 0;
  for(auto it : M) res += it.second*(it.second-1)/2;

  ll val, before, after;
  rep(i, N) {
    val = M[A[i]];
    before = val*(val-1)/2;
    after = (val-1)*(val-2)/2;
    cout << res - before + after << endl;
  }

  return 0;
}


Measured memory_bytes: 11008
#include  <bits/stdc++.h> 
using namespace std;
 
#define ll long long
#define ar array
#define pii pair<int,int>
#define mp make_pair
 
const ll INF = 1e18;
const ll mod = 1000000007;
const int mxn=10e6;

bool comp(pii a,pii b){
	return a.first<b.first;
}

void solve(){
	int n;cin>>n;
	int streak=0;
	for (int i = 0; i < n; ++i)
	{
		ll x,y;cin>>x>>y;
		if (x==y)
		{
			++streak;
			if (streak>=3)
			{
				cout<<"Yes"<<endl;return;
			}
		}else{
			streak=0;
		}
	}
	cout<<"No"<<endl;
}
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	// int t;
	// cin>>t;
	// while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 3540
#[allow(unused)]
use std::io::*;
#[allow(unused)]
use std::str::*;
#[allow(unused)]
use std::collections::*;

pub fn read_from<T: FromStr, R: Read>(s: &mut R) -> T {
    let s = s.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    if s.is_empty() {
        if cfg!(local) {
            // eprintln!("reached to EOF");
        }
        std::process::exit(0)
    }
    if let Ok(s) = s.parse::<T>() {
        s
    } else {
        panic!("faild to parse {}", s);
    }
}

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    read_from(&mut stdin)
}

pub const MOD: u64 = 1000000007;

fn main() {
    let t = read();
    match t {
        1 => println!("Hello World"),
        2 => {
            let a: u32 = read();
            let b: u32 = read();
            println!("{}", a + b)
        }
        _ => panic!(),
    }
}


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

using namespace std;

#define llong long long 
#define ii pair<int, int>
#define xx first
#define yy second
#define rep(i,n) for (int i = -1; ++i < n; )
#define sz(v) ((int)v.size())

#define maxn 101010
#define rem ((llong)1e9 + 7)

llong ppow(llong b, llong m) {
  llong ans = 1;
  for (; m > 0; m >>= 1) {
    if (m & 1) (ans *= b) %= rem;
    (b *= b) %= rem;
  }
  return ans;
}

llong fac[maxn], rfac[maxn];
void genfac() {
  fac[0] = 1;
  rep(i, maxn - 2) fac[i + 1] = (fac[i] * (i + 1)) % rem;
  rep(i, maxn - 1) rfac[i] = ppow(fac[i], rem - 2);
}

llong c(int n, int k) {
  llong u = fac[n];
  llong v = rfac[k] * rfac[n - k] % rem;
  return u * v % rem;
}

int n, pc, bc;
int a[maxn];
bool mark[maxn];

int main() {
  genfac();
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  cin >> n;
  int num = 0;
  rep(i, n + 1) {
    cin >> a[i];
    if (mark[a[i]]) num = a[i];
    mark[a[i]] = 1;
  }
  clog << num << endl;
  rep(i, n + 1) {
    if (a[i] != num) continue;
    pc = i;
    break;
  }

  for (int i = n + 1; i--; ) {
    if (a[i] != num) continue;
    bc = n + 1 - i - 1;
    break;
  }

  llong r = pc + bc;
  for (int i = 1; i <= n + 1; ++i) {
    llong ans = c(n + 1, i);
    //clog << ans << endl;
    if (r >= i - 1) ans = ((ans - c(r, i - 1)) % rem + rem) % rem;
    cout << ans << '\n';
  }

  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

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

  div_t d = div(N, 10);
  bool result = ((d.quot == 9) || (d.rem == 9));
  cout << (result ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

broken = [False for _ in range(N+1)]
for a in A:
    broken[a] = True
bp = [0 for _ in range(N+1)]
bp[0] = 1
for i in range(N+1):
    for j in range(1, 3):
        if i + j >= N+1:
            continue
        if not broken[i + j]:
            bp[i + j] = (bp[i+j] + bp[i]) % 1000000007
print(bp[-1])


Measured memory_bytes: 8616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
	int c[3][3];

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

	int t = c[0][0] + c[1][1] + c[2][2];

	int ok = 1;
	for (int i = 0; i < 3; i++){
		if (t != c[0][i] + c[1][(i+1)%3] + c[2][(i+2)%3])
			ok = 0;
	}

	for (int i = 0; i < 3; i++){
		if (t != c[0][i] + c[1][(i+2)%3] + c[2][(i+1)%3])
			ok = 0;
	}

	if (ok)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while (true) {
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0) {
            break;
        }
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if (0 < i && i < h - 1 && 0 < j && j < w - 1) {
                    cout << '.';
                }
                else {
                    cout << '#';
                }
            }
            cout << '\n';
        }
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 3200
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int n,q,a,b,p,x,cnt[200005]={};
vector<int> v[200005];
void dfs(int a,int b,int c) {
  cnt[a]+=c;
  for(auto p:v[a]) {
    if(p!=b) {
      dfs(p,a,cnt[a]);
    }
  }
}
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> q;
  for(int i=0; i<n-1; i++) {
    cin >> a >> b;
    a--,b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  while(q--) {
    cin >> p >> x;
    p--;
    cnt[p]+=x;
  }
  dfs(0,-1,0);
  for(int i=0; i<n; i++) {
    cout << cnt[i] << " ";
  }
  cout << "\n";
}

Measured memory_bytes: 23552