akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
  int i,j,k;
  int r,c;
  int b;
  cin >> r >> c;
  int rsum[100]={};
  int csum[100]={};
  int sum=0;
  for(i=0;i<r;i++){
    cin >> b;
    cout << b;
    rsum[i]+=b;
    csum[0]+=b; 
    for(j=1;j<c;j++){
      cin >> b;
      cout <<" " << b;
      rsum[i]+=b;
      csum[j]+=b; 
    }
    cout << " " << rsum[i] << endl;
    sum+=rsum[i];
  }
  cout << csum[0];
  for(j=1;j<c;j++){
    cout << " " << csum[j];    
  }
  cout << " " << sum <<  endl;
  return 0;
}



Measured memory_bytes: 3116
#[allow(unused_imports)]
use std::cmp::{min,max};

fn main() {
    let n = read_i64();
    let (d,x) = {
        let xs = read_vec_i64();
        (xs[0],xs[1])
    };
    let bs = {
        let mut xs = vec![];
        for _ in 0..n {
            let a = read_i64();
            xs.push(a);
        }
        xs
    };
    let mut res = x;
    for i in 0..n {
        for k in 0.. {
            let y = 1 + k * bs[i as usize];
            if y > d { break; }
            res += 1;
        }
    }
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int A = sc.nextInt();
	    int B = sc.nextInt();
	    
	    int cal1 = A + B;
	    int cal2 = A - B;
	    int cal3 = A * B;
	    
	    int max = 0;
	    
	    if (cal1 >= Math.max(cal2, cal3)) {
	    	max = cal1;
	    } else if (cal2 >= Math.max(cal3, cal1)) {
	    	max = cal2;
	    } else {
	    	max = cal3;
	    }
	    System.out.println(max);
	}	
}	

Measured memory_bytes: 22868
#include <stdio.h>

int main(void)
{
    int dish[5];
    int ans;

    int i;
    int min_mod, min_id;

    for(i=0;i<5;i++){
        scanf("%d", &dish[i]);
    }

    min_mod = dish[0] % 10;
    min_id = 0;
    for(i=1;i<5;i++){
        if(min_mod == 0){
            min_mod = dish[i] % 10;
            min_id = i;
        }
        if(((dish[i] % 10) < min_mod) && ((dish[i] % 10) != 0)){
            min_mod = dish[i] % 10;
            min_id = i;
        }
    }

    ans = 0;
    for(i=0;i<5;i++){
        if(i == min_id){
            continue;
        }else{
            if(dish[i] % 10 == 0){
                ans += dish[i];
            }else{
                ans += (dish[i] / 10 + 1) * 10;
            }
        }
    }

    ans += dish[min_id];

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
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;}
const long long INF = 1LL<<60;

int main(){
    int n,k;
    cin >>n>>k;
    //int h[100000+7];
    vector<long long>h(n+1); 
       vector<long long> dp(n+1,INF);
   // long long dp[100000+7];
   /* for(int i=0;i<n+1;i++){
        dp[i]=INF;
    }*/
    dp[0]=0;

    for(int i=0;i<n;i++){
        cin >>h[i];
     //   cout<<h[i]<<endl;
    }

    for(int i=0;i<n;i++){
        for(int j=max(i-k,0);j<i;j++){
          //  cout << abs(h[i] - h[j])<<"-";
         chmin(dp[i], dp[j] + (abs(h[i] - h[j])));
        }
      //  cout<<i <<"->"<<dp[i]<<endl;
    }
    cout<<dp[n-1]<<endl;
}


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

