akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int m1,m2;
string mp[5][5],tmp[5][5];
int A[30],B[30];
int n;
 
int Count(int z,int y,int x){
  int res=0;
  for(int i=-1;i<=1;i++)
    for(int j=-1;j<=1;j++){
      int nx=x+j,ny=y+i;
      if(nx<0||ny<0||nx>=5||ny>=5) continue;
      if((i!=0||j!=0)&&(mp[z][ny][nx])=='1')res++;
      if(z&&mp[z-1][ny][nx]=='1') res++;
      if(z<4&&mp[z+1][ny][nx]=='1')res++;
    }
  return res;
}
 
void solve(){
  while(n--){
    for(int i=0;i<5;i++)for(int j=0;j<5;j++) tmp[i][j]=mp[i][j];
 
    for(int i=0;i<5;i++)
      for(int j=0;j<5;j++)
    for(int k=0;k<5;k++){
      int cnt=Count(i,j,k);
      for(int l=0;l<m1&&mp[i][j][k]=='0';l++) if(cnt==A[l]) tmp[i][j][k]='1';
      int f=(mp[i][j][k]=='1');
      for(int l=0;l<m2&&mp[i][j][k]=='1';l++) if(cnt==B[l]) f=0;
      if(f) tmp[i][j][k]='0';
    }
    for(int i=0;i<5;i++)for(int j=0;j<5;j++) mp[i][j]=tmp[i][j];
  }
}
 
 
int main(){
  int cnt=0;
  while(cin>>n,n){
    cnt++;
    if(cnt!=1)cout <<endl;
    for(int i=0;i<5;i++)
      for(int j=0;j<5;j++) cin>>mp[i][j];
 
    cin>> m1;
    for(int i=0;i<m1;i++) cin>>A[i];
    cin>>m2;
    for(int i=0;i<m2;i++) cin>>B[i];
    solve();
    cout <<"Case "<<cnt<<":"<<endl;
    for(int i=0;i<5;i++){
      for(int j=0;j<5;j++)cout << mp[i][j]<<endl;
      if(i!=4)cout <<endl;
    }
  }
   
  return 0;
}

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

int main()
{
	int n, k, x, y, fee;
	scanf("%d %d %d %d", &n, &k, &x, &y);
	if(n<=k)
		fee = n*x;
	else{
		fee = k*x;
		fee+=((n-k)*y);
	}

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int N, K;
	cin >> N >> K;
	vector<vector<int>>kind(N, vector<int>());
	for (int i = 0; i < N; ++i) {
		int t, d;
		cin >> t >> d;
		t--;
		kind[t].push_back(d);
	}
	for (int i = 0; i < N; ++i) {
		sort(kind[i].begin(), kind[i].end());
	}
	vector<int>best;
	vector<int>remain;
	for (int i = 0; i < N; ++i) {
		if (kind[i].empty())continue;
		int key = kind[i][kind[i].size()-1];
		best.push_back(key);
		kind[i].pop_back();
		while (!kind[i].empty()) {
			int key = kind[i][kind[i].size() - 1];
			remain.push_back(key);
			kind[i].pop_back();
		}
	}
	sort(best.begin(), best.end(), greater<int>());
	sort(remain.begin(), remain.end(), greater<int>());
	vector<ll>bsum = { 0 };
	vector<ll>rsum = { 0 };
	for (int i = 0; i < best.size(); ++i) {
		bsum.push_back(bsum[i] + best[i]);
	}
	for (int i = 0; i < remain.size(); ++i) {
		rsum.push_back(rsum[i] + remain[i]);
	}
	ll ans = 0;
	for (ll i = 1; i <= N; ++i) {
		if (i >= bsum.size()) {
			break;
		}
		if (K - i >= rsum.size())continue;
		ans = max(ans, bsum[i] + rsum[K - i] + i * i);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 7288
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string n;
  cin>>n;
  if(n[0]==n[1]&&n[1]==n[2]||n[1]==n[2]&&n[2]==n[3])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		int d = in.nextInt();
		
		// 守備範囲
		d = d*2 +1;
		
		if(n%d == 0) {
			System.out.println(n/d);
		} else {
			System.out.println(n/d +1);
		}
		
		in.close();
	}
}


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

