akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let A: usize = sc.get();
    let mut B: usize = sc.get();
    let mut C: usize = sc.get();
    let K: usize = sc.get();
    for _ in 0..K {
        if A >= B {
            B *= 2;
        } else if B >= C {
            C *= 2;
        }
        if A < B && B < C {
            println!("Yes");
            return
        }
    }
    println!("No");
}


Measured memory_bytes: 2136
N, B = map(int, input().split())
ana = []
dp = [0] * (N+2)

for i in range(B):
    ana.append(int(input()))

mod = 1000000007

dp[N] = 1
for i in reversed(range(N)):
    if len(ana) >= 1 and i == ana[-1]:
        dp[i] = 0
        if len(ana) != 0:
            ana.pop(-1)
        continue
    dp[i] = dp[i + 1] + dp[i + 2]
print(dp[0] % mod)


Measured memory_bytes: 460020
#include <iostream>

#define rep(i, first, to) for(ll i = first; i < to; ++i)
#define REP(i, first, to) for(ll i = first; i <= to; ++i)

using namespace std;
typedef long long ll;

int a[101];
int n;

void solve() {
	cin >> n;
	rep(i, 0, n) {
		cin >> a[i];
	}

	int mini;
	int count = 0;
	rep(i, 0, n) {
		mini = i;
		rep(j, i + 1, n) {
			if (a[mini] > a[j]) {
				mini = j;
			}
		}
		if (mini != i) {
			++count;
			swap(a[i], a[mini]);
		}
	}
	rep(i, 0, n - 1) {
		cout << a[i] << " ";
	}
	cout << a[n - 1] << endl;
	cout << count << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3104
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
monster = [int(i) for i in input().split()] # 配列で数字

def gcd(x, y): #GCD
    # greatest_common_divisor
    if x < y:
        x, y = y, x
    if y == 0:
        return 0
    if x % y == 0:
        return y
    return gcd(y, x % y)


l = monster[0]
for m in monster:
    l = gcd(l, m)
print(l)

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

int main(){
  int A,B,M;
  vector<int> a,b,c,x,y;
  cin >> A >> B >> M;
  a.resize(A),b.resize(B);
  c.resize(M),x.resize(M),y.resize(M);
  for(int i=0; i<A; i++){
    cin >> a.at(i);
  }
  for(int i=0; i<B; i++){
    cin >> b.at(i);
  }
  for(int i=0; i<M; i++){
    cin >> x.at(i);
    cin >> y.at(i);
    cin >> c.at(i);
  }  
  int minp, mina=a.at(0),minb=b.at(0);
  for(int i=1; i<A; i++){
    if(a.at(i) < mina) mina=a.at(i);
  }
  for(int i=1; i<B; i++){
    if(b.at(i) < minb) minb=b.at(i);
  }
  minp = mina+minb;
  int wa;
  for(int i=0; i<M; i++){
    wa = a.at(x.at(i)-1) + b.at(y.at(i)-1) - c.at(i);
    if(wa < minp) minp=wa;
  }
  cout << minp << endl;
}


Measured memory_bytes: 2176
#include <stdio.h>
#define maxl 105

char s[maxl];

int main(int argc, char** argv)
{
	long long k;
	scanf("%s%lld", s, &k);
	for(int i=0; s[i] && i<k; i++)
		if(s[i] != '1')
		{
			putchar(s[i]);
			putchar('\n');
			return 0;
		}
	puts("1");
	return 0;
}

Measured memory_bytes: 128
/* Those who cannot remember the past are condemned to repeat it.*/
/* author:Ajeet */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <utility>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
#define ll long long int
#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int sz=1e7;
#define mod 1000000007
#define ull unsigned long long int
bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.first > j.first;
}
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    int dp[n+1];
    dp[0]=0;
    dp[1]=0;
   // dp[2]=min(dp[1],abs(arr[2]-arr[1]));
    for(int i=2;i<=n;i++){
        dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
        if(i>2)
        dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i]);
        
    }

    cout<<dp[n]<<endl;
    return 0;

}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

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

	int sum;
	rep(i, x+1) {
		sum = 2 * i + 4 * (x - i);
		if (sum == y) {
			cout << "Yes" << endl;
			return 0;
		}

	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3608
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// キーマップを作る
		HashMap<Integer, String[]> keyMap = new HashMap<Integer, String[]>();
		String[] key1 = { ".", ",", "!", "?", " " };
		keyMap.put(1, key1);
		String[] key2 = { "a", "b", "c" };
		keyMap.put(2, key2);
		String[] key3 = { "d", "e", "f" };
		keyMap.put(3, key3);
		String[] key4 = { "g", "h", "i" };
		keyMap.put(4, key4);
		String[] key5 = { "j", "k", "l" };
		keyMap.put(5, key5);
		String[] key6 = { "m", "n", "o" };
		keyMap.put(6, key6);
		String[] key7 = { "p", "q", "r", "s" };
		keyMap.put(7, key7);
		String[] key8 = { "t", "u", "v" };
		keyMap.put(8, key8);
		String[] key9 = { "w", "x", "y", "z" };
		keyMap.put(9, key9);

		int n = nextInt();// テストケース数

		Scanner scanner = new Scanner(System.in);// 大きな数字が入力されるが、数字としては意味のない文字列なので、文字列として受け取る

		for (int i = 0; i < n; i++) {
			String array = scanner.nextLine();
			for (int j = 0; j < array.length(); j++) {
				int key = Character.getNumericValue(array.charAt(j));// 1文字ずつ取り出す
				if (key != 0) {
					String[] map = keyMap.get(key);
					int push = -1;// 同じボタンを押した数（0起点なので最初に1引いておく）
					while (key != 0) {
						push++;
						j++;
						key = Character.getNumericValue(array.charAt(j));
					}

					push %= map.length;
					System.out.print(map[push]);
				}
			}
			System.out.print("\n");
		}

	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

}

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

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

