akhauriyash/Code-Regression huggingface dataset:
/*
░░░░██████████████████
░░▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ManavJ07▒▀██████▄
░███▀▒▒▒▒BITS▒▒▒▒▒▒▀█████
░▐██▒▒▒.........▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
*/
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define LONGMAX 1e18
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define endl "\n"
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define INF 1e9
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
void ceilsearch(ll ar[],ll low,ll high,ll x,ll &y){ll mid=(low+high)/2;if(low>high)return;if(ar[mid]>=x){y=mid;ceilsearch(ar,low,mid-1,x,y);}else{ceilsearch(ar,mid+1,high,x,y);}}
int main()
{
	fastio();
	ll N;
	string s;
	cin>>N>>s;
	ll ans=0;
	for(ll i=0;i<N-2;i++)
	{
	    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
	        ans++;
	}
	cout<<ans<<endl;
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    long long p = 0;
    while (pow(2, p) <= n) {
        p++;
    }
    cout << pow(2, p - 1) << endl;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#include<set>
#include<map>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
	int v = 0,c = 1;char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') c = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		v = v * 10 + ch - 48;
		ch = getchar();
	}
	return v * c;
}
int n;
int main(){
	n = read();
	bool flag = 0;
	for(int i = 1;i <= 9;++i){
		for(int j = 1;j <= 9;++j)
			if(i * j == n) flag = 1;	
	}
	if(flag) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int i=0;
	char moji[1001];
	scanf("%s",moji);
	while(moji[i]!='\0'){
		if(moji[i]=='A' || moji[i]=='B' || moji[i]=='C'){
			printf("%c",moji[i]+23);
			i++;
		}
		else{
			printf("%c",moji[i]-3);
			i++;
		}
	}
	printf("\n");
	return 0;
}



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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }	//最大公約数(Greatest Common Divisor)
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }			//最小公倍数(Least Common Multiple)


int main() {
	lli h, w;
	cin >> h >> w;
	lli ans = 0;

	if (h % 2 == 0 && w % 2 == 0) {
		ans = h * w / 2;
	}
	else if (h % 2 == 1 && w % 2 == 0) {
		ans = h * w / 2;
	}
	else if (h % 2 == 0 && w % 2 == 1) {
		ans = h * floor(w / 2) + h / 2;
	}
	else if (h % 2 == 1 && w % 2 == 1) {
		ans = h * floor(w / 2) + floor(h / 2)+1;
	}

	if (h == 1 || w == 1)
		ans = 1;

	cout << ans << endl;

}

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

int main() {
  int s;
  cin >> s;
  int s1 = s/100;
  int surs1 = s1 % 2;
  int s2 = s/10;
  int surs2 = s2 % 2;
  int s3 = s/1;
  int surs3 = s3 % 2;
  int count = surs1 + surs2 + surs3;
  cout << count << endl;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let cards = input();

    let mut checked: Vec<Vec<bool>> = vec![];
    for _ in 0..4 {
        let mut v = vec![];
        for _ in 0..13 {
            v.push(false);
        }
        checked.push(v);
    }

    for card in cards {
        match card {
            ('S', n) => checked[0][n - 1] = true,
            ('H', n) => checked[1][n - 1] = true,
            ('C', n) => checked[2][n - 1] = true,
            (_, n) => checked[3][n - 1] = true,
        }
    }

    for (k, cards) in checked.iter().enumerate() {
        for (n, is_check) in cards.iter().enumerate() {
            if !is_check {
                let kind = match k {
                    0 => 'S',
                    1 => 'H',
                    2 => 'C',
                    _ => 'D'
                };

                println!("{} {}", kind, n+1);
            }
        }
    }
}

fn input() -> Vec<(char, usize)> {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    
    let n: i32 = s.trim().parse().unwrap();

    let mut cards: Vec<(char, usize)> = vec![];
    for _ in 0..n {
        let mut s = String::new();
        io::stdin().read_line(&mut s).expect("");
        let mut iter = s.trim().split_whitespace();

        let kind: char = iter.next().unwrap().chars().nth(0).unwrap();
        let num: usize = iter.next().unwrap().parse().unwrap();

        cards.push((kind, num));
    }

    cards
}



Measured memory_bytes: 5036
'use strict'
let input = require("fs").readFileSync("/dev/stdin", "utf8");
input = input.split('\n');
let info = input.shift();
let H = input[0].split(' ').map(x=> x*1);
let ans = 0;
let max = H[0];
H.forEach(
  h=>{
    if(h >= max){
    	ans++;
      max = h;
    }
  }
);

console.log(ans);

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

enum{A, B, W, X, Y, Z, M};

int to(int now, int c){
	if( now == A ) return c? Y : X;
	if( now == B ) return c? X : Y;
	if( now == W ) return c? Y : B;
	if( now == X ) return c? Z : M;
	if( now == Y ) return c? M : X;
	if( now == Z ) return c? B : W;
	return M;
}

