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

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let x: usize = itr.next().unwrap().parse().unwrap();
    let mut c = vec![0; n];
    let mut a = vec![vec![0; m]; n];
    for i in 0..n {
        c[i] = itr.next().unwrap().parse().unwrap();
        a[i] = (0..m)
            .map(|_| itr.next().unwrap().parse().unwrap())
            .collect();
    }

    const INF: usize = 1 << 30;
    let mut ans = INF;
    for bit in 0..1 << n {
        let mut cnt = 0;
        let mut get = vec![0; m];
        let mut ok = true;
        for i in 0..n {
            if bit >> i & 1 == 1 {
                cnt += c[i];
                for j in 0..m {
                    get[j] += a[i][j];
                }
            }
        }
        for j in 0..m {
            if get[j] < x {
                ok = false;
            }
        }
        if ok {
            ans = min(ans, cnt);
        }
    }
    if ans == INF {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 2144
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main() {
	int i,j,k=1,N,mo=1;
  int flag = 0;
  double u[101] = { 0 };
  double ans = 0;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%lf", u + i);
  }
  for (i = 0; i < N; ++i) {
    for (j = i + 1; j < N; ++j) {
      if (u[i] > u[j]) {
        u[i] += u[j];
        u[j] = u[i] - u[j];
        u[i] = u[i] - u[j];
      }
    }
  }
  ans = u[0];
  for (i = 1; i < N; i++) {
    ans = (ans + u[i]) / 2;
  }
  printf("%.5lf", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef unordered_map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

vi adj[200001];

struct DSU
{
	int S;
	
	struct node
	{
		int p;
		unordered_map<int,int> ma;
	};
	vector<node> dsu;
	
	DSU(int n)
	{
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i;
			dsu.pb(tmp);
		}
	}
	
	void reset(int n, vi &vec)
	{
		dsu.clear();
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i;
			tmp.ma[vec[i]]++;
			dsu.pb(tmp);
		}
	}
	
	int rt(int u)
	{
		if(dsu[u].p == u) return u;
		dsu[u].p = rt(dsu[u].p);
		return dsu[u].p;
	}
	
	void merge(int u, int v)
	{
		u = rt(u); v = rt(v);
		if(u == v) return ;
		if(dsu[v].ma.size()>dsu[u].ma.size()) swap(u,v);
		dsu[v].p = u;
		while(!dsu[v].ma.empty())
		{
			mit it = dsu[v].ma.begin();
			dsu[u].ma[it->fi]+=it->se;
			dsu[v].ma.erase(it);
		}
	}
	
	bool sameset(int u, int v)
	{
		if(rt(u) == rt(v)) return true;
		return false;
	}

};
//DSU end

vi cc;
int cn = 0;
bool vis[200001];
void dfs(int u)
{
	vis[u]=1;
	cc[u]=cn;
	for(int i = 0; i < adj[u].size(); i++)
	{
		int v = adj[u][i];
		if(vis[v]) continue;
		dfs(v);
	}
}

DSU dsu(1);

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	srand(77);
	int n, k, l;
	cin>>n>>k>>l;
	for(int i = 0; i < k; i++)
	{
		int u, v; cin>>u>>v;
		u--; v--;
		adj[u].pb(v); adj[v].pb(u);
	}
	cc.resize(n);
	for(int i = 0; i < n; i++)
	{
		if(!vis[i])
		{
			dfs(i);
			cn++;
		}
	}
	dsu.reset(n,cc);
	for(int i = 0; i < l; i++)
	{
		int u, v; cin>>u>>v;
		u--; v--;
		dsu.merge(u,v);
	}
	for(int i = 0; i < n; i++)
	{
		cout<<dsu.dsu[dsu.rt(i)].ma[cc[i]];
		if(i<n-1) cout<<' ';
	}
}


