akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
 
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 1; i <= Math.min(a,b); i++) {
            if ((a % i == 0) &&(b % i == 0)) list.add(i);
        }   
        Collections.sort(list);
        System.out.println(list.get(list.size()-k));
    }
}


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: 21460
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr, class func> void array_output(itr start, itr goal, func out = [](itr x) { return x; } ){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr, class func> void nint_output(itr start, itr goal, func out = [](itr x) { return x; } ){ string ans; for(auto i = start; i != goal; i++){ ans += string(out(*i)) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)

int main(){
    int M, N;
    cin >> M >> N;
    int ans = 0;
    for(int i = 0; i < M; i++){
        int this_ans = 0;
        for(int j = 0; j < N; j++){
            int score;
            cin >> score;
            this_ans += score;
        }
        ans = max(ans, this_ans);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define len(val) static_cast<long long>(val.size())
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
typedef pair<int, int> P;


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

    string s;
    cin >> s;
    if(s.find("AC") != std::string::npos){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }

}


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

int main() {
	int n;
	int cnt = 0;
	int two = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		if (temp % 4 == 0)cnt++;
		else if (temp % 2 == 0)two++;
	}

	if (two != 0)two--;
	if (cnt * 2 + 1 + two >= n)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<algorithm>
#include <cstdlib>

using namespace std;
int main()
{
	int n, a, b, c, d,x=0;
	cin >> n;
	d = n % 10;
	c = ((n - d) % 100)/10;
	b = ((n - c*10 - d) % 1000)/100;
	a = ((n - b * 100 - c * 10 - d))/1000;
	x = a;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				if (i % 2 == 0) x += b;
				else x -= b;
				if (j% 2 == 0) x += c;
				else x -= c;
				if (k % 2 == 0) x += d;
				else x -= d;
				if (x == 7) {
					cout << a;
					if (i % 2 == 0) cout << "+";
					else cout << "-";
					cout << b;
					if (j % 2 == 0) cout << "+";
					else cout << "-";
					cout << c;
					if (k % 2 == 0) cout << "+";
					else cout << "-";
					cout << d;
					cout << "=7" << endl;
					goto end;
				}
				x = a;
			}
		}
	}
	end:;
    return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

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

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

bool cp(int n)
{
    if(n<2)
        return false;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","w",stdout);
    //FILE *fptr2=freopen("out.txt","w",stdout);


    int n;
    cin>>n;
    vector <int> a(n);
    loop(i,0,n) cin>>a[i];
    int c=0;
    loop(i,0,n)
    {
        loop(j,i+1,n)
        {
            loop(k,j+1,n)
            {
                if(a[i]+a[j]>a[k] and a[j]+a[k]>a[i] and a[i]+a[k]>a[j] and a[i]!=a[j] and a[j]!=a[k] and a[i]!=a[k])
                    c++;
            }
        }
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int N, M;
vii m[100005];
bool visited[100005];

void dfs(int s) {
  if (visited[s]) return;
  visited[s] = true;
  for (auto x : m[s]) {
    dfs(x);
  }
}

signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> N >> M;
  rep(i, 0, M) {
    int x, y, z;
    cin >> x >> y >> z;
    m[--x].push_back(--y);
    m[y].push_back(x);
  }
  int ans = 0;
  rep(i, 0, N) {
    if (visited[i]) continue;
    dfs(i);
    ans++;
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 8960
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
is_zero = False
if 0 in A:
    is_zero = True
minus = 0
plus = 0

for a in A:
    if a < 0:
        minus += 1
    elif a > 0:
        plus += 1    
ans = 0
for a in A:
    ans += abs(a)
tmp = INF
if is_zero == True or minus % 2 == 0:
    print(ans)
else:
    for a in A:
        if abs(a) < tmp:
            tmp = abs(a)
    print(ans - 2 * tmp)



    

Measured memory_bytes: 15092
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
#define reps(i, S, E) for (ll i = (S); i <= (E); i++)
#define rep(i, N) reps(i, 0, N-1)
#define deps(i, E, S) for (ll i = (E); i >= (S); i--)
#define dep(i, N) deps(i, N-1, 0)
void chmax(ll &a, ll b) { if (a < b) a = b; }
void chmin(ll &a, ll b) { if (a > b) a = b; }

const ll MOD = 1000000007;
const ll INF = 1LL << 60;

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

//C
int main() {
	ll X;
	scanf("%lld", &X);

	ll div = X / 100;
	ll mod = X % 100;

	if (div * 5 >= mod) {
		printf("1\n");
	}
	else {
		printf("0\n");
	}
}


//B
/*
int main() {
	ll N;
	scanf("%lld", &N);

	ll temp = (ll)((double)N / 1.08);

	ll result = 0;

	if ((ll)((double)temp * 1.08) == N) {
		result = temp;
	}
	else if ((ll)((double)(temp - 1) * 1.08) == N) {
		result = temp - 1;
	}
	else if ((ll)((double)(temp + 1) * 1.08) == N) {
		result = temp + 1;
	}
	else {
		printf(":(\n");
		return 0;
	}

	printf("%lld\n", result);
}
*/

//A
/*
int main() {
	ll M1;
	scanf("%lld", &M1);
	ll D1;
	scanf("%lld", &D1);
	ll M2;
	scanf("%lld", &M2);
	ll D2;
	scanf("%lld", &D2);

	ll result = 0;

	if (M1 != M2) {
		result = 1;
	}

	printf("%lld\n", result);
}
*/

Measured memory_bytes: 128
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    S = A.copy()
    S.sort()
    from_index = {a: i for i, a in enumerate(A)}
    to_index = {s: i for i, s in enumerate(S)}
    cnt = 0  # from_index と to_index の差が奇数であるものの個数
    for a in A:
        if abs(from_index[a] - to_index[a]) % 2 == 1:
            cnt += 1
    print(cnt // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 35204
/*
#include <bits/stdc++.h>
using namespace std;
int s, num[1010], dp[1010], ans;
int main() {
    cin >> s;
    num[1] = 0;
    for (int i = 1; i <= s; ++i) {
        for (int j = 2; i * j <= s; ++j) {
            num[i * j] += i;
        }
    }
    for (int i = 1; i <= s; ++i) {
        for (int j = s; j >= i; --j) {
            dp[j] = max(dp[j], num[i] + dp[j - i]);
        }
    }
    cout << dp[s] << endl;
    return 0;
}*/

#include <bits/stdc++.h>
using namespace std;
int n, ans;
int num[100010];
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> num[i];
    }
    sort(num, num + n);
    for (int i = 0; i < n;) {
        int tmp = 1;
        while (num[i + tmp] == num[i + tmp - 1]) {
            ++tmp;
        }
        if (tmp & 1) {
            ++ans;
        }
        i += tmp;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
n = int(input())
a = list(map(int,input().split()))
xor = 0
if n == 2:
  a,b = a
  if a >= b and (a+b)%2 == 0:
    print((a+b)//2-b)
  else:
    print(-1)
  exit()
for i in range(2,n):
  xor ^= a[i]
a,b = a[0],a[1]
sm = a+b
ls = []
smt = 0
for i in range(50)[::-1]:
  if xor&1<<i:
    ls.append(1)
    smt += 1<<i
  else:
    if smt+(2<<i) > sm:
      ls.append(0)
    else:
      ls.append(2)
      smt += 2<<i
if smt != sm:
  print(-1)
  exit()
mn = 0
mx = 0
for i in range(50):
  if ls[49-i] == 1:
    mx += 1<<i
  elif ls[49-i] == 2:
    mn += 1<<i
    mx += 1<<i
if not mn <= a:
  print(-1)
  exit()
ans = mn
for i in range(50):
  if ls[i] == 1:
    if ans+(1<<(49-i)) > a:
      continue
    else:
      ans += 1<<(49-i)
if ans == 0:
  print(-1)
else:
  print(a-ans)

Measured memory_bytes: 62332
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

fn main() {
    let mut ss: Vec<char> = read_line().chars().collect();
    ss.sort();
    println!("{}", if ss == ['a','b','c'] { "Yes" } else { "No" });
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


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

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

using namespace std;

const int INF=1<<29;

template<class T>
class network{
	struct edge{
		int to,rev;
		T capa,flow;
		edge(int to,int rev,const T& capa,const T& flow):to(to),rev(rev),capa(capa),flow(flow){}
	};

	int s,t;
	vector<vector<edge>> G;

	vector<int> layer,now;

	bool make_layer(){
		int n=G.size();
		rep(u,n) layer[u]=(u==s?0:-1);

		queue<int> Q; Q.emplace(s);
		while(!Q.empty()){
			int u=Q.front(); Q.pop();
			for(const edge& e:G[u]) if(layer[e.to]==-1 && e.capa-e.flow>0) {
				layer[e.to]=layer[u]+1;
				if(e.to==t) return true;
				Q.emplace(e.to);
			}
		}
		return false;
	}

	T augment(int u,const T& water){
		if(u==t) return water;

		for(int& i=now[u];i<G[u].size();i++){
			edge& e=G[u][i];
			if(layer[e.to]>layer[u] && e.capa-e.flow>0){
				T w=augment(e.to,min(water,e.capa-e.flow));
				if(w>0){
					e.flow+=w;
					G[e.to][e.rev].flow-=w;
					return w;
				}
			}
		}
		return 0;
	}

public:
	network(int n,int s,int t):s(s),t(t){
		G.resize(n);
	}

	void add_directed_edge(int u,int v,const T& capa){
		G[u].emplace_back(v,G[v].size()  ,capa,0);
		G[v].emplace_back(u,G[u].size()-1,   0,0);
	}

	T maximum_flow(){
		int n=G.size();
		layer.resize(n);

		T res=0;
		while(make_layer()){
			now.assign(n,0);
			for(T water=1;water>0;res+=water) water=augment(s,numeric_limits<T>::max());
		}
		return res;
	}
};

int main(){
	int h,w; scanf("%d%d",&h,&w);
	char B[100][101];
	rep(i,h) scanf("%s",B[i]);

	int sx,sy,tx,ty;
	rep(i,h) rep(j,w) {
		if(B[i][j]=='S') tie(sy,sx)=tie(i,j);
		if(B[i][j]=='T') tie(ty,tx)=tie(i,j);
	}

	network<int> G(2*h*w,sy*w+sx+h*w,ty*w+tx);
	rep(i,h) rep(j,w) if(B[i][j]!='.') {
		G.add_directed_edge(i*w+j,i*w+j+h*w,1);
		rep(k,h) if(k!=i && B[k][j]!='.') G.add_directed_edge(i*w+j+h*w,k*w+j,INF);
		rep(k,w) if(k!=j && B[i][k]!='.') G.add_directed_edge(i*w+j+h*w,i*w+k,INF);
	}

	int ans=G.maximum_flow();
	printf("%d\n",ans<INF?ans:-1);

	return 0;
}


Measured memory_bytes: 83456
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

signed main() {
    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '+') cout << a + b << "\n";
    else cout << a - b << "\n";
}

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

using namespace std;

int main()
{
    string s;
    cin>>s;

    for(int i=1; i<4; i++)
    {
        if(s[i]==s[i-1])
        {
            cout<<"Bad";
            return 0;
        }
    }
    cout<<"Good";
}


Measured memory_bytes: 256
#16:17
s = input()
n = len(s)
mod = 10 ** 9 + 7
left = [1]
stand = [1]
right = [1]
for i in range(1,n):
  right.append(right[-1] * 3 % mod)
  if s[i] == '1':
    left.append(left[-1] * 2 % mod)
    stand.append(1)
  else:
    left.append(left[-1])
    stand.append(0)
right.reverse()
ans = 0
for i in range(n):
  ans += left[i] * right[i] * stand[i]
  ans %= mod
#print(left)
#print(right)
#print(stand)
ans += left[-1] * 2
ans %= mod
print(ans)

Measured memory_bytes: 11924
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

mint dp[2005][2005];

int main() {
  // dp[i][j] iとjの数字を比較、ApplePen
  int N, M;
  cin >> N >> M;
  vector<int> A = {-1};
  rep(i, N) {
    int a;
    cin >> a;
    A.push_back(a);
  }
  vector<int> B = {-2};
  rep(i, M) {
    int b;
    cin >> b;
    B.push_back(b);
  }
  for (int i = 0; i < N+1; i++) {
    dp[i][0] = 1;
  }
  for (int j = 1; j < M+1; j++) {
    dp[0][j] = 1;
  }
  for (int i = 1; i < N+1; i++) {
    for (int j = 1; j < M+1; j++) {
      if (A[i] == B[j]) {
        dp[i][j] = dp[i-1][j] + dp[i][j-1];
      } else {
        dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
      }
    }
  }
  cout << dp[N][M] << '\n';
  return 0;
}

Measured memory_bytes: 190748
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define reps(i,n) for(int i=1;i<=(int)n;i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define MOD 1000000007
#define itn int
#define enld endl
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){
    ll A,V,B,W,T; cin >> A >> V >> B >> W >> T;
    if(V <= W){
        cout << "NO" << endl;
        return 0;
    }

    if(abs(A-B)<= T*abs(V-W)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  vll A(n);
  ll sum=0;
  	FOR(i,0,n){
	ci(A[i])
      sum+=A[i];
    }
  ll m;
  	ci(m);
  FOR(i,0,m){
    ll a,b;
    	ci(a>>b);
    co(sum-A[a-1]+b)
  }
}

Measured memory_bytes: 256
S=list(input())
a,b=[],[]
for i in range(len(S)):
	if i%2==0:
		a.append(S[i])
	else:
		b.append(S[i])

#偶数番目の0の出現回数
zero_gu=a.count('0')
#偶数番目の1の出現回数
iti_gu=a.count('1')

#奇数番目の0の出現回数
zero_ki=b.count('0')
#奇数番目の1の出現回数
iti_ki=b.count('1')

#奇数番目を0,偶数番目を1にすると
ans1=iti_ki+zero_gu

#その逆
ans2=iti_gu+zero_ki

print(min(ans1,ans2))

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

using namespace std;
typedef long long ll;

ll a,b,n;

int main()
{
	scanf("%lld%lld%lld",&a,&b,&n);
	ll t = min(n,b-1);
	printf("%lld\n",a*t/b-a*(t/b));
} 

Measured memory_bytes: 3832
def main():
    from collections import deque
    n, m = map(int, input().split())

    l = {i: [] for i in range(n + 1)}
    for _ in range(m):
        i, j = map(int, input().split())
        l[i].append(j)
        l[j].append(i)

    ll = [None] * (n + 1)
    vis = [False] * (n + 1)
    que = deque([1])
    vis[1] = True
    while que:
        now = que.popleft()
        nx = l[now]
        for i in nx:
            if vis[i]:
                continue
            vis[i] = True
            ll[i] = now
            que.append(i)
    if all(vis[1:]):
        print("Yes")
        s = "\n".join(map(str, ll[2:]))
        print(s)
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 50092
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 100005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
int N, M;
int cnt = 0;
vector<int> ord(MAX, NIL), lowLink(MAX);
vector<vector<int> > G(MAX, vector<int>());
/* function */
void dfs(int from, int parent) {
    ord[from] = lowLink[from] = cnt++;
    for (int to : G[from]) {
        // DFS木の親を訪れようとしたら何もしない
        if (to == parent) continue;
        if (ord[to] == NIL) {
            // nodeが使われていないならdfs
            dfs(to, from);
            // dfsが戻ってきたらlowlinkの更新
            lowLink[from] = min(lowLink[from], lowLink[to]);
        }
        // 使われている頂点まだ使ってない辺でを訪れようとした場合
        else {
            // これが後退辺となるのでusedEは0のままにしておく
            // lowlinkの更新
            lowLink[from] = min(lowLink[from], ord[to]);
        }
    }
    return ;
}
void bridge(vector<pii> edges) {
    int from, to;
    for (pii edge : edges) {
        from = edge.first, to = edge.second;
        if (ord[from] < lowLink[to] || ord[to] < lowLink[from])
            cout << from << ' ' << to << '\n';
    }
}
/* main */
int main(){
    cin >> N >> M;
    int u, v;
    vector<pii> edges;
    for (int i = 0; i < M; i++) {
        cin >> u >> v;
        if (u > v) swap(u, v);
        G[u].push_back(v);
        G[v].push_back(u);
        edges.push_back(pii(u, v));
    }
    dfs(0, -1);
    sort(edges.begin(), edges.end());
    bridge(edges);
}



Measured memory_bytes: 7872
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int[] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        Array.Sort(n);
        Console.WriteLine(n[0] == n[1] ? n[2] : n[0]);
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000


ll gcm(ll a,ll b);
ll lcm(ll a,ll b);
ll fac(ll a);

int main(){
  int n;
  cin >> n;
  vbool flag(9,false);
  int flag8count = 0;
  rep(i,n){
    int a;
    cin >> a;
    if(a < 400) flag[0] = true;
    else if(a < 800) flag[1] = true;
    else if(a < 1200) flag[2] = true;
    else if(a < 1600) flag[3] = true;
    else if(a < 2000) flag[4] = true;
    else if(a < 2400) flag[5] = true;
    else if(a < 2800) flag[6] = true;
    else if(a < 3200) flag[7] = true;
    else{
      flag[8] = true;
      flag8count++;
    }
  }
  //rep(i,9) cout << flag[i] << endl;
  int minans = 0;
  int maxans = 0;
  rep(i,8){
    if(flag[i]){
      minans++;
      maxans++;
    }
  }
  if(minans == 0 && flag[8]) minans = 1;
  cout << minans << " ";

  while(flag8count > 0){
    maxans++;
    flag8count--;
  }
  cout << maxans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S=sc.next();
		int count=0;
		int tmp=0;
		char[] weather=new char[3];
		for(int i=0;i<3;i++){
			weather[i]=S.charAt(i);
		}
		for(int j=0;j<3;j++){
			if(weather[j]=='R'){
				tmp++;
				if(count<tmp)count=tmp;
			}else{
				if(count<tmp)count=tmp;
				tmp=0;
			}
			
		}
		System.out.println(count);

	}
}

Measured memory_bytes: 35528
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define mod 1000000007
using namespace std;
inline int read()
{int x=0,f=0;
char c=getchar();
while (c<'0'||c>'9') 
{if (c=='-') f=1;
c=getchar();
}
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
if (f) x=-x;
return x;
}
int s,p[11];
int bel[25];
bool vis[200000005];
int main (){
	int i,ans=0,now=0,tp=1;
	scanf ("%d",&s);vis[0]=1;
	for (i=1;i<=25000000;i++)
	{now+=tp;vis[now]=1;
	if (tp>=2&&now-s<bel[tp-2]&&now>=s&&vis[now-s]) ans++;
	if (i==9||i==99||i==999||i==9999||i==99999||i==999999||i==9999999)
	{bel[tp]=now;tp++;}
	}
	p[0]=1;
	for (i=1;i<=9;i++)
	{p[i]=p[i-1]*10;}
	for (i=1;i<=8;i++)
	{int al=s/i,rm=s%i,n1=al-rm,n2=rm;
	if (n2==0) {n1-=(i+1);n2+=i;}
	if (n1<=0) continue;
	int mz=p[i]-p[i-1],mr=p[i+1]-p[i];
	if (n1>mz)
	{n1-=((n1-mz)/(i+1))*(i+1);
	while (n1>mz) n1-=(i+1);
	}
	if (n1<=0) continue;
	n2=(s-i*n1)/(i+1);
	if (n2>mr) continue;
	int o=min((n1-1)/(i+1)+1,(mr-n2)/i+1);
	ans+=o;
	if (ans>=mod) ans-=mod;
	}
	for (i=9;i<=s;i++)
	{int al=s/i,rm=s%i,n1=al-rm,n2=rm;
	if (n2==0) {n1-=(i+1);n2+=i;}
	if (n1<=0) continue;
	ans+=(n1-1)/(i+1)+1;
	if (ans>=mod) ans-=mod;
	}
	tp=9;
	for (i=1;i<=8;i++)
	{if (s%i) {tp=1ll*tp*10%mod;continue;}
	int o=s/i;
	if (o<=tp) {ans+=(tp-o+1);}
	if (ans>=mod) ans-=mod;
	tp=1ll*tp*10%mod;
	}
	for (i=9;i<=s;i++)
	{if (s%i) {tp=1ll*tp*10%mod;continue;}
	int o=s/i;
	ans+=(tp-o+1);
	if (ans>=mod) ans-=mod;
	if (ans<0) ans+=mod;
	tp=1ll*tp*10%mod;
	}
	printf ("%d\n",ans);
	return 0;
}

Measured memory_bytes: 186752
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int a,b,c;cin>>a>>b>>c;
    int x=100*a+10*b+c;
    if(x%4==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  N = N%10;

  if(N == 0 || N == 1 || N == 6 || N == 8){
    cout << "pon" << "\n";
  }else if(N == 3){
    cout << "bon" << "\n";
  }else{
    cout << "hon" << "\n";
  }


  return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

struct ST {
  int s;
  vector<ll> v;
  ST(int s) : s{s}, v(2 * s) {}
  void update(int p, ll d, bool assign) {
    p += s;
    if (assign) v[p] = d;
    else v[p] = max(v[p], d);
    for (p >>= 1; p >= 1; p >>= 1)
      v[p] = max(v[2 * p], v[2 * p + 1]);
  }
  ll query(int l, int r) {
    if (l > r) return 0;
    ll acc = 0;
    for (l += s, r += s; l <= r; (++l) >>= 1, (--r) >>= 1) {
      if (l & 1) acc = max(acc, v[l]);
      if (~r & 1) acc = max(v[r], acc);
    }
    return acc;
  }
};

vi sorted;
int getindex(int val) {
  assert(binary_search(all(sorted), val));
  return lower_bound(all(sorted), val) - begin(sorted);
}

void dfs(graph& g, int i, vi& a, ST& st, vi& res, int p = -1) {
  // cout << "At: " << i << " " << a[i] << endl;
  auto index = getindex(a[i]);
  assert(index >= 0 and index < sz(a));
  auto old = st.query(index, index);
  
  auto best = st.query(0, index - 1);
  assert(best >= 0);
  assert(best < sz(a));
  auto possible = best + 1;
  
  assert(possible >= old);

  res[i] = possible;
  st.update(index, possible, true);
  trav(e, g[i]) if (e.to != p) {
    dfs(g, e.to, a, st, res, i);
  }
  st.update(index, old, true);
}

void prop(graph& g, int i, auto& res, int p = -1, int best = 0) {
  res[i] = max(res[i], best);
  trav(e, g[i]) if (e.to != p) {
    prop(g, e.to, res, i, max(best, res[i]));
  }
}

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

  int n;
  cin >> n;
  vi a(n);
  trav(i, a) {cin >> i; --i;}

  sorted = a;
  sort(all(sorted));
  sorted.erase(unique(all(sorted)), end(sorted));
  graph g(n);
  rep(i, 0, n - 1) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    g[u].PB({v});
    g[v].PB({u});
  }

  
  ST st(n);
  vi res(n, -1);
  dfs(g, 0, a, st, res);
  prop(g, 0, res);
  rep(i, 0, n) {
    assert(res[i] >= 0);
    cout << res[i] << '\n';
  }
  
}


Measured memory_bytes: 36904
n, m = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]
c = [list(map(int, input().split())) for i in range(m)]

ans = []
for i in range(n):
    dis = float("inf")
    index = 0
    for j in range(m):
        if dis > abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1]):
            dis = abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
            index = j+1
    ans.append(index)

for i in ans:
    print(i)

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

const int MAX_A = 1000005;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> as(N);
    for(int i=0; i<N; i++) cin >> as.at(i);
    vector<int> bs(MAX_A, 0);
    sort(as.begin(), as.end());

    for(auto a : as)
    {
        if(bs[a] != 0)
        {
            bs[a] = 2;
            continue;
        }
        for(int i=a; i<MAX_A; i+=a) bs[i]++;
    }

    int ans = 0;
    for(auto a : as)
    {
        if(bs[a] == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
  int a;
  cin >> a;
  for(int i=1;i<=9;++i) {
    if( a % i == 0 ) {
	  int b = a / i;
      if( 1 <= b && b <= 9 ) { puts("Yes"); return 0; }
    }
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) (a).size() 
#define rep(i,n) for(int i=0;i<n;i++)
#define fors(i,s) for(int i=0;i<s.size();i++)
#define foreach(c,itr) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define INF 1e9;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
int main(){
	int n;
	cin>>n;
	cout<<n*n*n; 
	return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  if(a%3 == 0 or b%3 == 0 or (a+b)%3 == 0){
    cout << "Possible" << endl;
  }
  else{
      cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
n=int(input())

d={"num":1,"ans":1}
for i in range(1,n+1):
  if i%2==0:
    num=i
    ans=0
    while i%2==0:
      i=i/2
      ans+=1
    if ans>=d["ans"]:
      d["num"]=num
      d["ans"]=ans
    
print(d["num"])
  

Measured memory_bytes: 9148
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
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;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

template<class T> void printvec(vector<T> v){
    for (T t : v) cout << t << " ";
    cout << endl;
}

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

    int N, K;
    cin >> N >> K;

    vector<ll> v(N);
    REP(i,N) cin >> v[i];

    ll ans = 0;
    REP(l,N+1) REP(r,N+1) {
        if (l+r > N) continue;
        int d = K-l-r;
        if (d<0) continue;
        ll score = 0;
        vi s;
        REP(i,l){
            score += v[i];
            s.emplace_back(v[i]);
        }
        FOR(i,N-r,N){
            score += v[i];
            s.emplace_back(v[i]);
        }

        sort(ALL(s));
        REP(i,d){
            if (i >= s.size()) break;
            if (s[i] > 0) break;
            score -= s[i];
        }

        ans = max(ans, score);
    }

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

Measured memory_bytes: 256
import math

A,B,H,M = map(int,input().split())

C = 2*math.pi/12
D = 2*math.pi/60
E = 2*math.pi/(12*60)
x = abs(D*M - (C*H + E*M))


print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(x)))

Measured memory_bytes: 9464
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

using std::vector;

struct item_t {
  int w;
  int v;

  bool operator<(const item_t &r) const { return w < r.w; }
  void operator+=(const item_t &r) {
    w += r.w;
    v += r.v;
  }
};

vector<item_t> rekkyo(vector<item_t> item) {
  vector<item_t> a, b, c;
  a.reserve(1 << item.size());
  b.reserve(1 << item.size());
  c.reserve(1 << item.size());

  a.push_back({0, 0});
  for (auto i : item) {
    for (auto &e : a) {
      b.push_back(e);
      b.back() += i;
    }
    std::merge(a.begin(), a.end(), b.begin(), b.end(), std::back_inserter(c));
    std::swap(a, c);
    b.clear();
    c.clear();
  }
  return std::move(a);
}

void chmax(int &a, int b) { a = std::max(a, b); }

int solve(vector<item_t> item, int l) {
  int n = item.size();
  auto a = rekkyo({item.begin(), item.begin() + n / 2});
  auto b = rekkyo({item.begin() + n / 2, item.end()});
  std::reverse(a.begin(), a.end());

  int ans = 0;
  int maxv = -10000000;
  auto itr = b.begin();
  for (auto e : a) {
    while (itr != b.end() && e.w + itr->w <= l) {
      chmax(maxv, itr->v);
      ++itr;
    }
    chmax(ans, e.v + maxv);
  }

  return ans;
}

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

  int n;
  std::cin >> n;

  vector<item_t> item(n);
  for (auto &e : item) {
    std::cin >> e.v >> e.w;
  }
  item.insert(item.begin(), {0, 0});

  int q;
  std::cin >> q;
  for (int i = 0; i < q; ++i) {
    int v, l;
    std::cin >> v >> l;
    vector<item_t> qi;
    while (v != 0) {
      qi.push_back(item[v]);
      v /= 2;
    }
    std::cout << solve(qi, l) << "\n";
  }
}


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

typedef pair<int, int> P;

int main(void){
    int N; cin >> N;
    int x[N], y[N]; rep(i, N) cin >> x[i] >> y[i];

    map<P, int> m;
    int max_cnt = 0;

    rep(i, N){
      rep(j, N){
        if(i == j) continue;
        int p = x[i] - x[j], q = y[i] - y[j];
        max_cnt = max(max_cnt, ++m[P(p, q)]);
      }
    }

    cout << N - max_cnt << endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,w;
  int v[101],p[101];
  int dp[110][10010]={};
  cin>>n>>w;
  for(int i=1;i<=n;i++){
    cin>>v[i]>>p[i];
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=w;j++){
      if(j<p[i]) dp[i][j]=dp[i-1][j];
      else dp[i][j]=max(dp[i-1][j],dp[i-1][j-p[i]]+v[i]);
    }
  }
  cout<<dp[n][w]<<endl;
  return 0;
}



Measured memory_bytes: 7404
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
mint dp[1001][1001];
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int h, w; cin >> h >> w;
   vector<vector<char>> grid(h+1,vector<char>(w+1));
   rep(i,h)rep(j,w)cin>>grid[i+1][j+1];
   dp[1][1] = 1;
   for (int i = 1; i <= h; i++){
      for (int j = 1; j <= w; j++){
         if ((i==1&&j==1) || grid[i][j] == '#')continue;
         dp[i][j] = dp[i-1][j] + dp[i][j-1];
      }
   }
   cout << dp[h][w] << endl;
}

Measured memory_bytes: 12172
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long 
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd long long
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
using namespace std;
ll a[10005];
int main(){
   boost;
   ll n;
   cin>>n;
   for(ll i=1;i<=n;i++)cin>>a[i];
   ll ans=0;
   for(ll i=1;i<=n;i++){
   	  for(ll j=i+1;j<=n;j++){
   	  	   for(ll k=j+1;k<=n;k++){
   	  	   	   if(a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k]){
   	  	   	   	    if(a[i]+a[j]>a[k] && a[k]+a[i]>a[j] && a[j]+a[k]>a[i])ans++;
				}
			}
		}
   }
   cout<<ans;
}
	
 
    


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


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

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

  int N, A[2222];

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> A[i];

  if (N == 1) {
    std::cout << A[0] << std::endl;
  }
  else {
    std::bitset<4444444> bitset;

    bitset.set(0);

    for (int i = 0; i < N; i ++)
      bitset |= bitset << A[i];

    int S = std::accumulate(A, A + N, 0);

    for (int i = (S + 1) / 2; i <= S; i ++)
      if (bitset[i]) {
        std::cout << i << std::endl;

        break;
      }
  }

  return 0;
}


Measured memory_bytes: 1912
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    double l; cin >> l;
    double x=(l*l*l/27);
    cout << fixed << setprecision(10) << x << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	string S;
	int K;
	cin >> S >> K;
	
	unordered_set<string> h;
	for(int i=0;i<S.length();i++){
		for(int j=1;j<=5;j++){
			if(i + j > S.length()) break;
			h.insert(S.substr(i, j));
		}
	}
	
	vector<string> v;
	for(auto s : h) v.push_back(s);
	sort(v.begin(), v.end());
	unique(v.begin(), v.end());
	//for(auto s: v) cerr << s << endl;
	cout << v[K - 1] << endl;
	
    return 0;
}

Measured memory_bytes: 1792