int main(){
	string p;
	while( cin >> p ){
		if( p == "#" ) break;
		
		int now = A;
		for(int i=0 ; i < p.size() ; i++ ){
			now = to(now, p[i] - '0');
		}
		cout << ((now == B)? "Yes" : "No") << endl;
	}
}

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

int main(){
  ll n;
  cin>>n;
  ll p[n];
  rep(i,n) cin >>p[i];
  ll s =p[0];
  ll checker = 0;
  rep(i,n) {
    s = min(s,p[i]);
    //cout<<ans[0]<<endl;
    if(p[i]<=s) ++checker;
  }
  cout<<checker<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    vector<bool> v1(10);
    vector<vector<bool>> v2(10,vector<bool>(10));
    vector<vector<vector<bool>>> v3(10,vector<vector<bool>>(10,vector<bool>(10)));
    string s;
    in>>n>>s;
    fr(i,n){
        fr(j,10) fr(k,10) if(v2[j][k]) v3[j][k][s[i]-'0']=true;
        fr(j,10) if(v1[j]) v2[j][s[i]-'0']=true;
        v1[s[i]-'0']=true;
    }
    ll ans{};
    fr(i,10) fr(j,10) fr(k,10) if(v3[i][j][k]) ++ans;
    cout<<ans<<endl;
}

Measured memory_bytes: 384
high, wigh = map(int,input().split())
if high == 1:
    print("1")
elif wigh == 1:
    print("1")
else:
    if high % 2 == 1:
        if wigh % 2 == 1:
            print(round(high * wigh/2 + 0.5))
        else:
            print(round(high * wigh/2))
    else:
        print(round(high * wigh/2))

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

