akhauriyash/Code-Regression huggingface dataset:
N, Q = list(map(int, input().split()))
s = input()
spells =  [input().split() for i in range(Q)]
### 逆順で落ちるゴーレムの位置を戻す
#落ちるゴーレムの端の位置
LDpos = -1
RDpos = N
for sp in spells[::-1]:
    if sp[1] == "L":
        if LDpos < N-1 and s[LDpos+1] == sp[0]:
            LDpos +=1 #LDposのゴーレムは1spell前には一つ右に居た
        if RDpos <= N-1 and s[RDpos] == sp[0]:
            RDpos +=1 #RDposの一つ左(生き残りの右端)は1spell前にこのマスに居れるので境界が一つ戻る
    else:
        if LDpos >= 0 and s[LDpos] == sp[0]:
            LDpos -=1 #LDposの一つ右(生き残りの左端)は1spell前にこのマスに居れるので境界が一つ戻る
        if RDpos > 0 and s[RDpos-1] == sp[0]:
            RDpos -= 1 #RDposのゴーレムは1spell前には一つ左に居た
print(max(RDpos-LDpos-1,0))

Measured memory_bytes: 40892
<?php

$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$x = trim(fgets(STDIN));

$cnt = 0;
for ($i = $a; $i >= 0; $i--) {
    if ($x - 500 * $i <= 0) {
        if ($x - 500 * $i == 0) {
            $cnt++;
        }
        continue;
    }
    $tmp1 = $x - 500 * $i;
    for ($j = $b; $j >= 0; $j--) {
        if ($tmp1 - 100 * $j <= 0) {
            if ($tmp1 - 100 * $j == 0) {
                $cnt++;
            }
            continue;
        }
        $tmp2 = $tmp1 - 100 * $j;
        if ($tmp2 % 50 == 0 && $tmp2 / 50 <= $c) {
            $cnt++;
        }
    }
}

echo $cnt.PHP_EOL;


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct edge {
    int to, id;
};

vector<vector<edge>> g;
ll bit = 0;
bool dfs(int now, int goal, int pre) {
    if (now == goal) {
        return true;
    }
    for (edge e : g[now]) {
        int nxt = e.to;
        if (nxt == pre) continue;
        if (dfs(nxt, goal, now)) {
            bit |= (1LL << e.id);
            return true;
        }
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    g.resize(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back((edge){b, i});
        g[b].push_back((edge){a, i});
    }

    int m;
    cin >> m;
    vector<ll> cons(m);
    rep(i, m) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        bit = 0;
        dfs(u, v, -1);
        cons[i] = bit;
    }

    ll ans = 0;
    for (ll mask = 0; mask < (1 << m); mask++) {
        ll now = 0;
        rep(i, m) {
            if (mask & (1 << i)) {
                now |= cons[i];
            }
        }

        int cnt = n - 1 - __builtin_popcountll(now);
        if (__builtin_popcountll(mask) % 2 == 0) {
            ans += (1LL << cnt);
        } else {
            ans -= (1LL << cnt);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	// ２点間の距離
	public static double getDistance (double x1, double y1, double x2, double y2) {
		return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
	}

	// ヘロンの公式(３つの座標から求めるver)
	public static double getArea1 (double x1, double y1, double x2, double y2, double x3, double y3) {
		double a = getDistance(x1,y1,x2,y2);
		double b = getDistance(x1,y1,x3,y3);
		double c = getDistance(x2,y2,x3,y3);
		double s = (a + b + c) / 2;
		return Math.sqrt(s * (s - a) * (s - b) * (s - c));
	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			double x1 = sc.nextDouble();
			double y1 = sc.nextDouble();
			double x2 = sc.nextDouble();
			double y2 = sc.nextDouble();
			double x3 = sc.nextDouble();
			double y3 = sc.nextDouble();
			double xp = sc.nextDouble();
			double yp = sc.nextDouble();
			double area1 = getArea1(x1,y1,x2,y2,xp,yp);
			double area2 = getArea1(x1,y1,x3,y3,xp,yp);
			double area3 = getArea1(x2,y2,x3,y3,xp,yp);
			double area4 = area1 + area2 + area3;
			double area5 = getArea1(x1,y1,x2,y2,x3,y3);
			boolean res = Math.abs(area4 - area5) < 0.00001;
			System.out.println(res ? "YES" : "NO");
		}

	}

}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> e(m);
  for (auto& x : e) {
    cin >> x.first >> x.second;
    x.first--;
    x.second--;
  }
  vector<int> par(n, -1);
  auto root = [&](int t) {
    if (par[t] < 0) return t;
    for (int i = t;; i = par[i])
      if (par[i] < 0) return par[t] = i;
  };
  vector<ll> ans;
  ll a = (ll)n * (n - 1) / 2;
  for (int i = m; i--;) {
    ans.push_back(a);
    int r1 = root(e[i].first), r2 = root(e[i].second);
    if (r1 != r2) {
      a -= (ll)par[r1] * par[r2];
      if (par[r1] > par[r2]) swap(r1, r2);
      par[r1] += par[r2];
      par[r2] = r1;
    }
  }
  reverse(ans.begin(), ans.end());
  for (auto x : ans) cout << x << "\n";
}


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

