akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c ;
  
  if(a==7 && b==5 && c==5)
    cout << "YES" << endl;
  else if(a==5 && b==7 && c==5)
    cout << "YES" << endl;
  else if(a==5 && b==5 && c==7)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}


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

using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define ve vector
#define vi vector<int>
#define vi2 vector<vi>
#define vl vector<long long>
#define vl2 vector<vl>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}


/*int main(){
    long long n, m, k;
    cin >> n >> m >> k;
    vl a(n+1), b(m+1);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    a[n] = LLONG_MAX;
    b[m] = LLONG_MAX;
    long long indexa = 0, indexb = 0, sum = 0, ans = 0;
    while((sum <= k) && !(indexa == n && indexb == m)) {
        if (a[indexa] > b[indexb]) {
            sum += b[indexb];
            if (sum <= k) {
                ans++;
                indexb++;
            }
        } else {
            sum += a[indexa];
            if (sum <= k) {
                ans++;
                indexa++;
            }
        }
    }
    cout << ans << endl;
}*/

long long sum(long long div, long long n){
    return (n/div)*(div+(n-(n%div)))/2;
}

int main(){
    long long n, ans = 0;
    cin >> n;
    rep1(i, n){
        ans += sum(i, n);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3560
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;
typedef pair<int,int> PI;

const int INF=1e8;

int N,M;
vector<int> A;

int match[9]={2,5,5,4,5,6,3,7,6};
vector<int> usematch[9];

string dp[100005];

//(a>b)
bool comp(string a,string b){
    //cout<<a<<" "<<b<<endl;
    if(a.size()<b.size())return false;
    else if(a.size()>b.size())return true;
    return (a>b);
}

int main(){
    cin>>N>>M;
    for(int i=0;i<M;++i){
        int a;
        cin>>a;
        usematch[match[a-1]].push_back(a);
    }
    for(int i=0;i<100005;++i)dp[i]="";
    for(int i=0;i<=N;++i){
        if(i!=0&&dp[i]=="")continue;
        for(int j=0;j<=9;++j){
            for(int k=0;k<usematch[j].size();++k){
                int a=usematch[j][k];
                if(comp(dp[i]+(char)(a+'0'),dp[i+j]))dp[i+j]=dp[i]+(char)(a+'0');
            }
        }
    }
    cout<<dp[N]<<endl;
}

Measured memory_bytes: 45952
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<char> vi;
int main()
{
    // freopen("B.04.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    map<char,int> m;
    int n,q=0;
    cin >> n;
    char tc;
    while(n--){
        cin >> tc;
        m[tc]++;
    }
    q=sz(m);

    // vi a(n);
    // vi colors(4, 0);
    // trav(it, a)
    // {
    //     cin >> it;
        
    // }
    // rep(i, 0, n)
    // {
    //     if (a[i] == 'P')
    //     {
    //         colors[0]++;
    //     }
    //     if (a[i] == 'W')
    //     {
    //         colors[1]++;
    //     }
    //     if (a[i] == 'G')
    //     {
    //         colors[2]++;
    //     }
    //     if (a[i] == 'Y')
    //     {
    //         colors[3]++;
    //     }
    // }
    // rep(i, 0, 4){
    //     if(colors[i]!=0){
    //         q++;
    //     }
    // }
    if(q==3){
        cout << "Three" << endl;
    }
    else{
        cout << "Four" << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>

using namespace std;

int main(int argc, char const *argv[]){
    int N,M,K;
    cin>>N>>M>>K;
    vector<long long> A,B;
    A.reserve(N);
    B.reserve(M);

    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        if(i==0){
            A.push_back(a);
        }else{
            A.push_back(a+A.back());
        }
    }
    for(int i=0;i<M;i++){
        int b;
        cin>>b;
        if(i==0){
            B.push_back(b);
        }else{
            B.push_back(b+B.back());
        }
    }
    
    int max_num_of_book = 0;
   
    int i,j;
    j=0;
    for(i=N-1;i>=0;i--){
        while(j<M && A[i]+B[j]<=K){
            max_num_of_book = max(i+j+2,max_num_of_book);
            j++;
        }
    }
    while(j<M && B[j]<=K){
        max_num_of_book = max(i+j+2,max_num_of_book);
        j++;
    }
    for(i=N-1;i>=0;i--){
        if(A[i]<=K){
            max_num_of_book = max(i+1,max_num_of_book);
            break;
        }
    }
    
    cout<<max_num_of_book;
    
    return 0;
}


Measured memory_bytes: 6408
ans = []

number = input().split(" ")
A = int(number[0])
B = int(number[1])
M = int(number[2])
a = input().split(" ")
a = list(map(int, a))
b = input().split(" ")
b = list(map(int, b))

for i in range(M):
    dis = input().split(" ")
    x = int(a[int(dis[0])-1]) + int(b[int(dis[1])-1]) - int(dis[2])
    ans.append(x)
a.sort()
b.sort()
ans.append(int(a[0])+int(b[0]))
ans = list(map(int, ans))
ans.sort()
print(ans[0])

Measured memory_bytes: 18684
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	string s;
	cin >> s;
	int n;
	n = s.size();
	int cnt = 0;
	int ans = 0;
	for (int i = 0;i < n;i++) {
		if (s[i] == 'R')cnt++;
		else cnt = 0;
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int l,i,j,k,m,n,sum=0;
    cin >> n >> m;
    long long int a[m];
    for(i=0; i<m; i++)
    {
        cin >> a[i];
        sum+=a[i];
    }
    k=n-sum;
    if(k<0)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << k << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
# -*- coding: utf-8 -*-

import sys
from collections import deque

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
B=LIST()

ans=deque()
j=N
while len(B):
    for i in range(j-1, -1, -1):
        if B[i]==i+1:
            ans.appendleft(B.pop(i))
            j-=1
            break
    else:
        print(-1)
        exit()

for i in range(N):
    print(ans[i])


Measured memory_bytes: 3444
let l:[Int] = readLine()!.split(separator:" ").map{ Int($0)! }
let n = l[0], k = l[1]

func pow (_ base:Int, _ power:Int) -> Int {
  var answer : Int = 1
  for _ in 0..<power { answer *= base }
  return answer
}

func c2(_ num: Int) -> Int {
  var m = num, c = 0
  while m < k {
    m *= 2
    c += 1
  }
  return c
}

let a = c2(1)
var sum = 1

if n >= 2 {
  for i in 2...n {
    sum += pow(2, a-c2(i))
  }
}

print(Double(sum)/Double(pow(2,a) * n))

Measured memory_bytes: 8176
#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()
#define allR(x) (x).rbegin(), (x).rend()
using ll = long long;
using P = pair<int, int>;
const int INF (1<<30);

int GetId(char c) {
  if (c == 'R') return 0;
  else if (c ==  'G') return 1;
  else return 2;
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  ll ans = 0LL;
  vector<ll> cnt(3, 0);
  rep(i, N) {
    int id = GetId(S[i]);
    cnt[id]++;
    ans += cnt[0] * cnt[1] * cnt[2] / cnt[id];
  }

  for (int dx = 1; dx < N; dx++) {
    for (int i1=0,i2=dx, i3=2*dx; i3 < N; i1++, i2++, i3++) {
      if ((S[i1]!=S[i2]) && (S[i1]!=S[i3]) && (S[i2]!=S[i3])) ans--;
    }
  }

  cout << ans << endl;


  return 0;
}


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

using namespace std;

int main(){
	int num1, num2;
	string S;
	cin >> S;
	num1 = stoi(S.substr(0, 2));
	num2 = stoi(S.substr(2, 2));
	if(1 <= num1 && num1 <= 12){
		if(1 <= num2 && num2 <= 12){
			cout << "AMBIGUOUS";
			return 0;
		}else{
			cout << "MMYY";
			return 0;
		}
	}else if(1 <= num2 && num2 <= 12){
		if(1 <= num1 && num1 <= 12){
			cout << "AMBIGUOUS";
			return 0;
		}else{
			cout << "YYMM";
			return 0;
		}
	}else {
		cout << "NA";
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

ans = 0
for i in range(n):
    for j in range(2):
        ans += min(b[i], a[i + j])
        b[i], a[i + j]= max(0, b[i] - a[i + j]), max(0, a[i + j] - b[i])
        
print(ans)


Measured memory_bytes: 19648
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

int main() {
	int n,m,k;
	scanf("%d%d%d", &n, &m, &k);
	FOR(x,n+1) FOR(y,m+1) if (x*(m-y) + y*(n-x) == k) {
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Comparator;
    
class Main{
    
static final int INF=Integer.MAX_VALUE/2;
static final PrintWriter out=new PrintWriter(System.out);
    
static class Pair{
int x;
int y;
Pair(int x,int y){
this.x=x; this.y=y;
}
static final Comparator<Pair> DISTANCE_ORDER=new DistanceOrderComparator();
public static class DistanceOrderComparator implements Comparator<Pair>{
public int compare(Pair p1,Pair p2){
return (p1.x>p2.x)?1:(p1.x<p2.x)?-1:0;
}
}
}

static class Edge{
int to;
int cost;
Edge(int to,int cost){
this.to=to; this.cost=cost;
}
}

static class MyArrayList extends ArrayList<Edge>{}
    
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
StringTokenizer st1=new StringTokenizer(line);
int v=Integer.parseInt(st1.nextToken());
int e=Integer.parseInt(st1.nextToken());
int r=Integer.parseInt(st1.nextToken());
MyArrayList[] array=new MyArrayList[v];
int[] d=new int[v];
for(int i=0;i<v;i++) array[i]=new MyArrayList();
for(int i=0;i<e;i++){
line=br.readLine();
StringTokenizer st2=new StringTokenizer(line);
int s=Integer.parseInt(st2.nextToken());
int t=Integer.parseInt(st2.nextToken());
int c=Integer.parseInt(st2.nextToken());
array[s].add(new Edge(t,c));
}
djkstra(r,d,array);
for(int i=0;i<v;i++){
out.println((d[i]==INF)?"INF":d[i]);
}
out.flush();
}
}

private static void djkstra(int r,int[] d,MyArrayList[] array){
PriorityQueue<Pair> pque=new PriorityQueue<Pair>(1,Pair.DISTANCE_ORDER);
Arrays.fill(d,INF);
d[r]=0;
pque.offer(new Pair(0,r));
while(!pque.isEmpty()){
Pair p=pque.poll();
int v=p.y;
ArrayList<Edge> list=array[v];
if(d[v]<p.x||list.size()==0) continue;
for(int i=0;i<list.size();i++){
Edge e=list.get(i);
int to=e.to;
int dv=d[v];
int cost=e.cost;
if(d[to]>dv+cost){
d[to]=dv+cost;
pque.offer(new Pair(d[to],to));
}
}
}
}
}

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

int main(){
    int N;
    cin >> N;
    bool can_cal = false;
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            if(N == i*j) can_cal =true;
        }
    }
    if(can_cal)
    {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main() {
    ll x;
    cin >> x;
    ll set = x / 11;
    ll p = x - 11 * set;
    if (p == 0) cout << 2 * set << endl;
    else if (p <= 6) cout << 2 * set + 1 << endl;
    else cout << 2 * (set + 1) << endl;
}


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

typedef long long ll;
const ll INF = 1LL << 60;
const int mod = 1000000007;

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }

    return res;
} 

ll choose(ll n, ll a) {
    ll x = 1, y = 1;
    rep(i, a) {
        x *= (n - i);
        x %= mod;
    }
    rep(i, a) {
        y *= (i + 1);
        y %= mod;
    }
    ll y2 = mod_pow(y, mod - 2, mod);

    return (x * y2) % mod;
}
int n, a, b;
int main() {
    cin >> n >> a >> b;

    ll ans = mod_pow(2, n, mod) - 1;
    // cout << ans << endl;
    // cout << choose(n, a) << endl;
    ans -= choose(n, a);
    ans -= choose(n, b);
    // cout << ans << endl;
    ans%=mod;
    // cout << ans << endl;
    ans+=mod;
    // cout << ans << endl;
    ans%=mod;
    cout << ans << endl;
}

Measured memory_bytes: 256
//by Top1
#include <bits/stdc++.h>
     
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
 
const int inf = (1e9) + 1;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 111;
     
using namespace std;

int n, q, dp[maxn], a[maxn], b[maxn], t[4 * maxn];
set <int> s;

void upd(int v, int tl, int tr, int pos, int val){
	if (tl == tr){
		t[v] = val;
		return;
	}
	int tm = (tl + tr) >> 1;
	if (pos <= tm)
		upd(v * 2, tl, tm, pos, val);
	else
		upd(v * 2 + 1, tm + 1, tr, pos, val);
	t[v] = max(t[v * 2], t[v * 2 + 1]);
}

int get(int v, int tl, int tr, int l, int r){
	if (tr < l || r < tl)
		return 0;
	if (tl >= l && tr <= r)
		return t[v];
	int tm = (tl + tr) >> 1;
	int x = get(v * 2, tl, tm, l, r);
	int y = get(v * 2 + 1, tm + 1, tr, l, r);
	return max(x, y);
}

void solve(){
	cin >> n;  

	for (int i = 1; i <= n; i++)
		cin >> a[i];

	for (int i = 1; i <= n; i++)
		cin >> b[i];

	for (int i = 1; i <= n; i++){
		upd(1, 1, n, a[i], get(1, 1, n, 1, a[i]) + b[i]);
	}

	cout << t[1];
}

main(){
    boost;
	    
	q = 1;

	while (q--){
		solve();
	}
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef long double LD;

const int MOD = 1e9 + 7;
const int MAXS = 1 << 17;

int main() {
	int N, X, Y, Z;
	cin >> N >> X >> Y >> Z;

	int xyz = (1 << (X + Y + Z - 1)) | (1 << (Y + Z - 1)) | (1 << (Z - 1));
	int mask = (1 << (X + Y + Z)) -1;

	int dp[2][MAXS];
	int idx = 0, _idx;
	dp[idx][0] = 1;
	for (int k = 0; k < N; ++k) {
		_idx = idx;
		idx ^= 1;
		memset(dp[idx], 0, sizeof(dp[idx]));
		for (int i = 0; i <= mask; ++i) {
			if (dp[_idx][i] > 0) {
				for (int j = 1; j <= 10; j++) {
					int _i = ((i << j) | (1 << (j-1))) & mask;
					if ((_i&xyz) != xyz) (dp[idx][_i] += dp[_idx][i]) %= MOD;
				}
			}
		}
	}
	long res = 1;
	for (int i = 0; i < N; ++i) (res *= 10) %= MOD;
	for (int i = 0; i <= mask; ++i) (res -= dp[idx][i]) %= MOD;

	cout << (res + MOD) % MOD << endl;

	return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	
	private static boolean debug = false;
	
	private static int r;
	private static int c;
	
	private static int[][] senbeis;
	
	private static int URA = 0, OMOTE = 1; 
	
	@SuppressWarnings("unused")
	private static void debug(String format, Object... objects) {
		if (!debug)
			return;
		System.out.format(format, objects);
	}
	
	public static int solve() {
		int ans = 0;
		for (int trial = 0; trial < (2 << r); trial++) {
			int canSell = 0;
			for (int x = 0; x < c; x++) {
				int ura = 0;
				for (int y = 0; y < r; y++) {
					boolean reverses = ((trial >> y) & 1) == 0;
					int target = reverses ? URA : OMOTE;
					ura += (senbeis[y][x] == target) ? 1 : 0;
				}
				canSell += Math.max(ura, r - ura);
			}
			ans = Math.max(ans, canSell);
		}
		return ans;
	}
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			r = scanner.nextInt();
			c = scanner.nextInt();
			if (r == 0 && c == 0) {
				break;
			}
			senbeis = new int[r][c];
			for (int i = 0; i < r; i++) {
				for (int j = 0; j < c; j++) {
					senbeis[i][j] = scanner.nextInt();
				}
			}
			debug("===\n");
			debug("%d %d\n", r, c);
			for (int i = 0; i < r; i++) {
				for (int j = 0; j < c; j++) {
					debug("%d ", senbeis[i][j]);
				}
				debug("\n");
			}
			debug("===\n");
			System.out.format("%d\n", solve());
		}
		scanner.close();
	}
}

Measured memory_bytes: 67452
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n,k;
	cin>>n>>k;
	ll h[n];
	for(ll i=0;i<n;i++){
		cin>>h[i];
	}
	ll dp[n];
    for(ll i=0;i<n;i++) dp[i]=10000000000;
	dp[0]=0;
	for(ll i=1;i<n;i++){
		for(ll j=1;j<=k && j<=i;j++){
			dp[i] = min(dp[i] , dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout<<dp[n-1];
	
	
	return 0;
}

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

using namespace std;

const int maxn = 2010;
const int inf = 0x3f3f3f3f;

int ans = inf;

int n, l[maxn], sz[maxn], lb[maxn], rb[maxn], dep[maxn], e;
char S[maxn];

struct Edge {
	int v, x;
} E[maxn << 1];

int Max(int u, int v) {
	if ((u ^ v) & 1) ++ v;
	return max(u, v);
}

void dfs(int u, int fa) {
	sz[u] = (S[u] == '1'); lb[u] = inf; rb[u] = 0;
	int sum = 0, mx = 0, cmx = 0;
	for (int p = l[u]; p >= 0; p = E[p].x) {
		int v = E[p].v;
		if (v != fa) {
			dep[v] = dep[u] + 1;
			dfs(v, u);
			sz[u] += sz[v];
			rb[u] += sz[v] + rb[v];
			sum += sz[v] + lb[v];
			if (sz[v] + lb[v] >= mx) {
				cmx = mx;
				mx = sz[v] + lb[v];
			} else if (sz[v] + lb[v] > cmx) {
				cmx = sz[v] + lb[v];
			}
		}
	}
	lb[u] = sum;
	for (int p = l[u]; p >= 0; p = E[p].x) {
		int v = E[p].v;
		if (v != fa) {
			int t = mx;
			if (sz[v] + lb[v] == mx) t = cmx;
			int w = Max(sz[v] + lb[v], t);
			if (w > sz[v] + rb[v]) continue;
			int s = sum - sz[v] - lb[v] + w;
			lb[u] = min(lb[u], max(s & 1, s - 2 * (s - w)));
		}
	}
}

inline void addEdge(int u, int v) {
	E[e].v = v; E[e].x = l[u]; l[u] = e++;
}

int main() {
	memset(l, -1, sizeof(l));
	scanf("%d", &n);
	scanf("%s", S+1);
	for (int i = 1; i < n; i++) {
		int u, v; scanf("%d%d", &u, &v);
		addEdge(u, v);
		addEdge(v, u);
	}
	for (int i = 1; i <= n; i++) {
		dep[i] = 0;
		dfs(i, 0);
		int sum = 0;
		for (int j = 1; j <= n; j++) {
			if (S[j] == '1') {
				sum += dep[j];
			}
		}
		if (!lb[i]) ans = min(ans, sum / 2);
	}
	if (ans == inf) puts("-1");
	else printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

ll N, x, ans = infll, sum;

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

    for (int i = 0; i < N; i++, sum = 0LL)
    {
        for (int j = 0; j < N; j++)
        {
            b[j] = i == 0 ? a[j] : min(b[j], a[(N + j - i) % N]);
            sum += b[j];
        }
        ans = min(sum + x * i, ans);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            long n = s.Length;
            long sum = 0;
            for(int i = 0; i < n; i++)
            {
                int x = int.Parse(s[i].ToString());
                sum += x;
                sum %= 9;
            }
            if (sum == 0) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 33004
#include <cstdio>
#include <vector>
using namespace std;
#define NMAX 1000000

void printArr(int A[], int N){
    for(int i = 0; i < N; ++i){
        printf("%d\n", A[i]);
    }
}

void printG(vector<int> v){
    int N = v.size();
    for(int i = N - 1; i >= 1; --i){
        printf("%d ", v[i]);
    }
    printf("%d\n", v[0]);
}

long long insertionSort(int A[], int g, int N){
    long long cnt = 0;
    
    for(int i = g; i < N; ++i){
        int tmp = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > tmp){
            A[j + g] = A[j];
            j -= g;
            ++cnt;
        }
        A[j + g] = tmp;
    }

    return cnt;
}

void shellSort(int A[], int N){
    int m;
    long long cnt = 0;
    vector<int> G;

    for(int g = 1; g <= N; g = 3 * g + 1){
        G.push_back(g);
    }
    m = G.size();

    printf("%d\n", m);
    printG(G);

    for(int i = m - 1; i >= 0; --i){
        cnt += insertionSort(A, G[i], N);
    }

    printf("%lld\n", cnt);
    printArr(A, N);
}

int main(){
    int N;
    static int A[NMAX];

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

    shellSort(A, N);

    return 0;
}


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

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

int main(){
  int n,x,i,k,kotae;
  cin>>n>>x;
  cin>>k;
  kotae=abs(k-x);
  for(i=1;i<n;i++){
    cin>>k;
    kotae=gcd(kotae,abs(k-x));
  }
  cout<<kotae;
}

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

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

    ll c[n], s[n], f[n];
    rep(i, n - 1){
        cin >> c[i] >> s[i] >> f[i];
    }

    rep(i, n - 1){
        ll time = s[i] + c[i];
        for(int j = i + 1; j < n - 1; j++){
            if(time < s[j]){
                time = s[j];
            }

            if(time % f[j] != 0){
                time += f[j] - time % f[j];
            }

            time += c[j];
        }

        cout << time << endl;
    }

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


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(100000000)

while True:
  w, h = map(int, input().split())
  if not w:
    break

  n = int(input())

  xlst = [0, w - 1]
  ylst = [0, h - 1]
  plst = []

  for i in range(n):
    x1, y1, x2, y2 = map(int, input().split())
    plst.append([x1,y1,x2 - 1,y2 - 1])
    xlst.append(x1)
#    xlst.append(x1 + 1)
    xlst.append(x2)
    xlst.append(x2 - 1)
    ylst.append(y1)
#    ylst.append(y1 + 1)
    ylst.append(y2)
    ylst.append(y2 - 1)

  xlst = list(set(xlst))
  ylst = list(set(ylst))
  sorted_xlst = sorted(xlst)
  sorted_ylst = sorted(ylst)

  xdic = {}
  ydic = {}

  for i, v in enumerate(sorted_xlst):
    xdic[v] = i
  for i, v in enumerate(sorted_ylst):
    ydic[v] = i
  
  neww = xdic[sorted_xlst[-1]]
  newh = ydic[sorted_ylst[-1]]
#  print(neww, newh)

  painted = [[0] * (newh) for _ in range(neww)]

  def paint_area(x, y):
    painted[x][y] = 1
    for tx, ty in [(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)]:
      if 0 <= tx <= neww - 1 and 0 <= ty <= newh - 1 and not painted[tx][ty]:
        paint_area(tx, ty)

  for p in plst:
    x1, y1, x2, y2 = p
    x1, y1, x2, y2 = xdic[x1], ydic[y1], xdic[x2], ydic[y2]
    for x in range(x1, x2 + 1):
      for y in range(y1, y2 + 1):
        painted[x][y] = 1
        
#  for area in painted:
#    print(area)
#  print()

  ans = 0

  for x in range(neww):
    for y in range(newh):
      if not painted[x][y]:
        ans += 1
        painted[x][y] = 1
        que = [(x, y)]
        while que:
          px, py = que.pop()
          for tx, ty in [(px - 1, py), (px + 1, py), (px, py - 1), (px, py + 1)]:
            if 0 <= tx <= neww - 1 and 0 <= ty <= newh - 1 and not painted[tx][ty]:
              painted[tx][ty] = 1
              que.append((tx,ty))
  print(ans)


Measured memory_bytes: 25332
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int[] c = new int[n];
		int[][] a = new int[n][m];
		for(int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
			for(int j = 0; j < m; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		sc.close();

		int ans = Integer.MAX_VALUE;
		int all = 1<<n;
		for(int mask = 0; mask < all; mask++) {
			int[] level = new int[m];
			int cost = 0;
			for(int i = 0; i < n; i++) {
				if(((mask>>i)&1)==1) {
					cost += c[i];
					for(int j = 0; j < m; j++) {
						level[j] += a[i][j];
					}
				}
			}
			boolean ok = true;
			for(int j = 0; j < m; j++) {
				if(level[j] < x) {
					ok = false;
				}
			}
			if(ok) {
				ans = Math.min(ans, cost);
			}
		}
		if(ans == Integer.MAX_VALUE) {
			System.out.println(-1);
		} else {
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 37380
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = long.Parse(line[0]);
        var b = long.Parse(line[1]);
        var c = long.Parse(line[2]);
        var d = long.Parse(line[3]);
        getAns(a, b, c, d);
    }

    static long Aplus(long a, long b, long c, long d) => d <= 0 ? a * d : b * d;
    static long AminusBplus(long a, long b, long c, long d)
    {
        if (d <= 0) return a * c;
        else return Max(a * c, b * d);
    }
    static void getAns(long a, long b, long c, long d)
    {
        long ans;
        if (a >= 0) ans = Aplus(a, b, c, d);
        else if (c >= 0) ans = Aplus(c, d, a, b);
        else if (a <= 0 && b >= 0) ans = AminusBplus(a, b, c, d);
        else ans = a * c;
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 27368
Var s,x:ansistring;
    n,i:longint;
Begin
        readln(s);
        for i:=1 to length(s) do
        Begin
                if s[i] in ['C','F'] then
                Begin
                        x:=x+s[i];
                end;
                
                if pos('CF',x)<>0 then
                Begin
                        write('Yes');
                        halt;
                end;
        end;
        write('No');
end.

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        int[] h = new int[N];
        for (int i = 0; i < N; i++) h[i] = scanner.nextInt();

        int result = solve(h, N);
        System.out.println(result);

        //test();
    }

    private static int solve(int[] h, int N) {
        int known = 0;
        int tentativeNext = Integer.MAX_VALUE;

        for (int i = 0; i < N-1; i++) {
            int nextKnown = Math.min(tentativeNext, known + Math.abs(h[i+1] - h[i]));
            if (i + 2 < N) tentativeNext = known + Math.abs(h[i+2] - h[i]);
            known = nextKnown;
        }

        return known;
    }

    private static void test() {
        testCase(new int[] { 10, 20, 30, 40 }, 30);
        testCase(new int[] { 10, 10 }, 0);
        testCase(new int[] { 30, 10, 60, 10, 60, 50 }, 40);
        System.out.println("DONE");
    }

    private static void testCase(int[] h, int expected) {
        int result = solve(h, h.length);
        if (result != expected) {
            System.out.println("FAILED " + Arrays.toString(h) + ", was " + result + " expected " + expected);
        }
    }
}


Measured memory_bytes: 51228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int main() {
    ll n;
    cin >> n;
    vector<vector<ll>> v(n,vector<ll>(0));
    rep(i, n){
        ll x;
        cin >> x;
        v[x - 1].push_back(i);
    }
    ll ans = -1;
    ll rem = 0;
    ll p = -1;
    rep(i, n){
        if (v[i].size() == 0) break;
        ll m = 1e6;
        for (auto x : v[i]) {
            if (p < x) {
                m = min(x, m);
            }
        }
        if (m == 1e6) break;
        p = m;
        rem++;
        
    }
    if (rem  == 0) {
        ans = -1;
    }else {
        ans = n - rem;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14344
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string X,Y;
  cin>>X>>Y;
  if(X[0]<Y[0])
    {
      cout<<"<"<<endl;
    }
  if(X[0]==Y[0])
    {
    cout<<"="<<endl;
  }
  if(X[0]>Y[0])
    {
    cout<<">"<<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>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
ll a[6]={100,101,102,103,104,105};
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll x;
 	cin>>x;
 	ll dp[x+1][6];
 	memset(dp,0,sizeof(dp));
 	for(ll j=0;j<6;j++)
 		dp[0][j]=1;
	for(ll i=100;i<=x;i++)
	{	
		for(ll j=0;j<6;j++)
		{
			if(i-a[j]>=0)
			{
				for(ll k=0;k<6;k++)
				{
					if(dp[i-a[j]][k]==1)
					{
						dp[i][j]=1;
					}
				}	
			}
		}
	}	
	for(ll j=0;j<6;j++)
	{
		if(dp[x][j]==1)
		{
			cout<<1<<endl;
			return 0;
		}
	}
	cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 4992
n,m=map(int,input().split())

ab=[]

for i in range(m):
    a=[int(j) for j in input().split()]
    ab.append(a)

from operator import itemgetter
ab.sort(key=itemgetter(1))

ans=1
b=[ab[0][1]-1]
for i in range(m):
    if not b[-1]>=ab[i][0] and b[-1]<ab[i][1]:
        b.append(ab[i][1]-1)
        ans+=1

print(ans)

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

int main(){
  int a,b;cin>>a>>b;
  int aa=max(a,b),bb=min(a,b),c=1;
  while(c){
    c=aa%bb;
    aa=bb;
    bb=c;
  }
  cout<<(ll)a*b/aa<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for (int i=n;^i;i--)
#define ALL(v) v.begin(),v.end()
// #define int ll 
#define eps 1e-9
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
typedef long long ll;

signed main(void){
	int a[30];
	int w,n;
	scanf("%d %d",&w,&n);
	rep(i,w) a[i]=i;
	rep(i,n) {
		int sa,sb;
		scanf("%d,%d",&sa,&sb);
		swap(a[sa-1],a[sb-1]);
	}
	rep(i,w) printf("%d\n",a[i]+1);
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define PI 3.1415926535897932384626433832795
#define ll long long
#define MP make_pair
#define IN insert
#define PB push_back
#define fr first
#define se second
#define sf scanf
#define pf printf
#define MOD 1000000007
#define debug(x) cout<<"---------"<<x<<endl;
#define LEN(a) sizeof(a)/sizeof(a[0])
#define MEM(arr,k) memset(arr,k,sizeof arr)
#define input freopen("input","r",stdin)
#define output freopen("output","w",stdout)
#define allset ios_base::sync_with_stdio(false);cin.tie(NULL)

int X8[] = {0, 1, 0, -1, 1, -1, 1, -1};
int Y8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int X4[] = {1,-1, 0, 0};
int Y4[] = {0, 0, 1,-1};

using namespace std;

int main()
{

	
	int n;
	sf("%d",&n);
	int h[n];
	for(int &k:h)
		sf("%d",&k);
	
	int f,s,ans=0;

	vector<int>dp(n,INT_MAX);
	dp[0] = 0;
	for(int i=0;i<n;i++)
	{
		for(int j:{i+1,i+2})
		{
			if(j<n)
			{
				dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]));
			}
		}
		
	}
	
	cout<<dp[n-1]<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
[n, k] = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [10 ** 10 for _ in range(n)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    for j in range(1, min(i, k)+1):
        if i - j >= 0:
            dp[i] = min(dp[i] , dp[i-j] + abs(h[i] - h[i-j]))
print(dp[n-1])

Measured memory_bytes: 56544
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> T(N), A(N);
    for (int i = 0; i < N; i++){
        cin >> T.at(i);
        cin >> A.at(i);
    }
    long long int t = T[0];
    long long int a = A[0];
    for(int i = 1; i < N; i++){
        long long int t_tmp = 0;
        long long int a_tmp = 0;
        long long int k = max(t / T[i], a / A[i]);
        while (1){      // 両方超える値を探す
            t_tmp = k * T[i];
            a_tmp = k * A[i];
            if(t_tmp >= t && a_tmp >= a){   // 超える時
                t = t_tmp;
                a = a_tmp;
                break;
            }
            k = k + 1;
        }
    }
    cout << t + a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

int main() {
  std::string S;
  std::cin >> S;
  const auto N = S.size();
  
  int count = 0;
  std::vector<int> child(S.size());
  
  int cnt_r = 0;
  for(int i = 0; i < N; ++i) {
    if(S[i] == 'R') {++cnt_r;}
    else {
      child[i] += cnt_r / 2;
      child[i-1] += cnt_r - (cnt_r / 2);
      cnt_r = 0;
    }
  }
  int cnt_l = 0;
  for(int i = N-1; i >= 0; --i){
    if(S[i] == 'L') {++cnt_l;}
    else{
      child[i] += cnt_l / 2;
      child[i+1] += cnt_l - (cnt_l / 2);
      cnt_l = 0;
    }
  }
  for(auto c : child) {
  	std::cout << c << " ";
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 1152
def get_basis(a):
    basis=[]
    for e in a:
        for b in basis:
            e = min(e, e^b)
        if e:
            basis.append(e)
    return basis
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in a:
    ans^=i
k=~ans
for i in range(n):
    a[i]&=k
rank=0
basis=get_basis(a)
res=0
for i in basis:
    res=max(res,res^i)
print(ans+2*res)

Measured memory_bytes: 16052
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 0x3f3f3f3f
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


class toporogical_sort_fn_t {
public:
  toporogical_sort_fn_t(const std::vector<std::vector<int>>& G) :
    G_(G), N_(G_.size()), indices_(N_), visit_(N_)
  {
    assert(N_);
  };

public:
  std::vector<int> sort() {
    index_ = N_ - 1;

    std::fill(ALL(visit_), 0);

    for (int i = 0; i < N_; i ++)
      if (! visit_[i])
        if (! dfs(i))
          return {};

    return indices_;
  };

private:
  bool dfs(int i) {
    visit_[i] = 1;

    for (const auto& k : G_[i]) {
      // If self-loop is allowed, uncomment the following lines.
      // if (k == i)
      //   continue;

      if (visit_[k] == 2)
        continue;

      if (visit_[k] == 1)
        return false;	// Self-loop is detected.

      if (! dfs(k))
        return false;
    }

    visit_[i] = 2;

    assert(0 <= index_ && index_ < N_);

    indices_[index_ --] = i;

    return true;
  };

private:
  const std::vector<std::vector<int>>& G_;

private:
  int N_;

  std::vector<int> indices_;

  int index_;

  std::vector<uint8_t> visit_;
};


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, M, x, y;

  std::cin >> N >> M;

  std::vector<std::vector<int>> G(N), H(N);

  for (int i = 0; i < M; i ++) {
    std::cin >> x >> y;

    x --;
    y --;

    G[x].push_back(y);
    H[y].push_back(x);
  }

  toporogical_sort_fn_t fn(G);

  std::vector<int> a(fn.sort());

  std::reverse(ALL(a));

  int dp[111111], xp = 0;

  memset(dp, 0, sizeof(dp));

  for (const auto& i : a)
    for (const auto& j : H[i])
      xp = std::max(dp[j] = std::max(dp[i] + 1, dp[j]), xp);

  std::cout << xp << std::endl;

  return 0;
}


Measured memory_bytes: 13824
#include <iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i+=2) {
    int sosuu = 0;
    for (int j = 1; j <= N; j++) {
      if (i%j==0) sosuu++;
    }
    if (sosuu==8) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Contests.ABC160
{
    /// <summary>
    /// 
    /// </summary>
    static class B
    {
        static void Main(string[] args)
        {
            var x = NextInt();

            var fh = x / 500;
            var f = (x % 500) / 5;

            Console.WriteLine(fh * 1000 + f * 5);
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int read( ){
	int x=0,y=1;char ch=' ';
	for(;(ch!='-' && (ch>'9' || ch<'0'));ch=getchar( ));
	if(ch=='-')y=-1,ch=getchar( );
	for(;ch>='0' && ch<='9';ch=getchar( ))x=x*10+ch-48;
	return x*y;
}
const int inf=0x3f3f3f3f;
const int N=1010;
int n,tot,cnt,ans;
struct node{
	int to,nex;
}e[N*N];
int a[N][N],bgn[N*N],d[N*N],f[N*N];
queue<int> q;
void add(int x,int y){
	e[++cnt]=(node){y,bgn[x]};bgn[x]=cnt;++d[y];
}
void tops( ){
	int sum=0;
	for(register int i=1;i<=tot;++i)if(d[i]==0){
		q.push(i);f[i]=1;++sum;
	}
	while(q.size( )){
		int x=q.front( );q.pop( );
		for(register int i=bgn[x];i;i=e[i].nex){
			int y=e[i].to;--d[y];
			if(!d[y]){
				f[y]=f[x]+1;++sum;
				ans=max(ans,f[y]);q.push(y);
			}
		}
	}
	if(sum==tot)printf("%d\n",ans);
	else printf("-1\n");
}
int main( ){
	int x,y,z,k,ls;
	n=read( );
	for(register int i=1;i<=n;++i)
		for(register int j=i+1;j<=n;++j)a[i][j]=a[j][i]=++tot;
	for(register int i=1;i<=n;++i)
		for(register int j=1;j<n;++j){
			x=read( );
			if(j!=1)add(a[i][ls],a[i][x]);
			ls=x;
		}
	tops( );
	return 0;
}


Measured memory_bytes: 23936
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int key;
  node *left,*right,*p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
signed main(){
  int n;
  cin>>n;
  root=NULL;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    //cout<<(root==NULL?-1:root->key)<<endl;
    if(s=="print"){
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
      continue;
    }
    int x;
    cin>>x;
    insert(node(x));
  }
  return 0;
}


Measured memory_bytes: 26452
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int main(){
  int N;
  cin>>N;
  vi H(N);
  for(int i=0; i<N; i++){
    cin>>H[i];
  }
  for(int i=N-1; i>0; i--){
    if(H[i-1]==H[i]+1){
      H[i-1]--;
    }else if(H[i-1]>H[i]+1){
      cout<<"No\n";return 0;
    }
    /*
    for(int x: H){
      cout<<x<<",";
    }cout<<endl;
    */
  }
  cout<<"Yes\n";
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
#include<iomanip>
#include<numeric>
using namespace std;

int main(){
  string s;cin>>s;
  int l=s.length();
  vector<string> t(l);
  for(int i=0;i<l;i++)t.at(i)=s[i];

  vector<int> k;
  for(int i=0;i<l;i++){
    if(t.at(i)=="0")k.push_back(0);
    if(t.at(i)=="1")k.push_back(1);
    if(t.at(i)=="B"&&k.size()!=0)k.pop_back();
    //for(int i=0;i<k.size();i++)cout<<k.at(i);
    //cout<<"a"<<endl;
  }
  for(int i=0;i<k.size();i++)cout<<k.at(i);
  cout<<endl;
  //cout<<k.size()<<endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace Collections
{
	class program
	{
    //static long MAX_LONG = 5000000000000000;
		static void Main(string[] args)
		{

			// 入力
      decimal[] input = Console.ReadLine().Split().Select(p => decimal.Parse(p)).ToArray();
			decimal A = input[0];
			decimal B = input[1];

			decimal ret = Math.Ceiling((B-A)/(A-1));
			ret++;

			Console.WriteLine(ret + "");
    }
	}
}


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

class Main {
 	public static void main(String args[]) throws IOException {
     	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	String S = br.readLine();
      	String T = br.readLine();
      	int size = T.length();
      	int ans = Integer.MAX_VALUE;
      	for(int i=0;i<=S.length()-size;i++) {
          	int tmp = i;
          	int count = 0;
         	for(int j=0;j<T.length();j++,i++) {
             	 if(S.charAt(i) != T.charAt(j))
                    count++;
            }
            if(count < ans)
            	ans = count;
          	i = tmp;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 32632
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);
const long MOD = 1000000007;

std::string s;

long dp[100005][13];

void proc(long dig, long num){
    for(int i = 0; i < 13; i++){
        dp[dig][(i*10+num) % 13] += dp[dig-1][i] % MOD;
    }
}

int main(){
    std::cin >> s;
    if(s[0] == '?'){
        for(int i = 0; i < 10; i++){
            dp[0][i] = 1;
        }
    }else{
        dp[0][s[0] - '0'] = 1;
    }
    for(int i = 1; i < s.length(); i++){
        if(s[i] == '?'){
            for(int j = 0; j < 10; j++){
                proc(i, j);
            }
        }else{
            proc(i, s[i] - '0');
        }
    }
    printf("%ld\n", dp[s.length()-1][5] % MOD);
}


Measured memory_bytes: 10624
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int N,L;cin>>N>>L;
    int _min = 1e9;
    int ans = 0;
    for(int i=0;i<N;i++){
        ans += L + i;
        if(abs(L+i)<_min) _min = abs(L + i);
    }
    cout << (L >= 0 ? ans - _min : ans + _min) << endl;
    return 0;
}

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

set<ll> divisor(ll n) {
	set<ll> ret;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.insert(i);
			if (i * i != n) ret.insert(n / i);
		}
	}

	/*
	for (auto it = ret.begin(); it != ret.end(); it++) {
		cout << (*it) << " ";
	}
	cout << " DIV " << n << endl;
*/

	return (ret);
}

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

	ll N;
	cin >> N;

	map<ll,list<ll> > sq;
	for (ll i = (ll)sqrt(N); i >= 2; i--) {
		ll j = i;
		while (j <= N) {
			sq[j].push_back(i);
			j *= i;
		}
	}
//	for (auto it = sq.begin(); it != sq.end(); it++) {
//		cout << (it->first) << " ";
//	}
//	cout << "SQ size = " << sq.size() << endl;

	set<ll> ans;
	ans.insert(N);

	// MOD=1
	set<ll> divNm1 = divisor(N-1);
	for (auto it = divNm1.begin(); it != divNm1.end(); it++) {
		ans.insert(*it);
	}

	/*
	// 一乗
	for (auto it = divN.begin(); it != divN.end(); it++) {
		ll d = *it;
		if ((N / d) % d == 1) {
			ans.insert(d);
		}
	}
	*/
	// 三乗以上
	set<ll> divN = divisor(N);
	for (auto it = divN.begin(); it != divN.end(); it++) {
		auto f = sq.find(*it);
		if (f != sq.end()) {
			for (auto jt = f->second.begin(); jt != f->second.end(); jt++) {
				if ((N / (f->first)) % (*jt) == 1) {
					ans.insert(*jt);
				}
			}
		}
	}

	ans.erase(1);
	cout << ans.size() << endl;

/*
	for (auto it = ans.begin(); it != ans.end(); it++) {
		cout << (*it) << " ";
	}
	cout << " ANS " << endl;
	*/
}






Measured memory_bytes: 188672