Measured memory_bytes: 36068
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    X=list(zip(A,B))
    X.sort(lambda x:x[1])

    C=[(x[0],i) for i,x in enumerate(X)]
    C.sort()
    perm=[C[i][1] for i in range(n)]

    A.sort()
    B.sort()

    # A <= B を満たしていなければ不可能
    if(any(A[i]>B[i] for i in range(n))):
        print("No")
        return

    # 自由度が1つあれば可能
    if(any(A[i+1]<=B[i] for i in range(n-1))):
        print("Yes")
        return

    # permのYoung図が[n]かどうかで判断
    cnt=0
    visited=[0]*n
    def dfs(v)->int:
        if(visited[v]): return 0
        visited[v]=1
        stack=[v]
        cnt=0
        while(stack):
            cnt+=1
            v=stack.pop()
            nv=perm[v]
            if(visited[nv]):break
            visited[nv]=1
            stack.append(nv)
        return cnt

    print("Yes" if(dfs(0)<n) else "No")
resolve()

Measured memory_bytes: 83744
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int elementNum = Integer.parseInt(br.readLine());
		String line = br.readLine();
		int[] numArray = parseInt(getSplitLine(line));

		int count = 0;
		for (int i = 0; i < numArray.length - 1; i++) {
			for (int j = numArray.length - 1; j > i; j--) {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			}
		}
		System.out.println(Arrays.toString(numArray)
				.replaceAll("[\\[\\],]", ""));
		System.out.println(count);
	}

	private static String[] getSplitLine(String line) {
		return line.split("\\s");
	}

	private static int[] parseInt(String[] line) {
		int[] numArray = new int[line.length];
		for (int i = 0; i < line.length; i++) {
			numArray[i] = Integer.parseInt(line[i]);
		}
		return numArray;
	}

}

Measured memory_bytes: 16912
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long ans = 0;
        if(m / 2 >= n){
            ans = n;
        }else {
            ans = m / 2;
        }
        m -= ans * 2;
        ans += m / 4;
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
def between12(m):
    if 0 < m <= 12:
        return True
    else:
        return False

S = input()
left = int(S[:2])
right = int(S[2:])

if between12(left):
    if between12(right):
        print('AMBIGUOUS')
        exit()
    else:
        print('MMYY')
        exit()
else:
    if between12(right):
        print('YYMM')
        exit()

print('NA')

