akhauriyash/Code-Regression huggingface dataset:
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, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        ss: [String; n]
    }
    let firstc = |s: &String| s.chars().next();
    let lastc = |s: &String| s.chars().rev().next();
    let cnt_ab = |s: &String| {
        let mut lastchar = '_';
        let mut cnt = 0;
        for c in s.chars() {
            if lastchar == 'A' && c == 'B' {
                cnt += 1;
            }
            lastchar = c;
        }
        cnt
    };
    let mut cnt: usize = 0;
    let mut first_is_b = 0;
    let mut last_is_a = 0;
    let mut ba = 0;
    for s in ss {
        cnt += cnt_ab(&s);
        let f = firstc(&s);
        let fb = f.is_some() && f.unwrap() == 'B';
        let l = lastc(&s);
        let la = l.is_some() && l.unwrap() == 'A';
        match (fb, la) {
            (true, true) => {
                ba += 1;
            },
            (true, false) => {
                first_is_b += 1;
            },
            (false, true) => {
                last_is_a += 1;
            },
            _ => ()
        }
    }
    let result = cnt + ba + vec![first_is_b, last_is_a].into_iter().min().unwrap();
    let result = if ba > 0 && last_is_a == 0 && first_is_b == 0 {
        result - 1
    } else {
        result
    };
    println!("{}", result);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
// cd test ; rm -R ./*; cd ..

vector<vector<int>> CAKE(305, vector<int>(305, 0));
vector<vector<bool>> visited(305, vector<bool>(305, false));
vector<bool> all0(305, true);
int h, w, k;

void dfs(int idx, int cx, int cy, int now) {
  CAKE[cy][cx] = idx;
  visited[cy][cx] = true;

  if (now != 0) if (cx <= 0 || cx >= w - 1 /*|| (CAKE[cy][cx] != 0 && CAKE[cy][cx] != idx) */)return;
  if (CAKE[cy][cx] != 0 && CAKE[cy][cx] != idx) return;

  if (cx >= 1 && !visited[cy][cx - 1]) dfs(idx, cx - 1, cy, now + 1);
  if (cx <= w - 2 && !visited[cy][cx + 1]) dfs(idx, cx + 1, cy, now + 1);


}