int main(){
    int n,m;
    cin >> n;
    vector<int> t(n+1);
    int time = 0;
    for (int i = 1;i <= n;i++){
        cin >> t.at(i);
        time += t.at(i);
    }
    cin >> m;
    vector<int> ans(m);
    for (int i = 0;i < m;i++){
        int p,x;
        cin >> p >> x;
        ans.at(i) = time - t.at(p) + x;   
    }
    
    for (int i = 0;i < m;i++){
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 256
a = int(input())
l = [a]
for i in range(1000000):
  if a % 2 == 0:
    a = a//2
  else:
    a = a*3 + 1
  if l.count(a)==2:
    print(1+max([i for i, x in enumerate(l) if x == a]))
    break
  else:
    l.append(a)


Measured memory_bytes: 9036
#include <iostream>
#include <cmath>

const int max = 7368792;
bool prime[max] = {false};
int main(){
	while(true){
		int m, n;

		std::cin >> m >> n;

		if ( m == 0 && n == 0 ) break;
		for ( int i = 0; i < max; ++i ) {
			prime[i] = false;
		}
		for ( int i = 1; i * m < max; ++i ) {
			prime[i * m] = true;
		}
		int k = n - 1;

		int i;
		for ( i = m + 1; i < max; ++i ) {
			if ( prime[i] == false ) {
				if ( k != 0 ) {
					k--;
					for ( int j = 1; i * j < max; ++j ) {
						prime[j * i] = true;
					}
				} else {
					break;
				}
			}
		}
		std::cout << i << std::endl;
	}
	return 0;
}

Measured memory_bytes: 10264
#include <bits/stdc++.h>
using namespace std;
#define mx 103
long long int wt[mx],val[mx];
long long int dp[mx][100005];

long long int knapsack(int n,int w)
{
    for(int i=0;i<n+1;i++)
    {
        for(int j=0;j<w+1;j++)
        {
            if(i==0 || j==0)dp[i][j]=0;
            else if(j>=wt[i-1])dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
            else dp[i][j]=dp[i-1][j];
        }
    }
    return dp[n][w];
}

int main()
{
    int n,w;
    cin>>n>>w;
    for(int i=0;i<n;i++)cin>>wt[i]>>val[i];
    cout<<knapsack(n,w)<<endl;
    return 0;
}


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

answer = float('inf')
for s in range(len(S)):
    if len(S) - s < len(T):
        break
    count = 0
    for t in range(len(T)):

        if S[s+t] != T[t]:
            count += 1
            
    answer = min(answer, count)

print(answer)

Measured memory_bytes: 9036
class Arrow
  attr_reader :source, :sink, :label
   
  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
  end
end
 
class Result
  attr_reader :target, :spell
 
  def initialize(target, spell)
    @target = target
    @spell = spell
  end
end
 
def advance(table, n, goes, arrows)
  next_table = table
  (0...n).each do |node|
    best = table[node]
    goes[node].each do |arrow|
      result = table[arrow.sink]
      next unless result
      test = arrow.label + result.spell
      if !best || test < best.spell
        best = Result.new(arrow.sink, test)
      end
    end
    next_table[node] = best if best
  end
  next_table
end
 
def has_cycle(table, result, n)
  used = [false] * n
  loop do
    node = result.target
    return false unless node
    return true if used[node]
    used[node] = true
    result = table[node]
  end
end
 
def work(n, arrows, start, goal)
  goes = (0...n).map{[]}
  arrows.each do |arrow|
    goes[arrow.source] << arrow
  end
  table = [nil] * n
  table[goal] = Result.new(nil, '')
  n.times do
    table = advance(table, n, goes, arrows)
  end
  return nil unless table[start]
  (n*5).times do
    table = advance(table, n, goes, arrows)
  end
  result = table[start]
  has_cycle(table, result, n) ? nil : result.spell
end
 
loop do
  n, a, s, g = STDIN.gets.split.map(&:to_i)
  break if n == 0
 
  arrows = (0...a).map do |i|
    x, y, lab = STDIN.gets.split
    x = x.to_i
    y = y.to_i
    Arrow.new(x, y, lab)
  end
 
  start = s
  goal = g
 
  puts work(n, arrows, start, goal) || 'NO'
end

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

const int INF = 1000000;
typedef pair<int,int> P;

char maze[50+1][50+1];
int h,w;
int sx,sy,gx,gy;
int d[50+1][50+1];

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

int bfs(){
  queue<P> que;
    
  for(int i=0;i<h+1;i++){
    for(int j=0;j<w+1;j++){
      d[i][j] = INF;
    }
  }
  
  que.push(P(sy,sx));
  d[sy][sx] = 0;
  
  while(que.size()){
    
    P p = que.front();
    que.pop();
    //cout << p.first << ' ' << p.second << endl;
    if(p.first == gy && p.second == gx) break;
    
    for(int i=0;i<4;i++){
      int ny = p.first + dy[i] , nx = p.second + dx[i];
      
      if(nx > 0 && nx <= w && ny > 0 && ny <= h && maze[ny][nx] == '.' && d[ny][nx] == INF){
        que.push(P(ny,nx));
        d[ny][nx] = d[p.first][p.second] + 1;
        //cout << ny << ' ' << nx << endl;
        //cout << d[ny][nx] << endl;
      }
    }
  }
  return d[gy][gx];
}  

int main(){
  cin >> h >> w;
  //cin >> sy >> sx;
  //cin >> gy >> gx;
  sx = 1; sy = 1;
  gx = w; gy = h;
  int bcnt;
  
  for(int i=1;i<h+1;i++){
    string s;
    cin >> s;
    for(int j=1;j<w+1;j++){
      maze[i][j] = s.at(j-1);
      if(s.at(j-1) == '#') bcnt++;
    }
  }
  
  int cnt = bfs();
  //cout << cnt << endl;
  if(cnt == INF) cout << -1 << endl; 
  else{
    int ans = h*w - cnt - 1 - bcnt;
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	double r,area,zhou,PI;
	cin >> r;
	PI = M_PI;
	area = PI * r * r;
	zhou = PI * (r * 2);
	printf("%lf %lf",area,zhou);
	return 0;
}

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

int main(){
	bool cards[4][14];
	int n, rank;
	char suit;

	for ( int s = 0; s < 4; s++ )
	 for ( int r = 1; r <= 13; r++ )
	  cards[s][r] = 0;
	
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		cin >> suit >> rank;
		if ( suit == 'S' ) cards[0][rank] = 1;
		if ( suit == 'H' ) cards[1][rank] = 1;
		if ( suit == 'C' ) cards[2][rank] = 1;
		if ( suit == 'D' ) cards[3][rank] = 1;
	}

	for ( int s = 0; s < 4; s++ ){
		for ( int r = 1; r <= 13; r++){
			if ( cards[s][r] ) continue;
			if ( s == 0 ) suit = 'S';
			if ( s == 1 ) suit = 'H';
			if ( s == 2 ) suit = 'C';
			if ( s == 3 ) suit = 'D';
			cout << suit << " " << r << endl;
		}
	}
	return 0;

}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int main(){
  int w,h,n;
  cin>>w>>h>>n;
  int x,y,a;
  int lx=0,rx=w,uy=h,dy=0;
  while(n--){
    cin>>x>>y>>a;
    if(a==1)lx=max(lx,x);
    else if(a==2)rx=min(rx,x);
    else if(a==4)uy=min(uy,y);
    else dy=max(dy,y);
  }
  int ansx=rx-lx,ansy=uy-dy;
  if(rx-lx<=0)ansx=0;
  if(uy-dy<=0)ansy=0;
  cout<<ansx*ansy<<endl;
}


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



int main(){
  int i,seitosuu;
  double average,V,sigma,nijouwa,score;
  scanf("%d",&seitosuu);
  while(seitosuu!=0){
    sigma=0;
    nijouwa=0;
    for(i=1;i<=seitosuu;i++){
      scanf("%lf",&score);
      sigma+=score;
      nijouwa+=score*score;
    }
    average=sigma/seitosuu;
    V=nijouwa/seitosuu - average*average;
    printf("%lf\n",pow(V,0.5));
    scanf("%d",&seitosuu);
  }
  return 0;
}

Measured memory_bytes: 708
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		int ans = a[0];
		for (int i = 1; i < n; i++) {
			ans = gcd(ans, a[i]);
		}
		System.out.println(ans);
	}

	static int gcd(int a, int b) {
		return BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).intValue();
	}
}