int main(){
	int n, age;
	int ans[7];
	while(cin >> n, n){
		for(int i=0; i < 7; i++) ans[i] = 0;
		for(int i=0; i < n; i++){
			cin >> age;
			if(age < 10) ans[0]++;
			else if(age < 20) ans[1]++;
			else if(age < 30) ans[2]++;
			else if(age < 40) ans[3]++;
			else if(age < 50) ans[4]++;
			else if(age < 60) ans[5]++;
			else ans[6]++;
		}
		for(int i=0; i < 7; i++)cout << ans[i] << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {	
	int N; cin >> N;
	vector<set<string>> v(N); // 1文字~N文字
	v.at(0).insert("a");
	rep(i, N - 1) {
		// dbl(i);
		for (string s : v.at(i)) {
			int m = 0;
			for (char c : s) m = max(m, c - 'a');
			rep(j, m + 2) {
					v.at(i + 1).insert(s + (char)('a' + j));
			}		
		}
	}
	for (string s : v.at(N - 1)) {
		cout << s << endl;
	}	
}

Measured memory_bytes: 17024
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
using namespace std;
int main(){
    long long int N, A;
    cin >> N;
    int flag = 0;
    for(int i = 0; i < N; i++){
        cin >> A;
        if(A&0b01 == 1){
            flag = 1;
            break;
        }
    }
    if(flag){
        cout << "first" << endl;
    }else{
        cout << "second" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
int main(){
  ll n,k;cin>>n>>k;
  if(k%2!=0){
    cout<<(n/k)*(n/k)*(n/k)<<endl;
  }
  else {
    ll d=k/2;
    cout<<(n/k)*(n/k)*(n/k)+(n/d-n/k)*(n/d-n/k)*(n/d-n/k)<<endl;
  }
}

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

using namespace std;

const int INF = 1 << 29;

int N, X[1001];
vector< int > g[1000];

pair< int, int > rec(int idx)
{
  vector< int > dp1(5001, 0);

  for(auto &to : g[idx]) {
    auto get = rec(to);

    vector< int > dp2(5001, INF);
    for(int j = 0; j <= 5000 - get.second; j++) {
      dp2[j + get.second] = min(dp2[j + get.second], dp1[j] + get.first);
    }
    for(int j = 0; j <= 5000 - get.first; j++) {
      dp2[j + get.first] = min(dp2[j + get.first], dp1[j] + get.second);
    }
    dp1.swap(dp2);
  }
  return {X[idx], dp1[X[idx]]};
}

int main()
{

  cin >> N;
  for(int i = 1; i < N; i++) {
    int x;
    cin >> x;
    g[--x].emplace_back(i);
  }
  for(int i = 0; i < N; i++) {
    cin >> X[i];
  }
  if(rec(0).second == INF) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << "POSSIBLE" << endl;
  }
}

Measured memory_bytes: 8748
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		if (n <= 999){
			System.out.println("ABC");
		}
		else{
			System.out.println("ABD");	
		}
	}
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int arr[3];
  for(int i=0;i<3;i++)cin>>arr[i];
  for(int val:arr)
  {
    if(val%2==0)
    {
      	cout<<"0";
    	return 0;
    }
  }
  sort(arr,arr+3);
  cout<<1LL*arr[0]*arr[1];
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var K, S int
	fmt.Scan(&K, &S)
	cnt := 0
	for i := 0; i <= K; i++ {
		for j := 0; j <= K; j++ {
			if k := S - i - j; 0 <= k && k <= K {
				cnt++
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n, m;
	cin >> n >> m;
	int ans = pow(2, m) * (100 * (n - m) + 1900 * m);
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 4112
import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
                  log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

# For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')

# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')


def inp():
    return(int(input()))


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


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


def def_value():
    return 0


n, k = invr()
a = inlist()
a = sorted(a)
res = sum(a[:k])
print(res)


Measured memory_bytes: 10604
#include<bits/stdc++.h>
using namespace std;
int tot,QwQ;
string x,y;
int main(){
	cin>>x>>y;
	int lena=x.size(),lenb=y.size();
	for(int i=1;i<=lena+lenb;i++){
		if(i%2==1)
			cout<<x[tot++];
		else cout<<y[QwQ++];
	}
	return 0;
}

Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Int (Int64)
import qualified Data.ByteString.Char8 as BS

main = do
  s <- BS.getLine
  let gg = map (\t -> (BS.head t, fromIntegral $ BS.length t)) $ BS.group s
      g = case gg of
            ('>',_):_ -> ('<',0) : gg
            _ -> gg
      loop :: Int64 -> [(Char,Int64)] -> Int64
      loop !acc [] = acc
      loop !acc (('<',a):('>',b):xs) = loop (acc + a * (a-1) `quot` 2 + b * (b-1) `quot` 2 + max a b)xs
      loop !acc [('<',a)] = acc + a * (a+1) `quot` 2
  print $ loop 0 g


Measured memory_bytes: 1916
/*
* @Author: Samson
* @Date:   2018-05-07 21:12:41
* @Last Modified by:   Samson
* @Last Modified time: 2018-05-07 21:44:27
*/
//   @URL : 
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<stack>
#include <cstdlib>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e5+10;

int n,m,q,color[MAXN];
vector<int> v[MAXN];

void dfs(int x,int id)
{
	stack<int> s;
	int t;
	s.push(x);
	color[x] = id;
	while(s.size())
	{
		t = s.top();
		s.pop();
		for(int i = 0; i < v[t].size(); ++i)
		{
			int val = v[t][i];
			if(color[val] == -1)
			{
				color[val] = id;
				s.push(val);
			}
		}
	}
}

void fun()
{
	int id = 0;
	memset(color,-1,sizeof color);
	for(int i = 0; i < n; ++i)
		if(color[i] == -1)
			dfs(i,++id);
}

int main(void)
{
	ios::sync_with_stdio(false); 
	//cin.tie(0);
	cin>>n>>m;
	int s,e;
	for(int i = 0; i < m; ++i)
	{
		cin>>s>>e;
		v[s].push_back(e);
		v[e].push_back(s);
	}
	fun();
	cin>>q;
	while(q--)
	{
		cin>>s>>e;
		if(color[s] == color[e] && color[s]!=-1)
			cout<<"yes\n";
		else
			cout<<"no\n";
	}
	return 0;
}


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

int main() {

	int N;
	cin >> N;

	vector<double> v(N);
	for (int i = 0; i < N; i++)
	{
		cin >> v[i];
	}
	sort(v.begin(), v.end());

	for (int i = 0; i < N-1; i++)
	{
		v[i + 1] = (v[i] + v[i + 1]) / 2.0;
	}

	cout << v[N-1] << endl;


	return 0;
}

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


class Computes{
	public float[] Solve(int a, int b, int c, int d, int e, int f){
		float[] sols = new float[2];
		sols[0] = (float) (e*c-b*f)/(a*e-b*d);
		sols[1] = (float) (a*f-d*c)/(a*e-b*d);
		for(int i=0;i<=1;i++){
			if(sols[i]==-0){sols[i]=0;}
		}
		return sols;
	}
}

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = null;
		Computes comp = new Computes();
		try{
			while((line = br.readLine())!=null){
		//		System.out.println(line);
			String[] strs = line.split(" ");
			int[] ints = new int[strs.length];
			for(int i = 0; i< strs.length ; i++){
				 ints[i] = Integer.parseInt(strs[i]);
			//	 System.out.print(ints[i]);
			}
			float[] sols = comp.Solve(ints[0], ints[1], ints[2], ints[3], ints[4], ints[5]);
			System.out.printf("%.3f %.3f\n",sols[0],sols[1]);
			}
		} catch(Exception e){}
	}

}

Measured memory_bytes: 15136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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;
}


vector<ll> inv,fact,invfact;
void Mod_build(int n=201010){
	fact.resize(n+1);
	inv.resize(n+1);
	invfact.resize(n+1);
	fact[0]=inv[0]=invfact[0]=1;
	inv[1]=1;
	for(ll i=0;i<n;i++){
		fact[i+1]=fact[i]*(i+1)%mod;
		if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
		invfact[i+1]=invfact[i]*inv[i+1]%mod;
	}
}
ll perm(int n,int k){
	if(n<0||k<0||k>n)return 0;
	return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
	if(n<0||k<0||k>n)return 0;
	return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
	k%=mod-1;
	if(k<0)k+=mod-1;
	ll ret=1;
	while(k){
		if(k&1)ret=ret*n%mod;
		n=n*n%mod;
		k>>=1;
	}
	return ret;
}


ll modinv(ll a) {
    ll m=mod;
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int n;
vector<int> E[201010];
VI dp1(201010);
VI dp2(201010);
VI size1(201010,0);
VI size2(201010);
VI ans(201010);

void dfs1(int cu, int pa = -1) {
  dp1[cu]=1;
  for(int to:E[cu]) {
    if (to != pa) {
      dfs1(to,cu);
      dp1[cu]*=invfact[size1[to]]; dp1[cu]%=mod;
	  dp1[cu]*=dp1[to]; dp1[cu]%=mod;
	  size1[cu]+=size1[to];
    }
  }
  dp1[cu]*=fact[size1[cu]]; dp1[cu]%=mod;
  size1[cu]++;
  size2[cu]=n-size1[cu];
}

void dfs2(int cu, int pa = -1) {
  if(pa==-1) dp2[cu]=1;
  ll allproduct=dp2[cu]*invfact[size2[cu]]%mod;
  allproduct=allproduct*dp1[cu]%mod;
  allproduct=allproduct*invfact[size1[cu]-1]%mod;
  ans[cu]=allproduct*fact[n-1]%mod;
  for(int to:E[cu]){
	  if(to==pa) continue;
	  dp2[to]=allproduct*modinv(dp1[to]); dp2[to]%=mod;
	  dp2[to]=dp2[to]*fact[size1[to]]; dp2[to]%=mod;
	  dp2[to]=dp2[to]*fact[size2[to]-1]; dp2[to]%=mod;
	  dfs2(to,cu);
  }
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int i,j;
	cin>>n;
	Mod_build();
	for(i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--; b--;
		E[a].pb(b);
		E[b].pb(a);
	}
	dfs1(0);
	dfs2(0);
	for(i=0;i<n;i++) cout<<ans[i]<<endl;
	for(i=0;i<n;i++) {
		//cout<<size1[i]<<" "<<dp1[i]<<" "<<dp2[i]<<endl;
	}
}

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

#include <boost/range/adaptors.hpp>

int main() {
    int K;
    std::cin >> K;

    std::vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    std::cout << A[K - 1] << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip> 
#include <cstring>
#include <queue>
#include <stack> 
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
ll n,H,W,x,y;
ll cnt = 0;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >>H >>W;
	while(n--){
		cin >> x >>y;
		if(x >= H &&y >= W){
			cnt++;
		}
	}
	cout <<cnt <<endl;
	return 0;
}

Measured memory_bytes: 888
#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;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size()
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define PQS priority_queue <int, vector<int>, greater<int> >
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

int mul(int a, int b) {
  a += mod; b += mod;
  a %= mod; b %= mod; return ((a * b) % mod);
}
void solve(){
    int n,k;
    cin>>n>>k;
    int K=k;
    vector<int>pos,neg,zero;
    vector<pair<int,int>>v(n);
    for(int i=0;i<n;i++){
        int d;
        cin>>d;
        if(d>0)pos.push_back(d);
        else if(d<0)neg.push_back(abs(d));
        else zero.push_back(d);
        int s;
        if(d>=0)s=1;
        else s=-1;
        v[i]={abs(d),s};
    }
    sort(pos.begin(),pos.end());sort(neg.begin(),neg.end());sort(v.begin(),v.end());
    int ans=1;
    int pcur=(int)pos.size()-1,ncur=(int)neg.size()-1;
    if(k%2){
        if(pos.size()){
            ans=mul(ans,pos[pcur]);
            pcur--;
            k--;
        }
    }
    while(k && (pcur>0 || ncur>0)){
        int val1=-INF,val2=-INF;
        if(pcur>=1){
            val1=pos[pcur] * pos[pcur-1];
        }
        if(ncur>=1){
            val2=neg[ncur] * neg[ncur-1];
        }
        if(val1>val2){
            ans=mul(ans,val1);
            pcur-=2;
        }
        else{
            ans=mul(ans,val2);
            ncur-=2;
        }
        k-=2;
    }
    if(k){
        if(!zero.empty()){
            ans=0;
        }
        else{
            ans=1;
            for(ll i=0;i<K;i++){
                ans=mul(ans,v[i].first * v[i].second);
            }
        }
    }
    cout<<ans<<endl;
    return;
}
signed main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
   int t = 1;  //cin >> t;
   for(int i = 1; i <= t; i++) {
     solve();
  }
}



Measured memory_bytes: 8468
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;
const double PI = acos(-1);

int main(){
    int N; 
    ll ans = 0;
    cin >> N;
    vector<ll> A(100010, 0);
    for(int i = 0; i < N; i++){
        int a;cin>>a;
        ans += a;
        A[a] += 1;
    }
    int q;cin >> q;
    vector<ll> ANS(q);
    for(int i = 0; i<q; i++){
        ll b,c; cin>>b>>c;
        ans += (c - b) * A[b];
        A[c] += A[b];
        A[b] = 0;
        ANS[i] = ans;
    }
    for(int i = 0; i<q;i++) cout<<ANS[i]<<endl;
}

Measured memory_bytes: 4756
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, X, Y;
vector<P> G[200000];
int C[200000], W[200000];
int U[200000], R[200000];
int fact[200001], factinv[200001];
int ctr[200000];

int modpow(int x, int k) {
  int a = 1;
  while (k > 0) {
    if (k & 1) a = (1LL*a*x) % MOD;
    x = (1LL*x*x) % MOD;
    k >>= 1;
  }
  return a;
}

int inv(int x) {
  return modpow(x, MOD-2);
}

int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}

void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (R[x] < R[y]) swap(x, y);
  U[y] = x;
  R[x] += R[y];
  R[y] = 0;
}

