akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n, = map(int, readline().split())

M = 2*10**5+2
Uy = {}
Dy = {}
Rx = {}
Lx = {}

d1U = {} # 右上、x+y UR
d1R = {} # 右上、x+y UR
d2U = {} # 左上、x-y UL
d2L = {} # 左上、x-y UL
d3L = {} # 左下、x+y LD
d3D = {} # 左下、x+y LD
d4D = {} # 右下、x-y DR
d4R = {} # 右下、x-y DR

for _ in range(n):
    x,y,z = readline().split()
    x = int(x); y = int(y)
    if z=="U":
        ss,dp,dn = Uy,d1U,d2U
    elif z=="D":
        ss,dp,dn = Dy,d3D,d4D
    elif z=="R":
        ss,dp,dn = Rx,d1R,d4R
    elif z=="L":
        ss,dp,dn = Lx,d3L,d2L
    
    v = x+y
    if v in dp: dp[v].append(x)
    else: dp[v] = [x]

    v = x-y
    if v in dn: dn[v].append(x)
    else: dn[v] = [x]
    
    if z=="U" or z=="D": x,y = y,x
    if y in ss: ss[y].append(x)
    else: ss[y] = [x]
    
def get(a,b,r):
    a.sort()
    b.sort()
    v = INF
    lb = len(b)
    j = 0
    for ai in a:
        while j < lb and b[j] < ai:
            j += 1
        if j < lb:
            v = min(v,b[j]-ai)
    return v*r

INF = 1<<30
ans = INF

for D1,D2,r in [(Uy,Dy,5),(Rx,Lx,5),(d1R,d1U,10),(d2U,d2L,10),(d3D,d3L,10),(d4R,d4D,10)]:
    for k,lst in D1.items():
        if k in D2:
            ans = min(ans,get(lst,D2[k],r))

if ans == INF:
    print("SAFE")
else:
    print(ans)



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

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;


int a;
string s; 
int main()
{                   
	cin >> a;   
	cin >> s;
	if(a < 3200)
		s = "red";
	cout << s;
	return 0;
}


Measured memory_bytes: 256
object Main {
  def gcd(a: Int, b: Int): Int = {
    if (b == 0) {
      a
    } else {
      gcd(b, a % b)
    }
  }

  def main(args: Array[String]): Unit = {
    val Array(a, b) = io.StdIn.readLine().split(" ").map(_.toInt)
    println(gcd(a, b))
  }
}


Measured memory_bytes: 43960
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n,k = list(map(int, input().split()))
v = [[0]*(2*k) for _ in range(2*k)]

for i in range(n):
    x,y,c = input().split()
    x = int(x)
    y = int(y)
    if c=="B":
        x += k
    x %= 2*k
    y %= 2*k
    v[x][y] += 1
#     v[x][y+2*k] += 1
#     v[x+2*k][y] += 1
#     v[x+2*k][y+2*k] += 1
def cumsum2(v):
    # v: h*wの2次元リスト
    h,w = len(v), len(v[0])
    v.insert(0, [0]*w)
    for l in v:
        l.insert(0, 0)
    for i in range(1,h+1):
        for j in range(1,w+1):
            v[i][j] = v[i-1][j] + v[i][j-1] - v[i-1][j-1] + v[i][j]
    return v
cumsum2(v)

def sub(c, i, j):
    i %= 2*k
    j %= 2*k
    l = []
    if i<=k and j<=k:
        l = [[i,i+k,j,j+k]]
    elif i>k and j<=k:
        l = [[i,2*k,j,j+k], [0,i-k,j,j+k]]
    elif i<=k and j>k:
        l = [[i,i+k,j,2*k], [i,i+k,0,j-k]]
    else:
        l = [[i,2*k,j,2*k], [0,i-k,j,2*k], [i,2*k,0,j-k], [0,i-k,0,j-k]]
    return sum((c[z][w] - c[z][y] - c[x][w] + c[x][y]) for x,z,y,w in l)
ans = -1
for i in range(2*k):
    for j in range(2*k-i):
        val0 = sub(v, i,j) + sub(v, i+k, j+k)
#         val0 = v[i+k][j+k]-v[i+k][j]-v[i][j+k]+v[i][j] + v[i+2*k][j+2*k]-v[i+2*k][j+k]-v[i+k][j+2*k]+v[i+k][j+k]
#         val1 = v[i+2*k][j+k]-v[i+2*k][j]-v[i+k][j+k]+v[i+k][j] + v[i+k][j+2*k]-v[i+k][j+k]-v[i][j+2*k]+v[i][j+k]
        ans = max(ans, val0)
print(ans)

Measured memory_bytes: 143136
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int MOD =1000000007;
//

signed main() {
 int n,a,b;
 cin>>n>>a>>b;
 if((a-b)%2==0){
     cout<<abs(a-b)/2;
     return 0;
 }
 if(a>b)swap(a,b);
 cout<<min(a+(b-a-1)/2,n-b+1+(b-a-1)/2);
 return 0;
}


Measured memory_bytes: 256
S=input()
l=[]
for i in range(len(S)-2):
  a=int(S[i])*100+int(S[i+1])*10+int(S[i+2])
  if 753>=a:
    b=753-a
    l.append(b)
  else :
    b=a-753
    l.append(b)
