akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll a[n];
    rep(i, n) cin >> a[i];
    //i桁目を最適化した場合，k+1と同じにした場合，k+1と異なる場合，
    ll best[40], same[40] = {}, diff[40] = {};
    ll Max = 0;
    bitset<40> bk(k + 1);

    rep(i, 40) {
        ll cnt[2] = {};
        rep(j, n) {
            bitset<40> b(a[j]);
            cnt[b[i]]++;
            same[i] += (bk[i] ^ b[i]) * (1LL << i);
            diff[i] += !(bk[i] ^ b[i]) * (1LL << i);
        }
        best[i] = max(cnt[0], cnt[1]) * (1LL << i);
    }

    rep(i, 40) { //～i-1桁目：最適化 i桁目：k+1と異なる i+1桁目～：k+1と同じ
        if (bk[i] == 0) continue;
        ll sum = 0;
        rep(j, i) sum += best[j];
        sum += diff[i];
        REP(j, i + 1, 40) sum += same[j];
        Max = max(Max, sum);
    }
    cout << Max << endl;
    return 0;
}



Measured memory_bytes: 1024
#![allow(unused_imports)]
#![allow(dead_code)]
use proconio::input;
use proconio::fastout;
use proconio::marker::{Chars};

#[fastout]
fn main() {
    input! {
        a:i32,b:i32,
    }
    let v:[i32;12]=[31,28,31,30,31,30,31,31,30,31,30,31];
    let mut ans=0;
    for i in 1..a+1{
        if i==a{
            for j in 1..b+1{
                if i==j{
                    ans+=1;
                }
            }
        }else{
            for j in 1..v[(i-1) as usize]+1{
                if i==j{
                    ans+=1
                }
            }
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 2152
from bisect import bisect_right
N, M, Q = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(M)]
lr.sort(reverse=True)

lst = [[]]

j = N - 1
for i in range(M):
    if lr[i][0] - 1 < j:
        lst[-1].sort()
        while lr[i][0] - 1 < j:
            lst.append(lst[-1][:])
            j -= 1
    lst[-1].append(lr[i][-1]-1)
lst[-1].sort()
lst.reverse()

for i in range(Q):
    p, q = map(int, input().split())
    m = bisect_right(lst[p-1], q-1)
    print(m)

Measured memory_bytes: 306552
//check check
#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<queue>
#include<cstring>

#define ll long long
#define pb(x) push_back(x)

using namespace std;

const int NMAX = 0;


int main()
{
    int m,d,i,j,k;

    cin>>m>>d;

    int dig1 = d%10 , dig10 = (d/10)%10;
    int cnt = 0;
    for(i = 1 ; i <= m ; ++i)
    {
        for(j = 1 ; j <= d ; ++j)
        {
            dig1 = j%10 , dig10 = j/10%10;
            if(dig1 >= 2 && dig10 >=2 && dig1*dig10 == i)
                cnt++;
        }
    }

    cout<<cnt;

    return 0;
}


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

#define MIN 1E9
#define MAX -10000000

bool graph[60][60];
bool lg[60]={false};
int n,m,a[100],b[100];

void dfs(int x){
    if(lg[x]) return;
    lg[x]=true;
    for(int i=0;i<n;i++){
        if(graph[x][i]){
            dfs(i);
        }
    }
}

int main(void){
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d %d",&a[i],&b[i]);
        a[i]--;b[i]--;
        graph[a[i]][b[i]]=true;
        graph[b[i]][a[i]]=true;
    }
    int ans=0;
    bool connected=true;
    for(int i=0;i<m;i++){
        graph[a[i]][b[i]]=false;
        graph[b[i]][a[i]]=false;

        for(int j=0;j<n;j++)lg[j]=false;

        dfs(0);
        bool connect=false;
        for(int j=0;j<n;j++){
            if(!lg[j]) connect=true;
        }
        if(connect) ans+=1;

        graph[a[i]][b[i]]=true;
        graph[b[i]][a[i]]=true;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 10 05:50:12 2020

@author: baddude
"""


a, b, c = map(str, input().split())
abc = int(a + b + c)

if abc % 4 ==0 :
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process(int test_number)throws IOException
    {
        int d = ni(), t = ni(), s = ni();
        pn((d <= t* s) ? "Yes" : "No");
    }
 
    static final long mod = (long)1e9+7l;
    
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc = new FastReader();
 
        long s = System.currentTimeMillis();
        int t = 1;
        //t = ni();
        for(int i = 1; i <= t; i++)
            process(i);
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }

    static void trace(Object... o){ System.err.println(Arrays.deepToString(o)); };
    static void pn(Object o){ out.println(o); }
    static void p(Object o){ out.print(o); }
    static int ni()throws IOException{ return Integer.parseInt(sc.next()); }
    static long nl()throws IOException{ return Long.parseLong(sc.next()); }
    static double nd()throws IOException{ return Double.parseDouble(sc.next()); }
    static String nln()throws IOException{ return sc.nextLine(); }
    static long gcd(long a, long b)throws IOException{ return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{ return (b==0)?a:gcd(b,a%b); }
    static int bit(long n)throws IOException{ return (n==0)?0:(1+bit(n&(n-1))); }
    
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 36608
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>

#define INF 1000000000000000000
using namespace std;
typedef long long ll;


int main(){
	int w, a, b;
	cin >> w >> a >> b;
	int ans;
	ans = max(b - a - w, a - b - w);
	ans = max(0, ans);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import copy
import heapq

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)

print(ip()**2)

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

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        String s[]=bu.readLine().split(" ");
        int i,c=0,n=Integer.parseInt(s[0]),k=Integer.parseInt(s[1]),a[]=new int[n+1];
        for(i=0;i<k;i++)
        {
            int d=Integer.parseInt(bu.readLine()),j;
            s=bu.readLine().split(" ");
            for(j=0;j<d;j++)
                a[Integer.parseInt(s[j])]++;
        }
        for(i=1;i<=n;i++)
            if(a[i]==0) c++;
        System.out.print(c);
    }
}


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

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int a,b;
  cin >> a >> b;
  if((a+b)%2==1)
  {
    cout << (a+b)/2+1 << endl;
  }
  else{
  cout << (a+b)/2 << endl;}
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 10000
int isIncluded(int);
int arr[N];//first line
int n;//the number of first line
int main(void)
{
  int i;//counter
  int q;//the number of second line
  int x;//the element of second array
  int ans=0;//output
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&arr[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&x);
      ans+=isIncluded(x);
    }
  printf("%d\n",ans);
  return 0;
}
int isIncluded(int x)
{
  int i;//counter
  for(i=0;i<n;i++)
    {
      if(arr[i]==x) return 1;
    }
  return 0;
}




Measured memory_bytes: 2128
#include <iostream>
#include <deque>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main()
{
	ll i;
	ll sum=0;
	cin >> i;
	for(ll n=0; n<=i; n++)
	{
		if(n%5 !=0 && n%3 !=0)
			sum += n;
	}
	cout << sum;
	
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#define REP(i, a, n) for(int i = a; i <= n; i++)
using namespace std;


int N, cnt = 0;

int main(void) {
  cin >> N;
  REP(i, 1, N) {
    int A;
    cin >> A;
    if(A % 2 == 1) cnt++;
  }

  cout << (cnt % 2 == 0 ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n,k,r,ss,p,sc=0;
  string s;
  cin>>n>>k;cin>>r>>ss>>p;
  cin>>s;
  char arr[n+1];
  int l=s.size(),i;
  for(i=1;i<=l;i++)
  {
  	if(i<=k){
  	if(s[i-1]=='r'){arr[i]='p';sc=sc+p;}else if(s[i-1]=='p'){sc=sc+ss
	  ;arr[i]='s';}else {arr[i]='r';sc=sc+r;}}
  	else
  	{
  		if(s[i-1]=='r')
  		{
  			if(arr[i-k]=='p')
  			{
  				if(i+k-1<l&&s[i+k-1]=='s')arr[i]='s';
  				else if((i+k-1<l)&&s[i+k-1]=='p')arr[i]='r';
  				else{arr[i]='r';
				  }
			  }
			  else
			  {
			  	arr[i]='p';sc=sc+p;
			  }
		  }
		 else if(s[i-1]=='p')
  		{
  			if(arr[i-k]=='s')
  			{
  				if((i+k-1<l)&&s[i+k-1]=='s')arr[i]='p';
  				else if((i+k-1<l)&&s[i+k-1]=='r')arr[i]='r';
  				else{arr[i]='r';}
			  }
			  else
			  {
			  	arr[i]='s';sc=sc+ss;
			  }
		  }
		  else
  		{
  			if(arr[i-k]=='r')
  			{
  				if((i+k-1<l)&&s[i+k-1]=='r')arr[i]='s';
  				else if((i+k-1<l)&&s[i+k-1]=='p')arr[i]='p';
  				else{arr[i]='p';}
			  }
			  else
			  {
			  	arr[i]='r';sc=sc+r;
			  }
		  }
	  }
  }
  cout<<sc;
}

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

int main(){
    long int N,A,B;
    cin>>N>>A>>B;
    
    if(A>B){
    cout<<0<<endl;
    }
    
    else if(A==B&&N==1){
    cout<<1<<endl;
    }
    
    else if(N==1&&B>A){
    cout<<0<<endl;
    }
    
    else if(B>=A&&N>=2){
    cout<<(B-A)*(N-2)+1<<endl;
    }
}

Measured memory_bytes: 256
/*
 * 	Roses are red
 * 		Violets are blue
 * 			I cried
 * 				And so did you
 */
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifndef rd
#define endl '\n'
#endif
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=2e18;
const int infi=1e9;
//const int mod2=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> oset;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
auto clk=clock();
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

const int N=2e5+5;
int a[N];
void solve() {
	string s;
	int n;
	cin>>n>>s;
	for(int i=n-1; i>=0; i--) {
		a[i+1]=(s[i]=='#')?0:1;
		a[i+1]+=a[i+2];
//		cout<<a[i+1]<<" ";
	}
	int ans=a[1],te=0;
	fr(i,1,n) {
		if(s[i-1]=='#')
			te++;
//		cout<<te+a[i]<<endl;
		ans=min(ans,a[i+1]+te);
	}
	cout<<ans<<endl;

}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


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

typedef long long ll;

int main(){
	ll w[11][11] = {};
	w[0][1] = w[1][0] = 1;
	w[2][0] = w[0][2] = 2;
	w[2][1] = w[1][2] = 3;
	w[3][0] = w[0][3] = 4;
	w[3][1] = w[1][3] = 8;
	w[3][2] = w[2][3] = 13;
	ll l = 23;
	for(int k = 4 ; k < 10 ; k ++){
		vector<ll> vec;
		vec.push_back(1);
		vec.push_back(2);
		while(vec.size() < k){
			vec.push_back(vec[vec.size()-2]+vec[vec.size()-1]+1);
		}
		int cnt = 0;
		for(int i = 1 ; i <= k-2 ; i ++){
			cnt += i;
		}
		for(int t = 0 ; t < k ; t ++){
			w[k][t] = w[t][k] = (l-cnt)*vec[t];
		}
		l = (l-cnt)*(vec[vec.size()-2]+vec[vec.size()-1]+1)-12;
	}
	int n;
	cin >> n;
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < n ; j ++){
			printf("%lld%c",w[i][j],(j==n-1)?'\n':' ');
		}
	}
}

Measured memory_bytes: 256
<?php
while ($line = fgets(STDIN)) {
    $line = rtrim($line);
    $data = explode(" ", $line);
    sort($data, SORT_NUMERIC );
    foreach($data as $value) {
        if ($value === end($data )) {
            echo $value . PHP_EOL;
        } else {
            echo $value . " ";
        }
    }
}

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

int main()
{
  int n; cin >> n;
  map<string, int> mp;
  rep(i, n)
  {
    string s;
    cin >> s;
    mp[s]++;
  }
  int mx = 0;
  for (auto p : mp)
    mx = max(mx, p.second);
  for (auto p : mp)
    if (p.second == mx)
      cout << p.first << endl;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main () {
  ll n;
  cin >> n;
  ll half = (ll) sqrt(n);
  ll ans = 0;
  for(int i = half; i > 0; i--){
    if(n%i == 0){
      ans = n/i + i - 2;
      break;
    }
  }
  printf("%lld\n", ans);
    return 0 ;
}

 


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;

#define print(x) cout << x << endl
#define input(x) cin >> x

typedef long long llint;

const int N = 200200;
const llint INF = 0x3f3f3f3f3f3f3fLL;

struct Plane {
    int x, y;
    int dir;
};

vector<int> xp[N][4];
vector<int> yp[N][4];
vector<int> lp[N * 2][4];
vector<int> rp[N * 2][4];

llint check(vector<int>& p1, vector<int>& p2) {
    llint mini = INF;
    sort(p1.begin(), p1.end());
    sort(p2.begin(), p2.end());

    for (auto u: p1) {
        auto iter = lower_bound(p2.begin(), p2.end(), u);
        if (iter == p2.end()) {
            continue;
        }
        mini = min(mini, 1LL * (*iter - u));
    }
    return 5LL * mini;
}

llint check2(vector<int>& p1, vector<int>& p2) {
    llint mini = INF;
    sort(p1.begin(), p1.end());
    sort(p2.begin(), p2.end());

    for (auto u: p1) {
        auto iter = lower_bound(p2.begin(), p2.end(), u);
        if (iter != p2.end()) {
            mini = min(mini, 1LL * abs(*iter - u));
        }
    }
    return 10LL * mini;
}


int main() {
    int n;
    input(n);

    int x, y;
    char dir[4];
    for (int i = 0; i < n; i++) {
        scanf("%d%d%s", &x, &y, dir);
        int u = 0;
        switch (dir[0]) {
            case 'U': u = 0; break;
            case 'R': u = 1; break;
            case 'D': u = 2; break;
            case 'L': u = 3; break;
            default: {
                 assert(false);
            }
        }

        xp[x][u].push_back(y);
        yp[y][u].push_back(x);

        rp[x + y][u].push_back(x);
        // print("rp" << ' ' << x + y << ' ' << u << ' ' << x);

        lp[x - y + N][u].push_back(x);
        // print("lp" << ' ' << x - y + N << ' ' << u << ' ' << x);
    }

    llint mini = INF;
    for (int i = 0; i < N; i++) {
        mini = min(mini, check(yp[i][1], yp[i][3]));
        mini = min(mini, check(xp[i][0], xp[i][2]));
    }
    for (int i = 0; i < N * 2; i++) {
        mini = min(mini, check2(rp[i][1], rp[i][0]));
        mini = min(mini, check2(rp[i][2], rp[i][3]));

        mini = min(mini, check2(lp[i][0], lp[i][3]));
        mini = min(mini, check2(lp[i][1], lp[i][2]));
    }

    if (mini >= INF) {
        puts("SAFE");
    } else {
        printf("%lld\n", mini);
    }

    return 0;
}



Measured memory_bytes: 138920
S = sorted(list(input()))
T = sorted(list(input()))[::-1]
if S == T:
    print("No")
    exit()
s = ""
t = ""
for x in S:
    s += x
for x in T:
    t += x
compare_place = sorted([s,t])
if compare_place[0] == s:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include <stdio.h>

int main(void)
{
    int c[3][3], x[3], y[3];
    int i, j, no = 0;

    for (i=0; i<3; i++) {
        for (j=0; j<3; j++) {
            scanf("%d", &c[i][j]);
        }
    }

    for (i=0; i<3; i++) {
        x[i]=c[i][1]-c[i][0];
        y[i]=c[i][2]-c[i][1];
    }
    if (x[0]!=x[1] || y[0]!=y[1] ||
        x[0]!=x[2] || y[0]!=y[2] ||
        x[1]!=x[2] || y[1]!=y[2])
    { no=1; goto result; }

    for (i=0; i<3; i++) {
        x[i]=c[1][i]-c[0][i];
        y[i]=c[2][i]-c[1][i];
    }
    if (x[0]!=x[1] || y[0]!=y[1] ||
        x[0]!=x[2] || y[0]!=y[2] ||
        x[1]!=x[2] || y[1]!=y[2])
    { no=1; goto result; }

result:
    if (no) printf("No\n");
    else    printf("Yes\n");

    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    int a,b,h;
    cin >> a >> b >> h;
    int ans = (a+b)*h/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 2005
#define PR pair<ll,ll>
#define F first
#define S second
using namespace std;
typedef long long ll;

ll n, ans, d[N][N];
pair<ll, ll> a[N];
int main() {
	ll i, j, k;
	cin >> n;
	for(i=0; i<n; i++) scanf("%lld", &a[i].F), a[i].S = i;
	sort(a, a+n, greater<PR>());
	for(i=0; i<n; i++) for(j=0; j<=i; j++) {
		k = n - (i-j);
		d[j][k-1] = max(d[j][k-1], d[j][k] + a[i].F * abs(a[i].S - (k-1)));
		d[j+1][k] = max(d[j+1][k], d[j][k] + a[i].F * abs(a[i].S - j));
	}
	for(i=0; i<=n; i++) ans = max(ans, d[i][i]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 26344
#include<iostream>
#include<algorithm>
#define MAX 100000

using namespace std;

int A[MAX], n;

int partition(int p, int r) {
  int x = A[r];
  int i = p - 1;
  int j = p;
  while (j < r) {
    if (A[j] <= x) {
      i++;
      swap(A[i], A[j]);
    }
    j++;
  }
  swap(A[i+1], A[r]);
  return i + 1;
}

int main(void) {
  int q;

  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i];

  q = partition(0, n - 1);

  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    if (i == q) cout << "[";
    cout << A[i];
    if (i == q) cout << "]";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3420
#include<iostream>
#include<cstdio>
 
using namespace std;
 
int sieve[1000002], cnt[1000002], a[1000002], n, m, i, j, g, t;
 
int gcd(int x, int y) {
	return y? gcd(y,x%y) : x;	
}
 
int main() {
	scanf("%d",&n);
	for(i=0;i<n;i++) {
		scanf("%d",a+i);
		if(a[i]>m) m=a[i];
		if(g) g=gcd(g,a[i]);
		else g=a[0];
	}
	if(g>1){
		printf("not coprime\n");
		return 0;
	}
	for(i=2;i<=m;i++) {
		if(sieve[i]==0) {
			sieve[i]=i;
            if((long long)i*i<=m)
			  	for(j=i*i;j<=m;j+=i){
					if(sieve[j]==0) sieve[j]=i;
			  	}
		}	
	}
	for(i=0;i<n;i++){
		j=a[i];
		while(j>1){
			t=sieve[j];
			cnt[t]++;
			if(cnt[t]>1) {
				printf("setwise coprime\n");
				return 0;
			}
			while(j%t==0) j/=t;
		}
	}
	printf("pairwise coprime\n");
	return 0;
}

Measured memory_bytes: 11244
n,k = map(int,input().split())
if(k >= n+1):
    print(1)
else:
    t = 0
    for i in range(k,n+2):
        d = n - i
        s1 = i * (i - 1) // 2
        s2 = n * (n + 1) // 2 - d * (d + 1) // 2
        t += s2 - s1 + 1
        t %= 10**9+7
    print(t)


Measured memory_bytes: 9116
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def main():
    N = I()
    L = LI()
    ans = 0
    
    for i in L:
        while True:
            if i % 2==0:
                i //=2
                ans+=1
            else:
                break
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 10520
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var sch = new List<int>[30];
            for (int i = 0; i < 30; i++) sch[i] = new List<int>();
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var t = int.Parse(line[0]);
                for (int j = 1; j <= t; j++)
                {
                    var w = int.Parse(line[j]) - 1;
                    sch[w].Add(i);
                }
            }
            var map = setMap(n);
            var ret = getAns(sch, map);
            Console.WriteLine(ret);
        }
    }
    public static long[] setMap (int n)
    {
        var ret = new long[n];
        for (int i = 0; i < n; i++)
        {
            var w = "1" + new string('0', i);
            ret[i] = Convert.ToInt64(w, 2);
        }
        return ret;
    }
    public static int getAns(List<int>[] sch, long[] map)
    {
        var n = map.Length;
        for (int i = 0; i < 30; i++)
        {
            var ret = 0L;
            foreach (var x in sch[i])
                ret = ret | map[x];
            if (check(ret, n)) return i + 1;
            foreach (var x in sch[i]) map[x] = ret;
        }
        return -1;
    }
    public static bool check(long a, int n)
    {
        var w = Convert.ToInt64(new string('1', n), 2);
        return w == a;
    }
}




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

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

    string S;

    cin >> S;

    if (S=="Sunny")
    {
        cout << "Cloudy" << "\n";
    } else if (S=="Cloudy") {
        cout << "Rainy" << "\n";
    } else {
        cout << "Sunny" << "\n";
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;


int main()
{
	int D = 0;
	int N, X;
	cin >> N >> X;

	int ans = 1;
	for (int i = 0; i < N; ++i)
	{
		int L;
		cin >> L;
		
		D += L;
		if (D <= X)ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

a, b, c, x = [int(input()) for i in range(4)]

n = 0
for an in range(a+1):
    for bn in range(b+1):
        for cn in range(c+1):
            if 500 * an + 100 * bn + 50 * cn == x:
                n += 1
print(n)

Measured memory_bytes: 39536
div=10**9+7
def modinv(a, m=div):
    b = m
    u = 1
    v = 0
    while b:
        t = a//b
        a -= t*b 
        a = a^b
        b = a^b
        a = a^b
        u -= t*v
        u = u^v
        v = u^v
        u = u^v
    u %= m 
    if u < 0: u += m
    return u

N,A,B,C=list(map(int,input().split()))
ncr_memo = {}

def ncr(n, r):
    if r == 0: return 1
    if n in ncr_memo:
        return ncr_memo[n]
    if n-1 in ncr_memo:
        ncr_memo[n] = (ncr_memo[n-1]*n*modinv(n-(N-1))) % div
        return ncr_memo[n]
    orn = n

    res = 1
    for i in range(1, r+1):
        res = res*n*modinv(i, div) % div
        n = n-1
    res %= div
    ncr_memo[orn] = res
    return res

for i in range(N, 2*N):
    ncr(i-1, N-1)

res = 0
inv100 = modinv(A+B)

reveven = (modinv(100-C)*100) % div
memoA = [1]*(N+1)
memoB = [1]*(N+1)

for i in range(1, N+1): memoA[i] = (memoA[i-1]*A*inv100) % div
for i in range(1, N+1): memoB[i] = (memoB[i-1]*B*inv100) % div

for i in range(N, 2*N):
    kitai1 = (
        (((ncr(i-1, N-1)*memoA[N]) % div)*memoB[i-N]) + 
        (((ncr(i-1, N-1)*memoB[N]) % div)*memoA[i-N])) % div
    res += kitai1*reveven*i % div

print(res % div)


Measured memory_bytes: 79324
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()

typedef unsigned long long ll;
int N;


int main() {

	cin.tie(0);
    ios::sync_with_stdio(false);

	cin >> N;
	vector<ll> A(N);
	vector<ll> B(N);
	vector<ll> C(N);
	for(int i=0; i<N; i++){
		cin >> A.at(i);
	}
	for(int i=0; i<N; i++){
		cin >> B.at(i);
	}
	for(int i=0; i<N; i++){
		cin >> C.at(i);
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	ll ans=0;
	for(int i=0; i<N; i++){
		ll b = B.at(i);
		ll a = lower_bound(ALL(A), b)-A.begin();
		ll c = C.end()-upper_bound(ALL(C), b);
		ans += a*c;
	}
	cout << ans << endl;

}


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

//// additional to sort by secind element
// Driver function to sort the vector elements
// by second element of pairs
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
 
int main() {
    int n,sum;
    cin >> n;
    vector<pair<int, int>> tasks; // pairのvector
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        // if use second element sort
        tasks.emplace_back(a, b);
    }

    sort(tasks.begin(), tasks.end(),sortbysec); 
    bool isyes = true;
    for (auto v : tasks)
    {
        sum += v.first;
        if (sum > v.second)
        {
            isyes = false;
            break;
        }
    }
    
    cout << (isyes ? "Yes" : "No") << endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <ctype.h>
#include <utility>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <list>
#include <sstream>
#include <iomanip>

using namespace std;

#define FORST(X,S,T) for(int X=(S); X<=(T); X++)  
#define RFORST(X,S,T) for(int X=(S); X>=(T); X--)  
#define FOR(X,XB) for(int X=0; X<(XB); X++)
#define RFOR(X,XB) for(int X=(XB)-1; X>=0; X--)
#define FORSTL(X,C) for(X=C.begin();X!=C.end();X++)
#define RFORSTL(X,C) for(X=C.rbegin();X!=C.rend();X++)
#define SQR(X) ((X)*(X))
#define MID(X,Y) (((X)+(Y))/2)
#define MIN(X,Y) (X=min((X),(Y)))
#define MAX(X,Y) (X=max((X),(Y)))
#define FILL(X,V) memset(X,V,sizeof(X))
#define FILE_R(X) freopen(X, "r", stdin)
#define FILE_W(X) freopen(X, "w", stdout)  
#define ERREQ(X,Y) (fabs((X)-(Y))<EPS)
#define DBGL cout << "here" << endl;
#define INITLISTS {L=0; FILL(adj,-1);}
#define SZ(X) (int)sizeof(X)
const double PI = acos(-1.0);
const double EPS = 1E-9;
const int INF = (int)1E9;
typedef long long LL;
typedef vector<int> VI;
typedef unsigned int uint;

#define MAXN 100005


int main(){
	string x, y;
	while(getline(cin, y)){
		FORST(k, 0, 25){
			
			x = y;
			FOR(i, x.length()){
				if(x[i]>='a' && x[i]<='z')
					x[i] = (k+x[i]-'a')%26+'a';
			}
			if(x.find("this")!=-1 || x.find("that")!=-1 || x.find("the")!=-1){
				cout << x << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1180
#include <iostream>

using namespace std;

int N;
const int MAX_N = 100;
int A[MAX_N];

void bubbleSort(int A[], int N) {
	bool flag = 1;
	int cnt = 0;
	while (flag) {
		flag = 0;
		for (int j = N - 1; j > 0; j--) {
			if (A[j] < A[j - 1]) {
				int v = A[j - 1];
				A[j - 1] = A[j];
				A[j] = v;
				flag = 1;
				cnt++;
			}
		}
	}
	for (int i = 0; i < N - 1; i++) {
		cout << A[i] << " ";
	}
	cout << A[N - 1] << endl;
	cout << cnt << endl;
}

int main() {

	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	bubbleSort(A, N);
	return 0;
}


Measured memory_bytes: 3112
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>


#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

int main()
{

  string n;
  cin >>n;
  if(n=="SUN")
  {
    cout<<7;
  }
  else  if(n=="MON")
  {
    cout<<6;
  }
    else  if(n=="TUE")
  {
    cout<<5;
  }
    else  if(n=="WED")
  {
    cout<<4;
  }
    else  if(n=="THU")
  {
    cout<<3;
  }
    else  if(n=="FRI")
  {
    cout<<2;
  }
    else  if(n=="SAT")
  {
    cout<<1;
  }
	return 0;
}





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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	int w,h,n; cin >> w >> h >> n;
	vector<pair<llong, llong> > p(n);
	for(auto &e : p)cin >> e.first >> e.second;
	llong ans = 0;
	for(int i = 1; i < n; i++){
		if((p[i-1].first < p[i].first && p[i-1].second < p[i].second) ||
		   (p[i-1].first > p[i].first && p[i-1].second > p[i].second) ){
			ans += max(abs(p[i].first-p[i-1].first), abs(p[i].second-p[i-1].second));
		}
		else{
			ans += abs(p[i].first-p[i-1].first)+abs(p[i].second-p[i-1].second);
		}
	}
	cout << ans << endl;


	return 0;
}




Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
 
int main(){
  int N,T,A;
  cin>>N>>T>>A;
  int H[N];
  rep(i,N) cin >> H[i];
  int ans, n;
  int d = 1e9;
  rep(i,N){
    n = abs(1000*A-(1000*T-H[i]*6));
    if (d > n){
      ans = i+1;
      d = n;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i <= n; i++)
int n, a[3], t;
double p[305][305][305];

int main(){
	scanf("%d", &n);
	rep(i,n-1){
		scanf("%d", &t);
		a[t-1]++;
	}
	rep(i,a[2]) rep(j,n-a[0]) rep(k,n) if(i+j+k) p[i][j][k] = (n + (i?p[i-1][j+1][k]*i:0) + (j?p[i][j-1][k+1]*j:0) + (k?p[i][j][k-1]*k:0)) / (i+j+k);
	printf("%.10lf\n", p[a[2]][a[1]][a[0]]);
}

Measured memory_bytes: 219392
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<string,int> P;
const ll MOD=1e9+7;
string s[2000];
int irui[2000][2000];
int jrui[2000][2000];
int main()
{
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++)
		cin>>s[i];
	for(int i=0;i<h;i++)
	{
		if(s[i][0]=='.')
			jrui[i][0]=1;
	}
	for(int i=0;i<w;i++)
		if(s[0][i]=='.')
			irui[0][i]=1;
	for(int i=0;i<h;i++)
	{
		for(int j=1;j<w;j++)
		{
			if(s[i][j]=='#')
				jrui[i][j]=0;
			else
				jrui[i][j]=jrui[i][j-1]+1;
		}
	}
	for(int j=0;j<w;j++)
	{
		for(int i=1;i<h;i++)
		{
			if(s[i][j]=='#')
				irui[i][j]=0;
			else
				irui[i][j]=irui[i-1][j]+1;
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=w-2;j>-1;j--)
		{
			if(jrui[i][j]>0 && jrui[i][j+1]>0)
				jrui[i][j]=jrui[i][j+1];
		}
	}
	for(int j=0;j<w;j++)
	{
		for(int i=h-2;i>-1;i--)
		{
			if(irui[i][j]>0 && irui[i+1][j]>0)
				irui[i][j]=irui[i+1][j];
		}
	}
	/*
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
			cerr<<jrui[i][j]<<" ";
		cerr<<endl;
	}*/
	int ans=0;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			if(s[i][j]=='.')
				ans=max(ans,irui[i][j]+jrui[i][j]-1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 35584
N = input()

if N[-1] == '2' or N[-1] == '4' or N[-1] == '5' or N[-1] == '7' or N[-1] == '9':
    print('hon')
elif N[-1] == '0' or N[-1] == '1' or N[-1] == '6' or N[-1] == '8':
    print('pon')
else:
    print('bon')

Measured memory_bytes: 8916
#include <iostream>
#include<algorithm>
using namespace std;
int main(void) 
{
	int n,x,i,j=0,count=0;
	scanf("%d%d",&n,&x);
	int a[n];
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	sort(a,a+n);
	while(x>0)
	{
	    x=x-a[j];
	    count++;
	    if(count==n)
	    break;
	    j++;
	}
	if(x>0)
	printf("%d",(n-1));
	else if(x==0)
	printf("%d",count);
	else
	printf("%d",count-1);
	return 0;
}




Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <sstream>
#include <list>
#include <map>

#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define Sort(x) sort(x.begin(),x.end());
#define ll long long 
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi <vector<vector<vector<int>>> 
#define vc vector<char> 
#define vvc vector<vector<char>>
#define vvvc vector<vector<vector<char>>> 
#define INF 2000000000

using namespace std;

int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0)break;

		rep(i, 0, n) {
			int a, b, c;
			cin >> a >> b >> c;

			if (a == 100 || b == 100 || c == 100) {
				cout << "A" << endl;
			}
			else if ((a + b) / 2.0 >= 90) cout << "A" << endl;
			else if ((a + b + c) / 3.0 >= 80)cout << "A" << endl;
			else if ((a + b + c) / 3.0 >= 70) cout << "B" << endl;
			else if ((a + b + c) / 3.0 >= 50 && (a >= 80 || b >= 80))cout << "B" << endl;
			else cout << "C" << endl;
		}
	}

	

	


	return 0;
}

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

typedef long long LL;


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

    string s;
    cin >> s;
    cout << s[0];
    cout << s.size() - 2;
    cout << s.back();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int,int>
#define ppb pop_back
#define orta ((bas+son)>>1)
#define st first
#define nd second
#define ll long long
#define N 200005
#define inf 100000000000000ll
#define MOD 1000000007
#define LOG 31
#define EPS 0.000000001
#define M 305
#define PI 3.14159265359
using namespace std;

int n, k, all;
int ans[N];

int mul(int x, int y) {

	return (ll) x * y % MOD;

}

int add(int x, int y) {

	x += y;
	while(x < 0)
		x += MOD;
	while(x >= MOD)
		x -= MOD;
	return x;

}

int fe(int base, int pow) {

	if(pow == 0)
		return 1;
	if(pow & 1)
		return mul(fe(base, pow - 1), base);
	int result = fe(base, pow >> 1);
	return mul(result, result);

}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	cin >> n >> k;
	for(int i = k; i >= 1; i--) {
		int tot_num = k / i;
		ans[i] = fe(tot_num, n);
		for(int j = i + i; j <= k; j += i) 
			ans[i] = add(ans[i], -ans[j]);
		all = add(all, mul(ans[i], i));
	}
	cout << all;

}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
const int N=6060;
int f[N][N*2],mod,n,m,ans;
int main(){
	scanf("%d%d",&n,&mod);m=n;n*=3;f[n][N]=1;
	for(int i=n;i;i--){
		for(int j=-(n-i);j<=(n-i);j++){
			if(i>=3)f[i-3][j+N]=(f[i-3][j+N]+1ll*f[i][j+N]*(i-1)%mod*(i-2))%mod;
			if(i>=2)f[i-2][j+1+N]=(f[i-2][j+1+N]+1ll*f[i][j+N]*(i-1))%mod;
			f[i-1][j-1+N]=(f[i-1][j-1+N]+f[i][j+N])%mod;
		}
	}
	for(int i=-n;i<=0;i++)if(i%3==0)(ans+=f[0][i+N])%=mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 284928
#include<bits/stdc++.h>
using namespace std;
int dp[20005],tmp[20005];
int main()
{
    int a,b,c,x;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    int ans=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==x){
                    ans++;
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  int n,a,b; cin>>n>>a>>b;
  int m,p,q,r,s,t,ans=0;
  for(int i=1;i<=n;i++){
	p=i/10000; m=i%10000;
    q=m/1000; m=m%1000;
    r=m/100; m=m%100;
    s=m/10;
    t=m%10;
    if(a<=p+q+r+s+t and p+q+r+s+t<=b) ans+=i;
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

const int Nmax = 2e5 + 10;
const int Mod = 1e9 + 7;
const int oo = 1e9;

int n;
int dp[Nmax], aint[4 * Nmax], nor[Nmax], pre[Nmax];
pair <int, int> cost[Nmax];
vector <int> L[Nmax];

void Update(int node, int left, int right, int x, int y)
{
    if(left == right)
    {
        aint[node] = y;
        return ;
    }

    int mid = (left + right) / 2;
    if(x <= mid) Update(2*node, left, mid, x, y);
    else Update(2*node+1, mid + 1, right, x, y);

    aint[node] = max(aint[2*node], aint[2*node+1]);
}

int Query(int node, int left, int right, int x, int y)
{
    if(x <= left && right <= y)
        return aint[node];

    int answer = -oo;
    int mid = (left + right) / 2;

    if(x <= mid) answer = max(answer, Query(2*node, left, mid, x, y));
    if(y >= mid + 1) answer = max(answer,Query(2*node+1, mid + 1, right, x, y));

    return answer;
}

void Dfs(int nod, int tata)
{
    if(pre[nod] == 0) dp[nod] = 1;
    else dp[nod] = Query(1, 1, n, 1, pre[nod]) + 1;

    Update(1, 1, n, nor[nod], dp[nod]);
    for(auto i : L[nod])
    {
        if(i == tata) continue;
        Dfs(i, nod);
    }

    Update(1, 1, n, nor[nod], 0);
}

void Make_max(int nod, int tata)
{
    dp[nod] = max(dp[nod], dp[tata]);

    for(auto i : L[nod])
    {
        if(i == tata) continue;
        Make_max(i, nod);
    }
}

int main()
{

    #ifndef ONLINE_JUDGE

        ifstream cin("test.in");
        ofstream cout("test.out");
    #endif // ONLINE_JUDGE


    cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> cost[i].first, cost[i].second = i;

    sort(cost + 1, cost + n + 1);
    for(int i = 1; i <= n; i++)
    {
        nor[cost[i].second] = i;
        if(cost[i].first == cost[i - 1].first) pre[cost[i].second] = pre[cost[i - 1].second];
        else pre[cost[i].second] = i - 1;
    }

    int x, y;
    for(int i = 1; i < n; i++)
    {
        cin >> x >> y;
        L[x].push_back(y);
        L[y].push_back(x);
    }

    Dfs(1, 0);
    Make_max(1, 0);

    for(int i = 1; i <= n; i++)
        cout << dp[i] << "\n";

    return 0;
}


Measured memory_bytes: 32032
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<queue>
#include<deque>
#include<stack>
#include<ctime>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<utility>
#include<cctype>
#include<bitset>
#include<list>
using namespace std;

long long n,m;

int main(){
	cin>>n>>m;
	if(n==1&&m==1) cout<<1<<endl;
	else if(n==1||m==1) cout<<n*m-2<<endl;
	else cout<<(n-2)*(m-2)<<endl;
	return 0;
}

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

int main() {
  int k,x;
  cin >> k >> x;
  //vector<int> black(2*k-1);
  for(int i=x-k+1;i<=x+k-1;i++){
    cout << i;
    if(i==x+k-1) return 0;
    cout << ' ';
  }
 
    //black.at(i) ==
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;
use std::str::FromStr;
use std::cmp::Reverse;

#[allow(dead_code)]
type Error = Box<dyn std::error::Error>;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

struct Scanner {
    buff: Vec<String>,
    pos: usize,
}


#[allow(dead_code)]
impl Scanner {
    pub fn new() -> Self {
        Scanner {
            buff: Vec::new(),
            pos: 0,
        }
    }

    pub fn next<T: FromStr>(&mut self) -> T {
        while self.buff.len() <= self.pos {
            self.pos = 0;
            self.buff = read_line().split_whitespace().map(|s| s.to_owned()).collect();
        }

        let result = self.buff[self.pos].parse::<T>();
        self.pos += 1;
        result.ok().unwrap()
    }

    pub fn next_line(&mut self) -> String {
        let result  = read_line().trim().to_owned();
        self.buff.clear();
        self.pos = 0;

        result
    }

    pub fn next_vec<T: FromStr>(&mut self) -> Vec<T> {
        self.buff.clear();
        self.pos = 0;
        read_line().trim().split_whitespace().map(|s| s.parse().ok().unwrap()).collect()
    }
    
    pub fn next_line_chars(&mut self) -> Vec<char> {
        let result  = read_line().trim().chars().collect();
        self.buff.clear();
        self.pos = 0;

        result
    }
}


fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.next();
    let s = sc.next_line_chars();

    let initials = vec![['S', 'S'],['S', 'W'],['W', 'S'],['W', 'W']];
    let mut ans = None;
    for initial in initials.iter() {
        let mut tmp = Vec::with_capacity(n);
        tmp.extend_from_slice(initial);
        for i in 1..n-1 {
            if (tmp[i] == 'S' && s[i] == 'o') || (tmp[i] == 'W' && s[i] == 'x') {
                tmp.push(tmp[i-1]);
            } else {
                if tmp[i-1] == 'S' {
                    tmp.push('W');
                } else {
                    tmp.push('S');
                }
            }
        }
        if (tmp[n-1] == 'S' && s[n-1] == 'o') || (tmp[n-1] == 'W' && s[n-1] == 'x') {
            if tmp[0] != tmp[n-2] {
                continue;
            }
        } else {
            if tmp[0] == tmp[n-2] {
                continue;
            }
        }
        if (tmp[0] == 'S' && s[0] == 'o') || (tmp[0] == 'W' && s[0] == 'x') {
            if tmp[1] == tmp[n-1] {
                ans = Some(tmp);
                break;
            }
        } else {
            if tmp[1] != tmp[n-1] {
                ans = Some(tmp);
                break;
            }
        }
    }
    match ans {
        Some(v) => { println!("{}", v.iter().collect::<String>()); }
        None => { println!("-1"); }
    }
}


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

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    
    int x1,x2,x3;
    
    if (b < a && c < a) {
        if (b < c) {
            cout << b << " " << c << " " << a << endl;
        } else {
            cout << c << " " << b << " " << a << endl;
        }
    } else if (b < c) {
        if (a < b) {
            cout << a << " " << b << " " << c << endl;
        } else {
            cout << b << " " << a << " " << c << endl;
        }
    } else {
        if (a < c) {
            cout << a << " " << c << " " << b << endl;
        } else {
            cout << c << " " << a << " " << b << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <algorithm>

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

using namespace std;

typedef long long int lli;

const lli mod = 1000000007;

lli power(lli n, lli x) {
    if (x == 0) return 1;
    if (x % 2) {
        return (power(n, x - 1) * n) % mod;
    } else {
        lli c = power(n, x / 2);
        return (c * c) % mod;
    }
}

vector<lli> p;

lli nCr(int n, int r) {
    if (n < 0 || r < 0 || n < r) return 0;
    lli res = p[n];
    res = (res * power(p[r], mod - 2)) % mod;
    res = (res * power(p[n - r], mod - 2)) % mod;
    return res;
}

int main () {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    REP (i, 0, a.size()) cin >> a[i];
    p = vector<lli>(n + 1, 1);
    REP (i, 1, p.size()) {
        p[i] = (p[i - 1] * i) % mod;
    }


    int size = 0;
    {
        vector<int> nlist(n, 0);
        REP (i, 0, a.size()) nlist[a[i] - 1]++;
        int hastwo;
        REP (i, 0, n) if (nlist[i] == 2) hastwo = i + 1;
        int index = 0;
        int twoin[2] = {0, 0};
        REP (i, 0, a.size()) if (a[i] == hastwo) twoin[index++] = i;
        size = twoin[1] - twoin[0] - 1;
    }

    cout << n << endl;  // 1

    REP (i, 1, n) {
        lli base = nCr(n, i + 1);
        lli use1 = (nCr(n - 1, i) - nCr(n - 1 - size, i) + mod) % mod;
        lli use2 = nCr(n - 1, i - 1);
        cout << (base + (use1 + use2) % mod) % mod << endl;
       //cout << base << ' ' << use1 << ' ' << use2 << endl;
    }

    cout << 1 << endl;  // n + 1
    return 0;
}


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

int main() {
  int N, A, B;
  cin >> A;
  N=9;
  B=0;
  int C;
  
  for(int i=0;i<N;i++){
    C=pow(10,i);
    B += (A/C)%10;
  }
  
  if(A%B==0){
    cout << "Yes" <<endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
  
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
  
using namespace std;
  
class Point{
public:
  double x,y;
  
  Point(double x = 0,double y = 0): x(x),y(y){}
  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  bool operator < (const Point& p) const{ return !equals(x,p.x)?x<p.x:(!equals(y,p.y)&&y<p.y); }
  bool operator == (const Point& p)const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; }
  
};
  
Point rotate(Point a,double rad){ return Point(cos(rad)*a.x - sin(rad)*a.y,sin(rad)*a.x + cos(rad)*a.y); }
  
const double DINF = 1e20;
int n;
Point ps[2][1010],tmp[1010];
  
inline double getDist(Point p){ return sqrt(p.x*p.x+p.y*p.y); }
inline bool comp_arg(const double &a,const double &b) { return !equals(a,b) && a < b; }
  
void compute(){
  Point grv[2] = {Point(),Point()};
  rep(i,2) rep(j,n) grv[i] = grv[i] + ps[i][j];
  rep(i,2) grv[i] = grv[i] / (double)n;
  rep(i,2) rep(j,n) ps[i][j] = ps[i][j] - grv[i];
  sort(ps[0],ps[0]+n);
  
  vector<double> arg_buf;
  rep(i,n) {
    double dist[2] = { getDist(ps[0][0]), getDist(ps[1][i]) };
    if( !equals(dist[0],dist[1]) ) continue;
    double arg = atan2(ps[0][0].y,ps[0][0].x) - atan2(ps[1][i].y,ps[1][i].x);
    while( arg < 0 ) arg += 2*M_PI;
    arg_buf.push_back(arg);
  }
  sort(arg_buf.begin(),arg_buf.end(),comp_arg);
  arg_buf.erase(unique(arg_buf.begin(),arg_buf.end()),arg_buf.end());

  double mini = DINF;  
  rep(i,(int)arg_buf.size()){
    double arg = arg_buf[i];
    rep(j,n) tmp[j] = rotate(ps[1][j],arg);
    sort(tmp,tmp+n);
    bool failed = false;
    rep(j,n) if( !( tmp[j] == ps[0][j] ) ) { failed = true; break; }
    if( !failed ) mini = min(mini,min(arg,2*M_PI-arg));
  }
  printf("%.11lf\n",mini);
}
  
int main(){
  while( cin >> n, n ){
    rep(i,2) rep(j,n) cin >> ps[i][j].x >> ps[i][j].y;
    compute();
  }
  return 0;
}

Measured memory_bytes: 1408