const int MOD = 1e9 + 7;

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(i, vec) for(auto (i) = (vec).begin(); (i) != (vec).end(); (i)++)
#define vrREP(i, vec) for(auto (i) = (vec).end()-1;(i) != (vec).begin()-1;(i)--)

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

class Shitting_Man{
  private:
    int h, w, n;
    /* map[(i, j)] := (i ~ i+2, j ~ j+2)に含まれる黒の数 ; ただし, メモリサイズの都合上 0 は省く
       したがって, (0 ~ h-3, 0 ~ w-3)までが期待するkeyである */
    map<pii, int> data;
    vector<lli> res;
  public:
    Shitting_Man(int hh, int ww, int nn){
      h = hh; w = ww; n = nn;
      res.resize(10, 0); // <~ コ↑コ↓
    }
    ~Shitting_Man(void){};
    void PUSH(int x, int y){
      /* (x, y)を塗ると, (x-2~x, y-2~y)に影響を与える
      */
      for(int i = x; i >= x - 2 ; i--) if(0 <= i & i <= h - 3){
        for(int j = y; j >= y - 2; j--) if(0 <= j & j <= w - 3){
          data[make_pair(i, j)]++;
        }
      }
    }
    void calcu(){
      lli black_exist = 0;
      for(auto x : data){
        res.at(x.second)++;
        black_exist++;
      }
      res.at(0) = (lli)(h-2) * (lli)(w-2) - black_exist;
    }
    void all(void){
      int a, b;
      REP(i, n){
        cin >> a >> b;
        PUSH(a - 1, b - 1);
      }
      calcu();
      vREP(ele, res) cout << *ele << "\n";
    }
};

int main(void){
  int h, w, n; cin >> h >> w >> n;
  Shitting_Man A(h, w, n);
  A.all();
  return 0;
}

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

int main(){
    int H, W;
    int i, j;
    cin >> H >> W;
    vector<string> s(H*2);
    int L[H*2][W*2];
    int R[H*2][W*2];
    int D[H*2][W*2];
    int U[H*2][W*2];
    for(i = 0; i < H; i++){
        cin >> s[i];
    }
    for(i = 0; i < H; i++){
        for(j = 0; j < W; j++){
            if(s[i][j] == '#') L[i][j] = 0;
            else if(j == 0) L[i][j] = 1;
            else L[i][j] = L[i][j-1] + 1;
        }
    }
    for(i = H-1; i >= 0; i--){
        for(j = W-1; j >= 0; j--){
            if(s[i][j] == '#') R[i][j] = 0;
            else if(j == W-1) R[i][j] = 1;
            else R[i][j] = R[i][j+1] + 1;
        }
    }
    for(i = 0; i < H; i++){
        for(j = 0; j < W; j++){
            if(s[i][j] == '#') U[i][j] = 0;
            else if(i == 0) U[i][j] = 1;
            else U[i][j] = U[i-1][j] + 1;
        }
    }
    for(i = H-1; i >= 0; i--){
        for(j = W-1; j >= 0; j--){
            if(s[i][j] == '#') D[i][j] = 0;
            else if(i == H-1) D[i][j] = 1;
            else D[i][j] = D[i+1][j] + 1;
        }
    }
    int max = 0;
    for(i = 0; i< H; i++){
        for(j = 0; j<W;j++){
            int tmp = U[i][j]+R[i][j]+D[i][j]+L[i][j]-3;
            if(max < tmp) max = tmp;
            //cout << max << endl;
        }
    }
    cout  << max << endl;

    return 0;
}