print(min(l))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define maxn 100005
int tot=0,t[maxn],nxt[maxn],hd[maxn],dp[maxn];
inline void add(int u,int v){t[++tot]=v;nxt[tot]=hd[u];hd[u]=tot;}
inline int d(int u){
	if(!dp[u]) for(int i=hd[u];i;i=nxt[i]) dp[u]=max(dp[u],d(t[i])+1);
	return dp[u];
}
int main(){
	int n,m,u,v,ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){scanf("%d%d",&u,&v);add(u,v);}
	for(int i=1;i<=n;i++) ans=max(ans,d(i));
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
	char cent[10000];
	for(int i=0;;i++){
		if(scanf("%c",&cent[i]) == EOF){break;}
		if(cent[i]>=97 && cent[i]<=122){cent[i]-=32;}
	}
	cout<<cent;
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>

typedef long long LL;
const int Mod = 1000000007, Inv2 = (Mod + 1) / 2;
const int MN = 3005;

int N, Q, A[MN], p1[MN], p2[MN];
int dp[MN][MN], Coef, Sum;

int main() {
	scanf("%d%d", &N, &Q), Coef = 1;
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
	for (int i = 1; i <= Q; ++i) {
		scanf("%d%d", &p1[i], &p2[i]);
		if (p1[i] > p2[i]) std::swap(p1[i], p2[i]);
	}
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= N; ++j)
			dp[i][j] = A[i] > A[j];
	for (int i = 1; i <= Q; ++i) {
		static int tmp[MN][MN];
		for (int x = 1; x <= N; ++x)
			if (x != p1[i] && x != p2[i]) {
				tmp[x][p1[i]] = (LL)Inv2 * (dp[x][p1[i]] + dp[x][p2[i]]) % Mod;
				tmp[p1[i]][x] = (LL)Inv2 * (dp[p1[i]][x] + dp[p2[i]][x]) % Mod;
				tmp[x][p2[i]] = (LL)Inv2 * (dp[x][p2[i]] + dp[x][p1[i]]) % Mod;
				tmp[p2[i]][x] = (LL)Inv2 * (dp[p2[i]][x] + dp[p1[i]][x]) % Mod;
			}
		for (int x = 1; x <= N; ++x)
			if (x != p1[i] && x != p2[i]) {
				dp[x][p1[i]] = tmp[x][p1[i]];
				dp[p1[i]][x] = tmp[p1[i]][x];
				dp[x][p2[i]] = tmp[x][p2[i]];
				dp[p2[i]][x] = tmp[p2[i]][x];
			}
		dp[p2[i]][p1[i]] = dp[p1[i]][p2[i]] = (LL)Inv2 * (dp[p1[i]][p2[i]] + dp[p2[i]][p1[i]]) % Mod;
		Coef = 2ll * Coef % Mod;
	}
	for (int x = 1; x < N; ++x)
		for (int y = x + 1; y <= N; ++y)
			Sum = (Sum + dp[x][y]) % Mod;
	printf("%lld\n", (LL)Coef * Sum % Mod);
	return 0;
}

// Luogu : PinkRabbit

Measured memory_bytes: 70656
class BinaryIndexedTree():
  def __init__(self,n):self.bit=[0]*n
  def add(self,i,x):
    i+=1
    while i<=len(self.bit):
      self.bit[i-1]+=x
      i+=i&-i
  def sum_1(self,i):
    a=0
    i+=1
    while i:
      a+=self.bit[i-1]
      i-=i&-i
    return a
  def sum(self,i,j):
    a=self.sum_1(j-1)
    if i!=0:a-=self.sum_1(i-1)
    return a