int main() {
    int X, Y;  cin >> X >> Y;
    if ((4 * X - Y) % 2 == 0 && 4 * X - Y >= 0 && (Y - 2 * X) % 2 == 0 && Y - 2 * X >= 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3640
use std::cmp::{max, min};
use std::io::prelude::*;

fn main() {
    let mut input_str = String::new();
    std::io::stdin().read_to_string(&mut input_str).unwrap();

    let input_parts = input_str.split_whitespace().collect::<Vec<_>>();
    let mut input_parts_it = input_parts.iter().cloned();

    let n: i32 = input_parts_it.next().unwrap().parse().unwrap();
    let l: i32 = input_parts_it.next().unwrap().parse().unwrap();

    let eaten = max(min(0, l + n - 1), l);

    let sum: i32 = (l..l + n).filter(|&i| i != eaten).sum();

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


Measured memory_bytes: 4352
void main() {
	auto N = ri;
	auto a = readAs!(int[]);
	ulong cnt;
	foreach(i; a) {
		auto k = i;
		while(k % 2 == 0 && k != 0) {
			cnt++;
			k /= 2;
		}
	}
	cnt.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


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

typedef long long ll;
typedef vector<ll> vi;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;

#define rep(i,a,b) for(ll i = a; i<b;i++)
#define per(i,a,b) for(ll i = a; i>=b; i--)
#define inf LLONG_MAX
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto &a: x)
#define mp(x,y) make_pair(x,y)

ll bin(ll n, ll k){
  if (n == 0) return 1;
  ll ans = 0;
  ll pw = 2;
  while (pw <= n){
    ans += n/pw;
    ans -= k/pw;
    ans -= (n-k)/pw;
    pw *= 2;
  }
  if (ans > 0) return 0;
  else return 1;
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(NULL); cout.tie(NULL);
  cout << setprecision(15) << fixed;
  ll n; cin >> n;
  string s; cin >> s;
  vi a; a.assign(n,0);
  vi x; x.assign(n-1,0);
  rep(i,0,n) a[i] = s[i]-'1';
  rep(i,0,n-1) x[i] = abs(a[i+1]-a[i]);
  n = n-1;



  ll mod = 0;
  rep(i,0,n) mod += bin(n-1,i)*x[i];
  mod = mod%2;
  if (mod) {cout << 1 << endl; exit(0);}
  else {
    rep(i,0,n) {
      if (x[i] == 1) { cout << 0 << endl; exit(0); }
      else x[i] /= 2;
    }

    ll mod = 0;
    rep(i,0,n) mod += bin(n-1,i)*x[i];
    mod = mod%2;
    if (mod) {cout << 2 << endl; exit(0);}
    cout << 0 << endl;
  }
}


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

import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;

/**
 * Walking in JOI Kingdom
 */
public class Main {

	static final int EAST = 1;
	static final int WEST = -1;
	static final long NONSTOP = (long) Math.pow(10, 18) + 1;

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

		words = br.readLine().split(" ");

		int N, Q;
		long T;
		N = parseInt(words[0]);
		T = parseLong(words[1]);
		Q = parseInt(words[2]);

		long[] pos = new long[N];
		int[] dir = new int[N];
		long[] stop = new long[N];

		for (int i = 0; i < N; i++) {
			words = br.readLine().split(" ");
			pos[i] = parseLong(words[0]);
			dir[i] = parseInt(words[1]) == EAST ? EAST : WEST;
			stop[i] = NONSTOP;
		}

		//solve
		for (int i = 1; i < N - 1; i++) {
			if (dir[i] == EAST) {
				if (dir[i + 1] == WEST) {
					stop[i] = stop[i + 1] = (pos[i + 1] - pos[i]) / 2;
				}
			} else {
				if (dir[i - 1] == EAST) {
					stop[i - 1] = stop[i] = (pos[i] - pos[i - 1]) / 2;
				}
			}
		}

		for (int i = 0; i < N; i++) {
			if (stop[i] == NONSTOP) {
				if (dir[i] == EAST) {
					for (int j = i + 1; j < N; j++) {
						if (stop[j] != NONSTOP) {
							stop[i] = pos[j] - pos[i] + stop[j];
							break;
						}
					}
				} else {
					for (int j = i - 1; j >= 0; j--) {
						if (stop[j] != NONSTOP) {
							stop[i] = pos[i] - pos[j] + stop[j];
							break;
						}
					}
				}
			}
		}

		for (int i = 0; i < Q; i++) {
			int q = parseInt(br.readLine()) - 1;
			if (T < stop[q]) {
				System.out.println(pos[q] + dir[q] * T);
			} else {
				System.out.println(pos[q] + dir[q] * stop[q]);
			}
		}
	}
}

Measured memory_bytes: 65700
n = int(input())

c = [[0 for _ in range(10)] for _ in range(10)]

for k in range(1, n+1):
    i = int(str(k)[0])
    j = int(str(k)[-1])
    c[i][j] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
print(ans)

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

int main(){
    int n;
    cin >> n;
    long long maxa = 0;
    long long mina = 1000000000;
    long long a;
    for (int i = 0; i < n; i++){
        cin >> a;
        maxa = max(maxa,a);
        mina = min(mina,a);
    }

    cout << maxa - mina << endl;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    
    int n, k; cin >> n >> k;
    vi a(n);
    REP(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    int ans = 1e9;
    REP(i, n - k + 1) {
        ans = min(a[i + k - 1] - a[i], ans);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
<?php

class Simulator
{
    private $inputs;
    private $backslash = array();
    private $area_pond = array();
    private $pending_area = array();

    public function __construct()
    {
        $this->inputs = trim(fgets(STDIN));
    }

    public function calculateAreas()
    {
        $count = 0;

        for ($index = 0; $index < strlen($this->inputs); $index++) {
            if ($this->inputs[$index] == "\\") {
                $this->backslash[] = $index;
            } elseif ($this->inputs[$index] == "/" and $this->backslash) {
                $last_bs_index = array_pop($this->backslash);
                $diff = $index - $last_bs_index;
                $count += $diff;
                while ($this->area_pond and end($this->area_pond) > $last_bs_index) {
                    $diff += array_pop($this->pending_area);
                    array_pop($this->area_pond);
                }
                $this->area_pond[] = $last_bs_index;
                $this->pending_area[] = $diff;
            }
        }
        echo $count . PHP_EOL;
        echo implode(" ", array_merge([count($this->area_pond)], $this->pending_area)) . PHP_EOL;
    }
}

$simulator = new Simulator();
$simulator->calculateAreas();



Measured memory_bytes: 12152
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
bool used[55];
ll x[55], y[55];
int n;
ll p, q;
void dfs(int i) {
	if (used[i]) return;
	used[i] = true;
	for (int j = 0; j < n; ++j) {
		if ((x[i] - x[j] == p && y[i] - y[j] == q) ||
			(x[j] - x[i] == p && y[j] - y[i] == q)) {
			dfs(j);
		}
	}
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) scanf("%lld%lld", &x[i], &y[i]);
	int ans = n;
	for (int i = 0; i < n; ++i)
		for (int j = i + 1; j < n; ++j) {
			p = x[j] - x[i];
			q = y[j] - y[i];
			int v = 0;
			fill(used, used + n, false);
			for (int k = 0; k < n; ++k) {
				if (used[k]) continue;
				dfs(k);
				++v;
			}
			ans = min(ans, v);
		}
	printf("%d\n", ans);
}


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

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  int n,m; cin >> n >> m;
  int i,t,sum;
  sum = 0;
  rep(i,m){cin >> t; sum += t;}
  if(n < sum){cout << -1 << endl;} else {cout << n - sum << endl;}

  return 0;
}


Measured memory_bytes: 3636
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [0,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv

# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv

n = ni()
a = list(li())

MOD = 10**9+7

inv = inv_mod(n,MOD)
fac = fact(n,MOD)

inv.remove(0)
inv = [invi * fac[n] % MOD for invi in inv]
inv_cum = list(accumulate(inv))

ans = 0
for i in range(n):
    ans += a[i]*(inv_cum[i] + inv_cum[n-i-1] - inv[0])
    ans %= MOD
    
print(ans)

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

int main(void){
    string s, t;
    cin >> s >> t;
    reverse(t.begin(), t.end());
    if(s == t){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	private static void solve(){
		//Implement solution here.
		int n = ni();
		int k = ni();
		long[] a = nal(n);
		List<Long> b = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			long tmp = 0;
			for(int j = i; j < n;j++) {
				tmp += a[j];
				b.add(tmp);
			}
		}
		
		long x = 0;
		for(int i = 40; i >= 0; i--) {
			int tmpcnt = 0;
			long tmpx = x + (long)Math.pow(2, i);
			for(Long bl:b) {
				if((tmpx & bl) == tmpx) {
					tmpcnt++;
				}
				if(tmpcnt >=k) {
					x += Math.pow(2, i);
					break;
				}
			}
		}
		System.out.println(x);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 48596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, m; cin >> n >> m;
    ll x = 1900LL * m + 100LL * (n-m);
    cout << x * (1LL << m) << endl;
}

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

namespace ABC150
{
    class B
    {
        static void Main(string[] args)
        {
            int ans = 0;
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            for (int i = 0; i < n-2; i++)
            {
                if (s.Substring(i, 3) == "ABC") { ans++; }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
x = int(input())
flg = True
if x == 1:
    print(2)
elif x == 2:
    print(2)
else:
    if x % 2 == 0:
        x += 1
    while True:
        flg = False
        for i in range(2, x):
            if x % i == 0:
                flg = True
                break
        if flg:
            x += 2
        else:
            print(x)
            break

Measured memory_bytes: 3064
#include <stdio.h>
int main(){
  int N;
  int v;
  int i;
  int j;
  int count;
  int x;
  int A[10000];

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

  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i == N - 1) break;
    printf(" ");
  }
  printf("\n");
  
  for(i = 1;i<N;i++){
    v = A[i];
    j = i - 1;
    while(j>=0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
    }
    A[j+1] = v;
    
    for(x = 0;x<N;x++){
	printf("%d",A[x]);
	if(x == N-1) break;
	printf(" ");
    }
      printf("\n");
  }
}



Measured memory_bytes: 2140
def solve():
    from itertools import combinations
    from heapq import heappush, heappop
    
    def dot(c1, c2):
        return c1.real * c2.real + c1.imag * c2.imag
    
    def cross(c1, c2):
        return c1.real * c2.imag - c1.imag * c2.real
    
    # get distance between segment and point
    def d_sp(sp1, sp2, p):
        a = sp2 - sp1
        b = p - sp1
        if dot(a, b) < 0:
            return abs(b)
        c = sp1 - sp2
        d = p - sp2
        if dot(c, d) < 0:
            return abs(d)
        return abs(cross(a, b) / a)
    
    # get distance between two segments
    def d_s(p1, p2, p3, p4):
        return min(d_sp(p1, p2, p3), d_sp(p1, p2, p4), d_sp(p3, p4, p1), \
                   d_sp(p3, p4, p2))

    from sys import stdin
    
    file_input = stdin
    
    while True:
        W, N = map(int, file_input.readline().split())
        
        if W == 0:
            break
        if N == 0:
            print(W)
            continue
        
        polygons = []
        adj = [[] for i in range(N + 1)]
        adj_s = adj[0]
        goal = N + 1
        
        for i in range(1, N + 1):
            M = int(file_input.readline())
            p = [i]
            s_d = W
            g_d = W
            for j in range(M):
                x, y = map(int, file_input.readline().split())
                p.append(x + y * 1j)
                s_d = min(s_d, x)
                g_d = min(g_d, W - x)
            adj_s.append((i, s_d))
            adj[i].append((goal, g_d))
            p.append(p[1])
            polygons.append(p)
        
        for p1, p2 in combinations(polygons, 2):
            i = p1[0]
            j = p2[0]
            d = [d_s(v1, v2, v3, v4) for v3, v4 in zip(p2[1:], p2[2:]) \
                 for v1, v2 in zip(p1[1:], p1[2:])]
            
            d = min(d)
            adj[i].append((j, d))
            adj[j].append((i, d))
        
        # Dijkstra's algorithm
        PQ = [(0, 0)]
        isVisited = [False] * (N + 2)
        distance = [W] * (N + 2)
        
        distance[0] = 0
        
        while PQ:
            u_cost, u = heappop(PQ)
            
            if u == goal:
                print(u_cost)
                break
            
            if u_cost > distance[u]:
                continue
            
            isVisited[u] = True
            
            for v, v_cost in adj[u]:
                if isVisited[v]:
                    continue
                
                t_cost = distance[u] + v_cost
                if t_cost < distance[v]:
                    distance[v] = t_cost
                    heappush(PQ, (t_cost, v))

solve()


Measured memory_bytes: 10364
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(10);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
////////////////



void solve(){
  inl(N , K);

  auto f = [&](ll m){
    int num = 2;
    ll s = m;
    ll cur = m;
    while(num <= N){
      // 半分を渡す
      cur = cur / 2;
      if(cur == 0) return true;
      s += cur;
      if(s > K) return false;
      num++;
    };
    return true;
  };

  ll ok = 0 , ng = K + 1; 
  while(ok + 1 < ng){
    ll med = (ok + ng) / 2;
    (f(med) ? ok : ng) = med;
  }
  out(ok);

  

}


Measured memory_bytes: 3208
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)
ans = 0
t = n - 1
for i in range(n):
    lim = 2
    if i == 0: lim = 1
    for j in range(lim):
        if t > 0:
            ans += a[i]
            t -= 1

print(ans)


Measured memory_bytes: 31320
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};

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

int main(int argc, char *argv[])
{
  map<string,int> key;
  int n;
  cin >> n;
  string in;
  int op=0;
  rep(i,n){
    cin >> in;
    key[in]=0;
  }

  cin >> n;
  rep(i,n){
    cin >> in;
    if(key.count(in)){
      cout << (!op?"Opened":"Closed") << " by " << in << endl;
      op^=1;
    }else cout << "Unknown " << in << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	string s;
	int cnt = 0;
	cin >> s;
	rep(i, 3){
		if(s[i] == '1'){
			++cnt;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(a<c)a=c;
  if(b>d)b=d;
  printf("%d",b-a>0?b-a:0);
  return 0;
}

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

int main() {
    int a,b;
    cin >>a>>b;
    if(a%b==0){
        cout<<0<<endl;
    }
    else{
        cout<<1<<endl;
    }
}



Measured memory_bytes: 256
use std::collections::HashMap;
use std::io;
fn main() {
    let mut l1 = String::new();
    let stdin = io::stdin();
    stdin.read_line(&mut l1).unwrap();
    let trimed = l1.trim_end();
    let mut itr = trimed.split_ascii_whitespace();
    let a = itr.next().unwrap().parse::<usize>().unwrap();
    let mut map = HashMap::<String, i32>::new();
    for _x in 0..a {
        let mut l2 = String::new();
        stdin.read_line(&mut l2).unwrap();
        let trimed = l2.trim_end();
        let mut itr = trimed.split_ascii_whitespace();
        let a = itr.next().unwrap();
        map.insert(a.to_string(), 1);
    }
    println!("{}", map.len());
}


Measured memory_bytes: 18136
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;
vector<bool> prime_table(int n) {
  vector<bool> prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int Q;
    cin >> Q;
    auto primes = prime_table(100000);
    vector<int> s(primes.size(), 0);
    for (int i = 1; i < s.size(); i++) {
        s[i] = s[i - 1] + (primes[i] && primes[(i + 1) / 2]);        
    }
    for (int i = 0, l, r; i < Q; i++) {
        cin >> l >> r;
        cout << s[r] - s[l - 1] << "\n";
    }
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> s(N);

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

  sort(s.begin(), s.end());
  int b = 0;
  int sum = 0;
  for(int i = N - 1; i >= 0; i--) {
    if(s[i] % 10 != 0) {
      b = s[i];
    }
    sum += s[i];
  }

  if(sum % 10 != 0) {
    cout << sum << endl;
    return 0;
  }

  if(b == 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << sum - b << endl;


}


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

void roundup(int *money) {
    int excess, add;
    int power, i;
    
    for(i = 1; i < 4; i++) {
        power = pow(10, i);

        excess = (*money % power);
        *money -= excess;
                
        if(excess) {
            add = power;
            *money += add;
        }
    }
}

int main(void) {
    int money = 100000;
    int week, i;

    scanf("%d", &week);
    
    for(i = 0; i < week; i++) {
        money *= 1.05;
        roundup(&money);
    }
    
    printf("%d\n", money);
    
    return(0);
}

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

int main(){
  int a, b, c;
  char op;
  while(1){
    cin >> a >> op >> b;
    if (op == '?'){
      break;
    }
    if(op == '+'){
      cout << a + b << endl;
    }else if(op == '-'){
      cout << a - b << endl;
    }else if(op == '*'){
      cout << a * b << endl;
    }else if(op == '/'){
      cout << a / b << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define gcd __gcd

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define read(a) freopen(a,"r",stdin)
#define write(a) freopen(a,"w",stdout)
#define forall(i,a,b) for(int i=a;i<b;i++)
#define foreach(v, c) for(typeof((c).begin())v=(c).begin();v!=(c).end();++v)

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

clock_t start;
void Time(bool timeIt) {
	if (!timeIt) return;
	clock_t end = clock();
	double elapsed_time = ((db)end - (db)start) / (db)CLOCKS_PER_SEC;
	printf("Time elapsed = %0.4lf\n", elapsed_time); 
}

#define LINF (long long)1e18
#define EPS 1e-9
#define INF 1000000007ll
#define SIZE 100010
#define MAX_A 1000010

int main() {
	start = clock();

	int q;
	scanf("%d", &q);
	while (q--) {
		int a, b, c, d;
		scanf("%d %d %d %d", &a, &b, &c, &d);

		int num = cil(max(a, b), min(a, b) + 1);
		int e = min(a, b) + 1, s = 0;
		while (e - s > 1) {
			int m = (e + s) / 2;
			int num1 = a - num * m - (b - m) / num;
			int num2 = (b - m) % num;
			if (num1 < 0) e = m;
			else s = m;
		}

		int rem1 = a - s * num - (b - s) / num;
		int rem2 = (b - s) % num;
		int br1 = (num + 1) * s, br2 = br1 + rem1 + rem2;
		for (int i = c ; i <= d ; ++i) {
			if (i <= br1) {
				if (i % (num + 1) == 0) printf("B");
				else printf("A");
			}
			else if (i <= br1 + rem1) printf("A");
			else if (i <= br1 + rem1 + rem2) printf("B");
			else {
				if (i % (num + 1) == (br2 + 1) % (num + 1)) printf("A");
				else printf("B");
			}
		}
		printf("\n");
	}

	Time(false);
	return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> a(m), b(m);
  for (int i = 0; i < m; ++i) cin >> b[i];
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) cin >> a[j];
    int cur = 0;
    for (int j = 0; j < m; ++j) {
      cur += a[j] * b[j];
    }
    cur += c;
    if (cur > 0) ret++;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<bitset>
#include<cstdio>
#include<string>
#include<time.h>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int N=4e5+10,M=998244353;
long long c[N],l[N];
int main()
{
	int n;
	long long a,b,k,an=0;
	scanf("%d%lld%lld%lld",&n,&a,&b,&k);
	l[1]=1;
	c[0]=1;
	c[1]=n;
	for(int i=2;i<=n;i++)
	{
		l[i]=(M-M/i)*l[M%i]%M;
		c[i]=c[i-1]*(n-i+1)%M*l[i]%M;
	}
	for(int i=0;i<=n;i++)
		if((k-a*i)%b==0&&(k-a*i)/b<=n&&(k-a*i)/b>=0)
			an=(an+c[i]*c[(k-a*i)/b]%M)%M;
	printf("%lld",an);
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "DRUL";
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod;
}
*/

bool multicase = false;

ll n, m, k, num, a, b, c, d, e, h, q, ans, sum;

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

ll cost[505];
ll table[400][30];

string s, t;

void solve() {
    cin >> d;
    for(ll i=0;i<26;i++){
        cin >> cost[i];
    }
    for(ll i=0;i<d;i++){
        for(ll j=0;j<26;j++){
            cin >> table[i][j];
        }
    }
    for(ll i=0;i<d;i++){
        p(1);
    }

    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}



Measured memory_bytes: 3748
#include <bits/stdc++.h>
 
int main() {
	int a, b, c;
	long long k;
	scanf("%d%d%d%lld", &a, &b, &c, &k);
	if(k % 2 == 0)
		printf("%d", a - b);
	else if(k % 2 == 1)
		printf("%d", b - a);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;
using ll = long long;
char s[500010];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int b = 200005, e;
	cin >> s + b;
	int len = strlen(s + b);
	e = b + len;
	int n;
	int query, f;
	char c;
	int flag = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> query;
		if (query == 1) flag ^= 1;
		else {
			cin >> f >> c;
			f--;
			if (f == flag) {
				b--;
				s[b] = c;
			}
			else{
				s[e] = c;
				e++;
			}
		}
	}
	if (!flag)
		cout << s + b << endl;
	else {
		for (int i = e - 1; s[i] != '\0'; --i)
			cout << s[i];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 896
using System;
class Program{
  static void Main(){
    string[] AB = Console.ReadLine().Split(' ');
    int A = int.Parse(AB[0]);
    int B = int.Parse(AB[1]);
    if (A <= B*2)
      Console.WriteLine(0);
    else
      Console.WriteLine(A - B*2);
  }
}

Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

int in(){
	int t;
	cin >> t;
	return t;
}

struct sta{
	vi edges;
	vi costs;
	vi times;

};

int main()
{

	while(1){
		int n,m,k;
		cin >> n >> m;
		if(n==0 && m==0)
			break;
		vector<sta>stations(m);

		rep(i,n){
			int a,b,cost,time;
			cin >> a >> b >> cost >> time;
			a--;
			b--;
			stations[a].edges.pb(b);
			stations[a].costs.pb(cost);
			stations[a].times.pb(time);
			stations[b].edges.pb(a);
			stations[b].costs.pb(cost);
			stations[b].times.pb(time);
		}
		cin >> k;
		rep(i,k){
			int s,g,q;
			cin >> s >> g >> q;
			s--;
			g--;
			if(!q){
				priority_queue<pii,vector<pii>,greater<pii> > Q;
				vi cost(m,inf);
				cost[s]=0;
				Q.push(mp(0,s));
				while(!Q.empty()){
					pii f=Q.top();Q.pop();
					sta now=stations[f.second];
					rp(i,now.edges){
						int to=now.edges[i];
						int cos=now.costs[i];
						if(cost[to] > cost[f.second]+cos){
							cost[to]=cost[f.second]+cos;
							Q.push(mp(cost[to],to));
						}
					}
				}
				cout << cost[g] << endl;
			}else{
				priority_queue<pii,vector<pii>,greater<pii> > Q;
				vi time(m,inf);
				time[s]=0;
				Q.push(mp(0,s));
				while(!Q.empty()){
					pii f=Q.top();Q.pop();
					sta now=stations[f.second];
					rp(i,now.edges){
						int to=now.edges[i];
						int ti=now.times[i];
						if(time[to] > time[f.second]+ti){
							time[to]=time[f.second]+ti;
							Q.push(mp(time[to],to));
						}
					}
				}
				cout << time[g] << endl;
			}
		}
	}
}

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

int main(){
    int n, ans;
    cin >> n;
    if(n%10 == 0){
        ans = 10;
    }else{
        ans = 0;
        while(n>9){
            ans += n%10;
            n /= 10;
        }
        ans += n;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>
 
using namespace std;
  
/********** TEMPLATE STARTS HERE ***********/
    
#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define test int t; cin >> t; while(t--)
#define skip continue
#define stop break
#define sz(v) (int)v.size()
#define endl '\n'
#define PI 3.1415926535897932384626433832795
#define EPS 1e-9
#define gcd __gcd 
#define FO(i, a) for(auto & i : a)
#define debug(a) cout << #a << ": " << a << endl
#define debug1(a, l, r) FR(i, l, r) cout << a[i] << " "; cout << endl
#define SET(a, b) memset(a, b, sizeof(a));
#define refresh fflush(stdout);
#define digits(n) (int)(log10(n) + 1)
  
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pii> vii;
typedef vector <pll> vll;
    
const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;
    
template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
   
/*********** TEMPLATE ENDS HERE *************/

int v[140];

main()
{
	IOS
	int n, k;
	cin >> n >> k;
	
	for(int i = 1; i <= n; i++)
		cin >> v[i];
	
	sort(v + 1, v + 1 + n);
	
	int ans = 0;
	
	for(int i = 1; i <= n; i++)
		if(v[i] <= k)
			k -= v[i], ans++;
		else
		{
			k = -1;
			break;
		}
	
	if(k > 0)
		ans--;
		
	cout << ans;
}

Measured memory_bytes: 256
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    map <int, int> m;
    for (int i = 0; i< k; i++){
        int d;
        cin >> d;
        vector <int> v(d);
        for (int j = 0; j < d; j++) {
            cin >> v[j];
            m[v[j]]++;
        }
    }
    int ans=  0;
    for (int i = 1; i <= n; i++){
        if (m[i] == 0) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String[] line = new String[10001];
		for (int i = 0; i < line.length; i++) {
			line[i] = sc.nextLine();
			if (line[i].equals("0")) {
				break;
			}
		}
		for (int i = 1; i < line.length; i++) {
			if (line[i - 1].equals("0")) {
				break;
			}
			int v = Integer.parseInt(line[i - 1]);
			System.out.println("Case " + i + ": " + v);
		}

	}
}

Measured memory_bytes: 72904
#include "bits/stdc++.h"
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 100000000;
int dp[300100][2];


int main()
{

	int N; cin >> N;
	string S; cin >> S;
	dp[0][0] = 0;
	dp[0][1] = 0;
	for (int i = 1; i < N; i++) if (S.at(i) == 'E') dp[0][1]++;
	for (int i = 0; i < N-1; i++) {
		if (S.at(i) == 'E') dp[i + 1][0] = dp[i][0];
		else dp[i + 1][0] = dp[i][0] + 1;
		if (S.at(i+1) == 'E') dp[i + 1][1] = dp[i][1] - 1;
		else dp[i + 1][1] = dp[i][1];
	}
	
	int ans = INF;
	for (int i = 0; i < N; i++) chmin(ans, dp[i][0] + dp[i][1]);

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


Measured memory_bytes: 6116