akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
readInt = fst . fromJust . B.readInt
readInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
readIntegers = map (fst . fromJust . B.readInteger) . B.words <$> B.getLine :: IO [Integer]
read2dInts = map (map (fst . fromJust . B.readInt) . B.words) . B.lines <$> B.getContents

main :: IO ()
main = do
  n <- readLn :: IO Int
  -- abs <- replicateM n $ (\(a:b:_) -> (a,b)) . map read . words <$> getLine :: IO [(Int, Int)]
  abs <- map (\(a:b:_) -> (a,b)) <$> read2dInts :: IO [(Int, Int)]

  putStrLn $ if solve abs then "Yes" else "No"

solve :: [(Int, Int)] -> Bool
solve abs = all (\(x, y) -> x <= y) $ scanl' f (0, 0) sorted
  where
    sorted = sortOn snd abs
    f :: (Int, Int) -> (Int, Int) -> (Int, Int)
    f (a, b) (x, y) = (a + x, y)

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

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    while(!(a==0&&b==0)){
        if(a>b){
            int t;
            t=a;
            a=b;
            b=t;
        }
        printf("%d %d\n",a,b);
        scanf("%d %d",&a,&b);
    }
}


Measured memory_bytes: 3132
#include<iostream>
using namespace std;
int main(){
  int A,B,C,X;
  cin>>A>>B>>C>>X;
  int res=0;
  for (int a=0;a<=A;++a){
    for (int b=0;b<=B;++b){
      for (int c=0;c<=C;++c){
        int total=500*a+100*b+50*c;
        if (total==X) ++res;
      }
    }
  }
  cout<<res<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int h,n;
int main(){
    cin>>h>>n;
    vector<int> a(n,0),b(n,0);
    rep(i,n) cin>>a[i]>>b[i];
    vector<vector<int>> dp(n+1,vector<int>(h+1,inf));
    //配るDP
    for(int i=0;i<=n;i++) dp[i][0]=0;
    //for(int j=0;j<=)
    for(int i=0;i<n;i++){
        if(i!=0){
            for(int j=0;j<h+1;j++) dp[i][j]=min(dp[i][j],dp[i-1][j]);
        }
        for(int j=0;j<h+1;j++){
            int nj = min(j+a[i],h);
            dp[i][nj]=min(dp[i][nj],dp[i][j]+b[i]);
        }
    }
    /*
    rep(i,n+1){
        rep(j,h+1) cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    cout<<dp[n-1][h]<<endl;
    return 0;
}


Measured memory_bytes: 39552
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 100000
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
#define ggr getchar();getchar();return 0
using namespace std;
int n;
char a[510][510];
signed main() {
	cin>>n;
	bool pos=false;
	rep(i,n){
		rep(j,n){
			cin>>a[i][j];
			if(a[i][j]=='#')pos=true;
		}
	}
	if(!pos){
		cout<<-1<<endl;
		return 0;
	}
	int ans=INF;
	rep(i,n){
		bool f=false;
		int cnt=0;
		rep(j,n){
			if(a[j][i]=='#')f=true;
		}
		rep(j,n){
			if(a[i][j]=='.')cnt++;
		}
		if(!f)cnt++;
		ans=min(ans,cnt);
	}
	rep(i,n){
		bool f=false;
		rep(j,n)if(a[j][i]=='.')f=true;
		if(f)ans++;
	}
	cout<<ans<<endl;
	ggr;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
#include<stdio.h>
#include<climits>

// Binary heap structure.
int *H;  // H[1], H[2], ... , H[n], H[n+1], H[n+2], ... , H[2n].

// keep on condition: H[x] = min(H[2x], H[2x+1]). O(log(n)).
void update(int x, int y, int n)
{
    x++;
    for(x += n, H[x] = y; x > 1; x >>= 1) // x >>= 1 means x /= 2.
        H[x >> 1] = min(H[x], H[x ^ 1]);  // x ^ 1: x = 2m then x + 1, x = 2m + 1 then x - 1.
    return;
}

// binary search. O(log(n)). very fast.
int find(int x, int y, int n)
{
    int least = INT_MAX; // x, y starts from leaf, usually.
    x++; y++;
    for(x += n, y += n; x <= y; x = ((x + 1) >> 1), y = ((y - 1) >> 1)){
        if(x & 1){ least = min(least, H[x]); }
        if(!(y & 1)){ least = min(least, H[y]); }
    }
    return least;
}

int main()
{
    H = new int [1 << 18];
    int n, q;
    scanf("%d %d", &n, &q);
    int cmd, x, y;

    fill(H, H + 2 * n + 1, INT_MAX);

    while(q){
        scanf("%d %d %d", &cmd, &x, &y);
        if(cmd){
            printf("%d\n", find(x, y, n));
        }else{
            update(x, y, n);
        }
        q--;
    };
    delete [] H;
    return 0;
}

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

long long int H, W, N, B[11451], a, s, i, j;

int main(){
    scanf("%lld%lld%lld", &H, &W, &N);
    ++*B;
    for(; i < N; ++i){
        scanf("%lld", &a);
        s += a;
        ++B[s];
    }
    partial_sum(B, B + H * W, B);
    for(i = 0; i < H; ++i){
        for(j = 0; j < W; ++j){
            cout << B[W * i + (i & 1 ? W - j - 1 : j)] << (j == W - 1 ? "\n" :" ");
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // not prime num
            return false;
        }
    }
    // prime num
    return true;
}

struct edge{
    int cost, to;

    edge(int in_cost, int in_to){
        cost=in_cost;
        to=in_to;
    }
    bool operator<(const edge &a) const
    {
        return cost > a.cost;
    }
};

int main() {
    ll K,A,B;
    cin >> K >> A >> B;
    ll ans=1LL;

    // 1円に換えてからビスケットを得ても損をする場合
    if(A>=B-2){
        cout << 1+K << endl;
        return 0;
    }

    ans+=min(A-1, K);
    ll cnt=min(A-1,K);

    K-=cnt;
    ans+=(K/2)*(B-A)+(K%2);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*

// https://atcoder.jp/contests/abc141/submissions/7537431
// ↑のTLE解消できるかテスト
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextLong()
    val q = sc.nextInt()
    val a = (0 until q).map { sc.next().toInt() }
    println(problem141c(n, q, k, a))
}

fun problem141c(n: Int, q: Int, k: Long, a: List<Int>): String {
    val dp =  LongArray(n)
    val ans = StringBuffer()
    for (i in 0 until q) {
        val winner = a[i]
        dp[winner - 1] = dp[winner - 1] + 1
    }
    for (element in dp) {
        ans.append(if (q - k >= element) "No" else "Yes")
        ans.append(System.lineSeparator())
    }
    return ans.toString()
}


Measured memory_bytes: 48456
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        String s = sc.next();
        int placeOfA = s.indexOf("A");
        int placeOfZ = s.lastIndexOf("Z");
        String result = s.substring(placeOfA, placeOfZ + 1);
        System.out.println(result.length());

    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}

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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int N;
    ist >> N;

    vector<long long> A;

    for (int i = 0; i < N; i++)
    {
        long long input;
        ist >> input;
        A.emplace_back(input);
    }

    /* ------- 計算 ------- */

    long long min_tall = A.at(0);
    long long bastion_height_sum = 0;

    for (auto a : A)
    {
        if (a < min_tall)
        {
            bastion_height_sum += min_tall - a;
        }

        if( a > min_tall) {
            min_tall = a;
        }
    }

    ost << bastion_height_sum << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 5312
#!/usr/bin/env python3

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    ab = [list(map(int, input().split())) for _ in range(3)]
    count = [0] * 4
    for a, b in ab:
        count[a - 1] += 1
        count[b - 1] += 1
    if count.count(3) >= 1:
        print('NO')
    else:
        print("YES")


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 61928
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		double T = (double) Integer.parseInt(tokens[0]);
		double X = (double) Integer.parseInt(tokens[1]);
		System.out.println((T / X));
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <map>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    map<int, int> m;
    for (int i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;
        if (m.find(s) != m.end()) {
            if (m[s] != c) {
                cout << "-1" << endl;
                return 0;
            }
        }
        m[s] = c;
    }
    if (N == 3) {
        if (m.find(1) != m.end()) {
            if (m[1] == 0) {
                cout << "-1" << endl;
                return 0;
            }
            cout << m[1];
        }
        else cout << "1";
        if (m.find(2) != m.end()) cout << m[2];
        else cout << "0";
        if (m.find(3) != m.end()) cout << m[3];
        else cout << "0";
    } else if (N == 2) {
        if (m.find(1) != m.end()) {
            if (m[1] == 0) {
                cout << "-1" << endl;
                return 0;
            }
            cout << m[1];
        }
        else cout << "1";
        if (m.find(2) != m.end()) cout << m[2];
        else cout << "0";
    } else {
        if (m.find(1) != m.end()) cout << m[1];
        else cout << "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>
    #include <ext/pb_ds/detail/standard_policies.hpp>
 
    using namespace std;
    using namespace __gnu_pbds;
 
    #define endl "\n"
    #define fi first
    #define se second
    #define pb push_back
    #define int long long 
    #define ll long long
    #define ld long double
    #define pii pair<ll,ll>
 
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define For(i,n) for(ll i=0;i<n;i++)
 
    #define what(x) cerr << #x << " is " << x << endl;
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
 
    typedef tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> omultiset;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> oset;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> oset1;
 
/*.....................................................................................................................*/
 
    const ll mod=(ll)1e9+ 7;
 
    ll add(ll x,ll y) {return (x+y)%mod;}
    ll mult(ll x, ll y){return ((x%mod )* (y%mod)) % mod;}
 
    long long binpow(long long x, long long p) 
    {
        if (p == 0) {return 1;} 
    	if (p == 2 || (p & 1)) {return mult(x, binpow(x, p - 1));}
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}
 
    //A.erase(unique(A.begin(),A.end()),A.end());
    double pi=3.141592653589793238462641;
    ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    const ll  man  =   (int)200005   ,  inf   =   1e18;
 
 
/*......................................................................................................................*/

int n,m;
vector<int>adj[man];
vector<vector<int>>dp(man,vector<int>(2));
void dfs(int v,int p)
{
    dp[v][0]=1;
    dp[v][1]=1;
    for(int u:adj[v])
    {
        if(u==p)continue;
        dfs(u,v);
        (dp[v][0]*=(dp[u][0]+dp[u][1]))%=mod;
        // (dp[v][0]*=dp[u][1])%=mod;
        (dp[v][1]*=dp[u][0])%=mod;
    }
}
signed main()
{
    fast;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1,-1);
    cout<<(dp[1][0]+dp[1][1])%mod<<endl;
    
}   

Measured memory_bytes: 28716
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	long double A, B;
  	cin>>A>>B;
  	ll ans=A*B;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3744
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;

int main(){
    int n, m, sum = 0;
    cin >> n;
    vector<int> t(n);
    REP(i, n){
        cin >> t[i];
        sum += t[i];
    }
    cin >> m;

    REP(i, m){
        int p, x, ans = 0;
        cin >> p >> x;
        ans = sum - t[p - 1] + x;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
X = int(raw_input())
 
def check_prime(X):
    import math
    s = int(math.floor(math.sqrt(X)))
    for a in range(2, s+1):
        if X % a == 0:  
            return False
    return True
 
while True:
    if check_prime(X): break
    X += 1
 
print X

Measured memory_bytes: 2568
n=int(input())
a=list(map(int,input().split()))
left_ruiseki=[a[0]]
for i in range(1,n):
    left_ruiseki.append(left_ruiseki[i-1]+a[i])
a.reverse()
right_ruiseki=[a[0]]
for i in range(1,n):
    right_ruiseki.append(right_ruiseki[i-1]+a[i])

ans=10000000000
for i in range(n-1):
    ans=min(ans,abs(left_ruiseki[i]-right_ruiseki[-i-2]))
print(ans)

Measured memory_bytes: 115056
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] all = new int[n];
		int sum = 0;
		boolean flag = true;

		for(int i = 0; i < n; i++) {
			all[i] = sc.nextInt();
			sum += all[i];
			if(all[i] % 10 != 0) {
				flag = false;
			}
		}

		Arrays.sort(all);
		int calc = sum;
		int count = 0;
		while(calc % 10 == 0 && count < n) {
			if(count > 0) {
				calc = sum;
			}
			calc -= all[count];
			count++;
		}

		if(flag) {
			System.out.println(0);
		} else {
			System.out.println(calc);
		}

	}

}


Measured memory_bytes: 23252
def depth_first_search a_list, st, v_group, cnt
  while st.length > 0
    i = st.last
    v_group[i] = cnt
    found = false
    a_list[i].each do |a|
      unless v_group[a]
        st.push(a)
        found = true
        break
      end
    end
    st.pop unless found
  end
end

users_count, n = gets.chomp.split(' ').map(&:to_i)

a_list = Array.new(users_count).map{|m| []} # 隣接リスト
n.times do
  i, j = gets.chomp.split(' ').map(&:to_i)
  a_list[i].push(j)
  a_list[j].push(i)
end

v_group = Array.new(users_count, false) # 頂点のグループ分け
cnt = 1
0.upto(users_count - 1) do |i|
  next if v_group[i]
  depth_first_search(a_list, [i], v_group, cnt)
  cnt += 1
end
q_cnt = gets.chomp.to_i
ans = []
q_cnt.times do
  f1, f2 = gets.chomp.split(' ').map(&:to_i)
  ans.push((v_group[f1] && v_group[f1] == v_group[f2]) ? 'yes' : 'no')
end
puts ans.join("\n")


Measured memory_bytes: 17680
/*  ex3_3
    yy8332  */

#include <stdio.h>

int main(void){
  int number,base_number;
  int i = 1;

  //入力受け取り
  scanf("%d %d", &number, &base_number);

  //何桁か求める
  while(number >= base_number){
    number = number / base_number;
    i++;
  }

  //出力
  printf("%d\n",i);

return 0;
}


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

ll a[7];

int main(){
  rep(i,7) cin>>a[i];
  ll ans=0;
  if(a[0]!=0&&a[3]!=0&&a[4]!=0){
    rep(i,2){
      ll I=(a[0]-i)/2*2;
      ll J=(a[3]-i)/2*2;
      ll L=(a[4]-i)/2*2;
      ans=max(ans,I+J+L+3*i);
    }
  }else ans+=a[0]/2*2+a[3]/2*2+a[4]/2*2;
  cout<<ans+a[1]<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a = []

def g(x):
    for i in range(-1,2):
        last = int(x[-1]) + i
        if int(''.join(x)) <= 3234566667 and last != -1 and last != 10:
            y = copy.copy(x)
            y.append(str(last))
            f(y)
    return

def f(x):
    a.append(int(''.join(x)))
    g(x)
    return

f(['1'])
f(['2'])
f(['3'])
f(['4'])
f(['5'])
f(['6'])
f(['7'])
f(['8'])
f(['9'])
a.sort()

def main():
    n = inp()
    print(a[n-1])
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 110896
<?php
list($N, $D) = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$ans = 0;
for ($i = 0; $i < $N; ++$i) {
    list($X, $Y) = array_map(function ($n) {
        return (int)$n;
    }, explode(' ', fgets(STDIN)));
    if (sqrt($X ** 2 + $Y ** 2) <= $D) {
        $ans += 1;
    }
}
echo $ans;

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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

int main() {
    int N;
    cin >> N;
    int cnt = 0;
    for (int i = 1; i <= N; i++) {
        if(i % 2 == 1){
            cnt++;
        }
    }
    printf("%.10f\n",(double)((double)cnt / (double)N));
}

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

int main(){
    int n; cin >> n;
    vector <int> neg, s(n);
    long long ans=0;
    for(int i = 0; i < n; i++){
        cin >> s[i];
        if(s[i] >= 0) ans += s[i];
        else{
            s[i] *= -1;
            neg.push_back(s[i]);
            ans += s[i];
        }
    }
    if(neg.size() % 2){
        sort(s.begin(), s.end());
        ans -= 2 * s[0];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int n;
    cin >> n;
    int h[n-1], dp[n-1];
    for (int i=0; i<n; i++) { cin >> h[i]; }

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i=2; i<n; i++) {
        dp[i] = min(
            dp[i-2] + abs(h[i-2] - h[i]),
            dp[i-1] + abs(h[i-1] - h[i])
        );
    }
    cout << dp[n-1] << endl;
}

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

#define NL '\n'
#define C char
#define D double
#define F float
#define S string
#define PI (2.0*acos(0.0))
#define sfi(x) scanf("%d",&x)
#define sfl(x) scanf("%I64d",&x)
#define sfd(x) scanf("%lf",&x)
#define sfs(x) scanf("%s",x)
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
int main()
{
    int n,i=0,j=0;
    sfi(n);
    S s1,s2;
    cin>>s1>>s2;
    while(1)
    {
        if(i==s1.size() && j==s2.size()) break;
        cout<<s1[i]<<s2[j];
        i++;
        j++;
    }
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int D, N;
  int ans;
  cin >> D >> N;
  if(N > 0 && N <= 100){
    if(D == 0){
      ans = 1;
    }else if(D == 1){
      ans = 100;
    }else if(D == 2){
      ans = 10000;
    }else{
      return 0;
    }
  }else{
    return 0;
  }
  if(N == 100){
    //N = 100の時はもう一回割れるじゃん！盲点だった
    N = 101;
  }
  ans = ans * N;
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int E = sc.nextInt();
		int[] c = new int[N];
		for(int i=0;i<N;i++) {
			c[i] = sc.nextInt();
		}
		int ans = -1;
		loop:for(int i=0;i<N;i++) {
			if(c[i] > T+E) continue;
			for(int t=c[i];t<=T+E;t+=c[i]) {
				if(T-E <= t && t<= T+E) {
					ans = i+1;
					break loop;
				}
			}
		}
		System.out.println(ans);
	}	
}





Measured memory_bytes: 26468
using System;
class Program
{
	static void Main()
	{
	string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
	long n = long.Parse(input[0]);
	long x = long.Parse(input[1]);
	long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      
    long answer = nums[0] - x;
      if(answer < 0) answer *= -1;
    for(long i = 1; i < nums.Length; i++)
    {
    long sa = nums[i] - x;//差
      if(sa < 0) sa*=-1;
    answer = Gcd(answer,sa);
    }
      
      Console.WriteLine(answer);
      
    }

    static long Gcd(long a, long b) 
    {//引数a,bの最大公約数を返す
         if (a < b)
             return Gcd(b, a);//入れ替え
         while (b != 0) 
         {
             long c = a % b;
             a = b;
             b = c;
         }
         return a;
     }

	
}

Measured memory_bytes: 18784
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

int MOD=1000000007;

vector<long long> factorial(int N){
    vector<long long> ret(N+1,1);
    for(int i=1; i<=N; i++){
        ret[i]=ret[i-1]*i%MOD;
    }
    return ret;
}

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

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    a.push_back(MOD);
    b.push_back(MOD);

    vector<long long> fact=factorial(100000);

    int j=0;
    int k=0;
    int diff=0;
    long long ans=1;
    for(int i=0; i<N*2; i++){
        if(a[j]<b[k]){
            if(diff<0){
                ans*=-diff;
            }
            diff++;
            j++;
        }
        else{
            if(diff>0){
                ans*=diff;
            }
            diff--;
            k++;
        }
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1776
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define db double
#define ld long db
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}

const int N=1e5+5;
int a[N],n,p,v,m,b[N];
inline bool chk(ll mid){
	if(a[mid]>=a[n-p+1])return 1;
	ll tot=m*v,x=a[mid]+m,y=mid+1;
	tot-=mid*m;
	if(tot<=0)return x>=a[n-p+1];
	if(x<a[n-p+1])return 0;
	rep(i,mid,n)b[i]=a[i];
	while(tot>0&&y<=n){
		if(x-b[y]<=tot){
			tot-=x-b[y];b[y]=x;
		}
		else{
			b[y]+=tot;tot=0;
		}
		++y;
	}//if(mid<=3)cout<<mid<<' '<<tot<<endl;
	if(tot<=0)return x>=b[n-p+1];
	ll cur;
	REP(i,n,mid+1){
		if(b[i]-a[i]<m){
			cur=m-(b[i]-a[i]);
			if(cur<=tot){
				tot-=cur;b[i]+=cur;
			}else b[i]+=tot,tot=0;
		}
		if(tot<=0)break;
	}
	if(tot>0)return 0;
	return x>=b[n-p+1];
}

signed main()
{
	n=read();m=read();v=read();p=read();
	rep(i,1,n)a[i]=read();
	sort(a+1,a+n+1);
	ri l=1,r=n,res=n;
	while(l<=r){
		ri mid=(l+r)>>1;
		if(chk(mid))res=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",n-res+1);
	return 0; 
}

Measured memory_bytes: 1792
# include <stdio.h>
int main(void)
{
	int a, b, syou, sa, seki, waru;
	char op;
	
	while (1) {
		scanf("%d %c %d", &a, &op, &b);

		if (op == '+') {
			syou = a + b;
			printf("%d\n", syou);
		}
		else if (op == '-') {
			sa = a - b;
			printf("%d\n", sa);
		}
		else if (op == '*') {
			seki = a * b;
			printf("%d\n", seki);
		}
		else if (op == '/') {
			waru = a / b;
			printf("%d\n", waru);
		}
		else {
				break;
			}
	}

	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

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

		// standard input
		int height = sc.nextInt();
		int width = sc.nextInt();

		// solve
		String result = null;
		for (int i = 0; i < height; i++) {
			for (int j = 0; j < width; j++) {
				if ("snuke".equals(sc.next())) {
					result = Character.toString((char) (j + 65)) + (i + 1);

					// standard output
					System.out.println(result);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 9808
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val sx = sc.nextInt
  val sy = sc.nextInt
  val tx = sc.nextInt
  val ty = sc.nextInt

  val dx = tx - sx
  val dy = ty - sy

  val r1 = List.fill(dy)("U").mkString + List.fill(dx)("R").mkString
  val r2 = List.fill(dy)("D").mkString + List.fill(dx)("L").mkString
  val r3 = "L" + List.fill(dy + 1)("U").mkString + List.fill(dx + 1)("R").mkString + "D"
  val r4 = "R" + List.fill(dy + 1)("D").mkString + List.fill(dx + 1)("L").mkString + "U"

  val res = r1 + r2 + r3 + r4

  println(res)

}


Measured memory_bytes: 27600
#include <stdio.h>
int main(void){
	int a, b, c, k, max = 0, sum, i;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	sum = a+b+c;

	if(a>max) max = a;
	if(b>max) max = b;
	if(c>max) max = c; 

	sum -= max;
	for(i=0; i<k; i++) max *= 2;
	printf("%d\n",sum+max);
	return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var a, b, c, d, s int
	fmt.Scan(&a, &b, &c, &d)
	if b < c || d < a {
		s = 0
	} else if a == c {
		s = min(b-a, d-c)
	} else if c > a {
		s = min(d-c, b-c)
	} else {
		s = min(d-a, b-a)
	}
	fmt.Println(s)
}


Measured memory_bytes: 512
import sys

N = int(input())
A = list(map(int, input().split()))

num = 1

if 0 in A:
    print(0)
    sys.exit()

for i in range(N):
    num *= A[i]
    if num > (10 ** 18):
        print(-1)
        sys.exit()

print(num)

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

int is_kaibun(string S){
    for(int i =0; i < S.size(); i++){
        //cout << S[i] << ":" << S[S.size() - i - 1] << endl;
        if(S[i] != S[S.size() - i - 1]){
            return 0;
        }
    }    
    return 1;
}


int main(void){
    // Your code here!
    string S;
    cin >> S;
    
    if(is_kaibun(S) && is_kaibun(S.substr(0, (S.size()-1)/2))){
        cout << "Yes" << endl; 
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
string S;

ll c[26];

ll bfs(int n, bool b){
	if(n == 26)
		return (ll)b;
	return (bfs(n + 1, true) * c[n] + bfs(n + 1, b)) % MOD;
}
void solve(){
	rep(i, N){
		c[S[i] - 'a']++;
	}
	cout << bfs(0, false) << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> S;
		solve();
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main(){
    int K,N;cin >> K >> N;
    vector<int> a(N+1);
    int maxx = 0;
    
    rep(i,N){
        cin >> a[i];
    }
    a[N] = K+a[0];
    int l = 0;
    REP(i,1,N+1){
        l = max(a[i]-a[i-1],l);
    }
    int ans = K-l;
    cout << ans << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

typedef long double Real;
typedef complex<Real> Point;
typedef pair<Point, Point> Line;
typedef pair<Point, Real> Circle;
typedef vector<Point> Poly;

Real eps = 1e-7;

vector<Point> CCintersect (Circle c, Circle d) {
    vector<Point> ret;
    const Real dist = abs(c.first - d.first);
    const Real cr = c.second;
    const Real dr = d.second;

    if (dist > cr + dr) return ret;
    if (dist < abs(cr - dr)) return ret;

    const Real s = (cr + dr + dist) / 2.;
    const Real area = sqrt(s * (s - cr) * (s - dr) * (s - dist));
    const Real h = 2 * area / dist;

    Point v = d.first - c.first; v /= abs(v);
    const Point m = c.first + sqrt(cr * cr - h * h) * v;
    const Point n = v * Point(0, 1);

    ret.push_back(m + n * h);
    ret.push_back(m - n * h);
    return ret;
}

int main(){
    int n,k;cin >> n >> k;
    vector<long double> x(n),y(n),c(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> c[i];
    }
    long double l = 0, r = 1e7;
    while(abs(r-l)>eps){
        long double m = (r + l) / 2;
        vector<Circle> v(n);
        for (int i = 0; i < n; i++) {
            v[i].fs = Point(x[i],y[i]);
            v[i].sc = m / c[i];
        }
        vector<Point> p;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                auto q = CCintersect(v[i],v[j]);
                for (int k = 0; k < q.size(); k++) {
                    p.pb(q[k]);
                }
            }
            p.pb(v[i].fs);
        }
        bool f = false;
        for (int i = 0; i < p.size(); i++) {
            int cnt = 0;
            for (int j = 0; j < n; j++) {
                double r = abs(p[i] - v[j].fs);
                if(r <= v[j].sc + eps) cnt++;
            }
            if(cnt >= k) f = true;
        }
        if(f) r = m;
        else l = m;
    }
    cout << setprecision(30) << fixed << r << endl;
    return 0;
}


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

#define MAX 100000

int N;
int A[MAX];

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

	long long h = 0, v = 0;
	sort( A, A + N );
	for( int i = N - 1; i >= 0; i-- ) {
		if( h == 0 ) {
			if( A[i] == A[i - 1] ) {
				h = A[i];
				i--;
			}
		}
		else if( v == 0 ) {
			if( A[i] == A[i - 1] ) {
				v = A[i];
				break;
			}
		}
	}
	long long ans = h * v;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
import sys
from heapq import heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
works = [[] for _ in range(M+1)]
# M-1日後から選んでいく,
for _ in range(N):
    a, b = lr()
    if a > M:
        continue
    works[a].append(-b)

heap = []
answer = 0
for i in range(1, M+1):
    for x in works[i]:
        heappush(heap, x)
    if len(heap) == 0:
        continue
    answer += heappop(heap)

answer *= -1
print(answer)
# 08

Measured memory_bytes: 23752
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    D=list(map(int,input().split()))
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            ans+=D[i]*D[j]
    print(ans)
resolve()

Measured memory_bytes: 39024
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=15;
long long sum=1e9;
int n,m,p[N],c[N];
signed main() {
	cin >> n >> m;
	for (int i=0;i<n;i++)cin >> p[i] >> c[i];
	for (int t=0;t<1<<n;t++){
	 	int num=0,ans=0;
	 	for (int i=0;i<n;i++)
	 	 if ((1<<i)&t)num+=c[i]+p[i]*100*(i+1),ans+=p[i];
	 	for (int i=n-1;i>=0;i--)
		 if (num<m&&!((1<<i)&t))
		  {
		  	int s=min(p[i]-1,(m-num-1)/(100*(i+1))+1);
		  	num+=s*100*(i+1);
		  	ans+=s;
		  } 
		if (m<=num)sum=min(sum,ans);  
	 }
	cout << sum << endl; 
	return 0; 
} 


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var nk = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			int n = (int)nk[0];
			long k = nk[1];

			var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			var f = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

			long ng = -1;
			long ok = a.Max() * f.Max();

			Array.Sort(a, (x, y) => y.CompareTo(x));
			Array.Sort(f);

			while (ok - ng > 1) {
				long mid = (ok + ng) / 2;
				long num = 0;
				for (int i = 0; i < n; i++) {
					long na =  mid / f[i];
					num += Math.Max(0, (a[i] - na));
				}

				if (num <= k) {
					ok = mid;
				} else {
					ng = mid;
				}
			}

			Console.WriteLine(ok);
		}
	}
}

Measured memory_bytes: 43228
#include<stdio.h>
#include<limits.h>
 
int MatrixChainOrder(int P[], int n){
  int i,j,k,l,q;
  int M[n+1][n+1];
  for(i=1;i<=n;i++) M[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      M[i][j]=INT_MAX;
      for(k=i;k<=j-1;k++){
    q=M[i][k]+M[k+1][j]+P[i-1]*P[k]*P[j];
    M[i][j]=min(M[i][j],q);
      }
    }
  }
  return M[1][n];
}
 
int min(int a,int b){
  if(a>b)return b;
  else return a;
}
 
 
main(){
  int i,j,n;
  int P[10000];
  int *p;
 
  p=P;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d %d",&P[2*i],&P[2*i+1]);
  for(i=1;i<2*n;i++){
    if(P[i]==P[i+1]){
      for(j=i+1;j<2*n;j++)P[j]=P[j+1];
    }
  }
  printf("%d\n",MatrixChainOrder(P,n));
  return 0;
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
const cff = 0.006

func main() {
	var n, t, a int
	if sc.Scan() {
		n, _ = strconv.Atoi(sc.Text())
	}
	if sc.Scan() {
		s := strings.Split(sc.Text(), " ")
		t, _ = strconv.Atoi(s[0])
		a, _ = strconv.Atoi(s[1])
	}

	hs := []int{}
	if sc.Scan() {
		ss := strings.Split(sc.Text(), " ")
		for _, s := range ss {
			h, _ := strconv.Atoi(s)
			hs = append(hs, h)
		}

		if len(hs) != n {
			os.Exit(1)
		}
	}

	var tmp float64
	var hi int
	for i, h := range hs {
		if i == 0 {
			tmp = math.Abs(float64(a) - (float64(t) - float64(h) * cff))
			hi = i+1
			continue
		}

		tmp2 := math.Abs(float64(a) - (float64(t) - float64(h) * cff))
		if tmp2 < tmp {
			tmp = tmp2
			hi = i+1
			continue
		}
	}

	fmt.Println(hi)
}

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int p, q, r;

int calf(string s) {
	if(s.size() == 1) {
		if(s[0] == '0') return 0;
		if(s[0] == '1') return 1;
		if(s[0] == '2') return 2;
		if(s[0] == 'P') return p;
		if(s[0] == 'Q') return q;
		if(s[0] == 'R') return r;
	} else {
		if(s[0] == '-') {
			int n = calf(s.substr(1, s.size() - 1));
			switch(n) {
				case 0: return 2;
				case 1: return 1;
				case 2: return 0;
			}
		} else {
			int r = 0;
			REP(i, s.size()) {
				if(s[i] == '(') ++r;
				if(s[i] == ')') --r;
				if(r == 1 && s[i] == '*') {
					int x = calf(s.substr(1, i - 1));
					int y = calf(s.substr(i + 1, s.size() - 3 - (i - 1)));
					if(x == 0) {
						return 0;
					} else if(x == 1) {
						switch(y) {
							case 0: return 0;
							case 1: return 1;
							case 2: return 1;
						}
					} else if(x == 2) {
						switch(y) {
							case 0: return 0;
							case 1: return 1;
							case 2: return 2;
						}
					}
				}
				if(r == 1 && s[i] == '+') {
					int x = calf(s.substr(1, i - 1));
					int y = calf(s.substr(i + 1, s.size() - 3 - (i - 1)));
					if(x == 0) {
						switch(y) {
							case 0: return 0;
							case 1: return 1;
							case 2: return 2;
						}
					} else if(x == 1) {
						switch(y) {
							case 0: return 1;
							case 1: return 1;
							case 2: return 2;
						}
					} else if(x == 2) {
						switch(y) {
							case 0: return 2;
							case 1: return 2;
							case 2: return 2;
						}
					}
				}
			}
		}
	}
	return 114514;
}

int main(void) {
	while(true) {
		string s;
		cin>>s;
		ll ans = 0;
		if(s == ".") break;
		REP(i, 3) {
			REP(j, 3) {
				REP(k, 3) {
					p = i;
					q = j;
					r = k;
					if(calf(s) == 2) ++ans;
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main(){
    int N, L;
    std::string ans = "";
    std::cin >> N >> L;
    std::vector<std::string> v(N,"");
    for(int i = 0; i < N; i++){
        std::cin >> v[i];
    }
    std::sort(v.begin(), v.end());
    for(int i = 0; i < N; i++){
        ans += v[i];
    }
    std::cout << ans << std::endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

// graph by adjacency list
template <typename T>
struct Edge {
  int dst; T weight;
  Edge(int dst, T weight) : dst(dst), weight(weight) { }
  bool operator < (const Edge<T> &e) const {
    return weight > e.weight;
  }
};

template <typename T>
struct Graph {
  int V;
  vector<vector<Edge<T>>> E;
  Graph(int V) : V(V) { E.resize(V); }
  void add_edge(int src, int dst, T weight) {
    E[src].emplace_back(dst, weight);
  }
};

template <typename T>
struct HeavyLightDecomposition {
  const Graph<T> g;
  vector<int> vid, head, heavy, parent;
  HeavyLightDecomposition(const Graph<T> g, int root = 0) : g(g), vid(g.V, -1), head(g.V), heavy(g.V, -1), parent(g.V) {
    dfs(root, -1);
    bfs(root);
  }

  int dfs(int v, int par) {
    parent[v] = par;
    int sub = 1, max_sub = 0;
    for (Edge<T> child : g.E[v]) {
      if (child.dst != par) {
        int child_sub = dfs(child.dst, v);
        sub += child_sub;
        if (child_sub > max_sub) {
          max_sub = child_sub;
          heavy[v] = child.dst;
        }
      }
    }
    return sub;
  }

  void bfs(int root = 0) {
    int k = 0;
    queue<int> que({root});
    while (not que.empty()) {
      int r = que.front(); que.pop();
      for (int v = r; v != -1; v = heavy[v]) {
        vid[v] = k++;
        head[v] = r;
        for (Edge<T> child : g.E[v]) {
          if (child.dst != parent[v] and child.dst != heavy[v]) que.push(child.dst);
        }
      }
    }
  }

  int lca(int u, int v) {
    while(head[u] != head[v]) {
      if (vid[u] > vid[v]) swap(u, v);
      v = parent[head[v]];
    }
    if (vid[u] > vid[v]) swap(u, v);
    return u;
  }
};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  Graph<int> g(N);
  REP(i, N) {
    int k; cin >> k;
    REP(_, k) {
      int c; cin >> c;
      g.add_edge(i, c, 1);
      g.add_edge(c, i, 1);
    }
  }

  HeavyLightDecomposition<int> hld(g);

  int Q; cin >> Q;
  REP(_, Q) {
    int u, v; cin >> u >> v;
    cout << hld.lca(u, v) << endl;
  }


  return 0;
}

Measured memory_bytes: 24568
import sys

# sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def solve():
    n, k = read_int_list()
    a = read_int_list()
    if k > max(a):
        return 'IMPOSSIBLE'
    g = a[0]
    for i in range(n):
        g = gcd(g, a[i])
        if k % g == 0:
            return 'POSSIBLE'
    return 'IMPOSSIBLE'


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14224
import math
a,b,x =map(int,input().split())
theta1 = math.degrees(math.atan(a*(b**2)/(2*x)))
theta2 = math.degrees(math.atan((2/a**3)*((a**2)*b-x)))
if b*(a**2)/2 >x:
  print(theta1)
else:
  print(theta2)

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

using namespace std;

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

    vector<int64_t> C(3);

    for (const auto &s: S)
        C[s % 3]++;

    int64_t ans = C[0] * C[1] * C[2];
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            if (S[i] == S[j])
                continue;
            if (j + j - i < n and S[j + j - i] % 3 == (3 ^ (S[i] % 3) ^ (S[j] % 3)))
                ans--;
        }
    }

    cout << ans << endl;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    string S; cin >> S;

    
    int ans = 0;
    
    for(int i = 1; i < N-1; i++){
        vector<int> cx(26, 0);
        vector<int> cy(26, 0);
        for(int j = 0; j < i; j++){
            int a = int(S[j] - 'a');
            cx[a]++;
        }
        for(int j = i; j < N; j++){
            int a = int(S[j] - 'a');
            cy[a]++;
        }
        int cnt = 0;
        for(int k = 0; k < 26; k++){
            if(cx[k] != 0 && cy[k] != 0){
                cnt++;
            }
        }
        if(ans < cnt) ans = cnt;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256