akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MAX_V 300
#define INF 1e9
using namespace std;

struct edge{int to, cap,cost,rev;};
int V;
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back((edge){to,cap,cost,G[to].size()});
  G[to].push_back((edge){from,0,-cost,G[from].size()-1});
}

int min_cost_flow(int s,int t,int f){
  int res=0;
  while(f>0){
    fill(dist,dist+V,INF);
    dist[s]=0;
    bool update = true;
    while(update){
      update = false;
      for(int v=0; v<V ;v++){
	if(dist[v]==INF) continue;
	for(int i=0; i<G[v].size(); i++){
	  edge &e = G[v][i];
	  if(e.cap > 0 && dist[e.to] > dist[v]+e.cost) {
	    dist[e.to] = dist[v] + e.cost;
	    prevv[e.to] = v;
	    preve[e.to] = i;
	    update = true;
	  }
	}
      }
    }
    if(dist[t]==INF) return -1;

    int d = f;
    for(int v=t; v!=s; v=prevv[v])d=min(d,G[prevv[v]][preve[v]].cap);
    f -= d;
    res += d*dist[t];
    for(int v=t; v!=s; v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int can[MAX_V][MAX_V];
int Biparite_Matching(int N,int K){
   int s = N+K, t = s+1;
   for(int i=0; i<N; i++) add_edge(s,i,1,0);
   for(int i=0; i<K; i++) add_edge(N+i,t,1,0);

   for(int i=0;i<N;i++)
     for(int j=0;j<K;j++)add_edge(i, N+j , 1, can[i][j]);
   V=N+K+2;
  return min_cost_flow(s,t,N);
}

int main(){
  int n;
  cin>>n;
  int W[101][101],E[101][101];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) cin>>W[i][j];
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) cin>>E[i][j];
  
  string mp[101];
  for(int i=0;i<n;i++)cin>>mp[i];
  
  int sumW[101]={},sumH[101]={},sum=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      if(mp[i][j]=='o'){
	sumW[i]+=E[i][j];
	sumH[j]+=E[i][j];
	sum+=E[i][j];
      }
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)can[i][j]=mp[i][j]=='o'? -E[i][j]:W[i][j];

  cout<<sum+Biparite_Matching(n,n)<<endl;
  int cnt=0;
  ostringstream ans[10001],tmp;
  
  for(int i=0;i<n;i++)
    for(int j=0;j<G[i].size();j++) {
      int h=i,w=G[i][j].to-n,cap=G[i][j].cap;
      if(cap<=0&&mp[h][w]=='.')ans[cnt++]<<h+1<<" "<<w+1<<" write";
      if(cap> 0&&mp[h][w]=='o')ans[cnt++]<<h+1<<" "<<w+1<<" erase";
    }
  cout<<cnt<<endl;
  for(int i=0;i<cnt;i++)cout<<ans[i].str()<<endl;  
  return 0;
}

Measured memory_bytes: 8376
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto D = RD;
	auto c = RDA;
	auto s = new long[][](D);
	foreach (i; 0..D)
		s[i] = RDA;

	auto last = new long[](26);
	foreach (i; 0..D)
	{
		long dec;
		foreach (j; 0..26)
		{
			dec += c[j] * (i - last[j]);
		}

		long best;
		long pos;
		foreach (j; 0..26)
		{
			auto x = s[i][j] + c[j] * (i - last[j]);
			if (x > best)
			{
				best = x;
				pos = j;
			}
		}
		last[pos] = i;
		writeln(pos+1);
	}

	stdout.flush;
	debug readln;
}


Measured memory_bytes: 3224
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 101010 , inf = 1<<28;
int n , ans[N];
vi g[N];
pii a[N] , b[N];

pii merge(pii a,pii b){
    return mp(max(a.fi , b.fi) , min(a.se , b.se));
}

bool f;
void dfs(int c,int fa){
    for(auto t : g[c]) if(t != fa){
        dfs(t , c);
        pii nt = b[t];nt.fi--,nt.se++;
        a[c] = merge(a[c] , nt);
        nt = a[t];nt.fi--,nt.se++;
        b[c] = merge(b[c] , nt);
    }
    bool ok = a[c].se > a[c].fi || (a[c].se == a[c].fi && a[c].se % 2 != 0);
    ok |= b[c].se > b[c].fi || (b[c].se == b[c].fi && b[c].se % 2 == 0);
    if(!ok)
        f = false;
}
void dfs2(int c,int fa,int last){
    int cur = 0;
    if(fa != 0){
        if(last % 2 == 0){
            a[c] = merge(a[c] , mp(last - 1 , last + 1));
            b[c] = mp(inf , -inf);
        } else {
            b[c] = merge(b[c] , mp(last - 1 , last + 1));
            a[c] = mp(inf , -inf);
        }
    }
    if(a[c].se > a[c].fi || (a[c].se == a[c].fi && a[c].se % 2 != 0)){
        cur = a[c].fi;if(cur % 2 == 0) ++cur;
    } else {
        cur = b[c].fi;if(cur % 2 != 0) ++cur;
    }
    ans[c] = cur;
    for(auto t : g[c]) if(t != fa) dfs2(t , c , cur);
}