int main(void) {

  cin >> h >> w >> k;
  vector<vector<char>> s(305, vector<char>(w));
  vector<pair<int, int>> cakes;

  rep (i, h) {
    rep (j, w) {
      cin >> s[i][j];
      if (s[i][j] == '#') {
        cakes.push_back(make_pair(i, j));
        CAKE[i][j] = cakes.size();
        visited[i][j] = true;
        all0[i] = false;
      }

    }
  }



  rep (i, k) {
    int id, x, y;
    tie(y, x) = cakes[i];
    id = i + 1;
    dfs(id, x, y, 0);
  }

  
  

  rep (i, h) {
    rep (j, w) {
      if (CAKE[i][j] == 0 ) {
        if (i == 0) {
          CAKE[i][j] = CAKE[i + 1][j];
        }
        else CAKE[i][j] = CAKE[i - 1][j];
      }
    }
  }
  rep (i, h) {
    rep (j, w) {
      if (CAKE[i][j] == 0) {
        for (int k = i; k < h; k++) {
          if (CAKE[k][j] != 0) {
            CAKE[i][j] = CAKE[k][j];
            break;
          }
        }
        if (CAKE[i][j])continue;
        else {
          for (int k = i; k >= 0; k-- ) {
            if (CAKE[k][j] != 0) {
              CAKE[i][j] = CAKE[k][j];
              break;
            }
          }
        }
      }
    }
  }
  

 /*
 rep (i, h) {
   rep (j, h) {
     if (!all0[i] && !CAKE[i][j]) 
   }
 }

 */

  

  rep (i, h) {
    rep (j, w) cout << CAKE[i][j] << " ";
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 2036
s = gets.chomp.chars
odd = []
even = []
s.each_index do |i|
  if i.even?
    odd << s[i]
  elsif i.odd?
    even << s[i]
  end
end

if odd.include?('L')
  puts 'No'
elsif even.include?('R')
  puts 'No'
else
  puts 'Yes'
end


Measured memory_bytes: 1916
#include <iostream>
#include <cstring>

using namespace std;

void fill(char map[55][55], int x, int y, char c){
	if(map[x][y] == '.'){
		map[x][y] = c;
		fill(map, x+1, y,c);
		fill(map, x-1, y,c);
		fill(map, x, y+1,c);
		fill(map, x, y-1,c);
	}
}

int main(){
	int w,h;
	cin >> w >> h;
	while(w&&h){
		char mapb[55][55];
		memset(mapb, -1, sizeof mapb);
		for(int i = 0 ; i < h; ++i){
			for(int j = 0; j < w; ++j){
				cin >> mapb[i+1][j+1];
			}
		}
		char mapw[55][55];
		memcpy(mapw, mapb, sizeof mapb);
		for(int i = 1; i <= h; ++i){
			for(int j = 1; j <= w; ++j){
				if(mapb[i][j] == 'B'){
					fill(mapb, i+1, j,'b');
					fill(mapb, i-1, j,'b');
					fill(mapb, i, j+1,'b');
					fill(mapb, i, j-1,'b');
				}
				if(mapw[i][j] == 'W'){
					fill(mapw, i+1, j,'w');
					fill(mapw, i-1, j,'w');
					fill(mapw, i, j+1,'w');
					fill(mapw, i, j-1,'w');
				}
			}
		}
		int nb,nw;
		nw = nb = 0;
		for(int i = 0; i < 55; ++i){
			for(int j = 0; j < 55; ++j){
				if(mapb[i][j] == 'b' && mapw[i][j] == '.'){
					nb++;
				}
				if(mapw[i][j] == 'w' && mapb[i][j] == '.'){
					nw++;
				}
			}
		}
		cout << nb << " " << nw << endl;
		cin >> w >> h;
	}
}

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

int main() {
    string s; cin >> s;
    vector<int> a(26);
    for (int i = 0; i < s.size(); i++) a[s[i]-'a']++;
    
    for (int i = 0; i < 26; i++) {
        if (a[i] == 0) {
            cout << char(i + 'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}


Measured memory_bytes: 512
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;

void solve() {
    int n;
    cin >> n;
    V<ll> A(n);
    rep(i, n) cin >> A[i];
    rep(i, n) {
        if (A[i] == 0) {
            cout << 0 << "\n";
            return;
        }
    }
    __int128_t ret = 1, lim = (__int128_t)1e18;
    rep(i, n) {
        ret *= A[i];
        if (ret > lim) {
            cout << -1 << "\n";
            return;
        }
    }
    cout << (ll)ret << "\n";
}
int main() {
    cin.tie(nullptr);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  string s; cin >> s;

  string ans;
  for(int i=0;i<SZ(s);++i) {
    ans.push_back(((s[i] - 'A') + n) % 26 + 'A');
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int map[10][10], deep=0, white=100;
void drop(int x, int y)
{
	if (x>=0 && x<10 && y>=0 && y<10) {
		if (map[x][y] == 0)
			white --;
		if (++map[x][y] > deep) {
			deep = map[x][y];
		}
	}
}
int main()
{
	int x, y, s;
	while (scanf("%d,%d,%d", &x, &y, &s)>0) {
		switch(s) {
		case 3:
			drop(x-2, y);
			drop(x+2, y);
			drop(x, y-2);
			drop(x, y+2);
		case 2:
			drop(x-1, y-1);
			drop(x+1, y-1);
			drop(x-1, y+1);
			drop(x+1, y+1);
		case 1:
			drop(x, y);
			drop(x+1, y);
			drop(x-1, y);
			drop(x, y+1);
			drop(x, y-1);
		}
	}
	printf("%d\n%d\n", white, deep);
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        // スペース区切りの整数の入力
        int b = sc.nextInt();
        // 結果の出力
        System.out.println(Math.max((a*b),Math.max((a+b),(a-b))));
    }
}

Measured memory_bytes: 21972
#include<iostream>
#include<map>
using namespace std;
typedef long long li;
#define yn(i) ((i)?"Yes":"No")
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int judge(string s,string t){
  map<char,char> mp;
  int n=s.size();
  rep(i,n){
    char c1=s[i]; char c2=t[i];
    //    print(mp.count(c1));
    if(mp.count(c1) and mp[c1]!=c2){
      return 0;
    }
    mp[c1]=c2;
  }
  return 1;
}

int main(){
  string s,t; cin >>s >>t;
  map<char,char> mp;
  print(yn(judge(s,t) and judge(t,s)));
}


Measured memory_bytes: 4576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep(i, s.size()) ans += s[i]!=t[i];    
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3796
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

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

//for(int i = ; i < ; i++){}

int main(){
    int n;
    int m;
    cin>>n;
    m = n;
    int sum=0;
    while(n>0){
        sum+=n%10;
        n=n/10;
    }
    if(m%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int64_t,int64_t> pll;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

void solve() 
{
    string s1,s2;cin>>s1>>s2;
    int a,b;cin>>a>>b;
    string s;cin>>s;
    if(s==s1)cout<<a-1<<" "<<b<<endl;;
    if(s==s2)cout<<a<<" "<<b-1<<endl;;
}

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


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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

int main(void){
    int n;
    cin >> n;
    double p;
    p = (n-n/2);
    p/=n;
    cout << fixed << setprecision(10) << p << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	vector<int> g(K + 1);
	g[K] = 0;
	set<int> st;
	for (int i = K - 1; i >= 0; i--) {
		g[i] = 0;
		st.clear();
		for (int j = 0; j < N; j++) {
			if (i + A[j] <= K) {
				st.insert(g[i + A[j]]);
			}
		}
		int t = 0;
		while (st.count(t) == 1) {
			t++;
		}
		g[i] = t;

	}
	if (g[0] == 0) {
		cout << "Second" << endl;
	}
	else {
		cout << "First" << endl;
	}
}

Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

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

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

	int a, b, c, d, e;
	int na, nb, nc;

	void run(){
		for(;;){
			a=sc.nextInt();
			if(a==0){
				break;
			}
			b=sc.nextInt();
			c=sc.nextInt();
			d=sc.nextInt();
			e=sc.nextInt();
			na=sc.nextInt();
			nb=sc.nextInt();
			nc=sc.nextInt();
			solve();
		}
	}

	void solve(){
		int tot;
		if(nc>=d){
			tot=e*nc+b*nb+a*na;
		}else{
			// nc<d
			int sum=c*nc, count=nc;
			int D=min(d-count, nb);
			nb-=D;
			sum+=b*D;
			count+=D;
			D=min(d-count, na);
			na-=D;
			sum+=a*D;
			count+=D;
//			debug(sum, count, na, nb, nc);

			sum=min(sum, d*e);
			tot=sum+b*nb+a*na;
		}
//		debug(tot);
		println(tot+"");
	}

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

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

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

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 21148
#include <stdio.h>

int main()
{
    int H;
    int W;
    char canvas[50][50];
    int i;
    int j;
    int flag;

    scanf("%d %d%*c", &H, &W);

    for(i = 0; i < H; i++) {
        for(j = 0; j < W; j++) {
            scanf("%c", &canvas[i][j]);
        }
        scanf("%*c");
    }

    for(i = 0; i < H; i++) {
        for(j = 0; j < W; j++) {
            flag = 0;
            if(canvas[i][j] == '#') {
                if(i > 0 && canvas[i-1][j] == '#') {
                    flag = 1;
                }
                if(i < H-1 && canvas[i+1][j] == '#') {
                    flag = 1;
                }
                if(j > 0 && canvas[i][j-1] == '#') {
                    flag = 1;
                }
                if(j < W-1 && canvas[i][j+1] == '#') {
                    flag = 1;
                }
            } else {
                flag = 1;
            }
            if(flag == 0) {
                goto LOOP_OUT;
            }
        }
    }
LOOP_OUT:

    if(i == H && j == W) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int r, d, x;
    cin >> r >> d >> x;
    int current = x;

    for(int _ = 0; _ < 10; _++){
        int next = current*r - d;
        cout << next << endl;
        current = next;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * A - Round One
 * 高橋君はペーパークイズを解いています。高橋君はすらすらと解いていき、残すは最終問題のみとなりました。
 * この問題は、答えが 1,2,3 のいずれかである 3 択問題です。
 * 高橋君は超能力によって、A と B が誤答であることがわかりました。
 * この問題の答えを出力してください。
 */
public class Main {

    public static void main( String[] args ) {

        // 入力値
        Scanner sc = new Scanner( System.in );
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println( 6 - a - b );

        sc.close();
    }
}

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

map<int, int> a;
int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    string subS = t.substr(0, n);
    //cout << subS;
    if (subS == s)  cout << "Yes";
    else  cout << "No";
    return 0;
}


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

const int N = 500009;
const int mod = 1000000007;

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define int long long int
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()

int n;
int a[N];

bool check(int x)
{
	int found = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == (found + 1))
			found++;
	}
	if (found >= x)
		return 1;
	return 0;
}

int32_t main()
{
	IOS;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int l = 1, r = n;
	while (l < r)
	{
		if (check((l + r + 1) / 2))
			l = (l + 1 + r) / 2;
		else
			r = (((l + 1 + r) / 2) - 1);
	}
	if (check(l))
		cout << (n - l) << endl;
	else
		cout << "-1\n";
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
	int N;
	long long An=0;
	int A[200000];
	int B[200000]={0};
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
		A[i]-=1;
		B[A[i]]++;
	}
	for(int i=0;i<N;i++){
		An+=(long long)B[i]*(B[i]-1)/2;
	}
	long long Bn;
	for(int i=0;i<N;i++){
		Bn=An;
		Bn-=(long long)B[A[i]]*(B[A[i]]-1)/2;
		Bn+=(long long)(B[A[i]]-1)*(B[A[i]]-2)/2;
		printf("%lld\n",Bn);
	}
}

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

int main() {
  const int M = 1000005;
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<int> C(M);
  rep(i, M) C[i] = 0;
  for (int x : A) {
    if (C[x] == 1) {
      C[x] = 2;
      continue;
    }
    if (C[x] != 0) continue;
    for (int j = x; j < M; j += x) {
      C[j] = C[j] + 1;
    }
  }
  int ans = 0;
  for (int x : A) {
    if (C[x] == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8008
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let vec : Vec<i32> = input.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect();

    println!("{}", if vec[0] >= vec[1] {"10"} else {"0"});
}



Measured memory_bytes: 4352
N = int(input())
a = list(map(int,input().split()))
q = int(input())
num = []
summ = 0
for i in range(10**5):
  num.append(0)
for i in range(N):
  num[a[i]-1] += 1
  summ += a[i]
for i in range(q):
  b,c = map(int,input().split())
  summ += (c-b)*num[b-1]
  num[c-1] += num[b-1]
  num[b-1] = 0
  print(summ)


Measured memory_bytes: 20940
fun main(args: Array<String>) {
    val (n, m, q) = readLine()!!.split(' ').map(String::toInt)
    val railMap = Array(n + 1) { Array(n + 1) { 0 } }
    repeat(m) {
        val (l, r) = readLine()!!.split(' ').map(String::toInt)
        railMap[l][r] = railMap[l][r] + 1
    }

    val cumSum = Array(n + 1) { Array(n + 1) { 0 } }
    for (i in 1..n) {
        for (j in 1..n) {
            cumSum[i][j] = railMap[i][j] + cumSum[i][j - 1] + cumSum[i - 1][j] - cumSum[i - 1][j - 1]
        }
    }

    repeat(q) {
        val (pi, qi) = readLine()!!.split(' ').map(String::toInt)
        println(cumSum[qi][qi] - cumSum[pi - 1][qi] - cumSum[qi][pi - 1] + cumSum[pi - 1][pi - 1])
    }
}

Measured memory_bytes: 104416
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n==0||n==1)return dp[n]=1;
  if(dp[n]!=-1)return dp[n];
  return dp[n]=fib(n-1)+fib(n-2);
}

int main()
{
  int n=0,i;
  for(i=0;i<50;i++) dp[i]=-1;
  
  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}



Measured memory_bytes: 2112
from collections import defaultdict

def main():
    # 75 * 1
    # 25 * 3
    # 15 * 5
    # 5 * 5 * 3
    N = int(input())
    d = defaultdict(int)
    for n in range(1, N+1):
        for i in range(2, int(n ** 0.5) + 1):
            while n % i == 0:
                d[i] += 1
                n = n // i
        if n != 1:
            d[n] += 1

    d2 = 0
    d4 = 0
    d14 = 0
    d24 = 0
    d74 = 0
    for i in d.values():
        if i >= 2:
            d2 += 1
        if i >= 4:
            d4 += 1
        if i >= 14:
            d14 += 1
        if i >= 24:
            d24 += 1
        if i >= 74:
            d74 += 1

    ans = d74
    ans += d24 * (d2 - 1)
    ans += d14 * (d4 - 1)
    ans += (d4 * (d4 - 1) * (d2 - 2)) // 2

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 38352
#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
 
const int MAXN = 2e5 + 5;

ll N, A[MAXN], K, ans;

int m(ll a, ll b) {
	if(a && b) {
		if(a < 0 && b < 0) return 1;
		if(a > 0 && b > 0) return 1;
		if(a < 0 && b > 0) return -1;
		if(a > 0 && b < 0) return -1;
	}
	return 0;
}

ll cal(ll x) {
	ll ret = 0;
	for(int i=1; i<=N; i++) {
		if(A[i] == 0) ret += (x >= 0 ? (N-i) : 0);
		else if(A[i] > 0) {
			ll val = x / A[i];
			if(m(x, A[i]) < 0 && x % A[i]) val--;
			ll idx = lower_bound(A+1, A+1+N, val+1) - A - 1;
			if(idx > i) ret += idx - i;
		}
		else {
			ll val = x / A[i];
			if(m(x, A[i]) > 0 && x % A[i]) val++;
			ll idx = lower_bound(A+1, A+1+N, val) - A;
			idx = max(i+1LL, idx);
			ret += N-idx+1;
		}
	}
	return ret;
}
 
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> K;
	for(int i=1; i<=N; i++) cin >> A[i];
	sort(A+1, A+1+N);


	ll l = -1e18, r = 1e18;
	while(l <= r) {
		ll mid = l + r >> 1;
		if(cal(mid) >= K) {
			ans = mid;
			r = mid - 1;
		}
		else l = mid + 1;
	}
	cout << ans;
}


Measured memory_bytes: 1792
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
    int n;
    cin>>n;
    cout<<24+(24-n)<<endl;

return 0;
}

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

int main(){

	int N;
	int L[110];
	int Max = 0;
	int sum = 0;
	string ans;

	cin >> N;

	for (int i = 1; i <= N; i++){
		cin >> L[i];
		Max = max(Max, L[i]); 
		sum += L[i];
	}

	ans = (2 * Max < sum) ? "Yes" : "No";

	cout << ans << endl;

}

Measured memory_bytes: 256
//15-5
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

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

    int ans = 0;
    for(int i=1; i<=100; i++){
        int tmp = 0;
        for(int j=0; j<N; j++){
            if(p[j] >= i) tmp++;
        }
        if(tmp >= i) ans = i;
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>
void selectionSort(int A[],int N){ 
   int i,j,count=0;
   int minj,v;
   for(i=0;i<=N-1;i++){
    	minj = i;
    	for(j=i;j<=N-1;j++){
       		if (A[j] < A[minj])
         		minj = j;
 		}
 		if(minj!=i) count++;
    	v=A[i];
    	A[i]=A[minj];
    	A[minj]=v;
    }
    for(i=0;i<N-1;i++){
    	printf("%d ",A[i]);
    }
    printf("%d\n",A[N-1]);
    printf("%d\n",count++);
}

int main(){
	int i,j,n;
	int num[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&num[i]);
	}
	selectionSort(num,n);
	return 0;
}

Measured memory_bytes: 600
#n, m = map(int,input().split())
n = int(input())
#ls = list(map(int,input().split()))
#ls = [list(map(int,input().split()))[1:] for i in range(n)]
ls = [int(input()) for i in range(n)]
#s = input()
maxi = max(ls)
ls.remove(maxi)
print(sum(ls) + int(maxi/2))

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

int main()
{
    int n, m;
    int i, j, ans;
    
    cin >> n;
    
    int t[n];
    
    for(i = 0; i < n; i++) {
        cin >> t[i];
    }
    
    cin >> m;
    
    int p[m], x[m];
    
    for(i = 0; i < m; i++) {
        cin >> p[i] >> x[i];
    }
    
    for(i = 0; i < m; i++) {
        ans = 0;
        
        for(j = 0; j < n; j++) {
            
            if(j == p[i]-1) {
                ans = ans + x[i];
            } else {
                ans = ans + t[j];
            }
            
        }
        
        cout << ans << "\n";
    }
    
    return 0;
}

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

using namespace std;

int res, n;

int32_t main()
{
    cin >> n;
    for (int i=0; i<n; i++)
    {
        int x; cin >> x;
        while (x%2==0) x/=2, res++;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
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 (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll N;
    cin >> N;

    ll res = 0;
    for(int i=1;i<=N;i++){
        if(i%3 != 0 and i%5 != 0) res += i;
    }
    cout << res << endl;

    return 0;
}

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

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, M, X, Y; cin >> N >> M >> X >> Y;
	vector<int> x(N + 1, 0);
	rep (i, N) cin >> x[i];
	x[N] = X;

	vector<int> y(M + 1, 0);
	rep (j, M) cin >> y[j];
	y[M] = Y;

	sort(ALL(x));
	sort(ALL(y));

	int zx = x[N];
	int zy = y[0];

	string res = "";
	if (zx < zy){
		res = "No War";
	}else{
		res = "War";
	} // end if

	cout << res << endl;

	return 0;
}

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

using namespace std;

const int N = 1e5 + 5;
int dp[105][N];
int arr[105];
const int mod = 1e9 + 7;

int add(int a, int b)
{
  a = (a + mod) % mod;
  b = (b + mod) % mod;
  return (a + b) % mod;
}

int main()
{
  int n, k;
  cin >> n >> k;
  for(int i = 0; i < n; i++)
    cin >> arr[i];
  if(!k)
  {
    cout << 1;
    return 0;
  }
  for(int i = 0; i < N; i++)
    dp[n][i] = 1;
  for(int i = n - 1; i >= 0; i--)
  {
    for(int j = 0; j < N; j++)
    {
      if(j - arr[i] - 1 < 0)
        dp[i][j] = dp[i + 1][j];
      else
        dp[i][j] = add(dp[i + 1][j] , - dp[i + 1][j - arr[i] - 1]);
    }
    for(int j = 1; j < N; j++)
      dp[i][j] = add(dp[i][j], dp[i][j - 1]);
  }
  cout << add(dp[0][k], -dp[0][k - 1]);
  return 0;
}


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

using namespace std;

int main()
{
string s;

string now ="1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
vector <int> x;
int xs=0;
for (int i=0; i<now.size(); i++)
    {
        if (now[i]>='0' && now[i]<='9')
            {   xs*=10;
                xs+=now[i]-'0';
            }
        else
        { if (xs!=0) x.push_back(xs);
            xs=0;
        }

    }
if (xs!=0) x.push_back(xs);

//for (auto xx:x) cout << xx << " ";


int k;
cin >> k;
cout << x[k-1];

}




















/*
8 9
1 3
1 2
2 3
3 4
4 5
5 6
4 6
6 7
6 8





*/


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

using namespace std;
#define BUF (200005)
#define ll long long 

int n;
int p[BUF];
int b[BUF];

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

	int cnt = 0;
	int max_cnt=0;
	for(int i=1;i<n;i++){
		if(b[i]<b[i+1]){
			cnt++;
		}else 
			cnt = 0;
		max_cnt = max(cnt, max_cnt);
	}

	cout << n-max_cnt-1 << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
#define INF (1 << 29)
#define FOR(x, to) for (x = 1; x <= (to); x++)
int N, M, R;
int d[200 + 1][200 + 1];
int r[8 + 1];
int A, B, C;
int res;
bool used[8 + 1];

void dfs(int depth, int last, int dist) {
    if (depth == R) {
        if (res > dist) res = dist;
        return;
    }
    int i; FOR(i, R) if (!used[i]) {
        used[i] = true;
        if (last == -1) dfs(depth + 1, i, 0);
        else dfs(depth + 1, i, dist + d[r[last]][r[i]]);
        used[i] = false;
    }
}

int main() {
    int i, j, k;
    scanf("%d%d%d", &N, &M, &R);
    FOR(i, N) FOR(j, N) if (i != j) d[i][j] = INF;
    FOR(i, R) scanf("%d", &r[i]);
    FOR(i, M) {
        scanf("%d%d%d", &A, &B, &C);
        d[A][B] = d[B][A] = C;
    }
    // Warshall–Floyd algorithm
    FOR(k, N)
        FOR(i, N)
            FOR(j, N)
                if (d[i][j] > d[i][k] + d[k][j])
                    d[i][j] = d[i][k] + d[k][j];
    // try in all pattern of permutations
    res = INF;
    dfs(0, -1, 0);
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0, f = 1; char c = getchar();
	while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
	while (isdigit(c)) {x = x * 10 + c - '0', c = getchar();}
	return x * f;
}

const int MAXN = 20005;
const int inf = 0x3f3f3f3f;
int n, cnt1, cnt2, a[MAXN], b[MAXN], ans;
char s[MAXN], t[MAXN];

int main()
{
	n = read(), ans = inf;
	scanf("%s", s + 1);
	scanf("%s", t + 1);
	cnt1 = cnt2 = 5000;
	if (s[1] != t[1]) a[++ cnt1] = 0;
	for (int i = 1; i <= n; i ++)
		if (s[i] != s[i + 1]) a[++ cnt1] = i;
	for (int i = 1; i <= n; i ++)
		if (t[i] != t[i + 1]) b[++ cnt2] = i;
	int st1 = cnt1, st2 = cnt2;
	for (int i = 1; i <= 5000; i ++)
		a[++ cnt1] = b[++ cnt2] = n;
	while (cnt1 < cnt2) a[++ cnt1] = n;
	while (cnt2 < cnt1) b[++ cnt2] = n;
	for (int i = -st1; i <= st2; i ++) if (!(i & 1))
	{
		int now = 0;
		for (int j = 1; j <= cnt1; j ++)
		{
			int other = j + i;
			if (other >= 1 && other <= cnt1 && a[other] != b[j])
				now += abs(a[other] - b[j]);
		}
		ans = min(ans, now);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    int A, B, C;
    try(Scanner sc = new Scanner(System.in)) {
      A = sc.nextInt();
      B = sc.nextInt();
      C = sc.nextInt();
    }
    int answer = C - (int)(Math.min(C, A-B));
    System.out.println(answer);
  }
}

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

int main(){

    int n;
    cin >> n;

    vector<vector<int> >  abc(n,vector<int>(3));

    rep(i,n) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];

    vector<vector<int> > dp(n,vector<int>(3,0));

    dp[0][0]=abc[0][0];
    dp[0][1]=abc[0][1];
    dp[0][2]=abc[0][2];

    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(k==j) continue;
                dp[i][j]=max(dp[i][j],dp[i-1][k]+abc[i][j]);
            }
        }
    }

    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;

    return 0;
}

Measured memory_bytes: 11136
from queue import Queue
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    G[A].append(B)
    G[B].append(A)
que = Queue()
que.put(0)
visit = [0] * N
ans = [0] * N
while not que.empty():
    v = que.get()
    for next_v in G[v]:
        if visit[next_v] == 1:
            continue
        ans[next_v] = v
        visit[next_v] = 1
        que.put(next_v)
print("Yes")
print(*list(map(lambda x: x+1, ans[1:])), sep='\n')

Measured memory_bytes: 39556
'use strict';
var data = '';
process.stdin.on('end', function() {
    var inputs = data.toString().trim().split('\n');
    var params = inputs[1].split(' ').map(Number);
    var sum = params.reduce(function(a,b) {
      return a + b;
    });
    var min = params[0];
    var max = params[0];
    for (var i = 0; i < params.length; i++) {
      min = Math.min(min,params[i]);
      max = Math.max(max,params[i]);
    }
   
    console.log(min, max, sum);
   
});
   
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  data += chunk;
});