bool same(int x, int y) {
  return find(x) == find(y);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> X >> Y;

  fact[0] = 1;
  factinv[0] = 1;
  for (int i=1; i<=N; i++) {
    fact[i] = (1LL*i*fact[i-1]) % MOD;
    factinv[i] = inv(fact[i]);
  }
  for (int i=0; i<N; i++) U[i] = i, R[i] = 1;

  rep(i, N) {
    cin >> C[i] >> W[i];
    C[i]--;
    G[C[i]].pb(P(W[i], i));
  }

  vector<P> vs;
  rep(i, N) {
    sort(all(G[i]));
    if (G[i].empty()) continue;
    vs.pb(G[i][0]);
    for (P &p : G[i]) {
      if (p._1 + G[i][0]._1 <= X) unite(G[i][0]._2, p._2);
    }
  }
  sort(all(vs));

  rep(i, N) {
    int m = 0;
    if (C[i] == C[vs[m]._2]) {
      if (vs.size() < 2) continue;
      m = 1;
    }
    if (vs[m]._1 + W[i] <= Y) unite(i, vs[m]._2);
  }

  int rt = find(vs[0]._2);
  int ans = fact[R[rt]];
  rep(i, N) {
    if (find(i) == rt) ctr[C[i]]++;
  }
  rep(i, N) {
    ans = (1LL*ans*factinv[ctr[i]]) % MOD;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 16376
N = gets.to_i
a = gets.split.map(&:to_i)

minus = 0
absmin = 10**9
sum = 0

for i in 0..N-1 do
  if a[i] < 0
    minus += 1
    a[i] = -a[i]
  end
  tmp = a[i].abs
  sum += tmp
  absmin = tmp if absmin > tmp
end

if minus %2 == 0
  puts sum
else
  puts sum - 2*absmin
end


Measured memory_bytes: 8580
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace at
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            var a = int.Parse(str[0]);
            var b = int.Parse(str[1]);

            if(a==b)
            {
                Console.WriteLine("Draw");
                return;
            }
            if(a==1) 
            {
                Console.WriteLine("Alice");
                return;
            }
            if(b==1) 
            {
                Console.WriteLine("Bob");
                return;
            }
            
            if(a<b) Console.WriteLine("Bob");
            if(a>b) Console.WriteLine("Alice");
        }    
    }
}