int main()
{
    std::string s;
    std::cin >> s;

    int N = s.size();
    for(int i=0; i<N-1; i++){
        if(s[i] == s[i+1]){
            printf("%d %d\n", i+1, i+2); return 0;
        }
        else if(i != N-2 && s[i] == s[i+2]){
            printf("%d %d\n", i+1, i+3); return 0;
        }
    }
    printf("%d %d\n", -1, -1);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a[ohara],b[ohara],c[ohara],d[ohara],tmp,tmpp,m,h,w,x,y,sum,p,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
bool negative[ohara];

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>n>>m>>p;
    rep(i,m)cin>>a[i]>>b[i]>>c[i],a[i]--,b[i]--;
    rep(i,n)d[i]=LINF;
    d[0]=0;
    rep(i,n-1){
        rep(j,m){
            if(d[a[j]]==LINF)continue;
            if(d[b[j]]>d[a[j]]-c[j]+p){
                d[b[j]]=d[a[j]]-c[j]+p;
            }
        }
    }
    ans=d[n-1];

    rep(i,n){//nについては適宜調節
        rep(j,m){
            if(d[a[j]]==LINF)continue;
            if(d[b[j]]>d[a[j]]+-c[j]+p){
                d[b[j]]=d[a[j]]-c[j]+p;
                negative[b[j]]=true;
            }
            if(negative[a[j]]==true){
                negative[b[j]]=true;
            }
        }
    }
    if(negative[n-1]==true)Cout(-1);
    else Cout(max(-ans,0LL));
    return 0;
}


Measured memory_bytes: 6400
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    if (n == 1) {
        println(1)
    } else if (n % 2 == 0) {
        println(0.5)
    } else {
        val double = n.toDouble()
        val result: Double = ((double + 1) / 2) / double
        println(result)
    }
}

Measured memory_bytes: 29920
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, x, y, a[N], b[N] = {1}, c[N], v[N];
ll M = 1e9 + 7;
int main()
{
	ll i, j;
	cin >> n;
	n++;
	for (i = 1; i <= n; i++) b[i] = b[i - 1] * i % M;
	for (c[n] = 1, i = b[n], j = M - 2; j; i = i * i % M, j >>= 1)
		if (j & 1) c[n] = c[n] * i % M;
	for (i = n - 1; i >= 0; i--) c[i] = c[i + 1] * (i + 1) % M;
	for (i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		if (v[a[i]]) x = v[a[i]] - 1, y = n - i;
		v[a[i]] = i;
	}
	for (i = 1; i <= n; i++) {
		j = b[n] * c[i] % M * c[n - i] % M;
		printf("%lld\n", (j + M - b[x + y] * c[i - 1] % M * c[x + y - i + 1] % M * (x + y >= i - 1)) % M);
	}
    return 0;
}

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

using namespace std;
typedef long long ll;

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

    int n, x, t;
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << "\n";

    return 0;
}


Measured memory_bytes: 3652
N = int(input())
Ass = tuple(tuple(map(int, input().split())) for _ in range(N))
index = [0 for _ in range(N)]

Q = set(range(N))
ans = -1
while Q:
    ans += 1
    Q2 = Q.copy()
    Q.clear()
    for i in Q2:
        if index[i] >= N - 1:
            continue
        t = Ass[i][index[i]] - 1
        if Ass[t][index[t]] == i + 1:
            Q.add(i)
            Q.add(t)
    for i in Q:
        index[i] += 1

if min(index) < N - 1:
    print(-1)
else:
    print(ans)

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int main() {
	string s;
	cin >> s;
	
	bool f[4] = {};
	REP(i, s.size()) {
		if (s[i] == 'N') f[0] = true;
		if (s[i] == 'S') f[1] = true;
		if (s[i] == 'W') f[2] = true;
		if (s[i] == 'E') f[3] = true;
	}
	
	bool ans = true;
	if (f[0] && !f[1] || !f[0] && f[1]) ans = false;
	if (f[2] && !f[3] || !f[2] && f[3]) ans = false;
	
	puts(ans ? "Yes" : "No");
	
	return 0;
}


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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
#define PRINT_ENTER() cout << endl;

int main() {
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    REP(i, n) { cin >> v[i]; }
    REP(i, n) { cin >> c[i]; }

    int ans = 0;
    REP(i, n) {
        if ((v[i] - c[i]) > 0) {
            ans += (v[i] - c[i]);
        }
    }
    PRINT(ans)
    return 0;
}

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

int main() {
	string S;
	cin >> S;

	if (S[0] == S[1] || S[1] == S[2] || S[0] == S[2]) {
		cout << "No";
	}
	else cout << "Yes";
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!{
        n: usize,
        a: [isize; n]
    }
    let mut p_sum = 0;
    let mut m_sum = 0;
    let mut p_ans = 0;
    let mut m_ans = 0;
    for i in 0..a.len() {
        p_sum += a[i];
        m_sum += a[i];
        if i % 2 == 0 {
            if p_sum >= 0 {
                p_ans += p_sum + 1;
                p_sum = -1;
            }
            if m_sum <= 0 {
                m_ans += m_sum.abs() + 1;
                m_sum = 1;
            }
        } else {
            if p_sum <= 0 {
                p_ans += p_sum.abs() + 1;
                p_sum = 1;
            }
            if m_sum >= 0 {
                m_ans += m_sum + 1;
                m_sum = -1;
            }
        }
    }
    println!("{}", std::cmp::min(p_ans, m_ans));
}