Measured memory_bytes: 138624
H,W=gets.split.map(&:to_i)
S=[]
H.times{
    S<<gets.chomp
}
H.times{|h|
    W.times{|w|
        next if S[h][w]=="#"
        c=0
        (h-1 .. h+1).each{|y|
            next if y<0
            next if y>=H
            (w-1 .. w+1).each{|x|
                next if x<0
                next if x>=W
                if S[y][x]=="#"
                    c+=1
                end
            }
        }
        S[h][w]=c.to_s
    }
}
puts S


Measured memory_bytes: 14240
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

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

		String str[] = br.readLine().split("");

		long sum = 0;
		long temp = 0;

		for (int i = 0; i < (1 << (str.length - 1)); i++) {
			temp = Integer.parseInt(str[0]);
			for (int j = 0; j < (str.length - 1); j++) {
				if ((i & (1 << j)) != 0) {
					sum += temp;
					temp = 0;
				}

				temp = temp * 10 + (Integer.parseInt(str[j + 1]));
			}
			sum += temp;
		}

		System.out.println(sum);
	}
}


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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    string s, t;
    cin >> s >> t;

    s = '-' + s;
    t = '-' + t;

    auto dp = make_vector(s.size(), t.size(), 0);
    range(i, 1, s.size()) range(j, 1, t.size()) {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        if (s[i] == t[j]) chmax(dp[i][j], dp[i - 1][j - 1] + 1);
    }
    
    string ans;
    int i = s.size() - 1, j = t.size() - 1;
    while (dp[i][j]) {
        if (s[i] == t[j] && dp[i - 1][j - 1] + 1 == dp[i][j]) {
            ans += s[i];
            i--;
            j--;
            continue;
        }
        
        if (dp[i - 1][j] > dp[i][j - 1]) i--;
        else j--;
    }

    whole(reverse, ans);
    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 35584
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
struct edge { int to;ll cost; };
vector<edge> G[100000];
int main() {
	ll c; ll d[100000] = {}; int i, n, q, k, a, b, x, y;
	cin >> n;
	for (i = 0; i < n-1; i++) {
		cin >> a >> b >> c;
		a--; b--;
		G[a].push_back({ b, c });
		G[b].push_back({ a, c });
	}
	cin >> q >> k; k--;
	vector<int> m;
	m.push_back(k);
	int used[100000] = {};
	used[k] = 1;
	while(!m.empty()) {
		int l = G[m[0]].size();
		for (i = 0; i < l; i++) {
			if (used[G[m[0]][i].to] != 1) {
				used[G[m[0]][i].to] = 1;
				m.push_back(G[m[0]][i].to);
				d[G[m[0]][i].to] = d[m[0]] + G[m[0]][i].cost;
			}
		}
		m.erase(m.begin());
	}
	for (i = 0; i < q; i++) {
		cin >> x >> y;
		x--; y--;
		cout << d[x] + d[y] << endl;
	}
	return 0;
}


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

using ll = long long;

const int N = 300005;
const ll K = ll(2e16);
int n, c;
ll x[N];
vector<ll> a;

ll f(ll x){
    ll r = 0;
    while(x){
        r += x % 10;
        x /= 10;
    }
    return r;
}

int main(){
    for(int i = 1; i < 10000; i++) x[c++] = i;
    for(ll t = 9; t < 9999999999999LL; t = 10 * t + 9){
        for(int j = 1000; j <= 9999; j++){
            ll v = j * (t + 1) + t;
            if(v < K) x[c++] = v;
        }
    }
    ll ma = f(x[c - 1]), mb = x[c - 1];
    for(int i = c - 2; i >= 0; i--){
        ll ca = f(x[i]), cb = x[i];
        if(cb * ma <= mb * ca){
            a.push_back(x[i]);
            ma = ca; mb = cb;
        }
    }
    reverse(a.begin(), a.end());
    scanf("%d", &n);
    for(int i = 0; i < n; i++) printf("%lld\n", a[i]);
}

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

int main() {
    int n;
    cin >> n;
    int l, r;
    int counter = 0;
    for (int i=0; i<n; i++) {
        cin >> l >> r;
        counter += (r - l + 1);
    }
    cout << counter << endl;
}


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

int N, M;
vector<vector<int>> G;
vector<int> d;
vector<double> E, C;

double expectation(int u) {
  if (E[u] != -1) return E[u];

  double res = 0;
  rep(v, N) if (G[u][v]) res += expectation(v);
  res /= d[u];
  res += 1;
  return E[u] = res;
}

double coefficient(int v) {
  if (C[v] >= 0.0) return C[v];

  double res = 0.0;
  rep(u, N) if (G[u][v]) res += coefficient(u) / d[u];
  return C[v] = res;
}

