akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

// (行き先,容量,逆辺)
struct edge{ int to,cap,rev; };

const int MAX_V = 30; // TODO:initialize
const int F_INF = 19191919; // TODO:initialize
vector<edge> G[MAX_V];
int level[MAX_V]; // sからの距離
int iter[MAX_V]; // どこまで調べ終わったか

void add_edge(int from, int to, int cap){
    G[from].pb({to,cap,(int)G[to].size()});
    G[to].pb({from,0,(int)G[from].size()-1});
}

void dinic_bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        rep(i,G[v].size()){
            edge &e = G[v][i];
            if(e.cap>0 && level[e.to]<0){
                level[e.to] = level[v]+1;
                que.push(e.to);
            }
        }
    }
}

// 増加パスをdfsで探す
int dinic_dfs(int v, int t, int f){
    if(v==t) return f;
    for(int &i=iter[v]; i<(int)G[v].size(); ++i){
        edge &e=G[v][i];
        if(e.cap>0 && level[v]<level[e.to]){
            int d = dinic_dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// sからtへの最大流
int max_flow(int s, int t){
    int flow = 0;
    while(1){
        dinic_bfs(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof(iter));
        int f;
        while((f=dinic_dfs(s,t,F_INF))>0) flow+=f;
    }
}

const int A = 26;
int ct[A][A]={};

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

    rep(i,n){
        string s;
        cin >>s;
        int S = s.size();
        ++ct[s[0]-'a'][s[S-1]-'a'];
    }

    rep(i,A){
        bool exist = false;
        rep(h,A)if(ct[h][i]) exist = true;
        if(!exist) continue;

        int S = A+1, T = S+1;
        rep(j,MAX_V) G[j].clear();

        int out = 0;
        rep(j,A) out += ct[i][j];

        bool ok = true;
        rep(h,A)rep(t,A){
            int u = h, v = t;
            if(h==i) u=S;
            if(t==i) v=T;
            add_edge(u,v,ct[h][t]);
        }

        int f = max_flow(S,T);
        // printf("%d %d\n",out,f);
        if(out<=f) printf("%c\n", 'a'+i);
    }

    return 0;
}



Measured memory_bytes: 3376
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); 
		int [] a = new int[n];
		int cnt = 1;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt(); 
		}
		Arrays.sort(a);
		for(int i = n-1; i > 0; i--) {
			if(a[i] > a[i-1]) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

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

#define MAX_N 3000
long long n;
long long dp[MAX_N][MAX_N];
long long a[MAX_N];
long long minx;

long long solve(){
	long long res,X,Y,SA=3;
	while(SA<=n+1){
		for(int i=0;i<n;i++){
			X=i;
			Y=(i+SA)%n;
			//X wo toru.
			if(a[(X+n-1)%n]<a[Y%n]){
				dp[(X+n-1)%n][(Y+1)%n]=max(dp[(X+n-1)%n][(Y+1)%n],dp[X][Y]+a[X%n]);
			}
			else{
				dp[(X+n-2)%n][Y%n]=max(dp[(X+n-2)%n][Y%n],dp[X][Y]+a[X%n]);
			}
			//Y wo toru.
			if(a[X%n]<a[(Y+1)%n]){
				dp[X%n][(Y+2)%n]=max(dp[X%n][(Y+2)%n],dp[X][Y]+a[Y%n]);
			}
			else{
				dp[(X+n-1)%n][(Y+1)%n]=max(dp[(X+n-1)%n][(Y+1)%n],dp[X][Y]+a[Y%n]);
			}
		}
		SA+=2;
	}
	if(n%2==1){
		for(int i=0;i<n;i++){
			minx=max(dp[i][i]+a[i],minx);
		}
	}
	else{
		for(int i=0;i<n;i++){
			minx=max(dp[i][(i+1)%n],minx);
		}
	}
	return minx;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	if(n==1){cout<<a[0]<<endl;return 0;}
	if(n==2){cout<<max(a[0],a[1])<<endl;return 0;}
	for(int i=0;i<n;i++){
		if(a[(i+1)%n]>a[(i+n-1)%n]){
			dp[(i+n-1)%n][(i+2)%n]=max(dp[(i+n-1)%n][(i+2)%n],a[i]);
		}
		else{
			dp[(i+n-2)%n][(i+1)%n]=max(dp[(i+n-2)%n][(i+1)%n],a[i]);
		}
	}
	cout<<solve()<<endl;
	return 0;
}

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

typedef long long ll;
const ll MD = 1e9+7;

inline ll ADD(ll A, ll B) {
  return (A + B) % MD;
}

int main() {
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  for (ll i = K; i <= N + 1; ++i) {
    ll bawah = (i) * (i - 1) / 2LL;
    ll atas = (i) * (N + N - i + 1) / 2LL;
    ans = ADD(ans, (atas-bawah+1));
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i=s;i<n;i++)

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,0,n){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  double a;
  a=(double)(v[0]+v[1])/2;
  rep(i,2,n){
    a=(double)(a+v[i])/2;
  }
  cout << a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
//struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;


void solve(long long X){
	FOR(i, X, 1000000) {
		if (isprime(i)) {
			cout << i << "\n";
			return;
		}
	}
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;
const bool DEBUG = false;

signed main() {
	string a[] = { " ","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ" };
	for (string s; cin >> s;) {
		char prev = '0';
		int cnt = 0;
		string ans = "";
		rep(i, 0, s.size()) {
			if (prev == s[i])cnt++;
			else {
				if (prev == '0') {
					rep(j, 0, cnt)ans += " ";
				}
				else {
					ans += a[prev - '0'][cnt%a[prev - '0'].size()];
				}
				prev = s[i];
				cnt = 0;
			}
		}
		if (prev == '0') {
			rep(j, 0, cnt)ans += " ";
		}
		else {
			ans += a[prev - '0'][cnt%a[prev - '0'].size()];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
n,p=map(int,input().split())
a=[int(i)%2 for i in input().split()]
g=a.count(0)
k=len(a)-g
if (p==1 and k==0):
    ans=0
else:
    ans=(2**g)*(2**k)//(2 if k>0 else 1)
print(ans)

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[1000000000*2];
		int n = sc.nextInt();
		int k = sc.nextInt();
		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			list.add(a);
		}
		Collections.sort(list);
		if(k>=n)
			System.out.println(0);
		else {
			long count=0;
			for(int i=0;list.size()-k>i;i++) {
				count=count+list.get(i);
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 94124
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int c0 = 0;
  int c1 = 0;  
  int c2 = 0;
  int c3 = 0;
  for (int i = 0; i < n; i++){
    string S;
    cin >> S;
    if (S == "AC"){
      c0 += 1;
    }else if (S == "WA"){
      c1 += 1;
    }else if (S == "TLE"){
      c2 += 1;
    }else if (S == "RE"){
      c3 += 1;
    }
  }
  cout << "AC" << " " << "x" << " " << c0 << endl;
  cout << "WA" << " " << "x" << " " << c1 << endl;
  cout << "TLE" << " " << "x" << " " << c2 << endl;
  cout << "RE" << " " << "x" << " " << c3 << endl;
}

Measured memory_bytes: 3628
import math

A, B, N = tuple(map(int, input().split()))

m = 0
n = 1

def cal(x):
  return math.floor(A*x/B)-A*math.floor(x/B)

while n<N:
  c = B*(math.floor((n+1)/B)+1)-1
  n = min(N, c)
  m = max(cal(n), m)
  if (A*n)%B == 0:
    break
  
print(m)


Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1,
    x=-x;
  }
  while(x){
    f[s++]=x%10,
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N, Y;
int main(){
  int i, j, k;
  rd(N);
  rd(Y);
  Y /= 1000;
  for(i=0;i<N+1;i++){
    for(j=0;j<N+1-i;j++){
      k = N - i - j;
      if(10*i+5*j+k==Y){
        wt_L(i);
        putchar_unlocked(' ');
        wt_L(j);
        putchar_unlocked(' ');
        wt_L(k);
        putchar_unlocked('\n');
        return 0;
      }
    }
  }
  wt_L(-1);
  putchar_unlocked(' ');
  wt_L(-1);
  putchar_unlocked(' ');
  wt_L(-1);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20171023-1 [beta]

// --- original code ---
// int N, Y;
// {
//   int i, j, k;
//   
//   rd(N,Y);
//   Y /= 1000;
// 
//   rep(i,N+1) rep(j,N+1-i){
//     k = N - i - j;
//     if(10*i+5*j+k==Y){
//       wt(i,j,k);
//       return 0;
//     }
//   }
//   wt(-1,-1,-1);
// }


Measured memory_bytes: 256
while n = gets.to_i
  break if n.zero?

  total = 0
  n.times do
    x, y, h, w = gets.split.map(&:to_i)
    s = x + y + h
    if s <= 60 && w <= 2
      total += 600
    elsif s <= 80 && w <= 5
      total += 800
    elsif s <= 100 && w <= 10
      total += 1000
    elsif s <= 120 && w <= 15
      total += 1200
    elsif s <= 140 && w <= 20
      total += 1400
    elsif s <= 160 && w <= 25
      total += 1600
    end
  end
  puts total
end

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

int main() {
  int64_t Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  
  int64_t ans, one;
  one = min(S, min(2*H, 4*Q));
  ans = N/2*min(D, one*2)+N%2*one;
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
n = int(input())
a = list(map(int, input().split()))

s = sum(a) // 2
b_0 = (s - sum(a[1::2])) * 2

b = [0] * n
b[0] = b_0

for i in range(n-1):
    b[i+1] = (a[i] - b[i] // 2) * 2

print(" ".join([str(x) for x in b]))

Measured memory_bytes: 94104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

ll fac[1000007], inv[1000007], finv[1000007];

void settable(){
    fac[0] = fac[1] = 1;
    inv[1] = 1;
    finv[0] = finv[1] = 1;
    for(int i = 2;i <= 1000000 ; i++){
        fac[i] = fac[i-1]*i%mod;
        inv[i] = mod-inv[mod%i]*(mod/i)%mod;
        finv[i] = finv[i-1]*inv[i]%mod; 
    }
}

ll com(ll n, ll k){
    return ((fac[n]*finv[k])%mod)*finv[n-k]%mod;
}

int main(){
    settable();
    ll x, y;
    cin >> x >> y;
    if(x<y) swap(x,y);
    if((2*y-x)%3!=0 || 2*y-x < 0){
        cout << 0 << endl;
        return 0;
    }else{
        cout << com((x+y)/3,(2*y-x)/3) << endl;
    }
}


Measured memory_bytes: 23680
import numpy as np
def factor(N):
    ans = []
    for i in range(1,int(np.sqrt(N))+1):
        if N%i == 0:
            ans.append(i)
            if N//i != i:
                ans.append(N//i)
    return ans

def check(K,N):
    while N >= K:
        if N%K == 0:
            N //= K
        else:
            N %= K
    if N%K == 1:
        return True
    else:
        return False

N = int(input())
ans = len(factor(N-1))-1

for K in factor(N)[1:]:
    if check(K,N):
        ans += 1

print(ans)            


Measured memory_bytes: 12476
#include <stdio.h>

int main() {
  int h, w;
  while(1) {
    scanf("%d %d", &h, &w);
    if (h == 0 && w == 0) {
      break;
    }
    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++ ) {
        if (y == 0 || x == 0 || y == h-1 || x == w-1) {
          printf("#");
        } else {
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2696
N = int(input())
string = ""
while not N == 0:
  if N % 2 == 0:
    N = - N // 2
    string = '0' + string
  else:
    N = N - 1
    N = - N // 2
    string = '1' + string
print(string if not string == "" else "0")


Measured memory_bytes: 2940
#![allow(dead_code, unused_imports, non_snake_case)]

use std::io::*;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::str::FromStr;

const MOD: i32 = 1_000_000_007;

macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn solve(h: i64, w: i64) -> i64 {
    if w % 3 == 0 {
        return 0;
    }
    let mut ans = h;
    for i in 1..w {
        let a = h * i;
        let b = (h / 2) * (w - i);
        let c = (h - h / 2) * (w - i);
        ans = min(ans, max((a - b).abs(), max((b - c).abs(), (c - a).abs())));
    }
    ans
}

fn main() {
    let (h, w) = get!(i64, i64);
    println!("{}", min(solve(h, w), solve(w, h)));
}

Measured memory_bytes: 4352
//encoding:utf-8
#include <iostream> //c++
#include<time.h> //時間にかんして
#include<stack> //スタックに関して　最新のデータから捨てる
#include<queue> //キューに関して　最古のデータから捨てる
#include<math.h>
#include<vector>
#include<algorithm> //sort とかにいる

#define ll long long
using namespace std;
int main(){
  int a,b;
  int ans;
  cin>>a>>b;
  if(b%a==0){
    ans = a+b;
  }
  else{
    ans=b-a;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
string s;
int main(){
    while(cin>>s){
        s[0]='2';
        s[1]='0';
        s[2]='1';
        s[3]='8';
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		String str = scan.next();
		long k = scan.nextLong();
		int result = 0;
		for (int i = 0; i <= k - 1; i++) {
			if (Character.getNumericValue(str.charAt(i)) == 1) {
				result = Character.getNumericValue(str.charAt(i));
			} else {
				result = Character.getNumericValue(str.charAt(i));
				break;
			}
		}
		System.out.println(result);
		scan.close();

	}

}

Measured memory_bytes: 22612
#include "stdio.h"

int main()
{
	int input = 0;
	int a[3];
	int buff = 0;

	int i = 0;
	for(i = 0; i < 3; i++)
	{
		scanf("%d", &input);
		if(input < 1 || input > 10001)
		{
			return 0;
		}
		else
		{
			a[i] = input;
		}
	}

	while(a[0] > a[1] || a[1] > a[2])
	{
		if(a[0] > a[1])
		{
			buff = a[1];
			a[1] = a[0];
			a[0] = buff;
		}
		if(a[0] > a[2])
		{
			buff = a[2];
			a[2] = a[0];
			a[0] = buff;
		}
		if(a[1] > a[2])
		{
			buff = a[2];
			a[2] = a[1];
			a[1] = buff;
		}
	}

	printf("%d %d %d\n", a[0], a[1],a[2]);
	return 0;
}


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

int light[10][7]={
  {0,1,1,1,1,1,1},
  {0,0,0,0,1,1,0},
  {1,0,1,1,0,1,1},
  {1,0,0,1,1,1,1},
  {1,1,0,0,1,1,0},
  {1,1,0,1,1,0,1},
  {1,1,1,1,1,0,1},
  {0,1,0,0,1,1,1},
  {1,1,1,1,1,1,1},
  {1,1,0,1,1,1,1}
};

main(){
  int n;
  while(cin >> n,n!=-1){
    int s;
    int seg[7]={0};
    for(int i=0;i<n;i++){
      cin >> s;
      for(int j=0;j<7;j++){
	if(seg[j]==light[s][j]) cout << "0";
	else cout << "1";
      }
      cout << endl;
      for(int j=0;j<7;j++){
	seg[j]=light[s][j];
      }
    }
  }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int a,b,c,d;
 cin >> a >> b>> c>> d;
 if(a>b){
 cout << (b*c)+(a-b)*d << endl;
 }else{
   cout << a*c << endl;
 }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

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

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


///////////////////////////////////////////////////

int main()
{
    string T;
    cin >> T;
    for (char c : T)
    {
        if (c == '?') c = 'D';
        cout << c;
    }
    cout << endl;
}

Measured memory_bytes: 3728
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
inline ll read()
{
	ll f = 1, x = 0;
	char ch;

	do{
		ch = getchar();
		if (ch == '-')
			f = -1;
	}while(ch < '0' || ch > '9');
	do{
		x = x * 10 + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return f * x;
}
const int N = 1e5;

int n, q, top;
ll st[N + 2], f[N + 2], sum[N + 1];

inline void solve(ll x, ll y)
{
	if (!x)
		return;
	int w = upper_bound(st + 1, st + 1 + top, x) - st - 1;
	if (!w) {
		sum[1] += y;
		sum[x + 1] -= y;
	} else {
		f[w] += x / st[w] * y;
		solve(x % st[w], y);
	}
	return;
}
int main()
{
	n = st[++top] = read();
	q = read();

	for (int i = 1; i <= q; i++) {
		ll x = read();
		while (x <= st[top])
			top--;
		st[++top] = x;
	}
	f[top] = 1;
	for (int i = top - 1; i >= 1; i--) {
		f[i] += st[i + 1] / st[i] * f[i + 1];
		solve(st[i + 1] % st[i], f[i + 1]);
	}
	sum[1] += f[1];
	sum[st[1] + 1] -= f[1];

	for (int i = 1; i <= n; i++) {
		sum[i] += sum[i - 1];
		printf("%lld\n", sum[i]);
	}
	return 0;
}


Measured memory_bytes: 6072
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>

int main(int argc, void **argv)
{
	int N;
	int V[20], C[20];
	char *vp, *cp;
	int x, y, t;
	int sx, sy;

	scanf("%d\n", &N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &V[i]);
	}
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &C[i]);
	}

	t = 0;
	for (int i = 0; i < N; i++)
	{
		int s = V[i] - C[i];

		if( s < 0 ) continue;

		t += s;
	}

	printf("%d\n", t);

	return 0;
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
Pii BA[int(2e5 + 5)];

int main(){
  scanf("%d", &N);
  for (int i = 0; i < N; i++){
    int A, B; scanf("%d%d", &A, &B);
    BA[i] = {B, A};
  }
  sort(BA, BA + N);

  int now = 0;
  for (int i = 0; i < N; i++){
    now += BA[i].se;
    if (now > BA[i].fi){
      No(); return 0;
    }
  }
  Yes();

  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>
using namespace std;
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(int argc, char* argv[])
{
    
    while(1){
        int n,p;
        int cnt=0,ans;
        cin >> n >> p;
        
        if(n == 0 && p == 0){
            return 0;
        }
        int stone[50] = {0};
        
        while(1){
            
            for (int i=0; i<n; i++) {
                if(p != 0){
                    p--;
                    stone[i]++;
                }else{
                    p = stone[i];
                    stone[i] =0;
                }
                if(stone[i] == 0){
                    cnt++;
                }else{
                    ans=i;
                }
            }
            if(cnt == n-1 && p==0){
                cout << ans << endl;
                break;
            }
            cnt =0;
            ans = 0;
                
        }
    }
    return 0;
}

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

using namespace std;
typedef long long LL;

int main(){
  string S, T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  string U;
  cin >> U;
  if(S==U) cout << A-1 << " " << B << endl;
  if(T==U) cout << A << " " << B-1 << endl;

  return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<long long int>x(n);
    vector<long long int>copy(n);
    rep(i,n)cin>>x[i];
    rep(i,n)copy[i]=x[i];
    sort(copy.begin(),copy.end());
    int indeb=n/2-1;
    int indea=n/2;
    rep(i,n){
        if(x[i]>=copy[indea])cout<<copy[indeb]<<endl;
        else cout<<copy[indea]<<endl;
       

    }
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

struct Unifind{
	vector<int> par;

	Unifind(){}
	Unifind(int n) :
		par(n+1, -1)
	{}
	int root(int x){
		if(par[x] < 0) return x;
		return par[x] = root(par[x]);
	}
	int size(int x){
		return -par[root(x)];
	}
	bool same(int a, int b){
		return root(a) == root(b);
	}
	bool marge(int a, int b){
		a = root(a), b = root(b);
		if(a == b) return false;
		if(par[a] > par[b]) swap(a, b);
		par[a] += par[b];
		par[b] = a;
		return true;
	}
};

int main(){
	int N, M;
	Unifind uf;

	cin >> N >> M;
	uf = Unifind(N+M+1);
	int K, in;
	for(int i = 1; i <= N; i++){
		cin >> K;
		for(int j = 0; j < K; j++){
			cin >> in;
			uf.marge(i,in+N);
		}
	}

	bool check = true;
	for(int i = 2; i <= N; i++){
		if(!uf.same(i, i-1))
			check = false;
	}

	if(check)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 1024
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

template<typename InputIterator> constexpr std::string join(InputIterator first, InputIterator last, const std::string &sep) {
  if (first == last) return "";
  std::stringstream ss;
  ss << *(first++);
  for_each(first, last, [&](auto &x) { ss << sep << x; });
  return ss.str();
}

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(const int &s = 0, const int &d = 0, const Weight &w = 0) : src(s), dst(d), weight(w) {}
};

using Edges = std::vector<Edge>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

class Graph {
  std::vector<Edges> g;

public:
  Graph(const int &size = 0) : g(size) {}

  void addArc(const int &src, const int &dst, const Weight &w = 1) { g[src].emplace_back(src, dst, w); }

  void addEdge(const int &node1, const int &node2, const Weight &w = 1) {
    addArc(node1, node2, w);
    addArc(node2, node1, w);
  }

  const Edges &operator[](const int &i) const { return g[i]; }

  Graph toRootedTree(int r);
  std::pair<std::vector<Weight>, std::vector<int>> dijkstra(const int &src, const int &inf);
  Matrix warshallFloyd(const int &inf);
  std::pair<Weight, Edges> prim(const int &r);
  template<typename UnionFind> std::pair<Weight, Edges> kruskal();
  Weight solveTSP(const int &inf);
};

main {
  int n;
  cin >> n;
  Graph g(n);
  rep(_, n) {
    int u, k;
    cin >> u >> k;
    while (k--) {
      int v;
      cin >> v;
      g.addArc(u - 1, v - 1);
    }
  }
  Matrix d(n, Array(n, 0));
  rep(i, n) for (auto &e : g[i]) d[e.src][e.dst] = 1;
  for (auto &r : d) cout << join(all(r), " ") << endl;
}

Measured memory_bytes: 3260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,k;
        cin>>n>>k;
        ll a[n]={0};
        ll d[k]={0};
        for(ll i=0;i<k;i++)
        {
            cin>>d[i];
            for(ll j=0;j<d[i];j++)
                {
                    ll temp;
                    cin>>temp;
                    a[temp-1]++;
                }
        }
        ll ans = 0;
        for(ll i=0;i<n;i++)
        {
            if(a[i]==0)
            {
                ans++;
            }
        }

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




Measured memory_bytes: 3620
using System;
using System.Linq;

class Program {
    static void Main() {
        string s;
        while ((s = Console.ReadLine()) != null) {
            double[] n = s.Split().Select(double.Parse).ToArray();
            double a = n[0];
            double b = n[1];
            double c = n[2];
            double d = n[3];
            double e = n[4];
            double f = n[5];
            double y = (c * d - a * f) / (b * d - a * e);
            double x = (c - b * y) / a;
            Console.WriteLine("{0:f3} {1:f3}", x, y);
        }
    }
}


Measured memory_bytes: 9544
#include <iostream>
#include <string>

int s_to_i(const std::string &s){
	if(s == "Vacant")
		exit(0);
	else if (s == "Male")
		return 0;
	else if (s == "Female")
		return 1;
	return 3;
}

void get_state(std::pair<int, int> &n){
	std::string s;
	std::cout << n.first << std::endl;
	std::cin >> s;
	n.second = s_to_i(s);
}

int main(){
	int N;
	std::string s;
	std::cin >> N;
	std::pair<int, int> a, b, c;
	a.first = 0;
	get_state(a);
	b = a;
	b.first = N;
	while(1){
		c.first = (a.first + b.first)/2;
		get_state(c);
		if((c.first - a.first) % 2 == abs(c.second - a.second))
			a = c;
		else
			b = c;
	}
}


Measured memory_bytes: 852
N = int(input())
# 赤い点はy軸が大きい方順にソート
reds = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1])
# 青い点はx軸が小さい方順にソート
blues = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])

ans = 0
for bx, by in blues:
    for rx, ry in reds:
        if rx < bx and ry < by:
            ans += 1
            reds.remove((rx, ry))
            break
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>

int main(void) {
	int n,i;
	int an[200010];
	long long allsum[200010];
	unsigned long long minnum = 2ll << 49ll;
	long long x,y;
	scanf("%d",&n);
	for (i = 0; i < n; i++) {
		allsum[i] = 0;
	}
	for (i = 0; i < n; i++) {
		scanf("%d",&an[i]);
	}
	allsum[0] = an[0];
	for (i = 0; i < n - 1; i++) {
		allsum[i + 1] = allsum[i] + an[i + 1];
	}

	for (i = 0; i < n - 1; i++) {
		x = allsum[i];
		y = allsum[n - 1] - allsum[i];
		if (minnum > llabs(x - y)) {
			minnum = llabs(x - y);
		}
	}
	printf("%lld",minnum);
	return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;
    long long l[n];

    

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

    sort(l,l+n);

    long long e1 = 0;
    long long e2 = 0;
    int now = 0;
    int cnt = 0;

    for(int i = n-1;i >= 0;i--){
        if (now != l[i]) {
            now = l[i];
            cnt = 1;
        }else cnt++;

        if (cnt >= 2){
            if (e1 == 0){
                e1 = l[i];
                cnt = 0;
            } 
            else if(e2 == 0) {
                e2 = l[i];
                cnt = 0;
            }
        } 
    }

    cout << e1*e2 << endl;

    return 0;

}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;

int main()
{
	//?????°?????????
	string W1 = "";
	string W2 = "";
	string T1 = "";
	string T2 = "";
	int count = 0;

	//??????W??¨?????????T?????\???
	cin >> W1;
	for (int i = 0; W1[i] != '\0'; i++)
	{
		W2 += toupper(W1[i]);
	}

	while (1)
	{
		T2 = "";
		cin >> T1;
		if (T1 == "END_OF_TEXT")
		{
			break;
		}

		for (int i = 0; T1[i] != '\0'; i++)
		{
			int c;
			T2 += toupper(T1[i]);
		}

		
		if (W2 == T2)
		{
			count++;
		}

	}


	//?????°?????¨???
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 3132
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#include<unordered_map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(j,a,b) for(int j = a; j < (b); j++)
using namespace std;
using ll = long long;

int gcd(int x, int y) {
	if (y > x)swap(x, y);
	if (x % y==0) { return y; }
	else gcd(y, x % y);

}

int main() {

	int x, y;
	cin >> x >> y;

	cout << x + y - gcd(x, y) + 1 << endl;
	return 0;

}


Measured memory_bytes: 3100
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define reps(i, s, n) for (int i = (s); i < (n); ++i)
#define repse(i, s, n) for (int i = (s); i <= (n); ++i)
#define repsr(i, n, s) for (int i = (n); i >= (s); --i)
const int64_t inf = (int64_t)1e18;
const int64_t mod = (int64_t)1e9 + 7;

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

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

if __name__ == "__main__":# {{{
    solve()

# vim: set foldmethod=marker: }}}


Measured memory_bytes: 79632
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void solve() throws Exception {
		String s = scanString();
		int ans = 0;
		for (int i = 0; i < s.length(); i++) {
			ans += s.charAt(i) - '0';
		}
		out.print(ans == 1 ? 10 : ans);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 22996
using System;

class Program
{
    static void Main(string[] args) {
        int n   = int.Parse(Console.ReadLine());
        int[] a = new int[n];
        

        int max = 0;
        int second = 0;

        for(int i=0; i<n; i++) {
            a[i] = int.Parse(Console.ReadLine());
            if(max < a[i]) {
                second = max;
                max = a[i];
            }else if(second < a[i]) {
                second = a[i];
            }
        }
        
        for(int i=0; i<n; i++) {
            if(a[i] == max) {
                Console.WriteLine(second);
            } else {
                Console.WriteLine(max);
            }
        }
        //return null;
    }

}

Measured memory_bytes: 17108
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N,K;
	cin>>N>>K;
	if(K==1){
		cout<<0<<endl;
		return 0;
	}
	cout<<N-K<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         int N=gi();
         int K=gi();
         long[] a=new long[N];
         long sum=0;
         for(int i=0; i<N;i++) {
        	 a[i]=gl();
        	 if(i<K)sum+=a[i];
         }
         long max=sum;
         int mi=K-1;
         for(int i=K; i<N;i++) {
        	 sum+=a[i];
        	 sum-=a[i-K];
        	 if(max<sum) {
        	     max=sum;
        	     mi=i;
        	 }
         }

         double ans=0;
         for(int i=mi-K+1; i<=mi;i++) {
        	 double q=a[i]+1;
        	 ans+=q/2;
         }



         System.out.println(ans);
     }

     public static long f(long n) {
    	 if(n==1)return 1;
    	 return 2*f(n>>1);
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 60576
using System;
					
public class Program
{
	public static void Main()
	{
		string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int K = int.Parse(str[1]); 
		int[] A = new int[N];
		
		for(int i=0; i < K; i++){
			int d = int.Parse(Console.ReadLine());
			
			string[] str2 = Console.ReadLine().Split(' ');
			
			for(int j=0; j < d; j++){
				A[int.Parse(str2[j])-1]++;
			}
		}
		
		int cnt=0;
		for(int i=0; i < N; i++){
			if(A[i]==0){
			  cnt++;
			}
		}
		
		Console.WriteLine(cnt);
		
	}
}

Measured memory_bytes: 18248
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace atcoder;
using namespace std;

using mint = modint998244353;

const int N = 200005;

mint pot[N];
const mint inv9 = mint(1) / mint(9);

struct S {
	mint val;
	int sz;
};

struct F {
	int d;
};

S op(S a, S b) {
	return S{a.val * pot[b.sz] + b.val, a.sz + b.sz};
}
S e() {
	return S{0, 0};
}
S mapping(F f, S x) {
	if(f.d == -1) return x;
	return S{(pot[x.sz] - mint::raw(1)) * inv9 * mint::raw(f.d), x.sz};
}
F composition(F f, F g) {
	if(f.d == -1) return g;
	return f;
}
F id() {
	return F{-1};
}

int main() {
	pot[0] = mint::raw(1);
	for(int i = 1; i < N; i++) pot[i] = pot[i - 1] * mint::raw(10);

	int n, q;
	scanf("%d %d", &n, &q);

	auto st = lazy_segtree<S, op, e, F, mapping, composition, id>(n);

	for(int i = 0; i < n; i++) st.set(i, S{mint::raw(1), 1});

	while(q--) {
		int l, r, d;
		scanf("%d %d %d", &l, &r, &d);
		st.apply(l - 1, r, F{d});
		printf("%d\n", st.all_prod().val.val());
	}

}



Measured memory_bytes: 10656
using System;
using System.Collections.Generic;
public class ABC134C {
    public static void Main() {
        int N, max, max2, maxIndex, max2Index;
        List<int> A = new List<int>();
        N = int.Parse(Console.ReadLine());
        for (int i = 0; i < N; i++) {
            A.Add(int.Parse(Console.ReadLine()));
        }

        if (A[0] >= A[1]) {
            max = A[0];
            maxIndex = 0;
            max2 = A[1];
            max2Index = 1;
        } else {
            max = A[1];
            maxIndex = 1;
            max2 = A[0];
            max2Index = 0;
        };
        for (int i = 2; i < N; i++) {
            if (A[i] >= max) {
                max2 = max;
                max2Index = maxIndex;
                max = A[i];
                maxIndex = i;
            } else if (A[i] > max2) {
                max2 = A[i];
                max2Index = i;
            }
        }
        for (int i = 0; i < N; i++) {
            if (i == maxIndex) Console.WriteLine(max2);
            else Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 18260
import random
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
ans = 0
a = []
last = [0]*26
for i in range(1,d+1):
    res = -float("inf")
    index = 0
    for k in range(26):
        x = k
        tnplast = last
        tnplast[x] = i
        tnp = 0
        tnp += s[i-1][x]
        for j in range(26):
            tnp -= c[j]*(i-last[j])
        if (tnp > res):
            res = tnp
            index = k+1
    ans += res
    a.append(index)

def rec(t,x,y,ans):
    ans -= s[x-1][t[x-1]-1]
    ans += s[x-1][y-1]
    ma = d+1
    mi = 0
    for j in range(x+1,d+1):
        if (t[j-1]==t[x-1]):
            ma = j
            break
    for j in range(x-1,0,-1):
        if (t[j-1]==t[x-1]):
            mi = j
            break
    ans -= c[t[x-1]-1]*(x-mi)*(ma-x)
    ma = d+1
    mi = 0
    for j in range(x+1,d+1):
        if (t[j-1]==y):
            ma = j
            break
    for j in range(x-1,0,-1):
        if (t[j-1]==y):
            mi = j
            break
    ans += c[y-1]*(x-mi)*(ma-x)
    return ans
    
for i in range(190000):
    x = random.randrange(1,d+1)
    y = random.randrange(1,27)
    t = a
    A = rec(t,x,y,ans)
    if (ans < A):
        t[x-1] = y
        a = t
        ans = A

print(*a ,sep="\n")


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

char hash[1<<21],Dictionary[256];

int main(int argc,char *argv[]){
  int flg;
  int valume,x,y;
  char c;

  Dictionary['T'] = 1;
  Dictionary['G'] = 2;
  Dictionary['C'] = 3;
  Dictionary['A'] = 4;

  scanf("%d",&valume);
  getchar();
  while(valume--){
    x = 0;
    y = 1;
    flg = (c = getchar()) == 'i';
    while((c = getchar()) != ' ');
    while((c = Dictionary[getchar()]) != 0){
      x += c * y;
      y *= 4;
    }
    if(flg) hash[x] = 1; else puts(hash[x] ? "yes" : "no");
  }
  return 0;
}



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

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

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

int main(void){

    string s;
    cin >> s;

    int left = 0;
    int right = s.length();

    for(int i = 0;s[i] != '\0';i++){
        if(s[i] == 'A'){
            left = i;
            break;
        }
    }

    for(int i = s.length()-1;i >= 0;i--){
        if(s[i] == 'Z'){
            right = i+1;
            break;
        }
    }

    cout << right-left << endl;

    return 0;
}

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

long long calc(string fomula) {
	long long sum = 0;
	string tmp;
	for (int i = 0; i < fomula.length(); ++i) {
		if (fomula[i] == '+') {
			sum += stol(tmp);
			tmp = "";
		}
		else {
			tmp += fomula[i];
		}
	}
	sum += stol(tmp);
	return sum;
}

int main() {

	string s;

	cin >> s;
	long long sum = 0;
	int bit = 0;
	int len = s.length();
	int loop = pow(2, len-1);
	for (int i = 0; i < loop; ++i) {

		string news = s;
		int count = 0;
		for (int j = 0; j < len-1; j++) {
			if (bit&(1 << j)) {
				news.insert(j + 1 + count, "+");
				count++;
			}
		}
		sum += calc(news);
		

		bit++;
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

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

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

  sort(A, A+N);

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    x -= A[i];
    if (x >= 0) ++ans;
    else break;
  }

  if (ans == N && x > 0) --ans;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
# n, a, b = [int(i) for i in input().split()]
r = []
for i in range(N):
    A = int(input())
    r.append(A)

r_asc = sorted(r)
r_desc = sorted(r, reverse=True)
row = []
row2 = []

for i in range(N):
    if i % 2 == 0:
        row.append(r_asc[i//2])
        row2.append(r_desc[i//2])
    else:
        row.append(r_desc[i//2])
        row2.append(r_asc[i//2])
row3 = [row[-1]] + row[:-1]
row4 = [row2[-1]] + row2[:-1]
row_diff = [abs(row[i] - row[i-1]) for i in range(1, N)]
row2_diff = [abs(row2[i] - row2[i-1]) for i in range(1, N)]
row3_diff = [abs(row3[i] - row3[i-1]) for i in range(1, N)]
row4_diff = [abs(row4[i] - row4[i-1]) for i in range(1, N)]
print(max(sum(row_diff), sum(row2_diff), sum(row3_diff), sum(row4_diff)))


Measured memory_bytes: 72024
#include<stdio.h>
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
char a[12][13];
void func(int y,int x){
	int i,xx,yy;
	a[y][x]='0';
	for(i=0;i<4;i++){
		xx=x+dx[i]; yy=y+dy[i];
		if(xx>=0&&yy>=0&&xx<12&&yy<12&&a[yy][xx]=='1') func(yy,xx);
	}
}
int main(void){
	int i,j,cnt;
	while(scanf("%s",&a[0])!=EOF)	{
		for(i=1;i<12;i++) scanf("%s",a[i]);
		cnt=0;
		for(i=0;i<12;i++){
			for(j=0;j<12;j++){
				if(a[i][j]=='1'){
					cnt++;
					func(i,j);
				}
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 2596