int main(){
    cin >> n;
    rep(i,1,n){
        int u,v;cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    rep(i,1,n+1){
        a[i] = mp(-inf , inf);
        b[i] = mp(-inf , inf);
    }
    int m;
    cin >> m;
    int x , y;
    rep(i,0,m){
        cin >> x >> y;
        if(y&1) a[x] = mp(y,y) , b[x] = mp(inf,-inf);
        else b[x] = mp(y,y) , a[x] = mp(inf,-inf);
    }
    f = true;
    dfs(1 , 0);
    if(!f) puts("No");
    else{
        puts("Yes");
        dfs2(1 , 0 , 0);
        rep(i,1,n+1) printf("%d\n",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 16128
#include<iostream>
using namespace std;
int main(){
  int i; int l  = 0;
	   char str[21]; char str1[21];
  cin >> str;
  for(i=0;str[i] != '\0';){i++;}
    for(int k = i-1;k >=0 ;l++, k--){
      cout << str[k];    
  }
  cout << endl;
}
  

Measured memory_bytes: 0
#一昨日(a),昨日(b),今日(c)のペンキの色
a,b,c = input().split()
#買ったペンキの数
S = 1
#aとbが違う色か
if not a == b:
    S = S + 1
#aとc、かつbとcが違う色か
if not a == c and not b == c:
    S = S + 1
#買ったペンキの数を出力
print(S)

Measured memory_bytes: 2940
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

vector<int64_t> factorial;
vector<int64_t> inv_factorial;


pii gcdext(int a, int b) {
    if(a == 0) { return make_pair(0, 1); }
    pii p = gcdext(b%a, a);
    return make_pair(p.second - (b/a) * p.first, p.first);
}

void init_combi(int size) {
    factorial.resize(size+1);
    inv_factorial.resize(size+1);

    factorial[0] = factorial[1] = 1;
    inv_factorial[0] = inv_factorial[1] = 1;
    for(int i = 2; i <= size; i++) {
        factorial[i] = (factorial[i-1] * i)%DIVISOR;
        pii p = gcdext(i, DIVISOR);
        int inv = (DIVISOR + p.first)%DIVISOR;
        inv_factorial[i] = (inv_factorial[i-1] * inv)%DIVISOR;
    }
}

int64_t calc_combi(int n, int k) {
    int64_t res = 1;
    debug("%ld/(%ld * %ld)\n", factorial[n], inv_factorial[n-k], inv_factorial[k]);
    res = (res * factorial[n])%DIVISOR;
    res = (res * inv_factorial[n-k])%DIVISOR;
    res = (res * inv_factorial[k])%DIVISOR;
    return res;
}

int main(void) {
    pii p;
    cin >> p.first >> p.second;
    init_combi(p.first + p.second);

    int64_t res = 0;
    for(int x = 0; x <= p.first; x++) {
        int y = p.first - x;
        if(y%2) continue;
        if(y<0) continue;
        y /= 2;
        if((2*x + y) != p.second) continue;
        debug("%d %d\n", x, y);
        // x+y_C_x
        res = (res + calc_combi(x+y, x))%DIVISOR;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 34404
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  REP(i, (s.size() / 2)) {
    if (s[i] != s[s.size() - 1 - i]) {
      ans++;
    }
  }
  cout << ans << endl;
}


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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val > 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

struct Edge{
	Int to;
	Int a, b;
};

int main(){
	Int n, m, s;
	cin >> n >> m >> s;

	Int as = 0;

	std::vector<std::vector<Edge>> edge(n);
	RC(i, m){
		Int u, v, a, b;
		cin >> u >> v >> a >> b;
		--u;
		--v;
		edge[u].push_back(Edge{v, a, b});
		edge[v].push_back(Edge{u, a, b});
		as += a;
	}
	if(s > as) s = as;
	++as;

	std::vector<Int> c(n), d(n);
	RC(i, n){
		cin >> c[i] >> d[i];
	}

	std::vector<Int> ans(n * as, -1);
	std::priority_queue<std::pair<Int, Int>, std::vector<std::pair<Int, Int>>, std::greater<std::pair<Int, Int>>> queue;
	queue.push(std::make_pair(0, s));
	while(!queue.empty()){
		std::pair<Int, Int> top = queue.top();
		queue.pop();
		if(ans[top.second] == -1){
			ans[top.second] = top.first;
			for(int i = top.second / as * as; i < top.second; ++i) if(ans[i] == -1) ans[i] = top.first;
			if(top.second / as == (top.second + c[top.second / as]) / as){
				queue.push(std::make_pair(top.first + d[top.second / as], top.second + c[top.second / as]));
			}
			for(Edge &e : edge[top.second / as]){
				if(top.second % as >= e.a){
					queue.push(std::make_pair(top.first + e.b, e.to * as + top.second % as - e.a));
				}
			}
		}
	}

	ARC(i, 1, n){
		cout << ans[i * as] << endl;
	}
}


Measured memory_bytes: 4460
n = int(input())
lis = []
for i in range(n):
    a , b = input().split()
    lis.append([a,int(b)])

x = input()

ans = 0
p = 0
for i in range(n):
    if p == 0 and lis[i][0] == x:
        p = 1
    elif p == 1:
        ans += lis[i][1]
print(ans)

Measured memory_bytes: 62196
#include<iostream>
using namespace std;
int main(){
	int W, H;
	int x, y; -100 <= x, y <= 100;
	int  r; 0 < W, H, r<=100;
	cin >> W >> H >> x>>y>>r;

	if (x - r >= 0 && x + r <= W&&y - r >= 0 && y + r <= H){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3100
k,n = map(int,input().split())
a_list = list(map(int,input().split()))
result_list = []
for i in range(n):
  if i == 0:
    a_ = a_list[-1] - k
    result =  k - (a_list[0] -a_)
    result_list.append(result)
  else: 
    result =  k - (a_list[i] -a_list[i-1])
    result_list.append(result)
print(min(result_list))
  

Measured memory_bytes: 26444
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
mod = 10**9 + 7

fac = [0] * (N+1)
facinv = [0] * (N+1)
fac[0] = 1
facinv[0] = 1
for i in range(N):
    fac[i+1] = (fac[i] * (i + 1)) % mod
    facinv[i+1] = (facinv[i] * pow(i+1, -1, mod)) % mod

def nCk(n, k):
    return (fac[n] * facinv[k] * facinv[n-k]) % mod

p = 0
m = 0
for i in range(K-1, N):
    p = (p + A[i] * nCk(i, K-1)) % mod
    m = (m + A[N-i-1] * nCk(i, K-1)) % mod
    #print(A[i-K+1] , nCk(N-i+1, K-1))

print((p - m) % mod)

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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5;
int n, k;
vi tree[MAXN];

int dfs(int u, int p, int depth = 0, int siblings = 0) {
    // node cares about colors of: parent, grandparent, siblings
    int ans = max(0, k - min(depth, 2) - siblings);
    // cout << u << ' ' << ans << '\n';

    int children = 0;
    for (int v : tree[u]) {
        if (v == p) continue;

        ans = 1LL * ans * dfs(v, u, depth + 1, children) % MOD;
       // cout << u << ' ' << ans << '\n';
        ++children;
    }

    return ans;
}

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

    cin >> n >> k;
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        --u; --v;

        tree[u].push_back(v);
        tree[v].push_back(u);
    }

    int ans = dfs(0, -1);
    cout << ans << '\n';
    
    return 0;
}


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

int main(int argc, char const *argv[])
{
	int a, b; cin >> a >> b;
	cout << max({a + b, a - b, a * b})	 << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
		int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int ans = a+b+c+d+e;
        int A =10-a%10;if(A==10){A=0;}
        int B =10-b%10;if(B==10){B=0;}
        int C =10-c%10;if(C==10){C=0;}
        int D =10-d%10;if(D==10){D=0;}
        int E =10-e%10;if(E==10){E=0;}
        ans+=A+B+C+D+E;
        ans-=Math.max(A,Math.max(B,Math.max(C,Math.max(D,E))));
		System.out.println(ans);
  }
}


Measured memory_bytes: 21716
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let s: String = read().unwrap();
    let t: String = read().unwrap();
    let a: usize = read().unwrap();
    let b: usize = read().unwrap();
    let u: String = read().unwrap();

    if u == s {
        println!("{} {}", a - 1, b);
    } else if u == t {
        println!("{} {}", a, b - 1);
    } else {
        println!("error");
    }
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>
int main(void){
	int i,l,s;
	char a[1001];
	while(1){
		s=0;
		scanf("%s",a);
		l=strlen(a);
		if(l==1&&a[0]=='0')
			break;
		for(i=0;i<l;i++){
			s+=a[i]-'0';
		}
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 536
def f(a, w, pw)
	s = 0
	a.map{|vw, ef, th|
		if  (r = th - vw * w) > 0
			s += r * ef
		end
	}
	s + pw * w
end

loop.with_index do |_, itr|
	n = gets.to_i	
	break if n == 0
	pw = gets.to_i
	flowers = (1..n).map { vw, pf, vf, th = gets.split.map(&:to_f); [vw, pf / vf, th]}
	
	a = flowers.select{|x| x[0] > 0}
	if a.size > 0
		phi = (1 + Math.sqrt(5)) / 2
		x1 = 0.0
		x4 = [a.map(&:last).max, 0].max.to_f
		a = phi / (1 + phi)
		x2 = a * x1 + (1 - a) * x4
		x3 = (1 - a) * x1 + a * x4

		e = 0.000001

		loop do
			p1 = f(flowers, x2, pw)
			p2 = f(flowers, x3, pw)

			if p1 < p2
				break if (p2 - p1) / p1 < e
				x1, x2, x3, x4 = x1, a * x1 + (1 - a) * x3, x2, x3
			elsif p1 > p2
				break if (p1 - p2) / p2 < e
				x1, x2, x3, x4 = x2, x3, (1 - a) * x2 + a * x4, x4
			else
				break
			end
		end

		p f(flowers, x2, pw)
	else
		p f(flowers, 0, pw)
	end
end

Measured memory_bytes: 90552
#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];

  int g = 1, cnt = 0, i = 0;
  while (i<n) {
    if (v[i] == g) g++;
    else cnt++;
    i++;
  }

  if (g==1) cout << "-1\n";
  else cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

int gcd(int a,int b){
if(b==0) return a;
return gcd(b, a%b);
}

int main()
{
    ll x,y;
    cin >>x >>y;
    if(abs(x-y)>1) cout << "Alice" <<endl;
    else cout << "Brown" <<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;

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

		//String value[] = inputed.split("[\\s]+");
		int intInputed = Integer.parseInt(inputed);

		int minute = intInputed / 60;
		int hours =  minute / 60;

		System.out.println(hours + ":" + (minute % 60) + ":" + (intInputed % 60));

	}
}

Measured memory_bytes: 24336
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <limits>

using namespace std;

vector<unsigned> v;
vector<vector<size_t>> dp; 
vector<size_t> sums;

size_t solution(const int L, const int R)
{
  if (L+1 >= R) return 0;
  size_t s = L > 0 ? sums[R-1] - sums[L-1] : sums[R-1];
  size_t res = numeric_limits<size_t>::max();
  for (int i = L+1; i < R; ++i)
  {
    if (dp[L][i] == 0) dp[L][i] = solution(L, i); 
    if (dp[i][R] == 0) dp[i][R] = solution(i, R); 
    res = min(res, dp[L][i] + dp[i][R]);
  }
  return res + s;
}

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

  int N;
  cin >> N;
  dp = vector<vector<size_t>>(N+1, vector<size_t>(N+1, 0));

  v.resize(N);
  sums = vector<size_t>(N, 0);
  for (int i = 0; i < N; ++i)
  {
    cin >> v[i];
    sums[i] = v[i] + (i > 0 ? sums[i-1] : 0);
  }

  cout << solution(0, v.size());

  return 0;
}

Measured memory_bytes: 1536
d,g = map(int,input().split())
pc = [list(map(int,input().split())) for i in range(d)]

ans = float("inf")


for bit in range(1<<d):
    count = 0
    sum = 0
    nokori = set(range(1,d+1))

    for i in range(d):
        if bit & (1<<i):
            sum +=pc[i][0]*(i+1)*100+pc[i][1]
            count +=pc[i][0]
            nokori.discard(i+1)



    if sum < g:
        use = max(nokori)
        n = min(pc[use-1][0],-(-(g-sum)//(use*100)))
        count += n
        sum += n*use *100

    if sum >= g:
        ans = min(ans,count)
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<limits.h>

int main()
{
    signed long long int a[10000], max, min, sum;
    int n, i;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf ("%lld", &a[i]);

    max = min = sum = a[0]; 

    for (i = 0; i < n - 1; i++) {
      if (max <  a[i + 1])
        max = a[i + 1];
      if (min >  a[i + 1])
        min = a[i + 1];

      sum = sum + a[i + 1];
      }

    printf ("%lld %lld %lld\n", min, max, sum);

    return 0;
}

Measured memory_bytes: 676
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rvrep(i,n) for(ll i=n-1;i>(ll)0;i--)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    vll sum(n,0);
    sum[0]=abs(a[0]);
    for(int i=0;i<n-1;i++)sum[i+1]=sum[i]+abs(a[i+1]-a[i]);
    vll bsum(n,0);
    bsum[n-1]=abs(a[n-1]);
    for(int i=n-1;i>0;i--)bsum[i-1]=bsum[i]+abs(a[i]-a[i-1]);
    rep(i,n){
        ll res;
        if(i!=0&&i!=n-1){
            res=sum[i-1]+abs(a[i-1]-a[i+1])+bsum[i+1];
        }
        else{
            if(i==0)res=abs(a[1])+bsum[1];
            else res=sum[n-2]+abs(a[n-2]);
        }
        cout<<res<<endl;
    }
    return 0;
}




Measured memory_bytes: 3200
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sc second
#define st first
#define pii pair<int, int>
#define arr array
#define task "A"
#define task_check "A"

const int maxn = 5e5 + 5;
const int maxN = 1e5 + 5;
const int mod = 1e9 + 7;

using namespace std;

/// Count : 1

int n, m;
ll a[maxn];

int main()
{
    /*if(fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }*/
    ll ans = 0;
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        ans = ans + s[i] - '0';
        ans %= 9;
    }
    if(ans == 0){
        cout <<"Yes";
    }
    else{
        cout << "No";
    }
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;
const int M = 2e6 + 5;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   if(pow < 0) return 0;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;ll c = (a * b)%mod;return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(2e6 + 7)] , inv_fac[(int)(2e6 + 7)];
void precomp_factorial(){fac[0] = 1;for(ll i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(ll i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};

int vec[123456];

int main()
{
   int n, m;
   cin >> n >> m;
   string s1, s2;
   cin >> s1 >> s2;
   if(s1[0] != s2[0]){
       cout << -1;
   }
   else{
       int g = gcd(n, m);
       ll l = 1LL*n*m;
       l = l/g;
       map <int,char> mp;
       ll val1 = l/n;
       for(int i = 0; i < n; i++){
           mp[1+i*val1] = s1[i];
       }
       val1 = l/m;
       for(int i = 0; i < m; i++){
           if(mp.count(1+i*val1) == 0){
                mp[1+i*val1] = s2[i];
           }
           else{
               if( mp[1+i*val1] != s2[i]){
                   cout << -1;
                   return 0;
               }
           }
           
       }
       cout << l << endl;
   }
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3 = (y1 - y2) + x2;
    int y3 = -(x1 - x2) + y2;
    int x4 = -(y2 - y1) + x1;
    int y4 = (x2 - x1) + y1;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

Measured memory_bytes: 256
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;
const int MAX = 400;


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

    vector<pair<int, int>> ps(n);
    int x, l;

    for (int i=0; i<n; i++) {
        cin >> x >> l;
        ps[i] = make_pair(x+l, x-l);
    }

    sort(ps.begin(), ps.end());

    int ans = 0;
    int cur = -1001001001;

    for (auto p: ps) {
        if (cur <= p.second) {
            cur = p.first;
            ans++;
        }
    }

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



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

char s[200005];

int main(){
    scanf("%s", s + 1);
    int Pos = 1;
    int n = strlen(s + 1);
    for(; Pos <= n; Pos++) if(s[Pos] == 'A') break;
    int End = Pos + 1;
    for(int i = End; i <= n; i++){
        if(s[i] == 'Z') End = max(End, i);
    }
    printf("%d",End - Pos + 1);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
int main(){

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

    int ans = 0;

    for(int i = 0; i < n-2; ++i){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')++ans;
    }

    cout << ans << endl;

}

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

all_tenbo = list(range(1, N+1))

not_good = []
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] >= H[B-1]:
        not_good.append(B)
    if H[A-1] <= H[B-1]:
        not_good.append(A)
print(len(set(all_tenbo) - set(not_good)))

Measured memory_bytes: 29804
#include <stdio.h>
int pow2(int n){
    int ret = 1;
    while(n--) ret *= 2;
    return ret;
}
int main(void){
    int N, M;
    scanf("%d %d",&N,&M);
    
    int T = 1900*M+100*(N-M);
    printf("%d\n",T*pow2(M));
    
}


Measured memory_bytes: 128
#include <stdio.h>

#define N 100000

int main() {
    int a[N];
	int num, i, max= 0,cnt = 0;

	scanf("%d", &num);

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

	i = 1;

	while(i != num){
		if (a[i - 1] >= a[i]) {
			cnt++;
		}
		else {
			cnt = 0;
		}
		if (cnt > max) {
			max = cnt;
		}
		i++;
	}

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

Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var h, w int
	for {
		fmt.Scanln(&h, &w)
		if h == 0 && w == 0 {
			break
		}
		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				if (i+j)%2 == 0 {
					fmt.Print("#")
				} else {
					fmt.Print(".")
				}
			}
			fmt.Println()
		}
		fmt.Println("")
	}
}


Measured memory_bytes: 1124
import java.io.*;
import java.util.*;
import java.util.function.*;

class Restaurant {
	int idx;
	String city;
	int point;

	Restaurant(int idx, String city, int point) {
		this.idx = idx;
		this.city = city;
		this.point = point;
	}
}

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		Restaurant[] restaurants = new Restaurant[N];
 		for (int i = 0; i < N; i++) {
			String S = sc.get();
			int P = Integer.parseInt(sc.get());
			restaurants[i] = new Restaurant(i+1, S, P);
		}
 		Arrays.sort(restaurants, Comparator.comparing((Restaurant r) -> r.city).thenComparingInt(r -> -r.point));
 		StringJoiner joiner = new StringJoiner("\n");
		for (Restaurant restaurant : restaurants) {
			joiner.add(String.valueOf(restaurant.idx));
		}
		System.out.println(joiner);
	}
}

class Main {
	public static void main(String... args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<String>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
	}
}

Measured memory_bytes: 26964
import java.util.Scanner;

class Main{
    public static void main(String[] arg){

        Scanner in = new Scanner(System.in);

        String input = in.nextLine();
        String [] param_line = input.split(" ", 0);
        int [] dice_no = new int[6];
        for(int i=0; i<dice_no.length; i++)
            dice_no[i] = Integer.parseInt(param_line[i]);

        // create dice class instance
        Dice dice = new Dice(dice_no);

        //System.out.println(dice);

        // dice operation
        input = in.nextLine();
        for(int i=0; i<input.length(); i++){
            switch(input.charAt(i)){
                case 'W':
                    dice.toW();
                    break;
                case 'E':
                    dice.toE();
                    break;
                case 'S':
                    dice.toS();
                    break;
                case 'N':
                    dice.toN();
                    break;
            }
            //System.out.println(dice);
            //System.out.println(input.charAt(i));
        }
        System.out.println(dice_no[dice.get(0)]);
    }
}

class Dice{

    static final int W = 6;
    static final int E = 7;
    static final int S = 8;
    static final int N = 9;

    static  final int[][] dice_table = {

    // top,front,right,left,back,bottom,W,E,S,N
        {0, 1, 2, 3, 4, 5, 9, 15, 16, 6},
        {0, 2, 4, 1, 3, 5, 17, 7, 12, 10},
        {0, 4, 3, 2, 1, 5, 13, 11, 4, 18},
        {0, 3, 1, 4, 2, 5, 5, 19, 8, 14},
        {1, 0, 3, 2, 5, 4, 12, 8, 20, 2},
        {1, 3, 5, 0, 2, 4, 21, 3, 9, 13},
        {1, 5, 2, 3, 0, 4, 10, 14, 0, 22},
        {1, 2, 0, 5, 3, 4, 1, 23, 15, 11},
        {2, 0, 1, 4, 5, 3, 4, 16, 23, 3},
        {2, 1, 5, 0, 4, 3, 20, 0, 17, 5},
        {2, 5, 4, 1, 0, 3, 18, 6, 1, 21},
        {2, 4, 0, 5, 1, 3, 2, 22, 7, 19},
        {3, 0, 4, 1, 5, 2, 16, 4, 21, 1},
        {3, 4, 5, 0, 1, 2, 22, 2, 5, 17},
        {3, 5, 1, 4, 0, 2, 6, 18, 3, 23},
        {3, 1, 0, 5, 4, 2, 0, 20, 19, 7},
        {4, 0, 2, 3, 5, 1, 8, 12, 22, 0},
        {4, 2, 5, 0, 3, 1, 23, 1, 13, 9},
        {4, 5, 3, 2, 0, 1, 14, 10, 2, 20},
        {4, 3, 0, 5, 2, 1, 3, 21, 11, 15},
        {5, 1, 3, 2, 4, 0, 15, 9, 18, 4},
        {5, 3, 4, 1, 2, 0, 19, 5, 10, 12},
        {5, 4, 2, 3, 1, 0, 11, 13, 6, 16},
        {5, 2, 1, 4, 3, 0, 7, 17, 14, 8},
    };

    private int status;

    Dice(int [] a){
        status = 0;
    }

    void toW(){
        status = dice_table[status][W];
    }

    void toE(){
        status = dice_table[status][E];
    }

    void toS(){
        status = dice_table[status][S];
    }

    void toN(){
        status = dice_table[status][N];
    }

    int get(int index){
        return dice_table[status][index];
    }


    @Override
    public String toString(){
        String str = "";
        for(int i=0; i<5; i++)
            str += dice_table[status][i] + ", ";
        str += dice_table[status][5];
        return str;
    }
}

Measured memory_bytes: 26088
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
#define INF (1LL << 60)
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,k,n) for(int i=(k);(i)<(n);(i)++)
#define REP(i,n) for(int i = 0;(i)<(n);(i)++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define F first
#define S second

int main() {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int> l(q);
	vector<int> r(q);

	REP(i, q) { 
		cin >> l[i] >> r[i]; 
		l[i]--;
		r[i]--;
	}


	vector<int> ac;
	REP(i, n - 1) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			ac.push_back(i);
			i++;
		}
	}
	if (ac.size() == 0) {
		REP(i, q) {
			cout << 0 << endl;
		}
		return 0;
	}

	REP(i, q) {
		int ans = 0;
		auto itr1 = lower_bound(ALL(ac), l[i]);
		auto itr2 = lower_bound(ALL(ac), r[i]);
		if (*(itr2 - 1) < r[i]) {
			ans = distance(itr1, itr2 - 1) + 1;
		}
		else {
			ans = distance(itr1, itr2 - 2) + 1;
		}
		cout << ans << endl;
	}


	
	return 0;
}


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