Measured memory_bytes: 17380
#include<iostream>
using namespace std;
int main(){
  int N; cin>>N;
  string S; cin>>S;
  for(int i=0;i<S.size();i++){
    int t = S.at(i)-'A';
    t = (t+N)%26;
    S.at(i)= 'A'+t;
  }
  cout<<S<<endl;

}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#define ll long long
using namespace std;
string a;
int main()
{
	cin >> a;
	int t = a.size();
	ll dap = 0;
	ll x = 0;
	for (int i = t - 1; i >= 0; i--)
	{
		if (a[i] == 'B') {
			dap += x;
		}
		else {
			x++;
		}
	}
	cout << dap;
}

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

int main(){
  int ans=0;
  int tmp;
  for(int i=0;i<3;i++){
    cin >>tmp;
    ans+=tmp;
  }
  if(ans>=22){
    cout <<"bust"<<endl;
    return 0;
  }
  else{
    cout <<"win"<<endl;
    return 0;
  }
}

Measured memory_bytes: 3568
#include <iostream>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

#define ll long long
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define vint vector<int>

int main(){
    int N; cin >> N;
    vint H(N);
    rep(i, N) cin >> H[i];
    int count = 0, ans = 0;
    rep(i, N - 1){
        if (H[i] >= H[i + 1]) count++;
        else{
            ans = max(ans, count);
            count = 0;
        }
    }
    ans = max(ans, count);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

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

		long N = (long)Math.sqrt(n);
		long i;
		long min = Long.MAX_VALUE;
		for(i = 1; i <= N; i++) {
			if(n % i == 0) {
				if(i + (n / i) < min)
					min = i + (n / i);
			}
		}

		System.out.println(min - 2);
	}
}

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