Measured memory_bytes: 4352
import scala.io.Source._
import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    while (true) {
      val n = readInt
      if (n == 0) return

      var map = scala.collection.mutable.HashMap[Char, Char]()
      for (i <- 0 until n) {
        val s = readLine.split(' ').map(x => x.head)
        map += (s.head -> s(1))
      }

      val nn = readInt
      for (i <- 0 until nn) {
        val x = readLine.head
        print(map.get(x).getOrElse(x))
      }
      println
    }
  }
}

Measured memory_bytes: 68228
n = int(input())
h = list(map(int,input().split()))
cost = [100000] * n
cost[0] = 0
cost[1] = abs(h[0]-h[1])
for i in range(2,n):
    sgl = cost[i-1] + abs(h[i]-h[i-1])
    dbl = cost[i-2] + abs(h[i]-h[i-2])
    cost[i] = min(sgl,dbl)
print(cost[-1])

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

int main(int argc, const char * argv[]) {
    
    int k;
    int count=0;
    
    cin >> k;
    
    if(k%2==0){
        count=(k/2)*(k/2);
    }
    else{
        count=(k/2+1)*(k/2);
    }
    
    
    cout << count << endl;
    
    return 0;
}


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

void aroundSquare(int x){
  int sqx = (int)sqrt((double)x);
  cout << sqx * sqx << endl;
}

 int main(){
  int x;
  cin>> x;
  aroundSquare(x);
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder (1000000007)
#define pie acos(-1)
#define P std::pair<int,int>
#define prique priority_queue
#define ggr getchar();getchar();return 0;
using namespace std;
int n,m;
signed main(){
    while(cin>>n>>m){
        if(!n&&!m)break;
        set<int> st;
        for(int i=1;i<=n;i++)st.insert(i);
        int cnt=0;
        for(int i=1;st.size()>1;i++){
            if(st.find(i)!=st.end()){
                cnt++;
                if(cnt%m==0)st.erase(i);
            }
            if(i==n)i=0;
        }
        cout<<*st.begin()<<endl;
    }
}


Measured memory_bytes: 3124
import math

N, D = map(int, input().split())

dots = []
for i in range(N):
    dot = input().split()
    dot = [int(j) for j in dot]
    dots.append(dot)

combinations = []
for i in range(N):
    for j in range(N):
        if i != j:
            combinations.append([i, j])

combinations2 = []
for i in combinations:
    P = dots[i[0]]
    Q = dots[i[1]]
    r2 = 0
    for j in range(D):
        r2 += (P[j] - Q[j]) ** 2
    r = math.sqrt(r2)
    if r % 1 == 0:
        combinations2.append(i)

print(len(combinations2) // 2)


Measured memory_bytes: 3064
S = input()
T = input()

cumsa = [0]
cumsb = [0]
for c in S:
    cumsa.append(cumsa[-1] + int(c == 'A'))
    cumsb.append(cumsb[-1] + int(c == 'B'))
cumta = [0]
cumtb = [0]
for c in T:
    cumta.append(cumta[-1] + int(c == 'A'))
    cumtb.append(cumtb[-1] + int(c == 'B'))

Q = int(input())
ans = []
for i in range(Q):
    a,b,c,d = map(int,input().split())
    sa = cumsa[b] - cumsa[a-1]
    sb = cumsb[b] - cumsb[a-1]
    ta = cumta[d] - cumta[c-1]
    tb = cumtb[d] - cumtb[c-1]
    ans.append('YES' if (sa-sb)%3 == (ta-tb)%3 else 'NO')

print('\n'.join(ans))

Measured memory_bytes: 20900
#include <stdio.h>

int main(void)
{
	int w, h, x, y, r, flag = 0;
	
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
	
	if (r <= x && x <= w - r){
		if (r <= y && y <= h - r){
			flag = 1;
		}
	}
	
	if (flag == 1){
		printf("Yes\n");
	}
	else if(flag == 0){
		printf("No\n");
	}
	
	return (0);
}

Measured memory_bytes: 580
//omajinai c++
#include <iostream>
#include<cmath>

#include<vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#include <map>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
constexpr auto mod = 1000000007;
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> x(n);
	int sumx = 0;
	rep(i, n) {
		cin >> x[i];
		sumx += x[i];
	}
	int mean1 = sumx / n;
	int mean2 = mean1 + 1;

	int min1 = 0, min2 = 0;
	rep(i, n) {
		min1 += (mean1 - x[i]) * (mean1 - x[i]);
		min2 += (mean2 - x[i]) * (mean2 - x[i]);
	}

	cout << min(min1, min2);
}
/*
sum((xi-p)^2)
=sum(xi^2-2*p*xi+p^2)
=sum(xi^2)-2*p*sum(xi)+n*p^2
=n(p-sum(xi)/n)+(sum(xi))^2/n+sum(xi^2)

p=floor(sum(xi)/n) or ceil(sum(xi)/n)


*/


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

int main(){
  ll a; double b;
  cin >> a >> b;
  b *= 100;
  b += 0.1;
  ll c = b;
  cout << a*c/100 << endl;
  return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int S[210];
ll mod=1000000007, dp[210][100010], frac[210];

ll modpow(ll a, ll b, ll m){
    ll res=1, p=0, now=a;
    b %= (m-1);
    for(int i=0; b>p; ++i){
        if(b&((ll) 1<<i)){
            res=(res*now)%m;
            p |= ((ll) 1<<i);
        }
        now=(now*now)%mod;
    }
    return res;
}
ll modinv(ll a, ll m){
    return modpow(a, m-2, m);
}
ll moddiv(ll a, ll b, ll m){
    return (a*modinv(b, m))%m;
}

int main() {
	int N, X;
	cin >> N >> X;
	for(int i=0; i<N; ++i) cin >> S[i];
	sort(S, S+N, greater<int>());
	frac[0]=frac[1]=1;
	for(int i=2; i<210; ++i) frac[i]=(frac[i-1]*i)%mod;
	dp[0][X]=frac[N];
	for(int i=0; i<N; ++i){
	    ll op=modinv(N-i, mod);
	    for(int j=0; j<=X; ++j){
	        ll fork=(dp[i][j]*op)%mod;
	        dp[i+1][j%S[i]]=(dp[i+1][j%S[i]]+fork)%mod;
	        dp[i+1][j]=(dp[i+1][j]+dp[i][j]-fork+mod)%mod;
	    }
	}
	ll ans=0;
	for(int i=0; i<=X; ++i) ans=(ans+dp[N][i]*i)%mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 157184
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;

int n, a, b, cnt0, cnt1, cnt2;

int main() {
    scanf("%d%d%d", &n, &a, &b);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        if (x <= a) cnt0++;
        else if (x > a && x <= b) cnt1++;
        else cnt2++;
    }
    printf("%d\n", min(min(cnt0, cnt1), cnt2));
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define DATA 100

int main(void)
{
	int h[DATA], w[DATA];
	int i, j, k, dot;

	for(i = 0;i < DATA;i++)
	{
		scanf("%d %d", &h[i], &w[i]);
		if((h[i] == 0) && (w[i] == 0))
			break;
	}

	for(i = 0;(h[i] != 0) || (w[i] != 0);i++)
	{
		for(j = 0;j < h[i];j++)
		{
			if((j == 0) || (j == h[i] - 1)) 
			{
				for(k = 0;k < w[i];k++)
					printf("#");
				printf("\n");
			}
			else
			{
				printf("#");
				for(dot = 0;dot < w[i] - 2;dot++)
					printf(".");
				printf("#\n");
			}
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

int main(){
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(v<=w) cout<<"NO"<<endl;
    else{
        if((abs(a-b)+v-w-1)/(v-w)<=t) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>



using namespace std;


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

	string str;
	cin >> str;

	if (str[K - 1] == 'A') {
		str.erase(str.begin() + K - 1);
		str.insert(str.begin() + K - 1,'a');
	}
	if (str[K - 1] == 'B') {
		str.erase(str.begin() + K - 1);
		str.insert(str.begin() + K - 1, 'b');
	}
	if (str[K - 1] == 'C') {
		str.erase(str.begin() + K - 1);
		str.insert(str.begin() + K - 1, 'c');
	}

	cout << str << endl;
}


Measured memory_bytes: 256
#include<iostream>

int n;
using namespace std;
int a,b,c,d;

int main(){
	for(int i=0; i<4; i++){
		cin >> n;
		if(n==1){
			a=1;
		}
		if(n==4){
			b=1;
		}
		if(n==7){
			c=1;
		}
		if(n==9){
			d=1;
		}
	}
	if((a==1) && (b==1) && (c==1) && (d==1)){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	//"math"
)

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	ls := scanNums(n+1)
	sum := 0
	count := 0
	for _,v := range ls{
		if(sum > x){
			break
		}
		sum+= v
		count++
	}

	fmt.Print(count)
}

func scanNums(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}

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


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

int main() {
    int n;
    cin >> n;
    ll ans = 1;
    for(int i = 0; i < n; i++) {
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3584
ABs=[]
CDs=[]
n = int(input())
for i in range(n):
    x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4, = map(float, input().split())
    AB = [x_2 - x_1, y_2 - y_1]
    CD = [x_4 - x_3, y_4 - y_3]
    ABs.append(AB)
    CDs.append(CD)
for i in range(n):
    if abs(ABs[i][0]*CDs[i][1]-ABs[i][1]*CDs[i][0])<10**(-10):
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 7764
fun main(args:Array<String>?): Unit {

    while(true){
    
        val score: Array<IntArray>
        
        val (n, m) = readLine()!!.split(' ').map(String::toInt)
        // nは生徒の人数
        // mは旅行候補の場所の数
        if(n==0 && m==0)break;
        
        score = Array(m) { IntArray(2) }
        // スコア用配列
        
		for (i in 0 until m) {
            score[i][1] = i+1
        }
        
        for (i in 0..n-1){
		    val s = readLine()!!.split(' ').map(String::toInt)
		    
		    for(j in 0..m-1){
		        
		        score[j][0] -= s[j]
		        
		    }
		    
		}
	
	    val sortedList = score.sortedWith(compareBy({ it[0] }, { it[1] }))
	
        val res = Array<Int>(m, {0})
        
        for (i in 0 until m) {
            res[i] = sortedList[i][1]
        }

        
        println(res.joinToString(" "))
        
    }
    
}


Measured memory_bytes: 67956
#include <cstdio>
#include <string>
#include <math.h>

using namespace std;

int main()
{
    int a,t,x,y,c;
    while (~scanf("%d",&a))
    {
        c=1;
        while(a--)
        {
            scanf("%d%d%d",&t,&x,&y);
            if(x+y>t)
                c=0;
            else
            {
                if((x+y)%2==0)
                {
                    if(t%2==1)
                        c=0;
                }
                else
                {
                    if(t%2==0)
                    {
                        c=0;
                    }
                }
            }
        }
        if(c==0)
            printf("No\n");
        else
            printf("Yes\n");
    }

    return 0;
}


Measured memory_bytes: 128
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7

s = input()
cnt = 0
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        cnt+=1
print(cnt)

Measured memory_bytes: 3572
def main():
    n,a,b=map(int,input().split())
    mod=10**9+7
    c,d=1,1
    for i in range(n-a+1,n+1):
        c=i*c%mod
    for i in range(1,a+1):
        c=c*pow(i,mod-2,mod)%mod
    for i in range(n-b+1,n+1):
        d=i*d%mod
    for i in range(1,b+1):
        d=d*pow(i,mod-2,mod)%mod
    print((pow(2,n,mod)-c-d-1)%mod)
main()

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define enter "\n"

typedef long long ll;


int abc100_b(){
    //入力
    int d,n;
    cin >> d >> n;
    
    if(n==100) n++;
    ll ans = pow(100,d)*n;
    
    //出力
    cout << ans << enter;
    return 0;
}

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


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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    int right = 0, sum = 0;
    ll res = 0;
    for(int left = 0; left < n; left++){
        while(right < n && (sum ^ a[right]) == (sum + a[right])) sum += a[right++];
        res += right - left;
        if(right == left) right++;
        else sum -= a[left];
    }
    cout << res << endl;
    return 0;
}


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

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
   
    int n; cin>>n; string s={};
    for (int i = 0; i < n; i++){
        char c; cin>>c; s.push_back(c);
    }
    int l=0,r=0,la=0,ra=0;
    for (int i = 0; i < n; i++){
        if(s[i]=='(')l++;
        else r++;
        la=max(la,r-l);
    }
    r=0; l=0;
    for (int i = n-1; i >= 0; i--){
        if(s[i]==')')r++;
        else l++;
        ra=max(ra,l-r);
    }
    string ls={},rs={};
    for (int i = 0; i < la; i++) ls.push_back('(');
    for (int i = 0; i < ra; i++) rs.push_back(')');
    ls+=s; ls+=rs;
    cout<<ls<<'\n';
}

Measured memory_bytes: 256
N=int(input())
def money(n):
    dp=[n]*(n+1)
    dp[0]=0
    for i in range(1,n+1):
        power=1
        while power<=i:
            dp[i]=min(dp[i],dp[i-power]+1)
            power*=6
        power=1
        while power<=i:
            dp[i]=min(dp[i],dp[i-power]+1)
            power*=9
    return dp[n]
print(money(N))

Measured memory_bytes: 3828
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);
	var c = parseInt(tmp[2], 10);
	var d = parseInt(tmp[3], 10);
	if(a+b>c+d){
	    console.log('Left');
        }else if(a+b<c+d){
	    console.log("Right");
        }else{
	    console.log("Balanced");
        }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<stdio.h>
int main(void){
	int N,X;
	int a[1000];
	int D[1000];
	D[0]=0;
	int i;
	int sum;
	scanf("%d%d",&N,&X);
	for (i=0;i<N;i++){
		scanf("%d",&a[i]);
		D[i+1]=D[i]+a[i];
	}
   sum =0;
	for(i=0;i<=N;i++){
		if(X>=D[i]){
		sum ++;
	}
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

#define int long long

const int mod = 1e9 + 7;

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);    
  int n;
  cin >> n;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  int res = 1, cur = 1, k = 1;
  for (int i = 0; i < n; ++i) {
    res *= 10;
    res %= mod;
    cur *= 9;
    cur %= mod;
    k *= 8;
    k %= mod;
  }
  res -= 2 * cur - k;
  res %= mod;
  res += mod;
  res %= mod;
  cout << res;
  return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long x = Long.parseLong(sc.next());
		long[] a = new long[n];
		long[] b = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sc.next());
			b[i] = a[i];
		}
		if (a[0] > x)
			a[0] = x;
		for (int i = 1; i < n; i++)
			a[i] = Math.min(a[i], x - a[i - 1]);
		long ans = 0;
		for (int i = 0; i < n; i++)
			ans += b[i] - a[i];
		System.out.println(ans);
	}
}

Measured memory_bytes: 49032
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i<b; i++)
#define dep(i,a,b) for(int i = a; i>b; i--)
#define makeUnique(vec) sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin())
#define LOG_vec(vec, sep) for (int fl = 0; fl < vec.size(); fl++) { std::cout << vec[fl]<< sep; } std::cout << "\n"
#define LOG_ints(vec, sep) for (int fl = 0; fl < MAXSIZE; fl++) { std::cout << vec[fl]<< sep; } std::cout << "\n"
#define all(x) (x).begin(), (x).end()
#define ll long long
#define LSB(i) ((i) & -(i))
#define MAXSIZE 30

using namespace std;

int main() {
	string q;
	cin >> q;
	if (q[2] == q[3] && q[4] == q[5]) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;
//clang++ -std=c++11 -stdlib=libc++ 
const ll mod = 1e9+7;
int main() {
  int N; cin>>N;
  vector<ll> a(N);
  rep(i,N) cin>>a[i];
  ll ans =0;
  rep(i, 60) {
    ll x=0;
    rep(j,N) {
      if (a[j]>>i &1) x++;
    }
    ll now = x*(N-x)%mod;
    rep(j, i) now = now*2%mod;
    ans = (ans + now) % mod;
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{

  int n ;
  cin >> n  ;
  int a[n]  ;
  bool ans = 1 ;
  for(int i=0;i<n;i++){
    cin >> a[i] ;
    if(a[i]%2==0){
      if(a[i]%3==0 || a[i]%5==0){
        continue;
      }else{
        ans = 0;
        break;
      }
    }
  }
  
  if(ans)
   cout << "APPROVED" << endl;
  else
   cout << "DENIED" << endl;    
  return 0;
}



Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 

fn main() {
   input! {
       k: u32,
       s: u32,
   }
   let mut count = 0;

   for i in 0..(k+1) {
       for j in 0..(k+1) {
           if i+j <= s && s-(i+j) < (k+1) {
               count = count + 1;
           }
       }
   }

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


Measured memory_bytes: 4352
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [x1, y1, x2, y2] = input[0].map(Number);

  const diffX = x2 - x1;
  const diffY = y2 - y1;

  return [x2 - diffY, y2 + diffX, x1 - diffY, y1 + diffX].join(" ");
};

console.log(main(read()));


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

using namespace std;
typedef long long ll;

ll subproblem(int N, int gB, int sB, int bB, int gA, int sA, int bA) {
    vector<ll> dp(N+1, 0);
    for(int i=0; i<=N; i++){
        dp[i] = i;
    }

    int gD = gB - gA;
    int sD = sB - sA;
    int bD = bB - bA;
    // cout << gD << " " << sD << " " << bD << endl;

    for(int i=1; i<=N; i++) {
        if(i >= gA && gD >= 0) {
            dp[i] = max(dp[i], dp[i-gA] + gB);
        }
        if(i >= sA && sD >= 0) {
            dp[i] = max(dp[i], dp[i-sA] + sB);
        }
        if(i >= bA && bD >= 0) {
            dp[i] = max(dp[i], dp[i-bA] + bB);
        }
    }

    return dp[N];
}

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

    int gA, sA, bA;
    cin >> gA >> sA >> bA;

    int gB, sB, bB;
    cin >> gB >> sB >> bB;

    ll halfN = subproblem(N, gB, sB, bB, gA, sA, bA);
    //cout << halfN << endl;

    ll ans = subproblem((int)halfN, gA, sA, bA, gB, sB, bB);

    cout << ans << endl;
}


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

int main() {
  string s; cin >> s;
  for (int i = s.size()-2; i >= 0; i-=2) {
    if (s.substr(0,i/2) == s.substr(i/2,i/2)) { cout << i << endl; return 0; }
  }
  return 0;
}


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

int main(void) {
	string s;
	string p;

	cin >> s;
	for (int i = 0; i <= s.size() - 1; i++) {
		if (s[i] == '0') {
			p.push_back('0');
		}
		else if(s[i] == '1') {
			p.push_back('1');
		}else if((s[i] == 'B')&&(p.size()!=0)){
			p.pop_back();
		}
	}
	cout << p << endl;
	return 0;
}

Measured memory_bytes: 256
c=[list(map(int,input().split())) for i in range(3)]

tmp1=c[0][1]-c[0][0]
tmp2=c[0][2]-c[0][1]

tmp3=c[1][1]-c[1][0]
tmp4=c[1][2]-c[1][1]

tmp5=c[2][1]-c[2][0]
tmp6=c[2][2]-c[2][1]

if tmp1==tmp3==tmp5 and tmp2==tmp4==tmp6:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))

a = 0
for i in range(N):
  a += A[i] * (1 if not i%2 else -1)

ans = [0] * N
ans[0] = a

for i in range(1, N):
  ans[i] = 2 * A[i-1] - ans[i-1]

print(*ans)

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

long long A[100100];
int main(){
    int n; scanf("%d",&n);
    long long sum1=0,sum=0;
    int odd=0,p=0;
    int o=0;
    for(int i=1;i<=n;i++) {
        scanf("%lld",&A[i]);
        if(A[i]==0 && o==1) odd++,o=0;
        if(A[i]<0) odd++,o=1;
        sum += abs(A[i]);
//        cout<<sum<<endl;
    }
    if(odd % 2 == 0) {
        cout<<sum<<endl;
    }
    else {
        long long z=10000000000000;
        int p=0;
        for(int i=1;i<=n;i++) {
            if(A[i]<0) {
                p=i; break;
            }
        }

        for(int i=1 ;i<=n;i++) {
            if(abs(A[i])<z) z=abs(A[i]);
        }
        cout<<sum-(z*2)<<endl;
    }
    return 0;
}


/*
test9
*/


Measured memory_bytes: 1024
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, m = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    A = [list(map(int, input().split())) for i in range(m)]

    towns = {}
    for i in range(n):
        towns[i] = 0

    for j in range(m):
        for k in range(2):
            towns[A[j][k] -1] += 1

    for l in range(n):
        print(towns[l])
resolve()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int A[3][105],f[3][105],n;
int main(){
	cin>>n;
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
			cin>>A[i][j];
	for(int i=1;i<=n;i++){
		f[1][i]=f[1][i-1]+A[1][i];
		f[2][i]=max(f[1][i],f[2][i-1])+A[2][i];
	}
	cout<<f[2][n];
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String args[]) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(),ans=0;
        for(int i=1;i<n;i++)
            for(int j=1;i*j<n;j++)
                ans++;
        System.out.println(ans);
    }
}