using Graph=vector<vector<int>>;
using ll=__int128;

class Solver{
    int n;
    Graph g;
    vector<int> cnt;
    const ll INF=1e20;
    int dfs(int v,int pre,int dep){
        cnt[dep]=max(cnt[dep],(int)(g[v].size()-1));
        int res=dep;
        for(auto to:g[v]){
            if(to!=pre) res=max(res,dfs(to,v,dep+1));
        }
        return res;
    }
    pair<int,ll> calc(vector<int> vs,vector<int> pre){
        cnt.assign(n,1);
        int dep=0;
        for(auto v:vs){
            int prev=-1;
            for(int i=0;i<pre.size();i++) if(pre[i]!=v) prev=pre[i];
            dep=max(dep,dfs(v,prev,0)+1);
        }
        if(pre.size()==1) dep++;
        ll res=1;
        for(int i=0;i<n;i++) res=min(res*cnt[i],INF);
        return make_pair(dep,res*vs.size());
    }
    public:
    Solver(int n):n(n),g(n){
        for(int i=0;i+1<n;i++){
            int a,b;
            cin>>a>>b;
            a--,b--;
            g[a].push_back(b);
            g[b].push_back(a);
        }
    }
    pair<int,ll> solve(){
        pair<int,ll> res={n+1,INF};
        for(int i=0;i<n;i++){
            vector<int> vs;
            for(auto to:g[i]){
                vs.push_back(to);
            }
            res=min(res,calc(vs,vector<int>{i}));
            for(auto to:g[i]){
                res=min(res,calc(vector<int>{i,to},vector<int>{i,to}));
            }
        }
        return res;
    }
};