int main()
{
	int sum = 0;
	for (int i = 0; i < 4; i++) {
		int tmp;
		cin >> tmp;
		sum += tmp;
	}
	cout << sum / 60 << endl;
	cout << sum % 60 << endl;
	return 0;
}



Measured memory_bytes: 3092
from bisect import bisect_right

def main():
    N, Q = map(int, input().split())
    a = [-1 for i in range(N)]
    sum = [0 for i in range(N + 1)]
    for i, val in enumerate(input().split()):
        a[i] = int(val)
        sum[i + 1] = sum[i] + a[i]
    X = list(map(int, input().split()))

    # print("DEBUG: sum={}".format(sum))
    for x in X:
        ans = solve3(a, x, N, sum)
        print(ans)


def solve1(a, x, N, sum):
    l, r = 0, 0
    ret = 0
    while l < N:
        if r < N + 1:
            r = bisect_right(sum, sum[l] + x, r)
        if r > l:
            ret += (r - 1 - l)
        l += 1

    return ret

def solve2(a, x, N, sum):
    l, r, sum = 0, 0, 0
    ret = 0
    while l < N:
        while r < N and sum + a[r]  <= x:
            sum += a[r]
            r += 1
        ret += (r - l)
        sum -= a[l]
        l += 1

    return ret