int main() {
  cin >> N >> M;
  G.resize(N, vector<int>(N, 0));
  C.resize(N, -1.0);
  d.resize(N, 0);

  rep(i, M) {
    int s, t;
    cin >> s >> t;
    --s, --t;
    G[s][t] = 1;
    ++d[s];
  }

  E.resize(N, -1);
  E[N - 1] = 0.0;
  expectation(0);

  C[0] = 1.0;
  coefficient(N - 1);

  double m = 0.0;
  rep(u, N) {
    if (d[u] == 1 && (C[u] - 1.0) < 1e-9) continue;
    rep(v, N) if (G[u][v]) {
      double deltaE =
          (G[u].size() == 1 ? 1.0 : (E[u] - E[v] - 1) / (d[u] - 1.0));
      m = min(m, C[u] * deltaE);
    }
  }

  printf("%.7lf\n", E[0] + m);

  return 0;
}


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

typedef long long ll;
ll n, st, en, x1, x2, ans, d[55], s[55];
ll f(ll p1, ll q1, ll p2, ll q2) {
	if (q1 * p2 < q2 * p1) return 1;
	else if (q1 * p2 == q2 * p1) return 2;
	else return 3;
}
int main()
{
	ll i, j, a;
	cin >> n >> st >> en;
	s[0] = 1;
	for (i = 1; i <= n; i++) {
		scanf("%lld", &a);
		for (j = i; j >= 1; j--) {
			if (d[j - 1] + a > d[j]) s[j] = s[j - 1];
			else if (d[j - 1] + a == d[j]) s[j] += s[j - 1];
			d[j] = max(d[j], d[j - 1]+ a);
		}
	}
	x1 = st;
	x2 = d[st];
	ans = s[st];
	for (i = st + 1; i <= en; i++) {
		ll t= f(x1, x2, i, d[i]);
		if (t == 1) {
			x1 = i;
			x2 = d[i];
			ans = s[i];
		} else if (t == 2) ans += s[i];
	}
	printf("%.10f\n%lld", (double)x2 / x1, ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
       int H, W;
    while ( true ){
        cin >> H >> W;
        if ( H == 0 && W == 0){
            break;
        }
        for(int i = 0; i < H; i ++){
            for (int j = 0; j < W; j++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    
}


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

int main() {
    using namespace std;

    // Nが偶数なら、N/2枚必要
    // Nが奇数なら、N/2+1枚必要
    int n;

    cin >> n;

    if (n%2 == 0) {
        n = n / 2;
    } else
    {
        n = (n / 2) + 1;
    }

    cout << n << endl;
    return 0;
}

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

int bubbleSort(int a[], int n) {
    int sw{};
    for(int i = 0; i < n; i++) {
        for(int j = n - 1; j >= i + 1; j--) {
            if(a[j] < a[j - 1]) {
                swap(a[j], a[j - 1]);
                sw++;
            }
        }
    }
    return sw;
}

int main() {
    int a[100], n, sw;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    sw = bubbleSort(a, n);
    
    for(int i = 0; i < n; i++) {
        if(i)
            cout << " ";
        cout << a[i];
    }
    cout << endl;
    cout << sw << endl;
    
    return 0;
}


Measured memory_bytes: 3120
// C - To Infinity
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S;
	long long i,n,K;
	cin>>S>>K;
	n = min(K, (long long)S.size());
	for(i=0; i<n; ++i) if(S[i] != '1') break;
	cout<< S[i==n? 0:i] <<endl;
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n],i,j,k,b[n]={0};
    for(i=0;i<n-1;i++) {
        cin>>a[i];
        b[a[i]-1]++;
    }
    for(i=0;i<n;i++) {
        cout<<b[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 5188
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


ll power(ll x, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (res * x) % mod;
        }
        x = (x * x) % mod;
        n /= 2;
    }
    return res;

}

ll inv(int x) {
    return power(x, mod - 2);
}

ll binom(int n, int k) {
    if (n < k) 
        return 0;
    ll x = 1, y = 1;
    for (int i = 1; i <= k; ++i) {
        x = (x * (n - i + 1)) % mod;
        y = (y * i) % mod;
    }
    return (x * inv(y)) % mod;
}

void solve() {
    int n, m;
    cin >> n >> m;
    ll res = 1;
    for (ll d = 2; d * d <= m; ++d) {
        int k = 0;
        while (m % d == 0) {
            m /= d;
            ++k;
        }
        res = (res * binom(n + k - 1, k)) % mod;
    }
    if (m > 1) {
        res = (res * n) % mod;
    }
    cout << res << endl;


}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 256
#pragma region
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define dump(x) cerr << #x << " = " << x << endl
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);
int dig(int n){return (int)(log10(n) + 1);}
int abc(char x){return (int)(x)-(int)('a');} // 0~25
char abc(int x){return (char)(x+(int)('a'));} 
int ABC(char x){return (int)(x)-(int)('A');}
char ABC(int x){return (char)(x+(int)('A'));}
void solve();
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}
#pragma endregion

void solve() {
	int K; cin >> K;
	int ans = 0;
	rep(a, K) {
		rep(b, K) {
			rep(c, K) {
				ans += __gcd(a + 1, __gcd(b + 1, c + 1));
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define rep(i, a, b) for(int i = a; i < b; ++i)

int debug = 1;

const int N = 2e6 + 10;
int mod = 998244353;

int n, m;
int fac[N], fre[N], c[3][N];

int add(int a, int b) {
    a += b;
    while (a >= mod) a -= mod;
    return a;
}

int sub(int a, int b) {
    a -= b;
    while (a < 0) a += mod;
    return a;
}

int mul(int a, int b) {
    return a * b % mod;
}

int pw(int x, int p) {
    if (p == 0) return 1;
    if (p % 2) return pw(x, p - 1) * x % mod;
    int pp = pw(x, p / 2);
    return pp * pp % mod;
}

int rev(int a) {
    return pw(a, mod - 2);
}

void precalc() {
    fac[0] = 1;
    rep(i, 1, N) {
        fac[i] = mul(fac[i - 1], i);
    }
    fre[N - 1] = rev(fac[N - 1]);
    for (int i = N - 2; i >= 0; --i) {
        fre[i] = mul(fre[i + 1], i + 1);
    }
}

int C(int nn, int k) {
    if (nn - k < 0) return 0;
    return mul(fac[nn], mul(fre[k], fre[nn - k]));
}

int f(int s, int param) {
    return C(n-param+s, n-param);
}

int g(int s, int param) {
    int res = 0;
    rep(a, 0, m + 1) {
        if ((s - a) % 2 == 0 && (s - a) >= 0) {
            res = add(res, mul(f((s - a) / 2, param), C(n+1-param, a)));
        }
    }
    return res;
}

main() {
    cin >> n >> m;
    precalc();
    int ans = sub(g(3 * m, 1), mul(n, sub(g(m, 1), g(m, 2))));
    cout << ans << '\n';
}

Measured memory_bytes: 33280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
/**
 * Write a description of class Main here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Main
{
    public static void main(String[] args) throws IOException
    {
        //Declaración objeto tipo lector.
        //BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int y = scan.nextInt();
        int z = scan.nextInt();
        scan.close();
        int guardar = x;
        
        //Cambio 
        x = z;
        z = y;
        y = guardar;
        
        System.out.println(x + " " + y + " " + z);
        
    }
}



Measured memory_bytes: 23508
a,b = map(int, input().split())
s = input()
f = True
for i in range(len(s)):
    if i == a:
        continue
    if s[i] > "9" or s[i] < "0":
        f=False

if s[a] != "-":
    f= False

print("Yes" if f else "No")

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    cin.sync_with_stdio(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        sum += a[i];
    }

    int b = sum / n;
    if (sum % n > n / 2) b++;

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (b - a[i]) * (b - a[i]);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3264
#include <stdio.h>

int main(void) {
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  
  int pre_A,pre_B,pre_C;
  int count;

  if(A%2==0 && A==B && B==C){
    printf("-1\n");
  } else {
    for(count=0;;count++){
      pre_A = A;
      pre_B = B;
      pre_C = C;
      if(pre_A%2==1 || pre_B%2==1 || pre_C%2==1){
        break;
      } else {
        A = pre_B / 2 + pre_C /2;
        B = pre_C / 2 + pre_A /2;
        C = pre_A / 2 + pre_B /2;
      }
    }
    printf("%d\n",count);
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[106][100006];
int main() {
	ll n,a[106],i,j,w[106],ma=0,W;
	cin>>n>>W;
	for(i=0;i<n;i++)
	{
		cin>>w[i]>>a[i];
	}
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=W;j++)
		{
			if(i==0||j==0)
			dp[i][j]=0;
			else if(w[i-1]<=j)
			dp[i][j]=max(dp[i-1][j],a[i-1]+dp[i-1][j-w[i-1]]);
			else
			dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][W]<<endl;
return 0;
}

Measured memory_bytes: 80128
/// Great & Inimitable Vonatlus
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type,
less<T>, rb_tree_tag, 
tree_order_statistics_node_update>;

using ll = long long;
using pii = pair<int, int>;                                   

const int N = 4e3;
const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

ll a[N], dp[N][N][2];

ll calc(int l, int r, bool h) {
    if (~dp[l][r][h])
        return dp[l][r][h];
    if (l > r)
        return 0;
    if (h)
        return dp[l][r][1] = min(calc(l + 1, r, 0) - a[l], calc(l, r - 1, 0) - a[r]);
    else
        return dp[l][r][0] = max(calc(l + 1, r, 1) + a[l], calc(l, r - 1, 1) + a[r]);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];  
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            dp[i][j][0] = dp[i][j][1] = -1;
    cout << calc(1, n, 0);
    return 0;    
}

Measured memory_bytes: 250368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    int sum=0;
    vector<pair<int,int>> A,B,C,D;
    
    for(int i=0;i<N;i++){
        string U;cin>>U;
        int mi=si(U),now=0;
        
        for(char x:U){
            if(x=='(') now++;
            else now--;
            chmin(mi,now);
        }
        
        sum+=now;
        
        if(now>=0){
            if(mi>=0) A.push_back({now,mi});
            else B.push_back({now,mi});
        }else{
            if(mi>=0) C.push_back({now,mi});
            else D.push_back({now,mi});
        }
    }
    
    sort(all(B),[](auto a,auto b){
        return a.se>b.se;
    });
    
    sort(all(D),[](auto a,auto b){
        return a.se-a.fi<b.se-b.fi;
    });
    
    int now=0;
    
    bool ok=true;
    if(sum) ok=false;
    
    for(int i=0;i<si(A);i++){
        now+=A[i].fi;
    }
    
    for(int i=0;i<si(B);i++){
        if(now+B[i].se<0) ok=false;
        now+=B[i].fi;
    }
    
    for(int i=0;i<si(D);i++){
        if(now+D[i].se<0) ok=false;
        now+=D[i].fi;
    }
    
    for(int i=0;i<si(C);i++){
        if(now+C[i].se<0) ok=false;
        now+=C[i].fi;
    }
    
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 11240
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC134
{
    class Program
    {
        static void Main(string[] args)
        {
            var nd = Console.ReadLine().Split(' ');
            var n = int.Parse(nd[0]);
            var d = int.Parse(nd[1]);
            var range = d * 2 + 1;
            var result = n / range;
            var m = n % range;
            if (m != 0)
            {
                result++;
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13140
from itertools import accumulate
def E(i, x):
    if i == 1:
        return 5 * x
    return (2 * i + 1) * x
N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort(key=None, reverse=True)
x = list(accumulate(x))
x.insert(0, 0)
energy = 9223372036854775807
for k in range(1, N + 1):
    cost = (N + k) * X
    for i in range(1, N + 1):
        if i * k <= N:
            cost += E(i, x[i * k] - x[(i - 1) * k])
        else:
            cost += E(i, x[-1] - x[(i - 1) * k])
            break
    if cost < energy:
        energy = cost
print(energy)


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

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

int H, W;
char c_list[51][51];

bool solve()
{
	for (int y = 0; y < H; ++y)
	{
		for (int x = 0; x < W; ++x)
		{
			if (c_list[y][x] == '#')
			{
				double flag = false;
				for (int i = 0; i < 4; ++i)
				{
					int x_ = x + dx[i];
					int y_ = y + dy[i];
					if (c_list[y_][x_] == '#') flag = true;
				}
				if (!flag) return false;
			}
		}
	}
	return true;
}

int main(int argc, char **argv)
{
	cin >> H >> W;

	for (int y = 0; y < H; ++y)
		for (int x = 0; x < W; ++x)
			cin >> c_list[y][x];

	std::cout << (solve() ? "Yes" : "No")<< std::endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	
	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int N = sc.nextInt(), x[] = new int[N], y[] = new int[N];
		TreeSet<Pair> xCoords = new TreeSet<>(), yCoords = new TreeSet<>();
		for(int i = 0; i < N; ++i)
		{
			xCoords.add(new Pair(x[i] = sc.nextInt(), i));
			yCoords.add(new Pair(y[i] = sc.nextInt(), i));
		}
		long ans = 0;
		PriorityQueue<Pair> pq = new PriorityQueue<>();
		boolean[] vis = new boolean[N];
		pq.add(new Pair(0, 0));
		while(!pq.isEmpty())
		{
			Pair u = pq.remove();
			if(vis[u.idx])
				continue;
			vis[u.idx] = true;
			ans += u.coord;
			Pair ux = new Pair(x[u.idx], u.idx), uy = new Pair(y[u.idx], u.idx);
			xCoords.remove(ux);
			yCoords.remove(uy);
			
			Pair xBefore = xCoords.floor(ux), xAfter = xCoords.ceiling(ux);
			Pair yBefore = yCoords.floor(uy), yAfter = yCoords.ceiling(uy);
			checkAndAdd(pq, vis, x, xBefore, ux);
			checkAndAdd(pq, vis, x, xAfter, ux);
			checkAndAdd(pq, vis, y, yBefore, uy);
			checkAndAdd(pq, vis, y, yAfter, uy);
		}
		out.println(ans);
		out.close();
	}
	
	static void checkAndAdd(PriorityQueue<Pair> pq, boolean[] vis,  int[] coord, Pair v, Pair u)
	{
		if(v != null && !vis[v.idx])
			pq.add(new Pair(Math.abs(coord[u.idx] - coord[v.idx]), v.idx));
	}
	
	static class Pair implements Comparable<Pair>
	{
		int coord, idx;
		
		Pair(int a, int b) { coord = a; idx = b; }
		
		public int compareTo(Pair p)
		{
			if(coord != p.coord)
				return coord - p.coord;
			return idx - p.idx;
		}
	}
		
	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public Scanner(String s) throws FileNotFoundException{	br = new BufferedReader(new FileReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException { return Double.parseDouble(next()); }

		public boolean ready() throws IOException {return br.ready();} 
	}
}

Measured memory_bytes: 72808
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<complex>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#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 mp make_pair
#define fi first
#define sc second

int n,m;

struct E {
	int d;
	int index;
};
vector<E> G[100000];
int d[100000];
int min_d,max_d;

bool dfs(int i,int dis) {
	min_d = min(dis,min_d);
	max_d = max(dis,max_d);
	if(d[i] > -2000000000) {
		return d[i] == dis;
	}

	d[i] = dis;

	bool ret = true;
	REP(j,G[i].size()) {
		ret = (ret && dfs(G[i][j].index,dis + G[i][j].d));
	}
	return ret;
} 

int main(){
	cin >> n >> m;
	REP(i,m) {
		int l,r,dis;
		cin >> l >> r >> dis;

		l--;r--;
		G[l].pb((E){dis,r});
		G[r].pb((E){-dis,l});
	}
	REP(i,n) {
		d[i] = -2000000000;
	}

	REP(i,n) {
		if(d[i] <= -2000000000) {
			min_d = 2000000000;max_d = 0;
			if(!dfs(i,0) || max_d - min_d > 1000000000) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> g(n, vector<int>());
    int u, k;
    REP(i, n) {
        cin >> u >> k;
        u--;
        int v;
        REP(j, k) {
            cin >> v;
            v--;
            g[u].emplace_back(v);
        }
    }

    deque<pair<int, int>> q;
    q.emplace_back(0, 0);

    vector<int> ans(n, -1);
    while (!q.empty()) {
        auto p = q.front(); q.pop_front();
        if (ans[p.first] == -1) ans[p.first] = p.second;

        for (auto r : g[p.first]) {
            if (ans[r] != -1) continue;
            q.emplace_back(r, p.second + 1);
        }
    }
    REP(i, n) cout << i + 1 << " " << ans[i] << endl;
}



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

int main() {
  int N, K, a;
  cin >> N >> K;
  a = 1;
  
  for (int i = 0; i < N; i++){
    if (a <= K){
      a *= 2;
    }
    else{
      a += K;
    }
  }
  
  cout << a << endl;
}

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

int main(){
  int A, B, count;
  cin >> A >> B;
  count = 0;
  for (int i=A; i<B+1; i++) {
    if ((i/10000 == i%10) && ((i%10000)/1000 == (i/10)%10)) {
      count++;
    }
  }
  cout << count << endl;
}

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

int main(){
  int n; 
  cin >> n;
  int x = n % 1000;
  if(x != 0)cout << 1000 - x << endl;
  else cout << 0 << endl;
}

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

using namespace std;

int pre[100001], val[100001], prime[100001];

int main(void){
  prime[1] = 1;
  for(int i = 2; i < 100001; ++i){
    for(int j = 2 * i; !prime[i] && j < 100001; j+=i){
      prime[j] = 1;
    }
  }
  for(int i = 1; i < 100001; ++i){
    val[i] = (!prime[i] && !prime[int((i + 1) / 2)]);
    pre[i] = val[i] + pre[i - 1];
  }
  int n, l, r;
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> l >> r;
    cout << pre[r] - pre[l - 1] << "\n";
  }
}


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

// 低い順に平均をとっていく
int main() {
  int N;
  cin >> N;

  vector<int> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];

  // 低い順に並べる
  sort(v.begin(), v.end());

  float avg = (v[0] + v[1]) / 2.0;
  for (int i = 2; i < N; i++) {
    avg = (avg + v[i]) / 2.0;
  }

  cout << avg << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a%2== 1 || b%2== 1 || c%2== 1){
    cout << 0 << endl;
    return 0;
  }
  if(a== b && b== c ){
    cout << -1 << endl;
    return 0;
  }
  int count = 0;
  while(a%2==0 && b%2==0 && c%2==0){
    int _tmp = a/2;
    int _tmp2 = b/2;
    int _tmp3 = c/2;
    a = _tmp2 + _tmp3;
    b = _tmp + _tmp3;
    c = _tmp + _tmp2;
    count++;
  }
  cout << count << endl;
  return 0;
}

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

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

template <int MODULUS = 1000000007>
struct modulo_int {
private:

    long long value;
    constexpr void normalize() {
        value %= MODULUS;
        if (value < 0) value += MODULUS;
    }

public:

    constexpr modulo_int(const long long& value_ = 0) : value(value_) { normalize(); }
    constexpr modulo_int operator - () const { return modulo_int(MODULUS - value); }
    constexpr modulo_int operator ~ () const { return power(MODULUS - 2); }
    constexpr long long operator () () const { return value; }

    constexpr modulo_int operator + (const modulo_int& rhs) const { return modulo_int(*this) += rhs; }
    constexpr modulo_int& operator += (const modulo_int& rhs) {
        if ((value += rhs.value) >= MODULUS) value -= MODULUS;
        return (*this);
    }

    constexpr modulo_int operator - (const modulo_int& rhs) const { return modulo_int(*this) -= rhs; }
    constexpr modulo_int& operator -= (const modulo_int& rhs) {
        if ((value += MODULUS - rhs.value) >= MODULUS) value -= MODULUS;
        return (*this);
    }

    constexpr modulo_int operator * (const modulo_int& rhs) const { return modulo_int(*this) *= rhs; }
    constexpr modulo_int& operator *= (const modulo_int& rhs) {
        (value *= rhs.value) %= MODULUS;
        return (*this);
    }

    constexpr modulo_int operator / (const modulo_int& rhs) const { return modulo_int(*this) /= rhs; }
    constexpr modulo_int& operator /= (const modulo_int& rhs) {
        return (*this) *= ~rhs;
    }

    constexpr modulo_int power(const long long& power_) const {
        modulo_int result(1), mult(*this);
        for (long long t = power_; t > 0; t >>= 1) {
            if (t & 1) result *= mult;
            mult *= mult;
        }
        return result;
    }

    friend std::istream& operator >> (std::istream& stream, modulo_int& lhs) {
        stream >> lhs.value;
        lhs.normalize();
        return stream;
    }

    friend std::ostream& operator << (std::ostream& stream, const modulo_int& rhs) {
        return stream << rhs.value;
    }

};

int main() {

    int N;
    std::cin >> N;
    std::vector<std::vector<int>> graph(N);

    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        std::cin >> a >> b;
        --a; --b;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }

    modulo_int<> size;
    std::function<int(int, int)> dfs = [&] (const int& v, const int& prev) {
        int count = 0;
        for (const int& u : graph[v]) {
            if (u == prev) continue;
            int tmp = dfs(u, v);
            size += (modulo_int<>(1) - ~modulo_int<>(2).power(tmp)) * (modulo_int<>(1) - ~modulo_int<>(2).power(N - tmp));
            count += tmp;
        }
        return count + 1;
    };

    dfs(0, 0);
    std::cout << (size - ~modulo_int<>(2).power(N) + 1) - modulo_int<>(N) / modulo_int<>(2) << '\n';
    return 0;

}


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

int main(){
  int d;
  int c[27];
  int s[400][27];
  int t[400];
  static int last[27];//最後の開催日

  cin >> d;
  rep(i, 26)cin >> c[i+1];
  rep(i, d){
    rep(j, 26){
      cin >> s[i+1][j+1];
    }
  }

  //各日トップになる問題を計算しておく
  int top[400];
  for(int i=1;i<=d;i++){
    int mx = -INF;
    int mxi;
    for(int j=1;j<=26;j++){
      // int tmp=s[i][j]-5*c[j];
      int tmp=s[i][j]+c[j];
      if(tmp>mx){
        mx = tmp;
        mxi = j;
      }
    }
    top[i]=mxi;
  }
  
  rep(i, d)cout << top[i+1] << endl;
  return 0;
}


Measured memory_bytes: 3664
def main():
    N = int(input())
    X = list(map(int, input().split()))

    mini = float("inf")
    for p in range(1, 101):
        power = 0
        for n in range(N):
            power += (X[n] - p) ** 2
        if power < mini:
            mini = power
    
    print(mini)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

void swap(int* A, int a, int b) {
    int tmp = A[a];
    A[a] = A[b];
    A[b] = tmp;
}

int main() {
    int n;
    int A[100001];
    std::cin >> n;
    for (int i=0; i<n; i++) {
        std::cin >> A[i];
    }
    int div = A[n-1];
    int i=0;
    for (int j=1; j<=n; j++) {
        if (A[j-1] <= div) {
            i++;
            swap(A, i-1, j-1);
        }
    }

    for (int c=0; c<i-1; c++) {
        std::cout << A[c] << " ";
    }
    std::cout << "[" << div << "]";
    for (int c=i; c<n; c++) {
        std::cout << " " << A[c];
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 3436
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader cd = new BufferedReader(new InputStreamReader(System.in));
		String vd = cd.readLine();
		int ans =0;
		for(int i=0;i<vd.length();++i) {
			if(vd.charAt(i)=='+') ans++;
			if(vd.charAt(i)=='-') ans--;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21076