int main(){
    int n;
    cin>>n;
    Solver solver(n);
    auto ret=solver.solve();
    cout<<ret.first<<" "<<(long long)(ret.second)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	Rep(i, N) cin >> a[i];
	sort(a.begin(), a.end());
	set<int> c;
	Rep(i, N) c.insert(a[i]);
	vector<int> d; // 重複要素なし
	set<int>::iterator itr = c.begin();
	int n = c.size();
	for (int i = 0;i < n;i++) {
		d.push_back(*itr);
		itr++;
	}
	map<int, int> b;
	Rep(i, n) b[d[i]] = upper_bound(a.begin(), a.end(), d[i]) - lower_bound(a.begin(), a.end(), d[i]);
	int res = 0;
	for (int i = 0;i < n;i++) {
		int cn = b[d[i]];
		if (i - 1 >= 0 && d[i - 1] + 1 == d[i]) cn += b[d[i - 1]];
		if (i + 1 < n && d[i + 1] - 1 == d[i]) cn += b[d[i + 1]];
		if (res < cn) res = cn;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 6784
#include <iostream>

using namespace std;

int main(){
 
  char c;
  
  cin >> c;
  
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
def dfs(z,c)
	f=G[c].size==2?1:0
	r=[0,c]
	G[c].each{|e|
		next if e==z
		t=dfs(c,e)
		r=[r,[t[0]+f,t[1]]].max
	}
	r
end
N=gets.to_i
G=N.times.map{[]}
(N-1).times{
	a,b=gets.split.map(&:to_i)
	G[a-1]<<b-1
	G[b-1]<<a-1
}
p dfs(-1,dfs(-1,0)[1])[0]+G.count{|e|e.size==1}

Measured memory_bytes: 12412
#include<iostream>

using namespace std;
int main()
{
    int s;
    char ch[100005],pre;
    cin>>ch;
    pre=ch[0];
    int cnt=0;
    for(int i=0;ch[i]!='\0';i++){
        if(ch[i]!=pre){
            cnt++;
        }
        pre=ch[i];
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
	long long int st, r, D;
	while (cin >> r >> D >> st)
	{
		for (int i = 1; i <= 10; i++)
		{
			cout << (st * r) - D<<'\n';
			st = (st * r) - D;
		}
	}
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

const ll mod =  1000000007;
// Self settings
// clang-format off
#define MAX_N 1000000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) {res = (res * i) % mod ;} return res;}
// ll nCr(ll n, ll r) {return (fact(n)/(fact(n-r)*fact(r)));}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
// clang-format on

ll fact(ll m) {
  ll res = 1;
  for(int i = 2; i <= m; i++) {
    res = (res * i) % mod;
  }
  return res;
}

ll mypow(ll m, ll p) {
  if(m == 0) return 0;
  ll res = 1;
  while(p) {
    if(p & 1) res = (res * m) % mod;
    p >>= 1;
    m = (m*m) % mod;
  }
  return res;
}

int X, Y;
int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> X >> Y;

  ll n = (2*Y-X)/3;
  ll m = (2*X-Y)/3;

  if((X+Y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  if(n < 0 || m < 0 ) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = fact(n+m) * (ll)mypow(fact(n),mod-2) % mod * (ll)mypow(fact(m),mod-2) % mod;
  cout << ans << endl;
  return 0;
}


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

int main()
{
	int n, x{}, max{};
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		char s;
		scanf(" %c", &s);
		if (s == 'I') x++;
		else x--;
		max = std::max(x, max);
	}
	printf("%d\n", max);

	return 0;
}

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

def solve(N: int, A: int, B: int, C: int, l: "List[int]"):
    # 0: 使わない 1:A 2:B 3:C
    all = list(itertools.product([0,1,2,3], repeat=N))
    answer = 10**9
    for a in all:
        a_sum = 0
        a_count = 0
        b_sum = 0
        b_count = 0
        c_sum = 0
        c_count = 0

        for i in range(len(a)):
            if a[i] == 0:
                continue
            elif a[i] == 1:
                a_sum += l[i]
                a_count +=1
            elif a[i] == 2:
                b_sum += l[i]
                b_count +=1
            elif a[i] == 3:
                c_sum += l[i]
                c_count +=1
        
        if a_count == 0 or b_count == 0 or c_count==0 :
            continue

        MP = (a_count-1)*10+(b_count-1)*10+(c_count-1)*10+abs(A-a_sum)+abs(B-b_sum)+abs(C-c_sum)

        answer = min(MP,answer)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    l = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, C, l)

if __name__ == '__main__':
    main()


Measured memory_bytes: 10996
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint N;
	string S;
	cin >> N >> S;
	lint cntr = 0;
	lint cntw = 0;
	rep(i, N) {
		if (S[i] == 'R') {
			cntr++;
		}
		else {
			cntw++;
		}
	}
	string A;
	rep(i, cntr) {
		A.push_back('R');
	}
	rep(i, cntw) {
		A.push_back('W');
	}
	lint r = 0;
	lint w = 0;
	rep(i, N) {
		if (S[i] == 'W' && A[i] == 'R') {
			r++;
		}
		else if (S[i] == 'R' && A[i] == 'W') {
			w++;
		}
	}
	lint ans = min(r, w) + abs(r - w);
	cout << ans << endl;
}

Measured memory_bytes: 3920
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    
    int dx=tx-sx;
    int dy=ty-sy;
    
    cout<<string(dy,'U')<<string(dx,'R');
    cout<<string(dy,'D')<<string(dx,'L');
    
    cout<<'L'<<string(dy+1,'U')<<string(dx+1,'R')<<'D';
    cout<<'R'<<string(dy+1,'D')<<string(dx+1,'L')<<'U'<<endl;
    return 0;
}

Measured memory_bytes: 3568
n= int(input())
mod=10**9+7
a= [int(x ) for x in input().split()]
b= a[:]

s=0
for i in range(n-2,-1,-1):
    b[i]=b[i+1]+b[i]
for i in range(n):
    s += (b[i]-a[i])*a[i]
print(s%mod)

Measured memory_bytes: 31508
#include <algorithm>
#include <iostream>

int main() {
  char S[3];
  std::cin >> S;

  std::sort(S, S + 3);
  if ( S[0] == 'a' && S[1] == 'b' && S[2] == 'c' ) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int A, B, X;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> A >> B >> X;

    int ans = inf;
    rep(a, 0, 21) {
        int d = X - a * 1000;
        int cst = a * A;
        if (0 < d) {
            cst += (d + 499) / 500 * B;
        }
        chmin(ans, cst);
    }
    cout << ans << endl;
}



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

int bingo[3][3];
map <int, bool> num;
int n;
int vals[105];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 0; i < 3; i++) 
    for (int j = 0; j < 3; j++) {
      cin >> bingo[i][j];
      num[bingo[i][j]] = true;
    }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> vals[i];
    num[vals[i]] = false;
  }
  for (int i = 0; i < 3; i++) {
    bool ans = true;
    for (int j = 0; j < 3; j++) {
      if (num[bingo[i][j]] == true) ans = false;  
    }
    if (ans) {
      cout<< "Yes\n";
      return 0;
    }
  }
  for (int i = 0; i < 3; i++) {
    bool ans = true;
    for (int j = 0; j < 3; j++) {
      if (num[bingo[j][i]] == true) ans = false;  
    }
    if (ans) {
      cout<< "Yes\n";
      return 0;
    }
  }
  int ansx[2][3] = {{0,1,2},{0,1,2}};
  int ansy[2][3] = {{0,1,2},{2,1,0}};
  for (int i = 0; i < 2; i++) {
    bool ans = true;
    for (int j = 0; j < 3; j++) {
      if (num[bingo[ansx[i][j]][ansy[i][j]]]) ans = false;  
    }
    if (ans) {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
import math
s = input().split()
a = int(s[0])
b = int(s[1])
k = int(s[2])
for i in range(k):
	if(i % 2 == 0):
		b += int(math.floor(a / 2))
		a = int(math.floor(a / 2))
	else:
		a += int(math.floor(b / 2))
		b = int(math.floor(b / 2))
print("{0} {1}".format(a,b))

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

int main(){
 int R,G; cin>>R>>G;
 cout<<(G+G-R)<<endl;

 return 0;
}




Measured memory_bytes: 3564