Measured memory_bytes: 11092
#include <stdio.h>

int main() {
    int i, N, K;
    scanf("%d%d", &N, &K);
    for (i=0; N > 0 ;i++) {
        N = N - K;
        if (i == 0) K--;
    }
    printf("%d\n", i);
    return 0;
}

Measured memory_bytes: 128
/**
 * author: Behradm
 * Created: 2020.08.29 17:56:18
 * In The Name of God
**/
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10;
int a[N], cnt[N];

int main() {   
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int gcd = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      gcd = a[0];
    else
      gcd = __gcd(gcd, a[i]);
  }

  bool bad = false;
  for (int i = 0; i < n; i++) {
    bool prime = true;
		for (int j = 2; j * j <= a[i]; j++) {
			if (a[i] % j == 0) {
        prime = false;
				cnt[j]++;
				if(a[i] / j != j)
					cnt[a[i] / j]++;
        if (cnt[j] > 1 || cnt[a[i] / j] > 1) {
          bad = true;
          break;
        }
			}
		}
    if (prime && a[i] != 1) {
      cnt[a[i]]++;
      if (cnt[a[i]] > 1) {
        bad = true;
      }
    }
    if (bad)
      break;
	}

  if (!bad) {
    cout << "pairwise coprime\n";
  } else if (gcd == 1) {
    cout << "setwise coprime\n";
  } else {
    cout << "not coprime\n";
  }
  return 0;
}



Measured memory_bytes: 7792
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100010;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
using Graph = vector<vector<int>>;

vector<bool> seen;
vector<int> score;
vector<int> p, x;

void dfs(const Graph &G, int v, int parent){
    seen[v] = true;
    score[v] += score[parent];

    for(auto next_v : G[v]){
        if(seen[next_v]) continue;
        dfs(G, next_v, v);
    }
}