def tentousu(a):
  bit=BinaryIndexedTree(n)
  b=[0]*n
  for i in range(n):
    b[a[i]]=i
  ans=0
  for i in range(n):
    j=b[i]+bit.sum(b[i]+1,n)
    ans+=j-i
    bit.add(b[i],1)
  return ans
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(1,n,2):a[i],b[i]=b[i],a[i]
ans=inf=float('inf')
for i in range(2**n):
  s=bin(i)[2:].zfill(n)
  if s.count("0")!=n//2:continue
  ac=[]
  bc=[]
  for j in range(n):
    if s[j]=="1":ac.append((a[j],j))
    else:bc.append((b[j],j))
  ac.sort()
  bc.sort()
  x=[]
  for j in range(n):
    if j%2:x.append(bc[j//2])
    else:x.append(ac[j//2])
  f=False
  for j in range(1,n):
    if x[j-1][0]>x[j][0]:f=True
  if f:continue
  m=[]
  for j in range(n):m.append(x[j][1])
  ans=min(ans,tentousu(m))
if ans==inf:ans=-1
print(ans)

Measured memory_bytes: 53448
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

//セグメント木
//計算量 初期化:O(N)、クエリ:O(log(N))

template<typename Monoid>
struct Segment_Tree{
    Monoid f(Monoid a, Monoid b){
        return min(a, b);
    }
    const Monoid unit;
    int n;
    vector<Monoid> seg;
    
    Segment_Tree(int N, const Monoid &x) : unit(x){
        n = 1;
        while(n < N) n <<= 1;
        seg.assign(2*n, unit);
    }
    
    void change(int i, const Monoid &x){
        i += n;
        seg[i] = x;
        while(i > 0){
            i /= 2;
            seg[i] = f(seg[2*i], seg[2*i+1]);
        }
    }

    Monoid query(int a, int b, int i = 1, int l = 0, int r = -1){
        if(r < 0) r = n;
        if(a >= r || b <= l) return unit;
        if(a <= l && r <= b) return seg[i];
        Monoid vl = query(a, b, 2*i, l, (l+r)/2);
        Monoid vr = query(a, b, 2*i+1, (l+r)/2, r);
        return f(vl, vr);
    }
    
    Monoid operator [] (int i) const {return seg[n+i];}
    
    void clear(){
        fill(seg.begin(), seg.end(), unit);
    }
};

int main(){
    int N, Q;
    cin >> N >> Q;
    Segment_Tree<int> seg(N, INT_MAX);
    while(Q--){
        int q, x, y;
        cin >> q >> x >> y;
        if(q == 0) seg.change(x, y);
        else cout << seg.query(x, y+1) << endl;
    }
}


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

int main() {
    ll X;
    cin >> X;
    if(X >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3616
#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)->sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int cnt = 1;
    int sign = 0;
    REP(i, n - 1) {
        int diff = a[i + 1] - a[i];
        if (diff == 0) continue ;
        if (sign) {
            if ((sign == 1 && diff < 0) || (sign == -1 && diff > 0)) {
                sign = 0;
                cnt++;
            }
        } else {
            if (diff > 0) sign = 1;
            else sign = -1;
        }
    }

    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main() {
	stack<int> st;
	int a,b;
	string s;
	while(cin >> s) {
		if (s == "+") {
			a=st.top();st.pop();
			b=st.top();st.pop();
			st.push(a+b);
		} else if (s == "-") {
			a=st.top();st.pop();
			b=st.top();st.pop();
			st.push(b-a);
		} else if (s == "*") {
			a=st.top();st.pop();
			b=st.top();st.pop();
			st.push(a*b);
		} else {
			st.push(stoi(s));
		}
	}
	cout << st.top() << endl;
	return 0;
}



Measured memory_bytes: 3140
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::prelude::BufRead;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;


fn main() {
    let n = read::<usize>();
	let mut adj = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let line = read_vector::<usize>();
        let (a, b, c) = (line[0] - 1, line[1] - 1, line[2]);
        adj[a].push((b, c));
        adj[b].push((a, c));
    }
    let cols = dfs(&adj);
    for col in cols.into_iter() {
        println!("{}", col);
    }
}

fn dfs(adj: &[Vec<(usize, usize)>]) -> Vec<usize> {
    let mut cols = vec![0; adj.len()];
    let mut stack = vec![(0, 0)];
    let mut used = vec![false; adj.len()];
    while stack.len() > 0 {
        let (crt, dist) = stack.pop().unwrap();
        if used[crt] {
            continue;
        }
        used[crt] = true;
        if dist % 2 == 1 {
            cols[crt] = 1;
        } 
        for &(nxt, d) in adj[crt].iter() {
            if used[nxt] {
                continue;
            }
            stack.push((nxt, dist + d));
        }
    }
    cols
}

#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err: std::fmt::Debug {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf
        .trim()
        .parse()
        .unwrap();
}

#[allow(dead_code)]
fn read_vector<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect();
}

#[allow(dead_code)]
fn read_matrix<T>() -> Vec<Vec<T>> where T: std::str::FromStr, T::Err: std::fmt::Debug {
    use std::io::prelude::*;
    let stdin = stdin();
    return stdin
        .lock()
        .lines()
        .map(|line| line
            .unwrap()
            .split_whitespace()
            .map(|s| s.parse().unwrap())
            .collect())
        .collect();
}

Measured memory_bytes: 14716
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[100007];
int main(){
    int n;
    cin>>n;
    int ans=0;
    int cnt=0;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        if(a[i]<=a[i-1]&&i>1)
            cnt++;
        else
            cnt=0;
        ans=max(ans,cnt);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 640
H, W, D = [int(_) for _ in input().split()]
A = [[int(_) for _ in input().split()] for i in range(H)]
Q, = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for i in range(Q)]

"""
H, W, D = 300, 300, 1
Q = 1
A = [[j + i * 300 + 1 for j in range(300)] for i in range(300)]
LR = [[0, 300*300-1], [0, 300*300-1], [0, 300*300-1]]
"""

pos = {}
for i, row in enumerate(A):
    for j, x in enumerate(row):
        pos[x] = (i, j)

dt = [0] * (H * W + 1)
for x in range(1, D + 1):
    r = 0
    while 1:
        dt[x] = r
        y = x + D
        if y > H * W:
            break
        p1 = pos[x]
        p2 = pos[y]
        r += abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
        x = y

for l, r in LR:
    print(dt[r] - dt[l])


Measured memory_bytes: 41444
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		int max = 100000001;
		boolean [] x = new boolean[max];
		
		PrimeList(x, max);
		
		Output(x);
	}
	
	private static void PrimeList (boolean x[], int max){
		int i;
		int j;
		double sqrt = Math.sqrt(max);
		
		for (i = 2; i < max; i++){
			x[i] = true;
		}
		
		for (i = 2; i < sqrt; i++){
			if (x[i]){
				for (j = i + i; j < max; j += i){
					x[j] = false;
				}
			}
		}
	}
	
	private static void Output(boolean x[]){
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		int a;
		int count = 0;
		
		while (n > 0){
			a = cin.nextInt();
			if (x[a]){
				count++;
			}
			n--;
		}
		System.out.println(count);
	}
}

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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A + B > C + D){
    cout << "Left" << endl;
  }
  else if(A + B == C + D){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

ll p(ll a,ll n) {
    if (n <= 0)return 1;
    return a * p(a - 1, n - 1) % mod;
}
ll kaijo(ll a) {
    if (a <= 0)return 1;
    return a * kaijo(a - 1) % mod;
}

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

    int n;
    ll c, k;
    cin >> n >> c >> k;
    vector<ll> t(n);
    FOR(i, 0, n)cin >> t[i];

    SORT(t);
    int ans = 1, cnt = 1;
    ll lim = t[0] + k;
    FOR(i, 1, n) {
        if (lim < t[i] || cnt == c) {
            lim = t[i] + k;
            ans++;
            cnt = 1;
        }
        else cnt++;
    }
    cout << ans << "\n";
}

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