Measured memory_bytes: 3060
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000000
#define mod 1000000007

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

	int n,m;
	cin>>n>>m;
	ll num=0;
	map<ll,ll>mp;
	REP(i,n){
		int temp;
		cin>>temp;
		num+=temp;
		if(mp[num%m]==0)mp[num%m]=1;
		else mp[num%m]++;
	}
	ll ans=0;
	for(auto itr : mp){
		if(itr.first==0){
			ans+=itr.second;
		}
		if(itr.second>=2){
			ans+=itr.second*(itr.second-1)/2;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
ll INF = (1LL << 50) - 1;
int MOD = 1e9+7;
main(){
    ll x,y;
    cin >> x >> y;
    ll mini = INF;
    if(x == y)mini = 0;
    else if(abs(x) == abs(y))mini = 1;

    if(y == 0 && x > 0)mini = min(mini, x + 1);

    if(x < y)mini = min(mini, y - x);
    else mini = min(mini, x - y + 2);

    if((x < 0) ^ (y < 0)){
        mini = min(mini, abs(abs(x) - abs(y) ) + 1);
    }
    cout << mini << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;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>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = 2e18;

struct info {
    int v, d, c;
};

signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N + 1);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int Q;
    cin >> Q;
    vector<info> input(Q);
    for (int i = 0; i < Q; i++) {
        int v, d, c;
        cin >> v >> d >> c;
        input[i] = {v, d, c};
    }
    set<pair<int, int>> check;
    vector<int> ans(N + 1, 0);
    function<void(info)> explore = [&](info now) {
        if (check.find({now.v, now.d}) != check.end()) return;
        check.emplace(now.v, now.d);
        if (ans[now.v] == 0) ans[now.v] = now.c;
        if (now.d == 0) return;
        explore({now.v, now.d - 1, now.c});
        for (auto next : G[now.v]) explore({next, now.d - 1, now.c});
    };
    reverse(input.begin(), input.end());
    for (auto temp : input) explore(temp);
    for (int i = 1; i <= N; i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 67828
#include<bits/stdc++.h>
using namespace std;
vector<long long>ans;
long long asz(long long x)
{
long long num=pow(2,x);
while(x>1)
x-=2,
num+=pow(2,x);
return num;
}
int main(){
long long n;
cin>>n;
//cout<<n;
for(long long i=31;i>=0;i--){
if(i%2)
if(n<-asz(i-2))
n+=pow(2,i),
ans.push_back(1);
else
ans.push_back(0);
else
if(n>asz(i-2))
ans.push_back(1),
n-=pow(2,i);
else
ans.push_back(0);
}
long long i=0;
while(i<ans.size()-1&&!ans[i])i++;
for(i;i<ans.size();i++)cout<<ans[i];
}


Measured memory_bytes: 256
S = input()
N = len(S)
p_S = S[:int((N - 1) / 2)]
n_S = S[int((N + 3) / 2) - 1:]

def kaibun(S):
    N = len(S)
    if N % 2 == 0:
        flag = True
        for i in range(int(N / 2)):
            if S[i] != S[N - i - 1]:
                flag = False
                break
        if flag:
            return True
        else:
            return False
    else:
        flag = True
        for i in range((N // 2) + 1):
            if S[i] != S[N - i - 1]:
                flag = False
                break
        if flag:
            return True
            
if kaibun(S) and kaibun(p_S) and kaibun(n_S):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;

template<typename T, typename S>
istream& operator >> (istream& is, pair<T, S>& p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    vector<int64_t> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    int64_t ans = 0;
    for (int i = n - 1; i >= 0; --i) {
        int64_t A = a[i] + ans;
        int64_t m = A % b[i];
        if (m == 0) continue;
        ans += (b[i] - m);
    }
    cout << ans;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

int main(){

    int n;

    rep(i,5){
        cin >> n;
        if(n == 0) {
            cout << i + 1 << endl;
        }
    }
    

    return 0;
    
}

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

int main() 
{
  char a;
  vector<char> c1;
  vector<char> c2;
  for(int i=0;i<3;i++)
  {
    cin>>a;
    c1.push_back(a);
  }
  for(int i=0;i<3;i++)
  {
    cin>>a;
    c2.push_back(a);
  }
  if(c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0])
  {
    cout<<"YES"<<endl;
  }
  else
  {
    cout<<"NO"<<endl;
  }
  
  return 0;
}
  

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int k, a, b;
    cin >> k >> a >> b;

    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK\n";
            return 0;
        }
    }

    cout << "NG\n";
    return 0;
}

Measured memory_bytes: 3640
const main = (input) => {
  input = input.split(' ');
  const x = parseInt(input[0], 10);
  const a = parseInt(input[1], 10);
  const b = parseInt(input[2], 10);
  
  if (Math.abs(x-a)>=Math.abs(x-b)) {
    console.log("B");
  }else{
    console.log("A");
  }
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define int long long

using namespace std;

//int dp[3005][3005]={0};
//int dp[100005]={0};

signed main(){
	string a,b;
	cin>>a>>b;
	int count=0;
	for(int i=0;i<a.length();i++){
		if(a[i]!=b[i]) count++;
	}
	cout<<count;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<long> v(N);
  for(int i = 0; i < N; i++){
    cin >> v.at(i);
  }
  
  sort(v.begin(), v.end());
  
  long tmpmin = 10000000000;
  long tmp;
  for(int i = 0; i <= N-K; i++){
    tmp = v[i+K-1] - v[i];
    if(tmp < tmpmin){
      tmpmin = tmp;
    }
  }
  cout << tmpmin << endl;
  
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

int main(){
  int H,i,A[MAX+1];

  cin >> H;
  for(i = 1;i <= H;i++) cin >> A[i];
  for(i = 1;i <= H;i++){
    cout << "node " << i << ": key = " << A[i] << ", ";
    if(parent(i) >= 1)cout << "parent key = " << A[parent(i)] << ", ";
    if(left(i) <= H)cout << "left key = " << A[left(i)] << ", ";
    if(right(i) <= H)cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define Speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

#define st              first
#define nd              second
#define pb              push_back
#define pf              push_front
#define all(a)          (a).begin(), (a).end()
#define lwb             lower_bound
#define upb             upper_bound
#define vvll            vector<vector<ll> >
#define Mset(s, n)      memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       sort(all(a)); (a).resize(unique(all(a)) - (a).begin())

typedef long double ld;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const int oo = 2e9;
const ld PI = acos((ld) -1);
int Getbit(ll x, int k){return (x >> (k - 1)) & 1;}
ll Lcm(ll a, ll b) {return a / __gcd(a, b) * b;}
bool isPrime(ll n){for(ll i = 2; i * i <= n; i++){if(n % i == 0) return 0;} return (n > 1) ? 1 : 0;}
ll Powmod(ll n, ll k, ll p = MOD) {ll r = 1; for(; k; k /= 2, n = n * n % p){if(k & 1) r = r * n % p;} return r;}

const int N = 2e5 + 5;

ll n, m, k;
ll a[N];

void Solve(){
    cin >> n;
    ll sum = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum += a[i];
    }
    ll mn = LLONG_MAX;
    for(int i = 1; i < n; i++){
        a[i] += a[i - 1];
        mn = min(mn, abs(sum - 2 * a[i]));
    }
    cout << mn;

}

int main(){
    Speed;
    int query = 1; //cin >> query;
    while(query--){
        Solve();
    }
}





Measured memory_bytes: 1792
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int answer = 100000;
        int n = sc.nextInt();

        for(int i = 0; i < n; i++){
            answer *= 1.05;
            if(answer % 1000 == 0){continue;}
            answer += 1000 - (answer % 1000);
        }

        System.out.println(answer);


    }
}

Measured memory_bytes: 17160
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define mp(a, b) make_pair((a),(b))
#define bs(n) ((ull)1<<(ull)n)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;
constexpr double eps = 0.000000001;

bool kaibun(string s) {
    int n = s.length();
    rep(i, n)if (s[i] != s[n - 1 - i])return false;
    return true;
}

int main() {
    string s;
    cin >> s;
    int n = s.length();
    if (kaibun(s) && kaibun(s.substr(0, n / 2)) && kaibun(s.substr(n / 2 + 1, n / 2))) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, k;
    cin>>n>>k;
    vl as(n);
    cin>>as;
    vl ss(n + 1);
    rep(i, n) {
        ss[i + 1] = ss[i] + as[i];
    }
    vl bs;
    rep(l, n) for (int r = l + 1; r <= n; ++r) {
        ll num = ss[r] - ss[l];
        bs.push_back(num);
    }

    ll ans = 0;
    for (int i = 40; i >= 0; --i) {
        vl cs;
        ll cnt = 0;
        for (auto num : bs) {
            if (num>>i&1) {
                cnt++;
                cs.push_back(num);
            }
        }
        if (cnt >= k) {
            ans += (1ll<<i);
            swap(bs, cs);
        }
    }
    cout<<ans<<endl;
}

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

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

using namespace std;

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

    int n;
    cin >> n;
    if (n % 10 == 3) cout << "bon" << endl;
    else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;

//?????????
#pragma region MACRO 
#define putans(x)  std::cerr << "answer: " ; cout << (x) << endl
#define dputans(x) std::cerr << "answer: "; cout << setprecision(10) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //???????????????????????????????????????????????????
std::ifstream ifs("data.txt");
#define put ifs >>
#else //?????£????????????????????§?????????????????????
#define put cin >>
#endif
#pragma endregion

//???????????°??????????????´
#pragma region CODING_SUPPORT
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#ifndef _DEBUG
#define dbg1 {}
#define dbg2 {}
#define dbg3 {}
#define dbgArray {}
#endif 
#pragma endregion 
//typedef????????????????????????????¶????????????§?????????
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//??????????????°(???????????????????????§??????)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e9)
#pragma endregion

class Point {//????????????????????????
public:
	double x, y;
	Point(double x = 0, double y = 0) : x(x), y(y) {}

	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double a) { return Point(x * a, y * a); }
	double operator * (Point p) { return dot(p); }
	Point operator / (double a) { return Point(x / a, y / a); }

	double abs() { return sqrt(norm()); }
	double norm() { return x*x + y*y; }

	bool operator < (const Point &p) const {return  x != p.x ? x < p.x : y < p.y;}
	bool operator == (const Point &p) const {return  fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;;}
	//???????????????
	double dot(Point p) {return x * p.x + y * p.y;}
	double cross(Point p) { return x * p.y - y * p.x; }

};

int main() {
	int n; put n;
	int px, py;
	rep(j, n) {
		Point p[4];
		rep(i, 4) {
			put px >> py;
			p[i] = Point(px, py);
		}
		Point pa = p[1] - p[0];
		Point pb = p[3] - p[2];
		
		if (equals(pa*pb, 0.0)) {
			cout << 1 << endl;
			continue;
		}
		if (equals(pa.cross(pb),0.0)) {
			cout << 2 << endl;
			continue;
		}
		cout << 0 << endl;
	}

	
	return 0;
}

/*
#define i(x) int x; scanf("%d",&x);
#define l(x) ll x; scanf("%lld",&x);
#define d(x) double  x; scanf("%lf",&x);
*/
//??????????£?????????°???
//https://www23.atwiki.jp/akitaicpc/pages/65.html

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

typedef long long int ll;
ll x;

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

    cin >> x;

    ll ans = 0;
    ans += (x/500) * 1000;
    x %= 500;
    ans += (x/5) * 5;

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

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

#define ll long long
using namespace std;
int Cal(string s)
{
	int len = s.length();
	int ans = 0;
	for(int i = 0; i < len; i++)
		ans += s[i] - '0';
	return ans;
}
int main( )
{
	string n;
	while(cin >> n){
		int len = n.length();
		int ans = Cal(n);
		string now;
		now = char(n[0] - 1) + '\0';
		for(int i = 1; i < len; i++)
			now += '9';
		ans = max(ans,Cal(now));
		cout << ans << endl;
	}
}



Measured memory_bytes: 256
open System

// input
let readStr () = stdin.ReadLine()

let readInt () = stdin.ReadLine() |> int
let readInts () = stdin.ReadLine().Split() |> Array.map int

// utils

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let inline flip f a b = f b a  

// memoization
let inline memo size f =
  let dp = Array.create size None
  let rec g x =
    match dp.[x] with
    | None ->
      let v = f g x
      dp.[x] <- Some v
      v
    | Some v -> v
  g

let inline memo2 size1 size2 f =
  let dp = Array2D.create size1 size2 None
  let rec g x y =
    match Array2D.get dp x y with
    | None ->
      let v = f g x y
      Array2D.set dp x y (Some v)
      v
    | Some v -> v
  g

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

let L = readInt ()

((float L) / 3.) ** 3.
|> printfn "%f"

Measured memory_bytes: 11996
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;

int main() {
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << std::fixed;
    cout << std::setprecision(20) << W * H / 2 << " ";
    if (x + x == W && y + y == H) {
        cout << "1";
    }
    else {
        cout << "0";
    }
    cout << endl;

    return 0;
}

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


int main(){
    ll n,w;
    cin>>n>>w;
    vector<ll>vw(n+1),vv(n+1);
    for(ll i = 1 ; i <=n ; i++){
        cin>>vw[i]>>vv[i];
    }
    
    vector<vector<ll> >dp(w+1,vector<ll>(n+1,0));
    for(ll j = 1 ;j <= n ; j++ ){
        for(ll i = 1 ; i <= w ; i++ ){
            if(vw[j]>i)dp[i][j]=dp[i][j-1];
            else dp[i][j]=max(dp[i][j-1],dp[i-vw[j]][j-1]+vv[j]);
        }
    }
    
    
    
    cout<<dp[w][n];
}


Measured memory_bytes: 85116
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, K;
	string s;
	
	cin>>N>>K;
	
	cin>>s;
	
	s[K-1] -= 'A' - 'a';
	
	cout<<s<<endl;
	
	return 0;
}

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

using namespace std;

const int MAX_N = 1010, mod = 1e9 + 7;

typedef long long ll;

int n, m, mem[MAX_N];
ll X;

struct edge
{
    int src, dst, weight;
    bool operator<(const edge &rhs) const { return weight < rhs.weight; }
} edges[MAX_N << 1];

int find(int x) { return x == mem[x] ? x : mem[x] = find(mem[x]); }

int fpow(int bas, int tim)
{
    int ret = 1;
    while (tim)
    {
        if (tim & 1)
            ret = 1LL * ret * bas % mod;
        bas = 1LL * bas * bas % mod;
        tim >>= 1;
    }
    return ret;
}

ll kruskal(int eid)
{
    for (int i = 1; i <= n; i++)
        mem[i] = i;
    ll ret = 0;
    if (eid != 0)
        mem[find(edges[eid].src)] = find(edges[eid].dst), ret += edges[eid].weight;
    for (int i = 1; i <= m; i++)
        if (find(edges[i].src) != find(edges[i].dst))
        {
            ret += edges[i].weight;
            mem[find(edges[i].src)] = find(edges[i].dst);
        }
    return ret;
}

int main()
{
    scanf("%d%d%lld", &n, &m, &X);
    for (int i = 1; i <= m; i++)
        scanf("%d%d%d", &edges[i].src, &edges[i].dst, &edges[i].weight);
    sort(edges + 1, edges + 1 + m);
    ll min_val = kruskal(0);
    if (min_val > X)
        puts("0"), exit(0);
    int ceq = 0, cgeq = 0;
    for (int i = 1; i <= m; i++)
    {
        ll curt = kruskal(i);
        if (curt == X)
            ceq++;
        else if (curt > X)
            cgeq++;
    }
    if (min_val == X)
        printf("%lld\n", 1LL * ((0LL + fpow(2, ceq) + mod - 2) % mod) * fpow(2, cgeq) % mod);
    else
        printf("%lld\n", (2LL * fpow(2, ceq) % mod + mod - 2) % mod * fpow(2, cgeq) % mod);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;
int main(){
    INT(K);
    INT(A);
    INT(B);

    for(B;B >=A; B--){
        if(B % K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

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


ans = 0
for i in range(n):
    sum = 0
    for j in range(m):
        sum += int(b[j])*int(a[i][j])
#        print("j={} i={}".format(j, i))
#        print("b[{}]={} a[{}][{}]={}".format(j, b[j], i, j, a[i][j]))
        if(j == m-1):
            sum += c
#            print(sum, c)
            if(sum > 0):
                ans += 1

print(ans)


Measured memory_bytes: 3064
void main() {
  problem();
}

void problem() {
  auto X = scan!long;

  long solve() {
    long answer;

    auto num500 = X / 500;
    auto num5 = (X - num500 * 500) / 5;

    return num500 * 1000 + num5 * 5;
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 256
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;

struct Input
{
	int a;
	int b;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		a = readln().strip().to!int;
		b = readln().strip().to!int;
	}
}

struct Output
{
}

auto main2(Input* input)
{
	return 6 - input.a - input.b;
}

void parseExample(out Input input, string example)
{
	struct Adapter
	{
		string[] _lines;
		this(string input) { _lines = input.splitLines(); }
		string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
	}
	parseInput(input, Adapter(example));
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	auto result = main2(&input);
	writeln(result);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(input.readLine());
        StringTokenizer tokn = new StringTokenizer(input.readLine());

        int min = Integer.MAX_VALUE;
        int max = -1;

        for (int i = 0; i < n; i++) {
            int value = Integer.parseInt(tokn.nextToken());
            if (value < min) {
                min = value;
            }
            if (value > max) {
                max = value;
            }
        }
        System.out.println(max - min);
    }
}


Measured memory_bytes: 21204
import java.io.*;

public class Main {
    static double INF = 10000000.0;

    public static void main(String[] args) throws IOException {
        BufferedReader br = 
        new BufferedReader(new InputStreamReader(System.in));

        String line;
        while ((line = br.readLine()) != null) {
            String[] temp = line.split(" ");
            int w = Integer.parseInt(temp[0]);
            int[] r = new int[temp.length - 1];
            for (int i = 0; i < r.length; i++) {
                r[i] = Integer.parseInt(temp[i + 1]);
            }
            
            int n = r.length;
            double[][] dp = new double[1 << n][n];
            for (int i = 0;  i < (1 << n); i++) {
                for (int j = 0; j < n; j++) {
                    dp[i][j] = INF;
                }
            }
            
            for (int i = 0; i < n; i++) {
                dp[(1 << n) - 1 - (1 << i)][i] = r[i];
            }
            for (int s = (1 << n) - 2; s >= 0; s--) {
                for (int i = 0; i < n; i++) {
                    if ((s & (1 << i)) != 0) continue;
                    for (int j = 0; j < n; j++) {
                        dp[s][i] = Math.min(dp[s][i], dp[s | (1 << i)][j] +  2 * Math.sqrt(r[i] * r[j]));
                    }
                }
            }
            
            boolean flag = false;
            for (int j = 0; j < n; j++) {
                if (dp[0][j] + r[j] <= w) {
                    flag = true;
                }
            }
            System.out.println((flag) ? "OK" : "NA");
        }
    }
}

Measured memory_bytes: 32796
#include<bits/stdc++.h>
using namespace std;
#define sz 300005
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;


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

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

    cout<<"Good"<<endl;

    return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>

using namespace std;

#define Whats(x) cout<<#x<<" is "<<x<<endl
#define Divhe() cout<<"<<<<<<<<<<<<<<"<<endl
#define Divshe() cout<<">>>>>>>>>>>>>>>"<<endl
#define Oops() cout<<"!!!!!!!!!!!!!!"<<endl

#define Poly vector<int>

ostream& operator<<(ostream& os,Poly p)
{
	for(int i:p)
		os<<i<<" ";
	return os;
}

const int N=20000;
const int MOD=998244353;
const int g=3;

int Mul(int a,int b)
{
	unsigned long long x=(long long)a*b;
	unsigned xh=(unsigned)(x>>32),xl=(unsigned)x,d,m;
	asm
		(
		 "divl %4;\n\t"
		 :"=a"(d),"=d"(m)
		 :"d"(xh),"a"(xl),"r"(MOD)
		);
	return m;
}

int Qpow(int x,int y=MOD-2)
{
	int res=1;
	for(;y;y>>=1,x=Mul(x,x))if(y&1)
		res=Mul(res,x);
	return res;
}

int U(int x,int y)
{
	return ((x+=y)>=MOD)?(x-MOD):x;
}

void SU(int& x,int y)
{
	((x+=y)>=MOD)?(x-=MOD):0;
}

int D(int x,int y)
{
	return ((x-=y)<0)?(x+MOD):x;
}

void SD(int& x,int y)
{
	((x-=y)<0)?(x+=MOD):0;
}

void FFT(Poly& A,bool fl)
{
	int L=A.size();
	if(fl)
	{
		int t=Qpow(L);
		for(int& i:A)
			i=Mul(i,t);
		reverse(A.begin()+1,A.end());
	}
	for(int i=1,j=L>>1,k;i<L;++i,j^=k)
	{
		if(i<j)
			swap(A[i],A[j]);
		k=L>>1;
		while(j&k)
		{
			j^=k;
			k>>=1;
		}
	}

	static int w[N]={1};

	for(int i=1;i<L;i<<=1)
	{
		int t=Qpow(g,(MOD-1)/(i<<1));
		for(int j=1;j<i;++j)
			w[j]=Mul(w[j-1],t);
		for(int j=0;j<L;j+=(i<<1))
		{
			for(int k=0;k<i;++k)
			{
				t=Mul(A[i+j+k],w[k]);
				A[i+j+k]=D(A[j+k],t);
				SU(A[j+k],t);
			}
		}
	}
}

int n;
char A[N],B[N];

Poly operator*(Poly A,Poly B)
{
	int need=A.size()+B.size()-1,L,q=A.size();
	for(L=1;L<need;L<<=1);
	A.resize(L);
	FFT(A,false);
	B.resize(L);
	FFT(B,false);
	for(int i=0;i<L;++i)
		A[i]=Mul(A[i],B[i]);
	FFT(A,true);
	A.resize(q);
	return A;
}

Poly f;

Poly Qpow(Poly f,int y)
{
	int L=f.size();
	Poly res;
	res.resize(L);
	res[0]=1;
	for(;y;y>>=1,f=f*f)if(y&1)
			res=res*f;
	return res;
}

int jc[N],njc[N];

void Prework()
{
	jc[0]=1;
	for(int i=1;i<=n;++i)
		jc[i]=Mul(jc[i-1],i);
	njc[n]=Qpow(jc[n]);
	for(int i=n-1;i>=0;--i)
		njc[i]=Mul(njc[i+1],i+1);
}

int main()
{
	scanf("%s%s",A,B);
	n=strlen(A);
	int x=0,y=0;
	Prework();
	for(int i=0;i<n;++i)
		if(A[i]=='1')
			(B[i]=='0')?(++x):(++y);
	f.resize(y+1);
	for(int i=0;i<=y;++i)
		f[i]=njc[i+1];
	f=Qpow(f,x);
	int ans=0;
	for(int i=0;i<=y;++i)
		SU(ans,f[i]);
	ans=Mul(ans,Mul(Mul(jc[x],jc[y]),jc[x+y]));
	printf("%d",ans);
	return 0;
}


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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using piii = pair<pii, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 3 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

struct Edge{
	int from, to, cost;
	Edge(int _from, int _to, int _cost){
		from = _from;
		to = _to;
		cost = _cost;
	}
	Edge(){}
};
Edge g[2000];

bool neg[1000];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, m;
	cin >> n >> m;

	REP(i, m){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--; //0-indexed
		g[i] = Edge(a, b, -c); // 全ての辺を負にして最短経路探索をする
	}

	

	// 頂点0からの最短距離
	vector<ll> d(n, LLINF);
	d[0] = 0;

	// ベルマンフォード法
	REP(i, n){
		REP(j, m){
			Edge e = g[j];
			if(d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				if(i == n - 1 && e.to == n - 1){
					cout << "inf\n";
					return 0;
				}
			}
		}
	}

	// 最後にもとに戻す
	cout << -d[n - 1] << "\n";

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int x, y, z;
    cin >> x >> y >> z;

    cout << z << " " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    int N, A;
    cin >> N >> A;

    if ((N % 500) <= A)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
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<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

std::map<long long, long long> factorint(long long n)
{
    std::map<long long, long long> res;
    do {
    top:
        for (long long i = 2; i < std::sqrt(n)+10; ++i) {
            if (n % i == 0) {
                if (res.find(i) == res.end()) res[i] = 0;
                res[i]++;
                n /= i;
                goto top;
            } 
        }
        if (n != 1) res[n] = 1;
        break;
    } while (true);
    
    return res;
}

int main()
{
        ll N;
        cin >> N;
        vll a(N);
        rep(i, 0, N) cin >> a[i];
        ll ans = 0;
        rep(i, 0, N) {
                auto f = factorint(a[i]);
                if (f.find(2) != f.end()) {
                        ans += f[2];
                }
        }
        cout << ans << endl;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    l=list(map(int,input().split()))
    l.sort()
    print(sum(l[-K:]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import java.util.*;

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

        while (input.hasNext()) {
            int a = input.nextInt();
            int b = input.nextInt();
            int gcd = GCD(a, b);
            int lcm = a / gcd * b;

            System.out.println(gcd + " " + lcm);
        }
    }
    
    public static int GCD (int a, int b) {
        if (b == 0) {
            return a;
        }
        return GCD(b, a % b);
    }
}

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

int main() {
    int x, y;
    cin >> x >> y;
    // a+b = x, 2*a + 4*b = y
    if(y%2 != 0)
        cout << "No\n";
    else  
    {
        y=y/2;
        //a+2b = y, a+b = x
        int b = y - x;
        int a = 2*x-y;
        if(a < 0 || b < 0)
            cout << "No\n";
        else
            cout << "Yes\n";
    }
}

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

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

	string tmp="";
	while (1) {
		if (!tmp.empty()) {
			if (s.empty()) break;
			if (tmp[tmp.size() - 1] == 'T') {
				if (s[s.size() - 1] == 'S') {
					tmp.pop_back();
					s.pop_back();
					continue;
				}
			}
		}
		if (s.empty()) break;
		tmp += s[s.size() - 1];
		s.pop_back();

	}
	cout << tmp.size() << endl;

	return 0;
}

Measured memory_bytes: 776
//
//AtCoder Beginner Contest 047
//B
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

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

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int W, H, N;
    cin >> W >> H >> N;
    int tbl[100][100];
    REP(w, W)REP(h, H) tbl[w][h]=1;

    REP(i,N){
        int x, y, a;
        cin >> x >> y >> a;

        if (a==1){
            REP(w, x)REP(h,H) tbl[w][h]=0;
        }else if (a==2){
            FOR(w, x, W-1)REP(h,H) tbl[w][h]=0;
        }else if (a==3){
            REP(w, W)REP(h, y) tbl[w][h]=0;
        }else if (a==4){
            REP(w, W)FOR(h, y, H-1) tbl[w][h]=0;
        }
    }
    int ans=0;
    REP(w, W)REP(h, H) ans+=tbl[w][h];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3652