int main(){
    int n, q; cin >> n >> q;

    Graph G(n);
    seen.resize(n);
    p.resize(q);
    x.resize(q);
    score.resize(n);
    rep(i, n) score[i] = 0;

    rep(i, n - 1){
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i, q){
        cin >> p[i] >> x[i];
        p[i]--;
    }
    rep(i, q) score[p[i]] += x[i];
    dfs(G, 0, -1);

    rep(i, n){
        if(i == n - 1){
            cout << score[i] << endl;
            return 0;
        }
        cout << score[i] << " ";
    }
}

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

int main(){
  int x;
  cin >> x;
  int n=x%100,m=x/100,a=0;
  a=(n%5==0)?n/5:n/5+1;
  if(m<a)
    cout << 0 << endl;
  else 
    cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=1005;
#define M 1000000007
#define double long double
#define BINF 1000000000001
#define init(a,val) memset(a,val,sizeof(a))
const int LG = 22;


 
#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0); 
 
    


    int n;
    cin >> n;
    int ans = 0;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int c = 1;
    for(int i = 1; i < n; i++){
        if(a[i] <= a[i - 1])
            c++;
        else{
            ans = max(ans, c);
            c = 1;
        }
    }
    ans = max(ans, c);
    cout << ans - 1 << endl;



 
return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
s = list(input())

s.pop()
while True:
    if len(s) % 2 == 1:
        s.pop()
    flag = True
    for i in range(len(s) // 2):
        if s[i] != s[i + len(s) // 2]:
            flag = False
    if not flag:
        s.pop()
    if flag:
        print(len(s))
        break


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

int main() {
    int n;
    cin >> n;
    vector<ll> a(3 * n);
    rep(i, 3 * n) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    for (int i = 3*n-2; i >= n; i-=2){
        ans += a[i];
    }
    cout << ans << endl;
}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	ll n,k,x,y;
	cin>>n>>k>>x>>y;
	ll cost=min(n,k)*x;
	if(n>k) cost+=(n-k)*y;
	cout<<cost<<'\n';
}




Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, arr[101], W, w[101], v[101];
ll dp[101][100001];

ll solve(int i = 0, int rem = W) {
    if (i == n) {
        return 0;
    }
    ll& ret = dp[i][rem];
    if (~ret) {
        return ret;
    }
    return ret = max(solve(i+1, rem), (w[i] <= rem ? v[i] + solve(i+1, rem-w[i]) : 0));
}
int main()
{
    IOS
    cin >> n >> W;

    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
    }
    for (int i = 0; i <= n; ++i) {
        for (int rem = 0; rem <= W; ++rem) {
            if (i==0 || rem==0) {
                dp[i][rem] = 0;
            } else if (w[i-1]<=rem) {
                dp[i][rem] = max(dp[i-1][rem], v[i-1] + dp[i-1][rem-w[i-1]]);
            } else {
                dp[i][rem] = dp[i-1][rem];
            }
        }
    }
    cout << dp[n][W] << endl;

    return 0;
}


Measured memory_bytes: 79232
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    long long int x, t;
    cin>>x>>t;
    long long int ans=x-t;
    if(ans<0) ans=0;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (a, b, c) = readIntegerList()
    val ans = min(c,  b / a)
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}
const int MAXN = 333333;
int fa[MAXN], n, m, ans;
int find(int x){
    if (x == fa[x]) return x;
    return fa[x] = find(fa[x]);
}
void merge(int x, int y){
    x = find(x), y = find(y);
    fa[x] = y;
}
int main(){
    n = read(), m = read();
    for (int i = 1; i <= n; i++) fa[i] = i;
    for (int i = 1; i <= m; i++){
        int a = read(), b = read();
        merge(a, b);
    }
    for (int i = 1; i <= n; i++)
        if (find(i) == i)
            ans++;
    printf("%d\n", ans-1);
    return 0;
}

Measured memory_bytes: 4152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
const int inf = 1<<29;