using namespace std;
// 0 white, 1 black

#define mkp make_pair
#define pb push_back

typedef long long ll;
const ll modl = 1e9 + 7;

vector<int> gr[100005];
ll dp[100005][2];

ll getForComponent(ll node, int par , int color) {

	if (dp[node][color] != -1) {
		return dp[node][color];
	}

	ll cur = 1ll, one, two;

	for (int child : gr[node]) {

		if (child != par) {
			if (color == 1) {
				cur *= getForComponent(child, node, 0);
			} else {
				one = getForComponent(child, node, 0);
				two = getForComponent(child, node, 1);
				cur   *= (one + two);
			}
		}
		cur = (cur % modl);
	}

	return dp[node][color] = (cur % modl);

}

int main() {

	memset(dp, -1, sizeof dp);

	int n;
	cin >> n;

	for (int i = 0; i <= n; i++) gr[i].clear();
	for (int i = 0; i < n - 1; i++) {
		int s, l;
		cin >> s >> l;
		gr[s].pb(l);
		gr[l].pb(s);
	}

	ll ans = 1;
	ll one = getForComponent(1, -1, 0);
	ll second = getForComponent(1, -1, 1);
	ans = (( ans * ( one + second )) % modl ) ;

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

Measured memory_bytes: 17460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll k,a[55];

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

    cin>>k;

    for(ll i=0;i<50;i++)
        a[i]=i;

    ll d=k/50;
    if(k%50==0)
    {
        for(ll i=0;i<50;i++)
            a[i]+=d;
    }
    else
    {
        for(ll i=0;i<50;i++)
            a[i]+=d;
        k%=50;
        ll p=0;
        while(k)
        {
            k--;
            a[p]+=50;
            for(ll i=0;i<50;i++)
                if(i!=p)
                    a[i]--;
            p++;
        }
    }

    cout<<50<<endl;
    for(ll i=0;i<50;i++)
        cout<<a[i]<<" ";
    cout<<endl;

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
#define INF 1010101010
#define MOD 1000000007
#define LL long long

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> an(n);
    for (auto &e: an) cin >> e;
    
    LL cnt = 0;
    for (int i = 1; i < n; i++) {
        int over = an[i-1] + an[i] - x;
        if (over > 0) {
            cnt += over;
            an[i] = an[i] < over ? 0 : an[i] - over;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,m,ans;
//最大公約数
ll gcd(ll a,ll b){
    
    if(a==0 || b==0)return 0;
    if(a<b){
        ll sw;
        sw=a;
        a=b;
        b=sw;
    }
    
    ll r;
    while((r=a%b)!=0){
        a=b;
        b=r;
    }
    return b;
}
//最小公倍数
ll lcm(ll a,ll b){


    if(a==0 || b==0)return 0;

    return a/gcd(a,b)*b;

}
signed main(){
	cin>>n;
	rep(i,n)rep(j,n)rep(k,n){
		ans+=gcd(i+1,gcd(j+1,k+1));
		//cout<<i+1<<" "<<j+1<<" "<<k+1<<":"<<gcd(i+1,gcd(j+1,n+1))<<endl;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int x = c+d-a-b;
  string ans = x==0 ? "Balanced" : (x>0 ? "Right" : "Left");
  cout << ans << endl;
  return 0;
}

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

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(a>=k){
        cout << k << endl;
    }else if(b>=k-a){
        cout << a << endl;
    }else{
        cout << a -(k-a-b) << endl;
    }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL s;
int main()
{
	scanf("%lld",&s);
	LL a=LL(1e9);
	LL b=min(a,s/a+1);
	LL c=a*b-s;
	printf("0 0 1 %lld %lld %lld",a,b,c);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int t[] = new int[N];
		int x[] = new int[N];
		int y[] = new int[N];
		for(int i = 0; i < N; i++) {
			t[i] = sc.nextInt();
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		
		int now_x = 0;
		int now_y = 0;
		int now_time = 0;
		for(int i = 0; i < N; i++) {
			if((t[i] - now_time) - (Math.abs(x[i] - now_x) + Math.abs(y[i] - now_y)) < 0) {
				System.out.println("No");
				return;
			}
			
			if((Math.abs(x[i] - now_x) + Math.abs(y[i] - now_y)) % 2 != (t[i] - now_time) % 2) {
				System.out.println("No");
				return;
			}
			now_x = x[i];
			now_y = y[i];
			now_time = t[i];
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 90480
//#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

void solve() {
    ll n,m;cin>>n>>m;
    ll sum=0ll;
    ll temp;
    fr(i,1,m){
        cin>>temp;
        sum+=temp;
    }
    if(sum>n)cout<<"-1\n";
    else cout<<n-sum<<endl;
    return ;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
   
    return 0;
}

Measured memory_bytes: 3696
#include <stdio.h>
int main(void){
    int a,b,n,x,i;
    for(;;){
        i=0;
        scanf("%d%d",&n,&x);
        if(n+x==0)break;
        for(a=1;a<=n;a++){
            for(b=a+1;b<=n;b++){
                if(b<x-a-b&&x-a-b<=n)
                i++;
            }
        }printf("%d\n",i);
    }
    return 0;
}



Measured memory_bytes: 2044
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner S = new Scanner(System.in) ;
		int s = S.nextInt();
		System.out.println(s/3600 + ":" + (s%3600)/60 + ":" + (s%3600)%60);
		
	}

}

Measured memory_bytes: 17360
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(final String[] ars) {
    final Scanner scanner = new Scanner(System.in);
    final int N = Integer.parseInt(scanner.next());
    final int M = Integer.parseInt(scanner.next());
    final List<Shop> list = new ArrayList<>();
    for (int i = 0; i < N; i++) {
      list.add(new Shop(Long.parseLong(scanner.next()), Long.parseLong(scanner.next())));
    }
    list.sort(Comparator.comparingLong(e -> e.price));

    long price = 0;
    long count = 0;
    for (final Shop shop : list) {
      if (count + shop.count >= M) {
        price += (M - count) * shop.price;
        break;
      }
      count += shop.count;
      price += shop.count * shop.price;
    }
    System.out.println(price);
  }
}


class Shop {
  Long price;
  Long count;

  public Shop(final Long price, final Long count) {
    this.price = price;
    this.count = count;
  }
}

Measured memory_bytes: 67748
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = list(iss())
    odd = 'RUD'
    even = 'LUD'
    ret = 'Yes'
    for n in range(len(S)):
        if (n + 1) % 2 == 0 and S[n] not in even or (n + 1) % 2 != 0 and S[n] not in odd:
            ret = 'No'
    else:
        print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





string s;
int n;
vector<pair<char, int> > v;

vector<pair<char, int> > runlength(string str) {
    vector<pair<char, int> > ret;
    int cnt = 1;
    int n = sz(str);
    rep3(i, 1, n) {
        if (str[i] == str[i - 1]) {
            cnt++;
        } else {
            ret.eb(make_pair(str[i - 1], cnt));
            cnt = 1;
        }
    }
    ret.eb(make_pair(str[n - 1], cnt));
    return ret;
}





bool check(int x) {
    
    char m = s[x - 1];
    rep3(i, n - x, x - 1) {
        if (s[i] != m) return 0;
    }
    
    return 1;
}

template<typename T>
void binary_search(T ok, T ng) {
    while (abs(ng - ok) > 1) {
        T mid = (ng + ok) / 2;
        // cout << mid << endl;
        (check(mid) ? ok : ng) = mid;
        // cout << ok << " " << ng << endl;
    }
    cout << ok << endl;
}



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    // 二分探索を使おうとしたけどそのあと不可
    // 解説みた
    
    cin >> s;
    n = sz(s);
    // cout << n << endl;
    binary_search(1, n + 1);
    
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        String [] date = s.split("/");
        if (Integer.valueOf(date[1]) > 4) {
            System.out.println("TBD");
        } else {
            System.out.println("Heisei");
        }
    }
}


Measured memory_bytes: 21844
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M

main :: IO ()
main = do
  n <- readLn
  ss <- replicateM n B.getLine
  print $ solve ss

solve :: [B.ByteString] -> Int
solve = (+) <$> sum . map nABSubsters <*> solve' . map shoten

nABSubsters :: B.ByteString -> Int
nABSubsters = length . B.findSubstrings ab
  where ab = B.pack "AB"

shoten :: B.ByteString -> (Char, Char)
shoten s = (h, l)
  where
    h = case B.head s of
      'A' -> 'A'
      'B' -> 'B'
      _   -> 'X'
    l = case B.last s of
      'A' -> 'A'
      'B' -> 'B'
      _   -> 'X'

solve' :: [(Char, Char)] -> Int
solve' = solve'' . count

count :: [(Char, Char)] -> M.Map (Char, Char) Int
count [] = M.fromList
  [ (('A','A'), 0)
  , (('A','B'), 0)
  , (('A','X'), 0)
  , (('B','A'), 0)
  , (('B','B'), 0)
  , (('B','X'), 0)
  , (('X','A'), 0)
  , (('X','B'), 0)
  , (('X','X'), 0)
  ]
count (x:xs) = M.adjust succ x $ count xs

solve'' :: M.Map (Char, Char) Int -> Int
solve'' = go 0 'X'
  where
    go !n 'A' !mp
      | mp M.! ('B', 'A') > 0 = go (n+1) 'A' (M.adjust pred ('B', 'A') mp)
      | mp M.! ('B', 'B') > 0 = go (n+1) 'B' (M.adjust pred ('B', 'B') mp)
      | mp M.! ('B', 'X') > 0 = go (n+1) 'X' (M.adjust pred ('B', 'X') mp)
      | otherwise             = n
    go !n 'B' !mp
      | mp M.! ('X', 'A') > 0 = go n     'A' (M.adjust pred ('X', 'A') mp)
      | mp M.! ('A', 'A') > 0 = go n     'A' (M.adjust pred ('A', 'A') mp)
      | mp M.! ('B', 'A') > 0 = go n     'A' (M.adjust pred ('B', 'A') mp)
      | mp M.! ('X', 'X') > 0 = go n     'X' (M.adjust pred ('X', 'X') mp)
      | mp M.! ('A', 'X') > 0 = go n     'X' (M.adjust pred ('A', 'X') mp)
      | mp M.! ('B', 'X') > 0 = go n     'X' (M.adjust pred ('B', 'X') mp)
      | mp M.! ('X', 'B') > 0 = go n     'B' (M.adjust pred ('X', 'B') mp)
      | mp M.! ('A', 'B') > 0 = go n     'B' (M.adjust pred ('A', 'B') mp)
      | mp M.! ('B', 'B') > 0 = go n     'B' (M.adjust pred ('B', 'B') mp)
      | otherwise             = n
    go !n 'X' !mp
      | mp M.! ('X', 'A') > 0 = go n     'A' (M.adjust pred ('X', 'A') mp)
      | mp M.! ('A', 'A') > 0 = go n     'A' (M.adjust pred ('A', 'A') mp)
      | mp M.! ('B', 'A') > 0 = go n     'A' (M.adjust pred ('B', 'A') mp)
      | mp M.! ('X', 'X') > 0 = go n     'X' (M.adjust pred ('X', 'X') mp)
      | mp M.! ('A', 'X') > 0 = go n     'X' (M.adjust pred ('A', 'X') mp)
      | mp M.! ('B', 'X') > 0 = go n     'X' (M.adjust pred ('B', 'X') mp)
      | mp M.! ('X', 'B') > 0 = go n     'B' (M.adjust pred ('X', 'B') mp)
      | mp M.! ('A', 'B') > 0 = go n     'B' (M.adjust pred ('A', 'B') mp)
      | mp M.! ('B', 'B') > 0 = go n     'B' (M.adjust pred ('B', 'B') mp)
      | otherwise             = n


Measured memory_bytes: 3324
#include <cstdio>
#include <cstring>

int n,t,l,b;
int fie[101];
double dp[102][101];
int main(void){
	while(1){
		scanf("%d %d %d %d",&n,&t,&l,&b);
		if(n+t+l+b==0)break;
		memset(fie,0,sizeof(fie));
		memset(dp,0,sizeof(dp));
		for(int i=0;i<l;i++){
			int a;
			scanf("%d",&a);
			fie[a]=1;
		}
		for(int i=0;i<b;i++){
			int a;
			scanf("%d",&a);
			fie[a]=2;
		}
		dp[0][0]=1.0;
		for(int i=0;i<t;i++){
			for(int j=0;j<n;j++){
				if(dp[i][j]>0.0){
					for(int k=1;k<=6;k++){
						int next=j+k;
						if(next>=n)next=n*2-next;
						if(fie[next]==0)dp[i+1][next]+=dp[i][j]/6.0;
						if(fie[next]==1)dp[i+2][next]+=dp[i][j]/6.0;
						if(fie[next]==2)dp[i+1][0]+=dp[i][j]/6.0;
					}
				}
			}
			dp[i+1][n]+=dp[i][n];
		}
		printf("%.10f\n",dp[t][n]);
	}
	return 0;
}

Measured memory_bytes: 1152
(X, Y, Z, K) = gets.split.map(&:to_i)
data = []
3.times do
  data << gets.split.map(&:to_i).sort!.reverse!
end

ab = data[0].product(data[1]).map do |x, y|
  x + y
end.sort.reverse[0, K]
abc = ab.product(data[2]).map do |e, z|
  e + z
end.sort.reverse[0, K]
p *abc

Measured memory_bytes: 287592
#include <iostream>

struct Card {
    int value;
    char type;
};

void DumpArray(Card *C, int N)
{
    for (int i = 0; i < N; i++) {
        std::cout << C[i].type
                  << C[i].value;
        if (i != N - 1) {
            std::cout << " ";
        }
    }
    std::cout << std::endl;
}

bool IsStable(Card *c_bubble, Card *c_select, int N)
{
    for (int i = 0; i < N; i++) {
        if (c_bubble[i].type != c_select[i].type) {
            return false;
        }
    }
    return true;
}

void BubbleSort(Card *C, int N)
{
    for (int i = 0; i < N; i++) {
        for (int j = N-1; j > i; j--) {
            if (C[j].value < C[j-1].value) {
                Card tmp = C[j];
                C[j] = C[j-1];
                C[j-1] = tmp;
            }
        }
    }
}

void SelectionSort(Card *C, int N)
{
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (C[j].value < C[minj].value) {
                minj = j;
            }
        }
        if (i != minj) {
            Card tmp = C[i];
            C[i] = C[minj];
            C[minj] = tmp;
        }
    }
}