Measured memory_bytes: 62340
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	private static final int BIG_NUM  = 2000000000;
	private static final int MOD  = 1000000007;

	private static Node nodes[];

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

		nodes = new Node[N];
		for(int i = 0; i < N; i++)nodes[i] = new Node();

		int id,num,child_id;
		for(int loop = 0; loop < N; loop++){
			id = scanner.nextInt();
			num = scanner.nextInt();

			for(int i = 0; i < num; i++){
				child_id = scanner.nextInt();
				nodes[id].children.add(child_id);
				nodes[child_id].setParent_id(id);
			}
		}

		for(int i = 0; i < N; i++){
			if(nodes[i].getParent_id() == -1){
				calcDepth(i,0);
			}
		}

		StringBuilder ans = new StringBuilder();

		for(int i = 0; i < N; i++){
			ans.append("node ").append(Integer.toString(i)).append(": parent = ").append(Integer.toString(nodes[i].getParent_id()))
			.append(", depth = ").append(Integer.toString(nodes[i].getDepth())).append(", ");

			if(nodes[i].getParent_id() == -1){
				ans.append("root, ");
			}else if(nodes[i].children.size() == 0){
				ans.append("leaf, ");
			}else{
				ans.append("internal node, ");
			}

			ans.append("[");
			if(nodes[i].children.size() > 0){
				ans.append(Integer.toString(nodes[i].children.get(0)));
				for(int k = 1; k < nodes[i].children.size(); k++){
					ans.append(", ").append(Integer.toString(nodes[i].children.get(k)));
				}
			}
			ans.append("]\n");
		}
		System.out.print(ans.toString());
	}

	static void calcDepth(int id,int value){
		nodes[id].setDepth(value);

		for(int i = 0; i < nodes[id].children.size(); i++){
			calcDepth(nodes[id].children.get(i),value+1);
		}
	}
}

class Node{
	private int parent_id;
	private int depth;
	public ArrayList<Integer> children;

	Node(){
		children = new ArrayList<Integer>();
		parent_id = -1;
	}

	public int getParent_id() {
		return parent_id;
	}

	public void setParent_id(int parent_id) {
		this.parent_id = parent_id;
	}

	public int getDepth() {
		return depth;
	}

	public void setDepth(int depth) {
		this.depth = depth;
	}
}


Measured memory_bytes: 136240
#include<bits/stdc++.h>
#include<atcoder/segtree>
using namespace std;
using namespace atcoder;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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 lli MAX_A = 300005;
using S = int;

S op(S a, S b){
    return max(a, b);
}

S e(){ return 0;}

lli n, k;