int main(){
    int N; cin >> N;
    vector<int> P(N);
    REP(i,N) cin >> P[i];
    int now = inf;
    int ans = 0;
    REP(i,N) {
        if(now>=P[i]) ans ++;
        now = min(P[i],now);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int h;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> h;
        if (h >= k) cnt++;
    }
    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 256
/*

BISMILLAH - HIR - RAHMANIR - RAHIM

*/

#include<bits/stdc++.h>
using namespace std;



#define ll long long int
#define MAX 2268312229760322080

// No Copyright--You can copy and paste it without my permission......... (Wink Emoji)
// Break up but Never Give Up

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

    int a, b ;
    cin >> a >> b ;
    if(b%a==0)
    {
        cout << a + b <<endl;
    }
    else{
        cout << b - a <<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int k, s;
    cin >> k >> s;
    int ans = 0;
    for(int x = 0; x <= k; x++){
        for(int y = 0; y <= k; y++){
            if(s < x + y) break;
            ans += s - x - y <= k;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#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 110000

int s[MAX], t[MAX], x[MAX];
pair<int,int> temp[MAX], temp2[MAX], que[MAX];

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int A, B, Q;
	
	cin>>A>>B>>Q;
	
	rep(i,A)cin>>s[i];
	rep(i,B)cin>>t[i];
	rep(i,Q){
		cin>>x[i];
		que[i].first = x[i];
		que[i].second = i;
	}
	
	sort(x,x+Q);
	sort(que,que+Q);
	for(int i = 0; i < Q; i++){
		 que[i].first = que[i].second;
		 que[i].second = i;
	}
	sort(que,que+Q);
	for(int i = 0, j = 0; i < Q; i++){
		for(;j < A;j++){
			if(x[i] < s[j]) break;
		}
		if(j == 0) temp[i].first = INF;
		else temp[i].first = x[i]-s[j-1];
		
		if(j == A) temp[i].second = INF;
		else temp[i].second = s[j]-x[i];
		// cout<<i<<" "<<temp[i].first<<" "<<temp[i].second<<endl;
		// cout<<x[i]<<" "<<s[j]<<endl;
	}
	
	for(int i = 0, j = 0; i < Q; i++){
		for(;j < B;j++){
			if(x[i] < t[j]) break;
		}
		if(j == 0) temp2[i].first = INF;
		else temp2[i].first = x[i]-t[j-1];
		
		if(j == B) temp2[i].second = INF;
		else temp2[i].second = t[j]-x[i];
		// cout<<i<<" "<<temp2[i].first<<" "<<temp2[i].second<<endl;
	}
	
	for(int j = 0; j < Q; j++){
		int i = que[j].second;
		cout<<min(min(max(temp[i].first,temp2[i].first),max(temp[i].second,temp2[i].second)),min(min(temp[i].first,temp2[i].second)*2+max(temp[i].first,temp2[i].second),min(temp[i].second,temp2[i].first)*2 + max(temp[i].second,temp2[i].first)))<<endl;
		// cout<<temp[i].first<<" "<<temp[i].second<<endl;
		// cout<<temp2[i].first<<" "<<temp2[i].second<<endl<<endl;;
	}
	
	
	return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int sum[maxn];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    memset(sum,0,sizeof(sum));
    for(int i=1;i<=n;i++)
    {
        int l,r;
        scanf("%d%d",&l,&r);l--;
        for(int j=1,k;j<=l;j=k+1)
        {
            k=min(l/(l/j),r/(r/j));
            if(l/j!=r/j)
            {
                sum[j]++;
                sum[k+1]--;
            }
        }
        sum[l+1]++;
        sum[r+1]--;
    }
    for(int i=1;i<=m;i++)
    {
        sum[i]+=sum[i-1];
        printf("%d\n",sum[i]);
    }
    return 0;
}


Measured memory_bytes: 1280
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    Map<String, List<Integer>> map = new HashMap<>();

    Map<String, Integer> restaurants = new HashMap<>();

    for (int i = 0; i < n; i++) {
      String city = sc.next();
      int score = sc.nextInt();
      List<Integer> list = map.getOrDefault(city, new ArrayList<>());
      list.add(score);
      map.put(city, list);
      restaurants.put(city + score, i);
    }

    List<String> cities = new ArrayList<>(map.keySet());
    Collections.sort(cities);
    for (String city : cities) {
      List<Integer> scores = map.get(city);
      Collections.sort(scores);
      Collections.reverse(scores);
      for (int score : scores) {
        os.println(restaurants.get(city + score) + 1);
      }
    }
  }
}

Measured memory_bytes: 21076
#include<stdio.h>
int main(){
  int sum=0 ,cut=0 , a , i , j;
  while(1){
  scanf("%d",&a);
  if(a==0)break;
  for(i=1;i<a;i++){
    sum+=i;

      for(j=i+1;sum<a;j++){
	sum+=j;
	if(sum==a){
	  cut++;
	  break;
	}
      }
      sum=0;
  }
  printf("%d\n",cut);
  cut=0;
  }
  return 0;
}

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

int main(){
  int N; //ボールの数
  int K; //タイプBのロボットの配置場所(x座標)
  int x; //ボールの置かれた位置
  int kyoriA, kyoriB;
  int Total = 0;

  cin >> N >> K;

  for (int i=0; i<N; i++){
    cin >> x;
    kyoriA = ( x - 0 ) * 2;
    kyoriB = ( K - x ) * 2;
    if ( kyoriA <= kyoriB ) {
        Total += kyoriA;
      } else {
        Total += kyoriB;
    }
  } 

  cout << Total;
}


Measured memory_bytes: 256
from sys import stdin
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
x,y = map(int,stdin.readline().split())
ans = 'No'
if x in a and y in a:
    ans = 'Yes' 
if x in b and y in b:
    ans = 'Yes'
if x in c and y in c:
    ans = 'Yes'
print ans

Measured memory_bytes: 2568
N, Q = map(int, input().split())
S = input()

AC_appearance = [0] * len(S)
counter = 0
for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        counter += 1
    AC_appearance[i] = counter 

for i in range(Q):
    l, r = map(int, input().split())
    l = l - 1
    r = r - 1
    print(AC_appearance[r] - AC_appearance[l])

Measured memory_bytes: 6084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (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; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

  const int INF = 10000000;
  int ans = 0;
  int H,W;
  
  int sy,sx,gy,gx;
  char c[25][25];
  int d[25][25];

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

  int bfs(){
  queue<pair<int,int>> que;
  
  FOR(i,0,H-1){
    FOR(j,0,W-1){
      d[i][j] = INF;
    }
  }
  que.push(pair<int,int>(sy,sx));
  d[sy][sx] = 0;

  while(que.size()){
    pair<int,int> p = que.front();
    que.pop();

    if(p.first == gy && p.second == gx) break;

    FOR(i,0,3){
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];

      if(nx>=0 && nx<W && ny>=0 && ny<H && c[ny][nx]=='.' && d[ny][nx] == INF){
        que.push(pair<int,int>(ny,nx));
        d[ny][nx] = d[p.first][p.second] + 1;
      }
    }
  }
  if(d[gy][gx] == INF) d[gy][gx] = 0;
  return d[gy][gx];
}

int main() {
  cin >> H >> W;
  FOR(i,0,H-1){
    string s; cin >> s;
    FOR(j,0,W-1){
      c[i][j] = s[j];
    }
  }
  FOR(i,0,H-1){
    FOR(j,0,W-1){
      FOR(k,0,H-1){
        FOR(l,0,W-1){
          if(c[i][j] == '#' || c[k][l] == '#') continue;
          sy = i; sx = j; gy = k; gx = l;
          chmax(ans,bfs());
        }
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
S = input()
N = len(S)+1
A = [0 for i in range(N)]

num = 0
while(num<=N-2):
    i = num
    if(S[i]=="<"):
        A[i+1]=A[i]+1
        num += 1
    else:
        start = i
        j = 0
        while(i+j<len(S) and S[i+j]==">"):
            j += 1
        if(i==0):
            A[i] = j
        else:
            A[i] = max([A[i],j])
            #print(i,A[i],j)
        
        for j_ in range(j):
            A[i+j_+1] = j-1-j_
        num += j
print(sum(A))

Measured memory_bytes: 24100
//ysh_gpta
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
typedef long long ll;
#define vb vector<bool>
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define mkp make_pair
#define pb push_back
#define INF 1000000000000000
#define MOD 1000000007
#define ff first
#define ss second
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//ll gcd( ll a, ll b ){if(b==0) return a; else return gcd( b, a%b );}
//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}
//void printArray(vi &v){for(int i=0;i<v.size();i++) cout<<v[i]<<endl; cout<<endl; }
int main(){
   FastIO
   ll n,k;
   cin>>n>>k;
   vi v(n);
   for(int i=0;i<n;i++)
   cin>>v[i];
   vi dp(n);
   dp[0]=0;
   for(int i=1;i<n;i++){
       dp[i] = INT_MAX;
       for(int j=i-1;j>=0 && i-j<=k;j--)
       dp[i] = min(abs(v[i]-v[j])+dp[j],dp[i]);
   }
//    printArray(dp);
   cout<<dp[n-1];
   return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

struct prime_n {
  int p = -1;
  bool isPrime = true;
};
int struct_prime(vector<prime_n>&primes) {
  primes[0].isPrime = false;
  primes[1].isPrime = false;
  int cnt = 0;
  for (int i = 0; i < primes.size(); i++) {
    if (!primes[i].isPrime) continue;
    primes[i].p = i;
    cnt++;
    for (int k = 2 * i; k < primes.size(); k += i) {
      primes[k].isPrime = false;
    }
  }
  return cnt;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  vector<prime_n> primes(n+1);
  vector<ll> fs(n+1, 0);
  fs[1] = 1;
  struct_prime(primes);
  vector<ll> prime;
  for (int i = 2; i < n+1; i++) {
    if (primes[i].isPrime) prime.emplace_back(i);
  }

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll j = i;
    ll facts = 1;
    for (auto it = prime.begin(); it != prime.end(); it++) {
      ll p = *it;
      ll cnt = 1;
      if (primes[j].isPrime) {
        facts *= 2;
        break;
      }
      if (fs[j] != 0) {
        facts *= fs[j];
        break;
      }
      while (j % p == 0) {
        cnt++;
        j /= p;
      }
      facts *= cnt;
    }
    fs[i] = facts;
    ans += i * facts;
  }
  cout << ans << endl;

}


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

int main() {
  int n, k, sum = 0;
  cin >> n >> k;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
    sum += min(x.at(i), k - x.at(i));
  }
  cout << 2 * sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int N,K,i;
    scanf("%d %d",&N,&K);

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


    int count=0;
    int a=1;

    while(1)
    {
        count++;
        a = a+K-1;

        if(a>=N)
        {
            break;
        }
    }

    printf("%d\n",count);

}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100001

int main() {
    int n;
    int p[21];
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> p[i];
    }

    int ans=0;
    for (int i=1; i<n-1; i++) {
        if ((p[i-1] < p[i] && p[i] < p[i+1]) or  (p[i-1] > p[i] && p[i] > p[i+1])) {
            ans++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256