int main(int argc, char* argv[])
{
    int array_size = 0;
    Card array_1[100], array_2[100];

    std::cin >> array_size;
    for (int i = 0; i < array_size; i++) {
        std::cin >> array_1[i].type >> array_1[i].value;
        array_2[i].type = array_1[i].type;
        array_2[i].value = array_1[i].value;
    }


    BubbleSort(array_1, array_size);
    SelectionSort(array_2, array_size);
    
    DumpArray(array_1, array_size);
    std::cout << "Stable" << std::endl;
    
    DumpArray(array_2, array_size);
    if (IsStable(array_1, array_2, array_size)) {
        std::cout << "Stable" << std::endl;
    } else {
        std::cout << "Not stable" << std::endl;
    }
}


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

int N,M;
int a[10][10];
int p[10];
int cnt;
int lit;
int ans=0;

void cntlit(){
  for (int bit = 0; bit < (1<<N); ++bit){       
    lit=0;
    for(int i=0;i<M;i++){
      cnt=0;
      for(int j=0;j<N;j++){
        if((a[i][j]==1)&&(bit & 1<<j)){
          cnt++;
        }
      }     
       if(cnt%2==p[i]){
        lit++;
      }
    } 
    if(lit==M) ans++;   
  }
  return ;
}


int main(){
  cin>>N>>M;
  int k;
  int temp;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      a[i][j]=0;
    }
  }   
  for (int i=0;i<M;i++){
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>temp;
      temp--;
      a[i][temp]=1;
    }
  }

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

  cntlit();
  cout<<ans<<endl;
}

  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,M;
    cin >> N >> M;
    vector<P>AB(N);
    for(int i = 0; i < N; i++) {
        cin >> AB[i].first >> AB[i].second;
    }
    sort(AB.begin(),AB.end());
    int ans = 0;
    int cnt = 0;
    while(M) {
        if(M >= AB[cnt].second) {
            M-=AB[cnt].second;
            ans+=AB[cnt].first*AB[cnt].second;
            cnt++;
        }
        else {
            ans+=AB[cnt].first*M;
            M = 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4844
#include<cstdio>
#include<iostream>
#include<map>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
ll maze[200][200];
ll dp[200][200]={0};
char s[200];
int main()
{
	ll h,w;
	scanf("%lld%lld",&h,&w);
	for(ll i=0;i<h;i++)
	{
		scanf("%s",s);
		for(ll j=0;j<w;j++)
		{
			if(s[j]=='.')maze[i][j]=0;
			else maze[i][j]=1;
		}
	}
	if(maze[0][0]==1) dp[0][0]=1;
	for(ll i=1;i<w;i++)
	{
		if(maze[0][i-1]==0&&maze[0][i]==1)
		{
			dp[0][i]=dp[0][i-1]+1;
		}
		else
		{
			dp[0][i]=dp[0][i-1];
		}
	}
	for(ll i=1;i<h;i++)
	{
		if(maze[i-1][0]==0&&maze[i][0]==1)
		{
			dp[i][0]=dp[i-1][0]+1;
		}
		else
		{
			dp[i][0]=dp[i-1][0];
		}
	}
	for(ll i=1;i<h;i++)
	{
		for(ll j=1;j<w;j++)
		{
			ll ma=1000000;
			if(maze[i][j]==0)
			{
				ma=min(dp[i][j-1],dp[i-1][j]);
			}
			else
			{
				if(maze[i][j-1]==0)
				{
					ma=min(ma,dp[i][j-1]+1);
				}
				else
				{
					ma=min(ma,dp[i][j-1]);
				}
				if(maze[i-1][j]==0)
				{
					ma=min(ma,dp[i-1][j]+1);
				}
				else
				{
					ma=min(ma,dp[i-1][j]);
				}
			}
			dp[i][j]=ma;
		}
	}
	printf("%lld",dp[h-1][w-1]);
}

Measured memory_bytes: 512
import java.util.Scanner;

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

    int N = 26;
    int D = scanner.nextInt();
    int[] c = new int[N];
    int[][] s = new int[D][N];
    for (int i = 0; i < N; i++) c[i] = scanner.nextInt();
    for (int i = 0; i < D; i++) for (int j = 0; j < N; j++) s[i][j] = scanner.nextInt();

    int[] t = new int[D];
    for (int i = 0; i < D; i++) t[i] = scanner.nextInt() - 1;

    int v = 0;
    int[] last = new int[N];
    for (int d = 0; d < D; d++) {
      int type = t[d];
      v += s[d][type];
      last[type] = d + 1;
      for (int i = 0; i < N; i++) v -= c[i] * (d + 1 - last[i]);
      System.out.println(v);
    }
  }
}