Measured memory_bytes: 35700
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
class Main {
    public static void main(String args[]) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String t = "";
        int i = 1;
        t =  reader.readLine();
        while(!t.equals("0")){
            System.out.println("Case " + i + ": " + t);
            i++;
            t = reader.readLine();
        }
    }
}

Measured memory_bytes: 30752
// Practice Educational DP Contest
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
	std::io::Read::read_to_string(
		&mut std::io::stdin(),
		&mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
	let mut get = || stdin.next().unwrap();
	macro_rules! get {
		($t:ty) => (get().parse::<$t>().unwrap());
		() => (get!(usize));
	}
	let h = get!();
	let w = get!();
	let mut f = vec![];
	for _ in 0..h {
		f.push(get().as_bytes());
	}
	let mut dp = vec![vec![0_i64; w]; h];
	dp[0][0] = 1;
	for y in 0..h {
		for x in 0..w {
			if f[y][x] == b'#' {
				continue;
			}
			if y > 0 {
				let e = dp[y][x] + dp[y-1][x];
				dp[y][x] = e % 1_000_000_007;
			}
			if x > 0 {
				let e = dp[y][x] + dp[y][x-1];
				dp[y][x] = e % 1_000_000_007;
			}
		}
	}
	println!("{}", dp[h-1][w-1]);
}

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