def solve3(a, x, N, sum):
    l, sum, ans = 0, 0, 0
    for r in range(N):
        sum += a[r]
        while sum > x:
            sum -= a[l]
            l += 1
        ans += r - l + 1
    return ans


main()



Measured memory_bytes: 22284
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

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

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  int r,g; cin >> r >> g;
  cout << 2*g-r;

  return 0;
}


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

int main(void) {

    int h, w;
    scanf("%d %d", &h, &w);

    do {
        for(int i=1; i<=h; i++) {
            for (int j=1; j<=w; j++) {
                printf("#");
            }
            printf("\n");
        }
        scanf("%d %d", &h, &w);
        printf("\n");
    } while (!(h==0 && w==0));
    return 0;
}


Measured memory_bytes: 2556
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	double ans = 0;
	for (int i = 1; i <= n; i++) {
		int tmp = i;

		double p = 1.0;

		while (tmp < k) {
			tmp *= 2;
			p *= 0.5;
		}

		ans += p;
	}

	ans /= n;

	printf("%.12f\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>

using namespace std;
 
typedef long long ll;
const int N = 1e5+10;
const ll Maxn = 1e16;
const int MOD = 1e9 + 7;

int main(){
	ll a, b, k;
	scanf("%lld %lld %lld", &a, &b, &k);
	if((b - a) < (k * 2)){
		for(ll i = a; i < b; i++){
			printf("%lld\n", i);
		}
	//	printf("asdas\n");
		printf("%lld\n",b);
	}
	else{
		for(ll i = a; i <= a + k - 1; i++)
			printf("%lld\n", i);
		for(int i = b - k + 1; i < b; i++)
			printf("%lld\n", i);
		printf("%lld\n", b);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ');
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

int main () {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  rep(i,n) cin >> a[i];
  vector<string> b(m);
  rep(i,m) cin >> b[i];

  // n = 5, m = 2

  // 0 1 2 3 4
  // 1 2 3 4 5
  // 2 3 4 5 6
  // 3 4 5 6 7
  // 4 5 6 7 8

  // 0 1
  // 1 2

  bool exist = false;
  rep(lx,n) {
    rep(ly,n) {
      if (lx+m-1 >= n || ly+m-1 >= n) continue;
      bool match = true;
      rep(x,m) {
        rep(y,m) {
          if (a[ly+y][lx+x] != b[x][y]) match = false;
        }
      }
      if (match) exist = true;
    }
  }

  cout << (exist ? "Yes" : "No") << endl;
  return 0;
}

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

typedef long long ll;
using namespace std;

void rec(int d /*現在の桁*/, ll val /*現在の値*/, vector<ll>& all /*格納*/)
{
    all.push_back(val);
    if (d == 10)
        return;

    for (int i = -1; i <= 1; i++) {
        int add = val % 10 + i;
        if (add >= 0 && add <= 9)
            rec(d + 1, val * 10 + add, all);
    }
}

int main()
{
    int K;
    cin >> K;
    vector<ll> ans;
    for (int i = 1; i < 10; i++) {
        rec(1, i, ans);
    }
    sort(ans.begin(), ans.end());
    cout << ans[K - 1] << endl;
}

Measured memory_bytes: 2420
from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
comb = list(combinations_with_replacement(range(1, m+1), n))
ans = [0] * len(comb)
for _ in range(q):
    a, b, c, d = map(int, input().split())
    for i in range(len(comb)):
        if comb[i][b-1] - comb[i][a-1] == c:
            ans[i] += d
print(max(ans))

Measured memory_bytes: 25080
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define log(i,n) log(n)/log(i);
using namespace std;
typedef long long ll;


int main()
{
	ll cnt1 = 0,cnt2 = 0;
	string s;
	cin >> s;
	for (ll i = 0; i < s.length(); i += 2) {
		s[i] != '1' ? cnt1++ : cnt2++;
	}
	for (ll i = 1; i < s.length(); i += 2) {
		s[i] != '0' ? cnt1++ : cnt2++;
	}
	cout << min(cnt1,cnt2) << endl;
}



Measured memory_bytes: 512
A,B,M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m=[]
for i in range(M):
    array = list(map(int, input().strip().split()))
    m.append(array)

def hitachi02(a,b,m):
    results=[]
    cal01=min(a)+min(b)
    for k in range(len(m)):
        results.append(a[m[k][0]-1]+b[m[k][1]-1]-m[k][2])
    cal02=min(results)
    if cal01>=cal02:
        return cal02
    else:
        return cal01

result=hitachi02(a,b,m)
print(result)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
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(int i=(a);i<(b);i++)
#define rep(i,N) for(int 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; }

vector<ll> v;
vector<ll> prime;
bool is_prime[300000+1] = {};

ll sieve(ll n){
    ll p = 0;
    for (ll i = 0; i < n; i++)is_prime[i] = 1;
    is_prime[v[0]] = 0;
    for (ll i = 1; i < v.size(); i++){
        if (is_prime[v[i]]){
            prime.push_back(v[i]);
            for (ll j = 2 * v[i]; j <= 300000; j += v[i])is_prime[j] = 0;
        }
    }
    return p;
}

ll n;

int main(){
    int num = 0;
    while(1){
        ll a = 7*num+1;
        ll b = 7*num+6;
        if(a <= 300000)v.push_back(a);
        else break;
        if(b <= 300000)v.push_back(b);
        else break;
        num++;
    }
    sort(ALL(v));
    sieve(300000);
    while(cin >> n && n != 1){
        cout << n << ":";
        rep(i,prime.size()){
            if(n%prime[i] == 0){
                cout << " " << prime[i];
            }
        }

        cout << endl;
    }
}


Measured memory_bytes: 4524
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<char> c(n);
  int white = 0;
  int red = 0;
  int change = 0;
  rep(i, n){
    cin >> c[i];
    if(c[i] == 'W') white++;
    else red++;
    //cout << "W:"<< white << ",R:"<< red << endl;
  }
  rep(i, red){
    if(c[i] == 'W') change++;
    //cout << "Ch:"<< change << endl;
  }

  if(change <= red && change <= white){
    cout << change << endl;
  }else if(red <= white) cout << red << endl;
  else cout << white << endl;
  
return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define PSB push_back
#define M 1000000007
typedef long long LL;
//#define int long long

/*
//booooooooooooost
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int)
*/

int inv_mod(int a, int m)
{
	int b, x, u, q, tmp;

	b = m; x = 1; u = 0;
	while (b > 0) {
		q = a / b;
		tmp = u; u = x - q * u; x = tmp;
		tmp = b; b = a - q * b; a = tmp;
	}

	return (x < 0) ? m + x : x;
}



signed main() {

	const int AS = 97;
	const int NR = 26;
	string s;
	cin >> s;
	int N = s.size();
	int ans[2] = { -1, -1 };

	REP(i, N - 1) {
		if (s[i] == s[i + 1]) {
			ans[0] = i + 1;
			ans[1] = i + 2;
			break;
		}
		else if (i < N - 2 && s[i] == s[i + 2]) {
			ans[0] = i + 1;
			ans[1] = i + 3;
			break;
		}
	}

	cout << ans[0] << " " << ans[1] << endl;

	return 0;
}

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

int main()
{
  int64_t a, b, c;
  cin >> a >> b >> c;
  if (a + b > c)
    cout << "No\n";
  else
  {
    int64_t x = c - a - b;
    if (x * x > 4 * a * b)
      cout << "Yes\n";
    else
      cout << "No\n";
  }
}


Measured memory_bytes: 256