Measured memory_bytes: 38100
#include <iostream>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

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

  int res = 0;
  REP(i, N) {
    int a;
    cin >> a;
    while (a % 2 == 0) {
      a /= 2;
      ++res;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


string S;


int solve(){
	int N = SIZE(S);
	int ans = N/2;
	int l = N%2 ? N/2 : N/2-1, r = N/2;
	char c = S[l];
	while(0 <= l){
		if(S[l] != c || S[r] != c) break;
		ans++;
		l--, r++;
	}
	return ans;
}


signed main(){
	cin >> S;

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 512
H,W=map(int,input().split())
A=[]
for i in range(H):
	A.append(input())

while "."*W in A:
	A.remove("."*W)

H=len(A)
B=[[] for _ in range(H)]
X=[[] for i in range(W)]

for i in range(W):
	for j in range(H):
		X[i].append(A[j][i])

while ["." for p in range(H)] in X:
	X.remove(["." for c in range(H)])

W=len(X)
for i in range(H):
	for j in range(W):
		B[i].append(X[j][i])

for i in range(H):
  print("".join(B[i]))
  

Measured memory_bytes: 3188
#include<stdio.h>
#define MAX 500001
#define NIL -100
struct Node{
  int key;
  int p;
  int l;
  int r;
};
struct Node A[MAX];
void buildMaxHeap(struct Node *);
void maxHeapify(struct Node *,int);
int n;

int main(){
  int i,x;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].p=NIL;
    A[i].l=NIL;
    A[i].r=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d",&A[i].key);
    if(i!=0){
      if(i%2==1)
	A[i].p=A[i/2].key;
      else A[i].p=A[i/2-1].key;
    }
  }
  for(i=0;i<=n/2;i++){
    if((2*i+2)<n)A[i].r=A[2*i+2].key;
    if((2*i+1)<n)A[i].l=A[2*i+1].key;
  }
  buildMaxHeap(A);
  for(i=0;i<n;i++){
    printf(" %d",A[i].key);
  }
  printf("\n");
  return 0;
}
void buildMaxHeap(struct Node *A){
  int i;
  for (i=n/2-1;i>=0;i--)
    maxHeapify(A, i);
}
void maxHeapify(struct Node *A,int i){
  int largest;
  struct Node T;
  if( i*2+1 < n && A[i*2+1].key > A[i].key){
    largest = i*2+1;
  }
  else largest = i;
  if(i*2+2 < n && A[i*2+2].key > A[largest].key)
    largest = i*2+2;
  if (largest != i){
    T.key=A[i].key;
    A[i].key=A[largest].key;
    A[largest].key=T.key;
    maxHeapify(A, largest);
  }
}

Measured memory_bytes: 8412
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	
	int N,K;
	vector<int> arr;
	cin>>N>>K;
	arr.resize(N);
	REP(i,N){
		cin>>arr[i];
	}

	int min_number = INF;
	int min_i = -1;
	REP(i,N){

		if(min_number > arr[i]){
			min_number = arr[i];
			min_i = i;
		}
	}

	int ans = (arr.size()-1) / (K - 1) + ( ((arr.size()-1) % (K - 1)  == 0) ? 0 : 1);

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



Measured memory_bytes: 640
fun main() {
    val (n,s) = readLine()!!.split(" ").map { it.toInt() }
    val mod = 998244353L
    val arr = readLine()!!.split(" ").map { it.toInt() }
    val inf = Long.MIN_VALUE
    val dp = Array(2){LongArray(s+1){0} }

    var cur = 0
    var next = 1

    dp[cur][0] = 1L
    dp[next][0] = 1L

    // f(t) is the number of different non-empty subsets
    // dp[cur][x] = sum of f(x), 부분 집합의 총 합이 x 인 것들의 갯수.

    // f(x, s) 는 주어진 원소 집합 x 의 모든 부분 집합들에 대해서, 그 부분 집합들의 총합이 s 가 되는 것들의 갯수.
    // 목표는 모든 원소들의 집합 형태인 f(x,s) 의 합.
    // dp[idx][x]
    // 원소 idx 까지의 집합 형태를 고려했을때, f(idx, x) 의 합. => sum ( f(idx), x )
    //  sum (f(idx, x))  = sum( f(idx - 1, x) ) * 2 : 합이 x 가 되는 idx - 1 까지 고려한 set 과 idx 까지 고려한 set 에서, idx 를 포함하지 않는 경우
    //                     sum( f(idx - 1, x - a[idx]



    for(i in 0 until n) {
        val c = arr[i]
//        for(j in 1..s) {
//            dp[next][j] = 0
//        }
        for(j in 0..s) {
            dp[next][j] = (dp[cur][j] * 2L) % mod
        }
        for(j in 1..s) {
            if(j < c) continue
            dp[next][j] += dp[cur][j-c]
            dp[next][j] %= mod
        }
        cur = next
        next = (next + 1) % 2
    }
    print(dp[cur][s])
}

Measured memory_bytes: 38972
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  string S; int K; cin>>S>>K;

  set<string> words;
  for(int i = 0; i < (int)S.size(); i++) {
    for(int sub = 1; sub <= K; sub++) {
      string s = S.substr(i, sub);
      words.insert(s);
    }
  }

  auto itr = words.begin();
  for(int i = 0; i < K - 1; i++) {
    itr++;
  }

  cout << *itr << endl;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x>=10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int k,int mod){
	int res=1,bas=x;
	while(k){
		if(k&1) res=1ll*res*bas%mod;
		bas=1ll*bas*bas%mod,k>>=1;
	}
	return res;
}
ll r,D,x;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(r),read(D),read(x);
	for(ri i=1;i<=10;++i)
		x=x*r-D,print(x),puts("");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    string S;
    cin >> S;

    int h = S.size()/2,x;
    if(S.size()%2==1){
        x=1;
    }else{
        x=0;
    }
    string Sx = S;
    reverse(Sx.begin(),Sx.end());
    
    if(S==Sx){
        string S1 = S.substr(0,h);
        string S1x = S1;
        reverse(S1x.begin(),S1x.end());
        if(S1==S1x){
            string S2 = S.substr(h+x,h);
            string S2x = S2;
            reverse(S2x.begin(),S2x.end());
            if(S2==S2x){
                cout<<"Yes"<<endl;
            }else{
                cout<<"No"<<endl;
            }
        }else{
            cout<<"No"<<endl;
        }
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n, pm, pe, pj;
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      cin >> pm >> pe >> pj;
      if ((pm == 100 or pe == 100 or pj == 100) or (pm + pe >= 180)
          or (pm + pe + pj >= 240)) {
        cout << "A" << endl;
      } else if ((pm + pe + pj >= 210)
          or (pm + pe + pj >= 150 and (pm >= 80 or pe >= 80))) {
        cout << "B" << endl;
      } else {
        cout << "C" << endl;
      }
    }
  }
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
long gcd(long a,long b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
int main(){
  long a,b;
  cin >> a >> b;
  cout << a*b/gcd(max(a,b),min(a,b));
}


Measured memory_bytes: 256