akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let p = read::<i64>();
    let mut edges = vec![(0, 0, 0); m];
    for i in 0..m {
        let a = read::<usize>() - 1;
        let b = read::<usize>() - 1;
        let c = read::<i64>();
        edges[i] = (a, b, c);
    }
    let mut ans = 0;
    let mut bests = vec![-1 * (1 << 50); n];
    let mut coins = vec![-1 * (1 << 50); n];
    let mut ngs = vec![false; n];
    coins[0] = 0;
    for i in 0..3 * n {
        let mut ncoins = vec![-1 * (1 << 50); n];
        for j in 0..m {
            let from = edges[j].0;
            let to = edges[j].1;
            let coin = edges[j].2;
            if coins[from] == -1 * (1 << 50) {
                continue;
            }
            ncoins[to] = std::cmp::max(ncoins[to], coins[from] + coin);
            ngs[to] |= ngs[from];
        }
        for j in 0..n {
            if ncoins[j] == -1 * (1 << 50) {
                continue;
            }
            let nbest = ncoins[j] - p * (i as i64 + 1);
            if i >= n && bests[j] < nbest {
                ngs[j] = true;
            }
            bests[j] = std::cmp::max(bests[j], nbest);
        }
        let nans = ncoins[n - 1] - p * (i as i64 + 1);
        ans = std::cmp::max(ans, nans);
        coins = ncoins;
    }
    if ngs[n - 1] {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 4476
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

signed main(){
    ll n;
    ll s=0,ss=0,ans;
    ll d[109];
    cin>>n;
    rep(i,n){
        cin>>d[i];
        s += d[i];
        ss += d[i]*d[i];
    }
    ans = (s*s -ss)/2;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;

int N;
ll A[100000], B[100000], C[100000];

ll memoB[100000],memoC[100000];
ll ans = 0;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++)cin >> B[i];
	for (int i = 0; i < N; i++)cin >> C[i];

	for (int i = 0; i < N; i++) memoC[i] = -1;

	sort(A ,A + N), sort(B, B + N), sort(C, C + N);

	ll bef = 0, tmp = 0;

	for (int j = 0; j < N; j++) {
		memoC[j] = (C + N - lower_bound(C, C + N, B[j] + 1));
		tmp += memoC[j];
	}

	for (int i = 0; i < N; i++) {
		int naka = (lower_bound(B, B + N, A[i] + 1) - B);

		for (int j = bef; j < naka; j++) {
			//memoC[j] = (C + N - lower_bound(C, C + N, B[j] + 1));
			tmp -= memoC[j];
		}
		ans += tmp;
		//cout << ans << "A" << tmp << endl;

		bef = naka;

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

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>
#include <ctime>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SZ = 2010, INF = 1e9 * 1e9;

ll n;
vector<ll> vec;

map<tuple<ll, ll, ll, ll>, ll> mp;
ll ans(ll ind1, ll x1, ll ind2, ll x2) {
	if (mp.find({ ind1, x1, ind2, x2 }) != mp.end()) {
		return mp[{ ind1, x1, ind2, x2 }];
	}

	if (ind1 == ind2 - 1) {
		return 0;
	}

	ll cur = INF;
	for (int i = ind1 + 1; i <= ind2 - 1; i++) {
		cur = min(cur, ans(ind1, x1, i, x1 + x2) + ans(i, x1 + x2, ind2, x2) + (x1 + x2) * vec[i]);
	}

	mp[{ ind1, x1, ind2, x2 }] = cur;
	return cur;
}

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

	vec.resize(n);

	for (auto &cur : vec) cin >> cur;

	cout << ans(0, 1, n - 1, 1) + vec[0] + vec.back();

	return 0;
}

Measured memory_bytes: 24032
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

int main(void){
  string S;
  cin >> S;
  int i;
  map<string,int> m;
  m["A"] = 1;
  m["T"] = 1;
  m["C"] = 1;
  m["G"] = 1;
  int max=0,num=0;
  REP(i,S.length()){
    if(m.count(S.substr(i,1))){
      num++;
      if(max<num) max=num;
    }else{
      num = 0;
    }
  }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PL;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
int main(void) {
    ll i, j, k;
    
    ll N, C;
    cin >> N >> C;
    ll x[MAX], v[MAX];
    ll s[MAX]={}, t[MAX]={};
    
    x[0]=0; v[0]=0;
    x[N+1]=C; v[N+1]=0;
    for(i=1; i<=N; i++) cin >> x[i] >> v[i];
    for(i=1; i<=N; i++) s[i]=s[i-1]+v[i];
    for(i=N; i>=1; i--) t[i]=t[i+1]+v[i];
    
    ll ans=0;
    ll m=0, mm=0;
    for(i=0; i<=N; i++) {
        chmax(m, s[i]-x[i]);
        chmax(mm, s[i]-x[i]*2);
        
        chmax(ans, m+t[i+1]-(C-x[i+1])*2); //OA+OB*2
        chmax(ans, mm+t[i+1]-(C-x[i+1])); //OA*2+OB
    }
    
    pt(ans);
}


Measured memory_bytes: 3456
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////
char s[4010];
int main(){
    int n;
    cin >> n;
    long long r = 0, g = 0, b = 0;
    for (int i = 1;i <= n;i++){
        cin >> s[i];
        if (s[i] == 'R') r++;
        else if (s[i] == 'G') g++;
        else b++;
    }

    ll ans = r*g*b;

    for (int i = 1;i <= n;i++){
        for (int j = i + 1;j <= n;j++){
            if (s[i] != s[j]){
                int k = j + j - i;
                if (k > n) continue;
                if (s[i] != s[k] && s[j] != s[k]){
                    ans--;
                }
            }
        }   
    }

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


Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int input()
{
    int x = 0;
    char c;
    bool minus = false;
    for (;;)
    {
        c = getchar();
        if (c == '-')
        {
            minus = true;
            continue;
        }
        if (c == ' ' || c == '\n')
            if (minus)
                return -x;
            else
                return x;
        x = 10 * x + c - '0';
    }
}
void fix()
{
    char c;
    for (;;)
    {
        c = getchar();
        if (c == -1 || c != ' ' && c != '\n')
            break;
    }
    if (c != -1)
        ungetc(c, stdin);
}
int main()
{
    int N, i, j, k, d;
    int a[6];
    int m[32];
    int M[32];
    for (i = 0; i < 32; i++)
    {
        m[i] = 1000000000;
        M[i] = -1000000000;
    }
    d = 2;
    scanf("%d", &N);
    fix();
    for (i = 0; i < N; i++)
    {
        for (j = 0; j < d; j++)
            a[j] = input(); //,fix();
        for (j = 0; j < 1 << (d - 1); j++)
        {
            int x = a[0];
            for (k = 0; k < d - 1; k++)
                if (j & (1 << k))
                    x += a[k + 1];
                else
                    x -= a[k + 1];
            if (m[j] > x)
                m[j] = x;
            if (M[j] < x)
                M[j] = x;
        }
    }
    int ans = 0;
    for (i = 0; i < 1 << (d - 1); i++)
        if (ans < M[i] - m[i])
            ans = M[i] - m[i];
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

int main(){
    char c ;
    cin >> c ;
    string s = "abcdefghijklmnopqrstuvwxyz" ;
    for (size_t i = 0; i < s.size()-1; i++)
    {
        if (c == s.at(i))
        {
            cout << s.at(i+1) << endl ;
            break ;
        }

    }
}

Measured memory_bytes: 256
H,W = map(int,input().split())
A = []
dame = ["."]*W
for i in range(H):
  temp = str(input())
  temp = list(temp)
  if temp != dame:
    A.append(temp)
#print(A)
S = len(A)
ans = [[] for _ in range(S)]
for j in range(W):
  if all([A[i][j] == "." for i in range(S)]):
    continue
  for t in range(S):
    ans[t].append(A[t][j])
#print(ans)
for i in range(len(ans)):
  temp = "".join(ans[i])
  print(temp)
    

Measured memory_bytes: 67604
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


void solve(long long N, long long T, long long A, std::vector<long long> H){
	int res = -1;
	double a = 1000000000;

	for(int i = 0; i < N; ++i) {
		double t = abs(A - (T - H[i] * 0.006));
		if (t < a) {
			a = t;
			res = i;
		}
	}
	cout << res + 1 << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    long long T;
    scanf("%lld",&T);
    long long A;
    scanf("%lld",&A);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, T, A, std::move(H));
    return 0;
}


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

int main()
{
    int k,ans=1;
    cin>>k;
    long long x=7%k;
    for(int i=1;i<=k;i++)
    {
        if(x==0)
        {
            cout<<ans<<endl;
            return 0;
        }
        else
        {
            ans++;
            x=x*10+7;
            x%=k;
        }
    }
    cout<<-1<<endl;
    return 0;
}


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

int gcd(int a,int b){
  if(b<a)
    swap(a,b);
  int r = b % a;
  while(r!=0){
  b = a;
  a = r;
  r = b % a;
  }
  return a;
}
int main(){
  int N,ans;
  cin >> N;
  int a[N];
  for(int i=0;i<N;i++)
    cin >> a[i];
  int gcdleft[N];
  int gcdright[N];
  gcdleft[0]=a[0];
  gcdright[0]=a[N-1];
  for(int k=0;k<N-1;k++){
    gcdleft[k+1]=gcd(a[k+1],gcdleft[k]);
    gcdright[k+1]=gcd(a[N-2-k],gcdright[k]);
  }
  ans =  gcdleft[N-2];
  for(int j=1;j<N-1;j++)
    ans = max(ans,gcd(gcdleft[j-1],gcdright[N-j-2]));
  ans = max(ans,gcdright[N-2]);
  cout << ans << endl;
}


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

int main(){
    vector<int> pos(5);
    int k;
    for (int i =0; i < 5;i++){
        cin >> pos[i];
    }
    cin >> k ;
    for (int i = 0; i<5 ;i++){
            if( (pos[4]-pos[i]) > k ){
                cout << ":(" << endl;
                return 0;
        }
    }   
    cout << "Yay!" << endl;
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W,D;
pint co[111111];
inline int dist(pint &a,pint &b){
    return abs(a.fi-b.fi)+abs(a.se-b.se);
}

int latte[111111];

signed main(){
    cin>>H>>W>>D;
    rep(i,H)rep(j,W){
        int a;cin>>a;
        a--;
        co[a]={i,j};
    }

    rep(i,H*W){
        if(i<D)continue;
        latte[i]=latte[i-D]+dist(co[i-D],co[i]);
    }

    int Q;cin>>Q;
    while(Q--){
        int l,r;
        cin>>l>>r;
        l--;r--;
        cout<<latte[r]-latte[l]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include<stdio.h>
int main()
{
  int a,b,c,tmp;

  scanf("%d%d%d",&a,&b,&c);

  if(a>b){
    tmp = a;
    a = b;
    b = tmp;
  }
  if(b>c){
    tmp = b;
    b = c;
    c = tmp;
  }
  if(a>b){
    tmp = a;
    a = b;
    b = tmp;
  }

  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,a[100005],b[100005],c[100005],ans=0,bans[100005]{};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    int mi,ma,mid;
    for(int j=0;j<n;j++){
        mi=0;
        ma=n-1;
        while(mi<=ma){
            mid=(mi+ma)/2;
            if(c[mid]>b[j]){
                ma=mid-1;
            }
            else{
                mi=mid+1;
            }
        }
        bans[j]=n-mi;
    }
    for(int j=n-2;j>=0;j--){
        bans[j]+=bans[j+1];
    }
    for(int i=0;i<n;i++){
        int sum1=0,sum2=0;
        mi=0;
        ma=n-1;
        while(mi<=ma){
            mid=(mi+ma)/2;
            if(b[mid]>a[i]){
                ma=mid-1;
            }
            else{
                mi=mid+1;
            }
        }
        sum1=mi;
        if(mi>=n || mi<0)
            continue;
        ans+=bans[mi];
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 6720
def com(x,y):
    buns = 1
    bunb = 1
    for i in range(y):
        buns = buns * (x-i)
        bunb = bunb * (i+1)
    d = buns // bunb
    return d

n , p = map(int,input().split())
a = list(map(int,input().split()))
kisu = 0
gusu = 0
for i in a:
    if i % 2 == 0:
        gusu += 1
    if i % 2 == 1:
        kisu += 1

kar = 0
if p == 0:
    for i in range(0,kisu+1,2):
        kar += com(kisu,i)
    print(2**gusu * kar)
elif p == 1:
    for i in range(1,kisu+1,2):
        kar += com(kisu,i)
    print(2**gusu * kar)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = sc.nextInt();
		int[][] mat = new int[m][n];
		int[] vec = new int[n];
		for(int i = 0; i < m; i++){
			for(int k = 0; k < n; k++){
				mat[i][k] = sc.nextInt();
			}
		}
		for(int i = 0; i < n; i++){
			vec[i] = sc.nextInt();
		}
		for(int i = 0; i < m; i++){
			int c = 0;
			for(int k = 0; k < n; k++){
				c += mat[i][k] * vec[k];
			}
			System.out.println(c);
		}
	}
}



Measured memory_bytes: 40036
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let K = read!(usize);

    let mut x = 1;
    for _ in 0..N {
        x = min(x * 2, x + K);
    }
    println!("{}", x)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
#define RREP2(i, a, b) for (int i = (a); i > (int)(b); i--)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long ll;

ll Main(ll &n)
{
    ll sq = sqrt(n);
    ll a = 0;
    ll b = 0;
    for (ll i = sq; i > 0; i--)
    {
        if(n % i == 0)
        {
            a = n / i;
            break;
        }
    }
    b = n / a;
    return a + b - 2;
}

int main(void){
    ll N;
    cin >> N;
    cout << Main(N) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vi s,t,c;
vvi g;

int main(){
	cin>>n>>m;
	s=t=c=vi(m);
	g=vvi(n,vi(n,inf));
	for(int i=0;i<n;i++) g[i][i]=0;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v>>c[i];
		s[i]=--u;t[i]=--v;
		g[u][v]=g[v][u]=c[i];
	}
	for(int k=0;k<n;k++) for(int i=0;i<n;i++) for(int j=0;j<n;j++) g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
	int res=0;
	for(int i=0;i<m;i++){
		int B=1;
		for(int j=0;j<n;j++) for(int k=0;k<n;k++) if(g[j][k]==g[j][s[i]]+g[t[i]][k]+c[i]||g[j][k]==g[j][t[i]]+g[s[i]][k]+c[i]) B=0;
		res+=B;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;

int main(){
    ll a,b,c,d,e,k,l,m,n,o=0,p,q,x,y,z,max1=0,ans=0,min1=11;
    string s,t,u;
    cin>>a>>b>>c>>d>>e;
    if((a-1)%10<min1)min1=(a-1)%10;
    if((b-1)%10<min1)min1=(b-1)%10;
    if((c-1)%10<min1)min1=(c-1)%10;
    if((d-1)%10<min1)min1=(d-1)%10;
    if((e-1)%10<min1)min1=(e-1)%10;
    ans+=((a-1)/10+1)*10;
    ans+=((b-1)/10+1)*10;
    ans+=((c-1)/10+1)*10;
    ans+=((d-1)/10+1)*10;
    ans+=((e-1)/10+1)*10;
    cout<<ans-9+min1<<endl;
}




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

ans = 'Yes'
H[0] -= 1
for i in range(len(H) - 1):
    if H[i] < H[i+1]:
        H[i+1] -= 1
    elif H[i] > H[i+1]:
        ans = 'No'
print(ans)


Measured memory_bytes: 14524
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=get_nsp
A="CODEFESTIVAL2016".split("")
ans=0
S.each_with_index do|s,i|
    ans+=1 if s!=A[i]
end
puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){
  int N, K; cin >> N >> K;
  vector <ll> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  vector <ll> all;
  for (int i = 0; i < N; i++){
    ll sum = 0;
    for (int j = i; j < N; j++){
      sum += A[j];
      all.push_back(sum);
    }
  }
  sort(all.begin(), all.end(), greater<ll>());

  ll num = all[0]; int cnt = 0;
  while (num > 0){
    num = num / 2;
    cnt++;
  }

  ll ans = 0;
  vector <ll> now = all;
  for (int i = cnt - 1; i >= 0; i--){
    ll L = pow(2, i);
    vector <ll> next;
    for (int j = 0; j < now.size(); j++){
      if (now[j] >= L){
        now[j] -= L;
        next.push_back(now[j]);
      }
    }
    
    if (next.size() >= K){
      now = next; ans += L;
    }
  }
  cout << ans << endl;


  return 0;
}

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;



int main()
{    
    int N;
	scanf("%d",&N);
    //cin >> N;
    int M=N;
    int f=0;
    for(int i=0;i<8;i++){
      f+=N%10;
      N/=10;
    }  
    if(M%f==0)cout<<"Yes"<<endl;
    else cout << "No" << endl; 
    
  
}  

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c, ans int
	fmt.Scan(&a, &b, &c)
	if a == b {
		ans = c
	} else if a == c {
		ans = b
	} else {
		ans = a
	}
	fmt.Println(ans)
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m, q;
string s[2000];

int c[2002][2002];
int v[2002][2002];
int h[2002][2002];

int main() {
	cin >> n >> m >> q;
	inc(i, n) { cin >> s[i]; }
	
	inc(i, n) {
	inc(j, m) {
		c[i + 1][j + 1] = s[i][j] - '0';
		v[i + 1][j + 2] = (j + 1 < m && s[i][j] == '1' && s[i][j + 1] == '1');
		h[i + 2][j + 1] = (i + 1 < n && s[i][j] == '1' && s[i + 1][j] == '1');
	}
	}
	
	inc(i, n) {
	inc1(j, m) {
		c[i + 1][j] += c[i][j];
		v[i + 1][j] += v[i][j];
		h[i + 1][j] += h[i][j];
	}
	}
	inc1(i, n) {
	inc(j, m) {
		c[i][j + 1] += c[i][j];
		v[i][j + 1] += v[i][j];
		h[i][j + 1] += h[i][j];
	}
	}
	
	inc(qq, q) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		
		x1--;
		y1--;
		int C = (c[x2][y2] + c[x1][y1] - c[x1][y2] - c[x2][y1]);
		int V = (v[x2][y2] + v[x1][y1 + 1] - v[x1][y2] - v[x2][y1 + 1]);
		int H = (h[x2][y2] + h[x1 + 1][y1] - h[x1 + 1][y2] - h[x2][y1]);
		
		cout << (C - V - H) << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 52864
from math import ceil
n,h = map(int,input().split())
k = [list(map(int,input().split())) for i in range(n)]
a,b = [list(i) for i in zip(*k)]
b.sort(reverse=True)
a = max(a)
ans = 0
for i in b:
    if i > a:
        ans += 1
        h -= i
        if h <= 0:
            print(ans)
            exit(0)
    else:
        break
print(ans + ceil(h / a))

Measured memory_bytes: 35704
/*
    Author  :Ninnin
    School  :KVIS
    Language:CPP
    Problem :Runnning median
*/
#include "bits/stdc++.h"
#define MAXN 200020
using namespace std;
int dp[MAXN],input[MAXN];
int lendif(int a,int b){
	if(a>b) return a-b;
	return b-a;
}
int main()
{
	int N,med1,med2;
	scanf("%d",&N);
    for(int i=0;i<N;i++){
		scanf("%d",&input[i]);
		dp[i]=input[i];
	}
	sort(dp,dp+N);
	med1=dp[N/2];
	med2=dp[(N/2)-1];
	//for(int i=0;i<N;i++)	printf("%d %d\n",dp[i],i);
	for(int i=0;i<N;i++){
		int len1=lendif(med1,input[i]),len2=lendif(med2,input[i]);
		if(len1>len2){
			printf("%d\n",med1);
		}else{
			printf("%d\n",med2);
		}
	}
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int a,b;
  string s;
  cin >> a >> b >> s;
  rep(i, a){
    if(int(s[i] - '0') < 0 || int(s[i] - '0') > 9){
      cout << "No" << endl;
      return 0;
    }
  }
  if(s[a] != '-'){
    cout << "No" << endl;
    return 0;
  }
  rep(i, b){
    if(int(s[i + a + 1] - '0') < 0 || int(s[i + a + 1] - '0') > 9){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  vector<int> l(n);
  for (auto &e : l)
    cin >> e;

  for (int i = 0; i < n; ++i)
  {
    int sum = 0;
    for (int j = 0; j < n; ++j)
    {
      if (i == j)
        continue;
      sum += l[j];
    }
    if (l[i] >= sum)
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define MOD 1000000007
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int num_nodes,num_edges,dp[MAXN],res;
vector<int> connections[MAXN];

int solve(int node){
    if(dp[node] != -1) return dp[node];
    int ans = 0;
    for(int check:connections[node]){
        int nxt = solve(check);
        ans = max(ans,nxt+1);
    }
    return dp[node] = ans;
}

int main(){
    scanf("%d %d",&num_nodes,&num_edges);
    for(int i=1; i<=num_edges; i++){
        int a,b; scanf(" %d %d",&a,&b);
        connections[a].pb(b);
    }
    memset(dp,-1,sizeof dp);
    for(int i=1; i<=num_nodes; i++)
        res = max(res,solve(i));
    printf("%d\n",res);
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

map<int, int> M;

int main() {
	int N; cin >> N;
	vi a(N);
 
	bool allzero = true;
	bool zero = false;
 
	rep(i, N) {
		cin >> a[i];
		++M[a[i]];
 
		if (a[i] != 0) {
			allzero = false;
		} else {
			zero = true;
		}
	}
 
	bool ok = false;
 
	if (allzero) {
		puts("Yes");
		return 0;
	}
 
	if (N % 3 == 0) {
		int num = N / 3;
 
		if (zero) {
			int x = -1;
			rep(i, N) {
				if (a[i] != 0) {
					x = a[i];
				}
			}
			if (M[x] == num * 2 && M[0] == num) {
				ok = true;
			}
		} else {
			for (int i = 1; i < N; ++i) {
				if (a[i] != a[0]) {
					int x = a[0], y = a[i], z = x ^ y;
					if (M.count(z)) {
						if (M[x] == num && M[y] == num && M[z] == num) {
							ok = true;
						}
					}
				}
			}
		}
	}
 
	puts(ok ? "Yes" : "No");
 
	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int> vt(N,0);
    for(int i=0;i<N;i++){
        cin>>vt[i];
    }
    if(vt[0]>0){
        vt[0]--;
    }
    for(int i=1;i<N;i++){
        if(vt[i]>vt[i-1]){
            vt[i]--;
        }else if(vt[i]<vt[i-1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  ll N; cin >> N;
  ll L; cin >> L;
  ll m = 0;
  for (ll j=0; j < N; ++j) {
    m += j+L;
  }
  ll mm = 1000000000;
  ll x = -10000000;
  for (ll j=0; j < N; ++j) {
    if (mm > abs(m-(m-j-L))) {
      mm = abs(m-(m-j-L));
      x = j+L;
    }
  }
  cout << (m-x) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

////////////////////////////////////////
const int DAT_SIZE=(1<<20)-1;//調節！！！！！！！！！！！！！！
//セグメント木(0-indexed)！！！！！
ll data[DAT_SIZE],datb[DAT_SIZE];
//[a,b)にxを加算する kは節点の番号で区間[l,r)に対応
void add(int a,int b,int x,int k,int l,int r){
    if(a<=l&&r<=b){
        data[k]+=x;
    }else if(l<b&&a<r){
        datb[k]+=(min(b,r)-max(a,l))*x;
        add(a,b,x,k*2+1,l,(l+r)/2);
        add(a,b,x,k*2+2,(l+r)/2,r);
    }
}
//[a,b)の和を計算する kは節点の番号で区間[l,r)に対応
ll sum(int a,int b,int k,int l,int r){
    if(b<=l||r<=a){
        return 0;
    }else if(a<=l&&r<=b){
        return data[k]*(r-l)+datb[k];
    }else{
        ll res=(min(b,r)-max(a,l))*data[k];
        res+=sum(a,b,k*2+1,l,(l+r)/2);
        res+=sum(a,b,k*2+2,(l+r)/2,r);
        return res;
    }
}
/////////////////////////////////////////////////////////
//ex aにxを加算:add(a,a+1,x,0,0,n);

struct sec{
    int l;
    int r;
    int dis;
};
bool comp(sec a,sec b){
    if(a.dis<b.dis)return true;
    else return false;
}

int main(){
    int n,m;cin>>n>>m;
    sec s[n];
    rep(i,0,n-1){
        cin>>s[i].l>>s[i].r;
        s[i].dis=s[i].r-s[i].l+1;
    }
    sort(s,s+n,comp);
    int ans[m+1];
    int pos=0;
    
    rep(i,1,m){
        while(pos<=n-1&&s[pos].dis<i){
            add(s[pos].l,s[pos].r+1,1,0,0,m+1);
            pos++;
        }
        ans[i]=n-pos;
        for(int j=1;j*i<=m;j++){
            ans[i]+=sum(j*i,j*i+1,0,0,m+1);
        }
        cout<<ans[i]<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 9984
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;


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


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

int main () {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int count = 0;
  
  for (int i = 0; i < a +1 ; i++) {
    for (int j = 0; j < b +1 ; j++) {
      for (int k = 0; k < c + 1; k++) {
        if ((500 * i + 100 * j + 50 * k) == x) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
n, m, q = map(int, input().split())
queries = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    queries.append([a-1, b-1, c, d])

patterns = []

todo = ['0']
while todo:
    num = todo.pop()
    if len(num) == n:
        patterns.append(num)
        continue

    last = int(num[-1])
    for new_num in range(last, m):
        new = num + str(new_num)
        todo.append(new)

candidates = []
for pattern in patterns:
    res = 0
    for a, b, c, d in queries:
        if int(pattern[b]) - int(pattern[a]) == c:
            res += d

    candidates.append(res)

print(max(candidates))


Measured memory_bytes: 14368
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

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

fn maxu(a: usize, b: usize) -> usize {
    if a > b {
        a
    } else {
        b
    }
}

fn main() {
    input! {
        n: usize,
        a: usize,
        xs: [usize; n],
    }
    /*
    let n = 4;
    let a = 8;
    let mut xs = vec![4, 9, 8, 9];
    */

    let max =  xs.iter().max().unwrap();
    let max = maxu(*max, a);

    let mut dp = vec![vec![vec![0; n*max+1]; n+1]; n+1];

    for j in 0..n+1 {
        for k in 0..n+1 {
            for s in 0..n*max+1 {
                if j == 0 && k == 0 && s == 0 {
                    dp[j][k][s] = 1;
                } else if j >= 1 &&  s < xs[(j as i64 -1) as usize] {
                    dp[j][k][s] = dp[j-1][k][s];
                } else if j >= 1 && k >= 1 && s >= xs[(j as i64 -1) as usize] {
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-xs[(j as i64 -1) as usize]];
                } else {
                    dp[j][k][s] = 0
                }
            }
        }
    }
    let mut ret: usize =  0;
    for k in 1.. n + 1 {
        ret += dp[n][k][k*a];
    }
    println!("{}", ret);
}


Measured memory_bytes: 67836
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, m, ans[maxn + 10], res, tot[maxn + 10];
int fa[maxn + 10], dep[maxn + 10];
vector<int> g[maxn + 10];
bool vis[maxn + 10];

struct data {
	int x, y, id;
};
vector<data> a;

void solve(vector<data> a) {
	int rt = 0, cnt = 0, lk = 0;
	for (int i = 1; i <= n; ++i)
		if (!vis[i]) {
			++cnt; int now = 0, tmp = 0;
			for (auto j: g[i])
				if (!vis[j]) {
					++now; tmp = j;
				}
			if (now <= 1) {
				rt = i; lk = tmp;
			}
		}
	auto tmp = a;
	if (cnt == 1) {
		return;
	}
	vector<data> b;
	bool fd = 0;
	for (auto i: a)
		if (i.x == rt && i.y == rt) continue;
		else {
			if (i.y == rt) {
				fd = 1;
				b.push_back((data){i.y, i.x, i.id});
			} else b.push_back(i);
		}
	if (fd) {
		solve(b);
		for (auto i: a)
			if (i.x != rt && i.y == rt) ans[i.id] ^= 1;
		return;
	}
	a.clear(); vector<data> c;
	for (auto i: b) {
		if (i.x == rt) a.push_back(i);
		else c.push_back(i);
	}
	if (a.empty()) {
		vis[rt] = 1; solve(c);
		return;
	}
	if (a.size() == 1) {
		vis[rt] = 1;
		c.push_back((data){lk, a[0].y, a[0].id});
		solve(c);
		return;
	}
	int fir = 0, fid, sec = 0, sid;
	for (auto i: a)
		if (!fir) {
			fir = i.y;
			fid = i.id;
		} else if (!sec) {
			sec = i.y;
			sid = i.id;
		} else c.push_back(i);
	c.push_back((data){fir, sec, fid});
	solve(c);
	ans[sid] = ans[fid]; ans[fid] ^= 1;
}

void dfs(int p) {
	dep[p] = dep[fa[p]] + 1;
	for (auto i: g[p])
		if (i != fa[p]) {
			fa[i] = p; dfs(i);
		}
}

void mark(int x, int y) {
	while (x != y) {
		if (dep[x] < dep[y]) swap(x, y);
		++tot[x]; x = fa[x];
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i < n; ++i) {
		int l, r; scanf("%d%d", &l, &r);
		g[l].push_back(r); g[r].push_back(l);
	}
	for (int i = 1; i <= m; ++i) {
		int x, y; scanf("%d%d", &x, &y);
		a.push_back((data){x, y, i});
	}
	solve(a);
	for (auto &i: a)
		if (ans[i.id]) swap(i.x, i.y);
	dfs(1);
	for (auto i: a)
		mark(i.x, i.y);
	for (int i = 2; i <= n; ++i)
		res += min(tot[i], 2);
	printf("%d\n", res);
	for (auto i: a)
		printf("%d %d\n", i.x, i.y);
}


Measured memory_bytes: 277760
#include<cstdio>
#include<cstring> 
int n;
int read()
{
	int f=1,x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	n=read();
	if(n<1200) printf("ABC\n");
	else if(n<2800) printf("ARC\n");
	else printf("AGC\n");
}

Measured memory_bytes: 128
#include<stdio.h>
int search(int *,int,int);
int main() {
	int a[100000], b[100000], an, bn,i,j,num,key,ans = 0;
	scanf("%d", &an);
	num = 0;
	for ( i = 0; i < an ; i++)
	{
		scanf("%d", &key);
		if (i > 0 && a[i - 1 - num] == key)
		{
			num++;
		}
		else
		{
			a[i - num] = key;
		}
	}
	an -= num;
	scanf("%d", &bn);
	for ( i = 0; i < bn; i++)
	{
		scanf("%d", &b[i]);
	}
	for (i = 0; i < bn; i++)
	{
		ans += search(a, an, b[i]);
	}
	printf("%d", ans);
	printf("\n");
	
	return 0;
}
int search(int *x,int right, int y) {
	int left =0, mid;
	while (left < right)
	{
		mid = (left + right) / 2;
		if (x[mid] == y)
		{
			return 1;
		}
		else
		{
			if (x[mid] > y)
			{
				right = mid;
			}
			else
			{
				if (x[mid] < y)
				{
					left = mid + 1;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2288
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,h[N],a[N],dp[N],ans=0;
ll sm(ll x)
{
	ll ret=0;
	while(x>0)
	{
		ret=max(ret,dp[x]);
		x-=(x&(-x));
	}
	return ret;
}
void gb(ll x,ll val)
{
	while(x<=n)
	{
		dp[x]=max(dp[x],val);
		x+=(x&(-x));
	}
	return;
}
int main(){
	ll i,k;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>h[i];
	}
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	memset(dp,0,sizeof(dp));
	for(i=0;i<n;i++)
	{
		k=sm(h[i]);
		ans=max(ans,k+a[i]);
		gb(h[i],k+a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        //
		int X = Integer.parseInt(br.readLine());
		int t = 0;
		int sum = 0;
		
		
		List<Integer> l = new ArrayList<Integer>(Arrays.asList(0));
		List<Integer> l2 = new ArrayList<Integer>();
		
		while (true) {
			sum += ++t;
        	//System.out.println("t=["+t+"], sum=["+sum+"]");
        	//if (t > 10) { return; }
        	if (sum >= X) { System.out.println(t); return; }
		}


        //System.out.println(t);
        //return;
    }
    //-----------------------------------------------------------------
    // Debug.Print
    static void dp(String s) {
		System.out.println(s);
	}
    static void dp(StringBuilder s) { dp(s.toString()); }
    static void dp(int i) { dp(String.valueOf(i)); }
    static void dp(long i) { dp(String.valueOf(i)); }


	//-----------------------------------------------------------------
	// 入力値確認：リスト
	static void checkInput(List l) { System.out.println(l); }
	//-----------------------------------------------------------------
	// 入力値確認：配列、二次元、int型
	static void checkInput(int[][] i2) {
		StringBuilder sb = new StringBuilder();
		for(int[] i1: i2){
			for(int i: i1) sb.append("[" + i + "]");
			sb.append(System.getProperty("line.separator"));
		}
		System.out.println(sb);
	}

}

Measured memory_bytes: 21332
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    vector<int> sum(100001);
    for(int i = 2 ; i <= 100000 ; ++i){
        lint tmp = 1;
        for(int j = 2 ; j * j <= i ; ++j){
            if(i % j == 0){
                tmp *= j;
                if(j != i / j){
                    tmp *= (i / j);
                }
            }
            if(tmp >= i * 2){
                break;
            }
        }
        if(tmp >= i * 2){
            ++sum[i];
        }
        sum[i] += sum[i - 1];
    }

    int q;
    cin >> q;

    while(q--){
        int n;
        cin >> n;

        cout << sum[n] << endl;
    }

    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define oset tree<int , null_type, less_equal<int> , rb_tree_tag, tree_order_statistics_node_update>
#define MAX 1000000007

using namespace std;
using namespace __gnu_pbds;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int a,b;
  cin>>a>>b;
  cout<<max(max(a+b,a-b),a*b)<<endl;
  return 0;
}

Measured memory_bytes: 256
#!python3.8
# -*- coding: utf-8 -*-
# abc177/abc177_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S = i2s()
    T = i2s()
    n = len(S)
    m = len(T)
    ans = m
    for i in range(n - m + 1):
        cnt = 0
        for j in range(m):
            cnt += S[i+j] != T[j]
            if cnt >= ans:
                break
        else:
            ans = cnt
        if ans == 0:
            break
    print(ans)
    return

main()


Measured memory_bytes: 9204