int main(void){
    cin >> n >> k;
    segtree<S, op, e> dp(MAX_A);
    rep(i, n){
        lli a, l, r;
        cin >> a;
        l = max(0LL, a-k);
        r = min(MAX_A, a+k+1);
        lli now = dp.prod(l, r);
        dp.set(a, S(now+1));
    }
    lli ans = dp.all_prod();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8516
#include<stdio.h>
#include<math.h>
int main(void){
  int tate,yoko,takasa;
  int n;
  int r;
  int i;
  int tmp;

  while(1){
    scanf("%d %d %d",&tate,&yoko,&takasa);
    if(tate+yoko+takasa==0)
      break;
    scanf("%d",&n);
    if(tate>yoko){
      tmp=tate;
      tate=yoko;
      yoko=tmp;
    }
    if(yoko>takasa){
      tmp=yoko;
      yoko=takasa;
      takasa=tmp;
    }
    for(i=0;i<n;i++){
      scanf("%d",&r);
      if(sqrt(tate*tate+yoko*yoko)>=2*r)
	printf("NA\n");
      else
	printf("OK\n");
    }
  }
  return 0;
}
    

Measured memory_bytes: 584
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

const int K = 20;
const int N = 1e5 + 9;

struct Query {
	int v;
	int c;
	int color;
	int index;

	Query(int v_, int c_, int color_, int index_) {
		v = v_;
		c = c_;
		color = color_;
		index = index_;
	}
};


vector<tuple<int, int, int>> g[N];


int cnt[N];
int sm[N];

int cans[N];
int qcnt[N];
int qsm[N];
int qd[N];

vector<Query> q[N];

void dfs(int cur, int p) {
	for (auto qr : q[cur]) {
		qcnt[qr.index] += qr.c * cnt[qr.color];
		qsm[qr.index] += qr.c * sm[qr.color];
	}
	for (auto t : g[cur]) {
		int u, cl, w;
		tie(u, cl, w) = t;
		if (u != p) {
			cnt[cl]++;
			sm[cl] += w;
			dfs(u, cur);
			cnt[cl]--;
			sm[cl] -= w;
		}
	}
}

int alls[N];

int pr[N];
int up[K][N];
int tin[N];
int tout[N];

int timer = 0;

void jfs(int cur, int p, int len) {
	tin[cur] = timer++;
	pr[cur] = p;
	alls[cur] = len;
	for (auto t : g[cur]) {
		int u, cl, w;
		tie(u, cl, w) = t;
		if (u != p) {
			jfs(u, cur, len + w);
		}
	}
	tout[cur] = timer++;
}

void init(int n) {
	for (int i = 0; i < n; i++) {
		up[0][i] = pr[i];
	}
	for (int i = 0; i + 1 < K; i++) {
		for (int j = 0; j < n; j++) {
			int mid = up[i][j];
			if (mid == -1) {
				up[i + 1][j] = mid;
			} else {
				up[i + 1][j] = up[i][mid];
			}
		}
	}
}

int anc(int u, int v) {
	return tin[u] <= tin[v] && tout[v] <= tout[u];
}

int lca(int u, int v) {
	if (anc(u, v)) {
		return u;
	} else if (anc(v, u)) {
		return v;
	} else {
		for (int i = K - 1; i >= 0; i--) {
			if (up[i][u] != -1 && !anc(up[i][u], v)) {
				u = up[i][u];
			}
		}
		return pr[u];
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, qc;
	cin >> n >> qc;
	for (int i = 0; i + 1 < n; i++) {
		int u, v, c, w;
		cin >> u >> v >> c >> w;
		u--, v--;
		g[u].push_back(make_tuple(v, c, w));
		g[v].push_back(make_tuple(u, c, w));
	}
	jfs(0, -1, 0);
	init(n);
	for (int i = 0; i < qc; i++) {
		int cl, nd, u, v;
		cin >> cl >> nd >> u >> v;
		u--, v--;
		q[u].push_back(Query(u, 1, cl, i));
		q[v].push_back(Query(v, 1, cl, i));
		int l = lca(u, v);
		q[l].push_back(Query(l, -2, cl, i));
		qd[i] = nd;
		cans[i] = alls[u] + alls[v] - 2 * alls[l];
	}
	dfs(0, -1);
	for (int i = 0; i < qc; i++) {
		cans[i] -= qsm[i];
		cans[i] += qcnt[i] * qd[i];
		cout << cans[i] << '\n';
	}
}


Measured memory_bytes: 32244
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc096_a.cpp
 * time   : Thu Apr 30 18:35:37 2020
 * quest  : A - Day of Takahashi
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << ((b >= a) ? a : a - 1) << "\n";
  return 0;
}


Measured memory_bytes: 256
N , M = map(int,input().split())

A = []
B = []

for i in range(N):

    a = input()
    A.append(a)

for i in range(M):

    b = input()
    B.append(b)

if N-M < 0:
    print ("No")

elif N == M:

    flag = True
    for i in range(N):

        for j in range(N):

            if A[i][j] != B[i][j]:

                flag = False

    if flag:
        print ("Yes")
    else:
        print ("No")

else:

    for i in range(N-M+1):

        for j in range(N-M+1):

            flag = True
            for x in range(M):

                for y in range(M):

                    if A[i+x][j+y] != B[x][y]:

                        flag = False

            if flag:
                break
        if flag:
            break

    if flag:
        print("Yes")

    else:
        print("No")



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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  ll A, B; scanf("%lld %lld", &A, &B);
  vector<int> X(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &X[i]);
  }
  sort(X.begin(), X.end());
  ll ans = 0;
  for (int i = 0; i + 1 < N; ++i) {
    ans += min(A * (X[i + 1] - X[i]), B);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string S;
	map <char,int> mappy;
	int k=0;
	cin>>S;
	for(int i=0;i<S.length();i++)
	{
		mappy[S[i]]++;
	}
	for(auto i:mappy)
	{
		if(i.second!=2)
		{
			k=1;
			break;
		}
	}
	if(k)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
N, A, B = [int(x) for x in input().split()]
if (A-B)%2:
    print(min(B-1, (A-1)+ 1 + ((B-A)-1)//2, (N-B)+ 1 + (N-(A+(N-B+1)))//2, N-A))
else:
    print(min(B-1, (B-A)//2, N-A))


Measured memory_bytes: 38416
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

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

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    ll w, h, x, y; cin >> w >> h >> x >> y;
    double ans = (double)(w * h) / 2;
    int f = 0;
    if (x * 2 == w && y * 2 == h) f = 1;
    printf("%.10lf %d\n", ans, f);
    return 0;
}





















Measured memory_bytes: 256
#include <stdio.h>
int a[1000000];
long long i,j,s;
int main( void ){
	for(i=2;i<1000000;i++){
		if(!a[i])for(j=i*i;j<1000000;j+=i)a[j]=1;
		a[i]=s+=!a[i];
	}
	for(;~scanf("%d",&i);printf("%d\n",a[i]));
	return 0;
}

Measured memory_bytes: 0
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 scanner = new Scanner(System.in);
		int num = scanner.nextInt();
		if (num <= 100) {
			int array[] = new int[num];
			List<Integer> list = new ArrayList<Integer>();
			for (int i = 0; i < array.length; i++) {
				int next = scanner.nextInt();
				if (0 <= next && next < 1000) {
					list.add(next);
				}
			}
			Collections.reverse(list);

			for (int i = 0; i < list.size(); i++) {
				if (i == (list.size()-1)) {
					System.out.println(list.get(i));
				} else {
					System.out.print(list.get(i) + " ");
				}
			}
		}
	}
}

Measured memory_bytes: 26116
#include<stdio.h>
int main() {
  char *days[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
  int month[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  int i, n, a, b;
  while (1) {
    scanf("%d %d", &a, &b);
    if (!(a||b)) break;
    n = b;
    for (i = 1; i < a; i ++) n += month[i - 1];
    printf("%s\n", days[(n + 2) % 7]);
  }
  return 0;
}

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

const int N = 1e5+10;
int a[N];
int main(){
    ll k;
    cin >> k;
    ll ans = k/500*1000;
    k%=500;
    ans += k/5*5;
    cout << ans<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vite ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tst int T; cin>>T; while(T--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define ll long long int
#define vt vector
#define pb push_back
int main()
{
    vite;
    ll a,b;
    cin >> a >> b;
    cout << a * b;

    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int k=s.size();
  int ans=0;
  for(int i=0;i<k;i++){
    int count=0;
    for(int j=i;j<k;j++){
      if(s.at(j)=='A'||s.at(j)=='C'||s.at(j)=='G'||s.at(j)=='T'){
        count++;
      }
      else{
        break;
      }
    }
    ans=max(ans,count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<double> vec;
typedef vector<vector<ll>> mat;
typedef pair<double,int> P;

struct edge{int to;double cost;};
double INF=1.0e15;

int N;
//隣接リスト
vector<vector<edge>> G;

double dijkstra(){
    priority_queue<P,vector<P>,greater<P>> que;
    vec d(N+2,INF);d[0]=0.0;
    que.push(P(0.0,0));

    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for(auto e:G[v]){
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
    return d[N+1];
}

int main(){
    double xs,ys,xt,yt;cin>>xs>>ys>>xt>>yt>>N;
    vec x(N+1),y(N+1),r(N+1);
    for(int i=1;i<=N;i++) cin>>x[i]>>y[i]>>r[i];
    G.resize(N+2);
    G[0].push_back((edge){N+1,sqrt((xs-xt)*(xs-xt)+(ys-yt)*(ys-yt))});
    for(int i=1;i<=N;i++){
        double d=sqrt((x[i]-xs)*(x[i]-xs)+(y[i]-ys)*(y[i]-ys));
        if(d<r[i]) G[0].push_back((edge){i,0.0});
        else       G[0].push_back((edge){i,d-r[i]});
    }
    for(int i=1;i<=N;i++){
        double d=sqrt((x[i]-xt)*(x[i]-xt)+(y[i]-yt)*(y[i]-yt));
        if(d<r[i]) G[i].push_back((edge){N+1,0.0});
        else       G[i].push_back((edge){N+1,d-r[i]});
    }
    for(int i=1;i<=N;i++){
        for(int j=i+1;j<=N;j++){
            double d=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
            if(r[i]+r[j]>d){
                G[i].push_back((edge){j,0.0});
                G[j].push_back((edge){i,0.0});
            }
            else{
                G[i].push_back((edge){j,d-r[i]-r[j]});
                G[j].push_back((edge){i,d-r[i]-r[j]});           
            }
        }
    }
    printf("%.10lf\n",dijkstra());
    return 0;
}

Measured memory_bytes: 22532
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

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

    cin >> A;

    cout << A+A*A+A*A*A << endl;    

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;
int sum[2][101];

int main(){
  cin >> n;
  rep(i,2)rep(j,n)cin >> sum[i][j];
  rep(i,2){
    rep(j,n)sum[i][j+1] += sum[i][j];
  }
  ll ans = 0;
  rep(i,n){
    ll num = sum[0][i] + sum[1][n];
    if(i != 0)num -= sum[1][i - 1];
    ans = max(ans,num);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX(x,y) ((x)<(y)?(y):(x))
 
typedef long long ll;
 
typedef struct Hoge{
    int a;
    int b;
    int c;
    ll d;
}hoge;
 
void search(int i,int N,int M,int Q,int *A,hoge *AL,ll *max){
    if(i==N+1){
        int tmp = 0;
        for(int q = 0;q<Q;q++){
            if(A[AL[q].b-1]- A[AL[q].a-1] == AL[q].c) tmp+=AL[q].d;
        }
        *max = MAX(*max,tmp);
    }else if(i==1){
        for(int j = 1;j<=M;j++){
            A[i-1]=j;
            search(i+1,N,M,Q,A,AL,max);
        }
    }else{
        for(int j = A[i-2];j<=M;j++){
            A[i-1]=j;
            search(i+1,N,M,Q,A,AL,max);
        }
    }
}
 
int main(){
    int N,M,Q;
    scanf("%d %d %d",&N,&M,&Q);
    int A[N];
    hoge AL[Q];
    for(int i = 0;i<N;i++) A[i]=0;
    ll ans=0;
    for(int i = 0;i<Q;i++)scanf("%d %d %d %lld",&AL[i].a,&AL[i].b,&AL[i].c,&AL[i].d);
    search(1,N,M,Q,A,AL,&ans);
    printf("%lld\n",ans);
    
    return 0;
}

Measured memory_bytes: 1692
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
lli inf = 1e18;

int main(){
	int k,x;
	cin >> k >> x;
	if(500*k >= x){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k;
  cin>>a>>b>>k;
  if(2*k<=b-a+1){
    for(int i=0; i<k;i++){
      cout<<a+i<<endl;
    }
    for(int i=0;i<k;i++){
      cout<<b-k+1+i<<endl;
    }
  }else{
    for(int j=0;j<b-a+1;j++){
      cout<<a+j<<endl;
    }
  }
}

Measured memory_bytes: 256
#![allow(unused_imports)]
    #![allow(dead_code)]
    use std::io::prelude::*;
    use std::cmp::{max, min};
    use std::collections::{BinaryHeap, VecDeque};

    const MOD: i64 = 1e9 as i64 + 7; 

    fn main(){
        let s: Vec<char> = read::<String>().chars().collect();
        let mut e = [false; 26];
        let mut f = true;
        for i in s{
            let x = (i as u8 - b'a') as usize;
            if e[x]{
                f = false;
                break;
            }
            e[x] = true;
        }
        let ans = if f {"yes"} else {"no"};
        println!("{}", ans);
    }

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


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

int n, ans;

int main() {
  scanf("%d", &n);
  if (n < 10) {
     ans = n;
  } else if (n >= 10 && n < 100) {
    ans = 9;
  } else if (n >= 100 && n < 1000) {
    ans = 9 + (n - 100) + 1;
  } else if (n >= 1000 && n < 10000) {
    ans = 9 + 900;
  } else if (n >= 10000 && n < 100000) {
    ans = 9 + 900 + (n - 10000) + 1;
  } else ans = 90909;
  printf("%d\n", ans);
  return 0;
}


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

map<string, int> m;
vector<pair<int, string>> v;
vector<string> ans;

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

    while (n--)
    {
        string s;
        cin >> s;
        m[s]++;
    }

    for (auto x : m)
    {
        v.push_back(make_pair(x.second, x.first));
    }
    sort(v.begin(), v.end());

    /*
    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i].first << " " << v[i].second << endl;
    }
    */

    int index = v.size() - 1;
    while (index >= 0 && v[index].first == v[v.size() - 1].first)
    {
        ans.push_back(v[index].second);
        index--;
    }

    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 41128
#include <cstdio>
#define add(x, y) printf("%d %d\n", x, y);
int main()
{
	int n;
	scanf("%d", &n);
	if (__builtin_popcount(n) == 1)
	{
		puts("No");
		return 0;
	}
	puts("Yes");
	add(1, 2);
	add(2, 3);
	add(n + 3, 1);
	add(n + 3, n + 2);
	add(n + 2, n + 1);
	for (int i = 4; i + 1 <= n; i += 2)
	{
		add(1, i);
		add(i, i + 1);
		add(1, n + i + 1);
		add(n + i + 1, n + i);
	}
	if (n & 1 ^ 1)
	{
		for (int i = 2; i < n; i++)
		{
			int j = n ^ 1 ^ i;
			if (j < n && j >= 2 && i != j)
			{
				add(i + (i & 1) * n, n);
				add(j + (j & 1) * n, n * 2);
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2304
#include <iostream>

using namespace std;
int main(void){
    
    int n,a;
    cin >> n;
    
    int data[n];
    
    for(int i=0;i<n;i++){
        cin >> a;
        data[i] = a;
    }
    for(int i=n-1;i>=0;i--){
        if(i==n-1){
            cout << data[i];
        }else{
            cout <<" "<< data[i];
        }
    }
    cout << endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    vector<ll> d(N); rep(i, N){cin >> d.at(i);}
    sort(d.begin(), d.end());
    cout << d.at(N / 2) - d.at(N / 2 - 1) << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1024
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
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<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
int main(){
	int n;cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	vi t(n-1);
	rep(i,n){
		int r=in[i]%(n-1);
		if(t[r]){
			cout<<in[t[r]-1]<<" "<<in[i]<<endl;
			return 0;
		}
		t[r]=i+1;
	}
}













Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;
using tdata=pair<datas,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll modncr(ll n,ll r){
  if(r*2>n)return modncr(n,n-r);
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i,N,ch=0,sum=0;
  cin>>N;
  vec a(N);
  rep(i,N)cin>>a[i];
  vsort(a);
  rep(i,N){
    if(sum*2<a[i])ch=i;
    sum+=a[i];
  }
  cout<<N-ch<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int r, c;
	cin >> r >> c;
	int t[r+1][c+1];

	REP(i, r){
		REP(j, c){
			cin >> t[i][j];
		}
	}
	
	int sum  = 0;
	REP(i, r){
		REP(j, c){
			sum += t[i][j];
		}
		t[i][c] = sum;
		sum = 0;
	}

	REP(j, c){
		REP(i, r){
			sum += t[i][j];
		}
		t[r][j] = sum;
		sum  = 0;
	}

	REP(i, c){
		sum += t[r][i];
	}
	t[r][c] = sum;

	REP(i, r+1){
		REP(j, c+1){
			cout << t[i][j];
			if (j < c) cout << " ";
		}
		cout << endl;
	}
}





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

public class Main {

	static String matrix[][];
	static int dist[][];
	static boolean used[][];

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

	static int w;
	static int h;

	static int min = Integer.MAX_VALUE;

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String str[] = br.readLine().split(" ");
		String str1[] = str[0].split("");
		String str2[] = str[1].split("");

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			sb.append(str1[i]);
			sb.append(str2[i]);
		}
		System.out.println(sb);
	}
}

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

int h, w = 0;
int ct = 0;
vector<string> map;

void count(int y,int x){
	map[y][x] = 'X';
	if (y != 0){
		if (map[y-1][x] == '.'){
				count(y-1,x);
		}
	}
	if (y != h-1){
		if (map[y+1][x] == '.'){
				count(y+1,x);
		}
	}
	if (x != 0){
		if (map[y][x-1] == '.'){
				count(y,x-1);
		}
	}
	if (x != w-1){
		if (map[y][x+1] == '.'){
				count(y,x+1);
		}
	}
	ct++;
}

int main(){
	int stx, sty;
	while (1){
		cin >> w >> h;
		if (h == 0 && w == 0){
			break;
		}
		for (int i = 0; i < h; i++){
			string tmp;
			cin >> tmp;
			map.push_back(tmp);
			for (int j = 0; j < w; j++){
				if (map[i][j] == '@'){
					sty = i;
					stx = j;
				}
			}
		}
		count(sty,stx);
		cout << ct << endl;
		ct = 0;
		map.clear();
	}
	return 0;
}

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

const int mod = 1e9 + 7;
const int N = 100005;

int F(int n, int p, int m){
  if(p == 0) return 1;
  if(p & 1){
    return 1ll * n * F(n, p - 1, m) % m;
  }
  int d = F(n, p / 2, m);
  return 1ll * d * d % m;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector < int > vec(n), dp(n), f(n);
  for(int i = 0; i < n; i++){
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  f[0] = 1;
  for(int i = 1; i < n; i++){
    f[i] = 1ll * f[i - 1] * i % mod;
  }
  dp[0] = vec[0] % mod;
  for(int i = 1; i < n; i++){
    dp[i] = dp[i - 1] + vec[i];
    dp[i] %= mod;
  }
  int ans = 0;
  for(int i = k; i <= n; i++){
    int lft = dp[n - i];
    int rgt = dp[n - 1] - (i > 1 ? dp[i - 2] : 0);
    lft %= mod; lft += mod; lft %= mod;
    rgt %= mod; rgt += mod; rgt %= mod;
    int sum = rgt - lft;
    sum %= mod; sum += mod; sum %= mod;
    int ncr = 1ll * f[i - 2] * F(1ll * f[k - 2] * f[i - k] % mod, mod - 2, mod) % mod;
    ans = ans + 1ll * sum * ncr % mod;
    ans %= mod;
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 1408
def main():
    w,h,n=map(int,input().split())
    L=[tuple(map(int,input().split())) for _ in range(n)]
    xl,xr,yl,yu=0,w,0,h
    for l in L:
        if l[2]<2:
            xl = max(xl,l[0])
        elif l[2]<3:
            xr = min(xr,l[0])
        elif l[2]<4:
            yl = max(yl,l[1])
        else:
            yu = min(yu,l[1])
    # print(max((xr-xl)*(yu-yl),0)) は共に負の時にだめ.
    print(max(xr-xl,0)*max(yu-yl,0))
main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
using pii = pair<int, int>; using vi = vector<int>; using vl = vector<ll>;

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

char a[1002][1002];
mint dp[1002][1002];
bool visited[1002][1002];
int h, w;

mint dfs(int i, int j) {
    if(visited[i][j]) return dp[i][j];
    mint sum = 0;
    visited[i][j] = true;
    if(i+1<h && a[i+1][j] == '.') {
        sum += dfs(i+1, j);
    }
    if(j+1<w && a[i][j+1] == '.') {
        sum += dfs(i, j+1);
    }
    return dp[i][j] = sum;
}
signed main() {
    cin>>h>>w;
    rep(i,h) rep(j,w) cin>>a[i][j];

    dp[h-1][w-1] = 1;
    visited[h-1][w-1] = true;
    mint ans = dfs(0, 0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10112
require 'set'
ACGT_set = Set["A","C","G","T"]

s = gets.chomp.split("")
n = s.count
index_arr = (0..(n-1)).to_a
index_arr_two = (0..(n-1)).to_a
count_arr = []
arr = []

index_arr.each do |i1|
  index_arr_two.each do |i2|
    if i1 <= i2
      arr <<  s[i1..i2]
    end
  end
end

arr.each do |v|
  v_set = Set.new(v)
  if v_set <= ACGT_set
    count_arr << v.count
  end
end

if count_arr.count == 0
  p 0
else
  p count_arr.max
end


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

int main(){
    int H, N;
    cin >> H >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    for(int i = 0; i < N; i++){
        H -= A.at(i);
    }

    if(H <= 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n; cin >> n;
    ll a[n+1];
    ll b[n];
    ll sum = 0;
    for(int i = 0; i < n+1; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n; i++){
        if(a[i] < b[i]){
            sum += a[i];
            ll d = b[i] - a[i];
            if(a[i+1] < d){
                sum += a[i+1];
                a[i+1]=0;
            }else{
                sum += d;
                a[i+1] -= d;
            }
        }else{
            sum += b[i];
        }
    }
    cout << sum;
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int D = 1000000007;

// input
string A, B, C;

int main() {
    while (true) {

        // input
        cin >> A ;
        if (A == "0") break;
        cin >> B >> C;

        // reverse A, B, C
        reverse(A.begin(), A.end());
        reverse(B.begin(), B.end());
        reverse(C.begin(), C.end());

        int N = A.size();

        // DP table
        vector<vector<int>> dp(N+1, vector<int>(2, 0));

        // initial condition
        dp[0][0] = 1;

        // DP loop
        for (int i = 0; i < N; i++) {
            for (int ai = 0; ai <= 9; ai++) {
                for (int bi = 0; bi <= 9; bi++) {
                    for (int ci = 0; ci <= 9; ci++) {
                        if (A[i] != '?' && A[i] != ai + '0') continue;
                        if (B[i] != '?' && B[i] != bi + '0') continue;
                        if (C[i] != '?' && C[i] != ci + '0') continue;

                        if (i == N - 1 && ai * bi * ci == 0) continue;

                        if (ai + bi     == ci     ) dp[i + 1][0] += dp[i][0];
                        if (ai + bi + 1 == ci     ) dp[i + 1][0] += dp[i][1];
                        if (ai + bi     == ci + 10) dp[i + 1][1] += dp[i][0];
                        if (ai + bi + 1 == ci + 10) dp[i + 1][1] += dp[i][1];

                        dp[i + 1][0] %= D;
                        dp[i + 1][1] %= D;
                    }
                }
            }
        }

        // output answer
        cout << dp[N][0] << endl;
    }
    return 0;
}


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

int *dice(int *me,char *houi){
  int kari,i=0;
  while(1){
    if(houi[i]=='E'){
      kari=me[0];
      me[0]=me[3];
      me[3]=me[5];
      me[5]=me[2];
      me[2]=kari;
    }else if(houi[i]=='N'){
      kari=me[0];
      me[0]=me[1];
      me[1]=me[5];
      me[5]=me[4];
      me[4]=kari;
    }else if(houi[i]=='S'){
      kari=me[0];
      me[0]=me[4];
      me[4]=me[5];
      me[5]=me[1];
      me[1]=kari;
    }else if(houi[i]=='W'){
      kari=me[0];
      me[0]=me[2];
      me[2]=me[5];
      me[5]=me[3];
      me[3]=kari;
    }
    if(houi[i]=='\0')break;
    i++;
  }
  return me;
}

int main(){
  int me[5];       //サイコロの目
  char houi[100];  //方位の命令

  for(int i=0;i<6;i++){
  scanf("%d",&me[i]);
  }
  scanf("%s",houi);
  int *ue=dice(me,houi);
  printf("%d\n",ue[0]);
  return 0; 
}







Measured memory_bytes: 2048