char sym[128];

void init() {
  sym['['] = ']';
  sym['{'] = '}';
  sym['('] = ')';
  sym[']'] = '[';
  sym['}'] = '{';
  sym[')'] = '(';
  sym['i'] = 'i';
  sym['w'] = 'w';
}

int main() {
  
  init();

  string str;
  cin >> str;

  int res = 3;
  
  // テ・ツ?ィテヲツ篠「テァツエツ「
  for(int i=0; i<(1<<str.size()); i++) {
    string nstr;
    for(unsigned j=0; j<str.size(); j++) {
      if((i >> j & 1)
	 || (str[j]=='i' || str[j]=='w')) nstr += str[j];
    }
    int sz = nstr.size(), cnt = 0;
    for(int j=0; j<sz/2+1; j++) {
      if(sym[(int)nstr[j]] == nstr[sz-j-1]) cnt ++;
    }
    if(cnt == sz/2+1) res = max(res, sz);
  }
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;

int main(){
    int n,a,b,c,l[8],g[8][3],gcnt[3],caseNum,lenSum[3],costSum,costMin=10000;
    cin>>n>>a>>b>>c;
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    for(int i=0;i<(int)pow(4,n);i++){
        gcnt[0]=gcnt[1]=gcnt[2]=0;
        for(int j=0;j<n;j++){
            caseNum=(i/(int)pow(4,j))%4;
            if(caseNum){
                caseNum--;
                g[gcnt[caseNum]][caseNum]=l[j];
                gcnt[caseNum]++;
            }
        }
        if(gcnt[0]==0||gcnt[1]==0||gcnt[2]==0)continue;
        costSum=10*(gcnt[0]+gcnt[1]+gcnt[2]-3);
        lenSum[0]=lenSum[1]=lenSum[2]=0;
        for(int j=0;j<3;j++){
            for(int k=0;k<gcnt[j];k++){
                lenSum[j]+=g[k][j];
            }
        }
        sort(lenSum,lenSum+3);
        costSum+=abs(lenSum[0]-c)+abs(lenSum[1]-b)+abs(lenSum[2]-a);
        if(costSum<costMin)costMin=costSum;
    }
    cout<<costMin<<endl;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	int h[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += 1;
		for (int j = i; j >= 0; j--) {
			if (h[i] < h[j]) {
				ans -= 1;
				break;
			}
		}
	}
	
	cout << ans << endl;
}

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

int main( )
{
    int n;
    int ara[111];
    int i, j, s1 = 0, s2 = 0;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> ara[i];
    }
    sort(ara + 1, ara + n + 1, greater<int>());
    for (i = 1; i <= n; i += 2) {
        s1 += ara[i];
    }
    for (i = 2; i <= n; i += 2) {
        s2 += ara[i];
    }
    cout << s1 - s2 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int w,n;
  int p;
  cin >> w >> n;
  int c[w];
  int a[n];
  int b[n];
  int j = 0;
  int j2 = 0;
  char q[n];
  for(int i=0;i<w;i++) c[i] = i + 1;
  for(int i=0;i<n;i++){
    cin >> a[i] >> q[n] >> b[i];  
  } 
 for(int i=0;i<n;i++){
    j = a[i] - 1;
    j2 = b[i] - 1; 
    p = c[j];
    c[j] = c[j2];
    c[j2] = p;
  }  
  for(int i=0;i<w;i++) cout << c[i] << endl; 
  return 0;
}

Measured memory_bytes: 1164
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	as := intSliceScanner(n)
	x := max(as)
	y := min(as)
	if x-y > 1 {
		fmt.Println("No")
	} else if x == y {
		if x == n-1 || n >= x*2 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	} else {
		c := 0
		for _, v := range as {
			if v == y {
				c++
			}
		}
		if n-c >= (x-c)*2 && x-c > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, k; cin>>a>>b>>k;
    if(a+k>=b||a+k-1>=b-k+1){
        REP(i,b-a+1) print(a+i);
    }
    else{
        REP(i,k) print(a+i);
        for(int i=k-1; i>=0; i--) print(b-i);
    }

    return 0;
}

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


def solve(N: int, D: int):
    p, r = divmod(N, D * 2 + 1)
    res = p
    if r > 0:
        res += 1
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(N, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=505;
const long long INF=4557430888798830399;
int n;
int a[N][N];
long long s1[N][N],s2[N][N];
long long f[N][N];
long long calc1(int l1,int r1,int l2,int r2)
{
	swap(l1,l2);
	swap(r1,r2);
	if(l1>r1) return 0;
	if(l2>r2) return 0;
	return s1[r1][r2]-s1[l1-1][r2]-s1[r1][l2-1]+s1[l1-1][l2-1];
}
long long calc2(int l1,int r1,int l2,int r2)
{
	if(l1>r1) return 0;
	if(l2>r2) return 0;
	return s2[r1][r2]-s2[l1-1][r2]-s2[r1][l2-1]+s2[l1-1][l2-1];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i!=j) scanf("%d",&a[i][j]);
	for(int i=1;i<=n+1;i++)
		for(int j=1;j<=n+1;j++)
		{
			s1[i][j]=s1[i-1][j]+s1[i][j-1]-s1[i-1][j-1];
			if(i>j) s1[i][j]+=a[i][j];
			s2[i][j]=s2[i-1][j]+s2[i][j-1]-s2[i-1][j-1];
			if(i<j) s2[i][j]+=a[i][j];
		}
	memset(f,63,sizeof(f));
	f[0][0]=0;
	for(int i=0;i<=n;i++)
		for(int j=i;j<=n;j++)
			if(f[i][j]<INF)
				for(int k=j+1;k<=n+1;k++)
					f[j][k]=min(f[j][k],f[i][j]+calc1(i+1,j,k+1,n+1)+calc2(j+1,k,j+1,k));
	long long res=INF;
	for(int i=0;i<=n;i++)
		res=min(res,f[i][n+1]);
	printf("%lld",res);
	return 0;
}


Measured memory_bytes: 10704
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp::{max, min};

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<i64>();
    let x = scan.read::<i64>();
    let mut l = max(n - x, x);
    let mut s = min(n - x, x);
    let mut ret = n;
    while s != 0 {
        let q = l / s;
        let r = l % s;
        ret += q * 2 * s;
        if r == 0 {
            ret -= s;
        }
        l = s;
        s = r;
    }
    println!("{}", ret);
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut ret = vec![];
        for _ in 0..n { ret.push(self.read::<T>()) }
        ret
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

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

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  string ans = "";

  while(n) {
    n--;
    ans += 'a' + (n % 26);
    n /= 26;
  }

  reverse(ans.begin(), ans.end());

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int main()
{
  int r;
  cin >> r;
  cout << 3*r*r << endl;
  return 0;
}


Measured memory_bytes: 256