akhauriyash/Code-Regression huggingface dataset:
class SegTree():
    def __init__(self,data,unit,f):
        self.size=n=len(data)
        self.data=[unit for _ in range(n)]+data
        for i in range(n-1,0,-1):self.data[i]=f(self.data[i+i],self.data[i-~i])
        self.unit=unit
        self.f=f
    def update(self,i,x):
        c,f=self.data,self.f
        i+=self.size
        c[i]=x
        while i>1:
            i>>=1
            c[i]=f(c[i+i],c[i-~i])
    def add(self,i,x):
        c,f=self.data,self.f
        i+=self.size
        c[i]=f(c[i],x)
        while i>1:
            i>>=1
            c[i]=f(c[i+i],c[i-~i])
    def query(self,l,r):
        c,f=self.data,self.f
        x,y=self.unit,self.unit
        l+=self.size
        r+=self.size
        while l<r:
            if l&1:
                x=f(x,c[l])
                l+=1
            if r&1:
                r-=1
                y=f(c[r],y)
            l>>=1
            r>>=1
        return f(x,y)
def main():
    from fractions import gcd
    n,*a=map(int,open(0).read().split())
    f=SegTree(a,0,gcd).query
    m=max(f(1,n),f(0,n-1))
    for i in range(n-2):
        m=max(m,gcd(f(0,i+1),f(i+2,n)))
    print(m)
main()

Measured memory_bytes: 16168
H, W, D = map(int, input().split())
mp = {}

def ipt():
    for x in range(H):
        A = list(map(int, input().split()))
        for y in range(W):
            mp[A[y]] = (x, y)


ipt()
Q = int(input())

def get_dist(prev, x):
    dx = mp[x][0] - mp[prev][0]
    dy = mp[x][1] - mp[prev][1]
    return abs(dx) + abs(dy)


dist = [0 for i in range(H*W+1)]
for i in range(0, D):
    tmp = 0
    for x in range(1+i, H*W-D+1, D):
        tmp += get_dist(x, x+D)
        dist[x+D] = tmp


for i in range(Q):
    L, R = map(int, input().split())
    print(dist[R]-dist[L])

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

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

    std::vector<int> v(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> v[i];
    }

    const auto minmax = std::minmax_element(v.cbegin(), v.cend());
    const int ret = *minmax.second - *minmax.first;

    std::cout << ret << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;

ll uni[300005];
ll root(ll u){
    if(uni[u]<0)return u;
    return uni[u]=root(uni[u]);
}

void connect(int a,int b){
    a=root(a);
    b=root(b);
    if(a==b)return;
    if(uni[a]>uni[b]){
        a^=b;
        b^=a;
        a^=b;
    }
    uni[a]+=uni[b];
    uni[b]=a;
    return;
}
ll size(ll u){
    return -uni[root(u)];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    memset(uni,-1,sizeof(uni));
    ll n,m,ans=0;
    cin>>n>>m;
    ll p[n+1],a[n+1];
    for(int i=1;i<=n;i++){
        cin>>p[i];
        a[p[i]]=i;
    }
    ll x,y;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        connect(x,y);
    }
    for(int i=1;i<=n;i++){
        if(root(i)==root(a[i])){
            ans++;
        }
    }
    cout << ans<<endl;
    return 0;
}





Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define rg register
#define oo 0x7fffffff
#define ll long long
using namespace std;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		{
			fh=-1;
			jp=getchar();
		}
	while (jp>='0'&&jp<='9')
		{
			out=out*10+jp-'0';
			jp=getchar();
		}
	return out*fh;
}
const int MAXN=1e5+10;
const int P=1e9+7;
inline int add(int a,int b)
{
	return (a + b) % P;
}
inline int mul(int a,int b)
{
	return 1ll * a * b  % P;
}
char s[MAXN];
int pre[MAXN],f[MAXN],nx[3];
int main()
{
	//freopen("composer.in","r",stdin);
	//freopen("composer.out","w",stdout);
	scanf("%s",s);
	int n;
	int flag=0;
	for(; s[n]; ++n)
		{
			pre[n+1]=pre[n]+(s[n]=='a'? 1:2 );
			pre[n+1]%=3;
		}
	for(rg int i=1; i<n; ++i)
		if(s[i]==s[i-1])
			flag=1;
	if(flag==0)
		{
			putchar('1');
			return 0;
		}
	f[n]=1;
	for(rg int i=0; i<3; ++i)
		nx[i]=i==pre[n]?n:n+1;
	for(rg int i=n-1; i; --i)
		{
			f[i]= pre[i]==pre[n];
			for(rg int c=1; c<=2; ++c)
				f[i]=add(f[i],f[nx[(pre[i]+c)%3]]);
			nx[pre[i]]=i;
		}
	cout<<add(f[nx[1]],f[nx[2]]);
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define X real()
#define Y imag()

using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef complex<double> P;

const int INF = 1 << 24;

bool isNoConv(P, P, P, P);

int main(void){
    for(vector<P> p(4);;){
        if(!~scanf("%lf,%lf", &p[0].X, &p[0].Y)) break;
        char c;
        COUNT(i, 3) cin >> c >> p[i].X >> c >> p[i].Y;
        
        cout << ((isNoConv(p[0], p[2], p[1], p[3]) || isNoConv(p[1], p[3], p[0], p[2])) ? "NO":"YES") << endl;
    }
 
    return 0;
}

bool isNoConv(P p1, P p2, P p3, P p4){
    return ((p1.X - p2.X) * (p3.Y - p1.Y) - 
            (p1.Y - p2.Y) * (p3.X - p1.X)) * 
           ((p1.X - p2.X) * (p4.Y - p1.Y) - 
            (p1.Y - p2.Y) * (p4.X - p1.X)) > 0;
}

Measured memory_bytes: 1272
n, m = map(int, input().split())

e = [[int(i) for i in input().split()] for i in range(n)] 

marray = [0] * m
count = 0

for i in e:
    for j in i[1:]:
        marray[j-1] += 1

for i in marray:
    if i == n:
        count += 1

print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;

const int N=1e5;
int n, vis[N];
long long ans=1e18;
std::pair<int, int> p[2*N];
void check() {
	bool a[2]={};
	long long res=0;
	for(int i=0; i<n; ++i) res+=p[i].first;
	if(res>=ans) return;
	memset(vis, 0, n*sizeof(int));
	for(int i=0; i<n; ++i) {
		++vis[p[i].second%n];
		a[p[i].second<n]=true;
	}
	if(!a[0]||!a[1]||std::find(vis, vis+n, 2)!=vis+n) ans=res;
}
int main() {
	n=rd();
	for(int i=0; i<n; ++i) {
		p[i]={rd(), i};
		p[n+i]={rd(), n+i};
	}
	std::sort(p, p+2*n);
	check();
	std::swap(p[n-1], p[n]);
	check();
	std::swap(p[n-1], p[n+1]);
	check();
	std::swap(p[n-2], p[n]);
	std::swap(p[n-1], p[n+1]);
	check();
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
template<class T>inline int cmp(vector<T>&v,T &a){
	return lower_bound(all(v),a)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N;
signed main(){
	cin>>N;
	int ans=0;
	REP(i,N+1){
		ans+=(1+i)*i/2;
	}
	rep(i,N-1){
		int a,b;cin>>a>>b;
		if(a>b)swap(a,b);
		ans-=a*(N-b+1);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                bool[] memo = new bool[n];

                for (int i = 1; i < n; i++)
                {
                    int temp = (i * i) % n;
                    memo[temp] = true;
                }

                HashSet<int> hs = new HashSet<int>();

                for (int i = 0; i < n; i++)
                {
                    if (memo[i]) hs.Add(i);
                }

                var nums = hs.ToList();

                int m = (n - 1) / 2;

                int[] counts = new int[m + 1];

                for (int i = 0; i < nums.Count; i++)
                {
                    for (int j = i + 1; j < nums.Count; j++)
                    {
                        int a = nums[i];
                        int b = nums[j];

                        int temp = a - b;

                        if (a - b < 0) temp += n;

                        if (temp > m) temp = n - temp;

                        counts[temp]++;
                    }
                }

                for (int i = 1; i <= m; i++)
                {
                    sb.AppendLine((counts[i] * 2).ToString());
                }
            }
            Console.Write(sb);
        }
    }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
int k, a,b;
string st = "NG";
  cin >> k;
  cin >> a >>b ;
  for(int  i = 0 ; i<max(a ,b)+1;i++){
    if (k*i <= b && k*i >= a){
      st = "OK";
      break;
    }
  }
 cout << st << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 2019;



int main(){
    ll A, B, X; cin >> A >> B >> X;
    if(A == 0 && B == 0){
        cout << 1 << endl;
        return 0;
    }
    if(A == 0){
        cout << B / X + 1 << endl;
        return 0;
    }

    A--;
    ll num1 = A/X;
    ll num2 = B/X;
    cout << num2-num1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT false

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == 1)return;for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(vector<int>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}


//CODE
bool BIN_check(int N,int A,int B,vector<int> vec)
{
  int NUM = 0;
  for (int i = 0; i < vec.size(); i++)
  {
    vec[i] -= N*B;
  }
  DEBUG(vec);
  for (int i = 0; i < vec.size(); i++)
  {
    if(vec[i] > 0)
    {
      NUM += vec[i]/(A - B) + (int)(vec[i]%(A-B) > 0);
      DEBUG(vec);
    }
  }

  DEBUG(NUM); 
  DEBUG(N);
  DEBUG("OK",NUM <= N);
  return NUM <= N;
  
  
}
int BIN_S(int N,int A,int B,vector<int> & vec)
{
  int NG = -1; int OK = 10e9+1;
  while(OK - NG > 1)
  {
    int mid =(OK + NG) /2;
    if(BIN_check(mid,A,B,vec)) OK = mid;
    else NG = mid;

  }
  
  return OK;

}
void solve(void)
{
  int N,A,B;
  cin>>N>>A>>B;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }

  cout<<BIN_S(N,A,B,vec)<<endl;
  
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
ll dp[1<<22];
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int a[21][21];
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    dp[0]=1;
    for(int bit=0;bit<(1<<n);bit++){
        int num=__builtin_popcount(bit)-1;
        for(int i=0;i<n;i++){
            if((bit&(1<<i))&&a[num][i]){
                dp[bit]+=dp[bit^(1<<i)];
                dp[bit]%=mod;
            }
        }
    }
    cout << dp[(1<<n)-1]<<endl;
    return 0;
}


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


int a[200050];
pair<int,int>b[200050];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        b[i]={a[i],i};
    }
    sort(b+1,b+n+1);
    int ans=0,len=0,last=-1;
    for(int i=1;i<=n;i++)
    {
        int x=b[i].second;
        if(x>last)
        {
            last=x;
            len++;
        }
        else
        {
            last=x;
            len=1;
        }
        ans=max(ans,len);
//        printf("***%d %d\n",i,len);
    }
    printf("%d\n",n-ans);
	return 0;
}


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

main()
{
	int n,m;
	cin>>n>>m;
	int sum = 0;
	for(int i=0;i<m;i++)
	{
		int x;
		cin>>x;
		sum += x;
	}
	if(sum>n) cout<<-1;
	else cout<<n-sum;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
  seen[v] = true; // v を訪問済にする

  // v から行ける各頂点 next_v について
  for (auto next_v : G[v]) {
      if (seen[next_v]) continue; // next_v が探索済だったらスルー
      dfs(G, next_v); // 再帰的に探索
  }
}

int main()
{
    int N,M;
    cin >> N >> M;
    vint red(N,0);
    vint cnt(N,1);
    red[0] = 1;
    REP(i,M){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        cnt[a]--;
        cnt[b]++;
        if(red[a] == 1)red[b] = 1;
        if(cnt[a] == 0)red[a]--;
    }
    int ans = 0;
    REP(i,N){
        if(cnt[i] != 0 && red[i] == 1)ans++;
    }
    cout << ans << endl;

}

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

int main() {

    int n;
    cin >> n;
    vector<int> vec(2 * n);
    for (int i = 0; i < 2 * n; i++) {
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end(), std::greater<int>());

    int ans = 0;
    for (int i = 0; i < 2*n ; i+=2) {

        ans += min(vec[i], vec[i + 1]);
    }
    cout << ans << endl;

   return 0;
}


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

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


int main(){
  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5])cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
use std::io::{self, BufRead, Write, BufWriter};

fn read<R: BufRead, T: std::str::FromStr>(input: &mut R) -> T {
    let mut s = String::new();
    input.read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let mut a = vec![];
    {
        let input = io::stdin();
        let mut input = input.lock();
        let n = read::<_, usize>(&mut input);
        for _ in 0..n {
            let ai = read::<_, usize>(&mut input);
            a.push(ai);
        }    
    }

    let mut max1 = 0;
    let mut max2 = 0;
    for &ai in a.iter() {
        if max1 <= ai {
            max2 = max1;
            max1 = ai;
        } else if max2 <= ai {
            max2 = ai;
        }
    }

    let stdout = io::stdout();
    let mut buf = BufWriter::new(stdout.lock());

    for ai in a.into_iter() {
        let res = if ai == max1 {
            max2
        } else {
            max1
        };
        writeln!(buf, "{}", res).unwrap();
    }
}

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

int main(){
	long long x,k,d,s;
	cin>>x>>k>>d;
	x=abs(x);
	s=min(k,x/d);
	if((k-s)%2==0){
		cout<<x-s*d<<endl;
	}else{
		cout<<(1+s)*d-x<<endl;
	}
}

Measured memory_bytes: 3568
#include <stdio.h>
#include <stdlib.h>
#define N 100

void push(int);
int top=0;
char s[N];
int pop();
int a[N];

int main(){

  int c,b,x;
 
  while(scanf("%s",s) != EOF){
  
  if(s[0]=='+'){
    push(pop()+pop());
  }

  else if(s[0]=='-'){
    b=pop();
    c=pop();
    push(c-b);

  }

  else if(s[0]=='*'){
    push(pop()*pop());
  }

  else {
    x=atoi(s);
    push(x);
  }
  }
  printf("%d\n",pop());
  
  return 0;

}

void push(int x){

  top++;
  a[top]=x;
}

int pop(){
 
  top--;

  return a[top+1];
  
}

	   




Measured memory_bytes: 2044
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()

int  main()
{
    int n,k;
    cin>>n>>k;
    if(k==1)cout<<0<<endl;
    else{
        cout<<n-k<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
int  n,a,b;
scanf("%d",&n);
if(n==1){
    printf("Hello World");
}
else{
if(n==2)
{
    scanf("%d%d",&a,&b);
    printf("%d\n",a+b);
}}
    return 0;
}


Measured memory_bytes: 128
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    double y, t, v;

    for(;sc.hasNext();){
      v = sc.nextDouble();
      t = v / 9.8;
      y = 4.9 * t * t;
      out.println((int)y / 5 + 2);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 18580
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 100100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



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

    int N;long long K;cin >> N >> K;
    vector<long long> retu(N);
    for(int i = 0;i<N;i++) cin >> retu.at(i);
    vector<long long> fact_2(45);
    for(long long i = 0;i<45;i++){
        fact_2.at(i) = pow(2,i);
    }
    vector<long long> bitCount(45);
    for(int i = 0;i<N;i++){
        bitset<45> BIT(retu.at(i));
        for(int j = 0;j<45;j++){
            if(BIT.test(j)){
                bitCount.at(44-j)++;
            }
        }
    }
    long long ans = 0;
    for(int i = 44;i>=0;i--){
        if(K >= fact_2.at(i)){
            if(bitCount.at(44-i) < N-bitCount.at(44-i)){
                K -= fact_2.at(i);
                ans += fact_2.at(i)*(N-bitCount.at(44-i));
            }
            else{
                ans += bitCount.at(44-i)*fact_2.at(i);
            }
        }
        else{
            ans += bitCount.at(44-i)*fact_2.at(i);
        }
        //cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4108
N, K, Q = list(map(int, input().split()))
ans_list = [0 for i in range(N)]
for i in range(Q):
    a = int(input())
    ans_list[a-1] += 1
for a in ans_list:
    if a + K > Q:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 4684
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
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; }

int main()
{
	map<ll, ll>prime;
	ll n, p; cin >> n >> p;
	ll p_now = p;
	for (ll i = 2; i*i < p; i++)
	{
		ll cnt = 0;
		while (p_now%i==0)
		{
			p_now /= i;
			cnt++;
		}
		if (cnt)prime[i] = cnt;
	}
	ll ans = 1;
	for (auto e : prime)
	{
		e.second /= n;
		if (e.second)rep(i, e.second)ans *= e.first;
	}
	if (n == 1)ans = p;
	co(ans);
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  ll n,S=0;
  std::cin >> n;
  ll a[n];
  for(ll i=0; i<n; i++){
    std::cin >> a[i];
  }
  sort(a,a+n,greater<ll>());

  int flag=0;
  ll h=0,w=0;
  for(int i=0; i<n-1; i++){
    if(a[i]==a[i+1]){
      if(flag==0){
        h=a[i];
        flag=-1;
        i++;
      }
      else{
        w=a[i];
        break;
      }

    }
  }
  std::cout << h*w << '\n';
  return 0;
}


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

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),i,a[]=new int[n+1];
        long k=Long.parseLong(s[1]);
        s=bu.readLine().split(" ");
        int pos=1,l=1;
        for(i=0;i<n;i++)
            a[i+1]=Integer.parseInt(s[i]);
        ArrayList<Integer> path=new ArrayList<>();
        HashMap<Integer,Integer> hm=new HashMap<>();
        path.add(1);
        hm.put(1,1);
        while(true)
        {
            pos=a[pos];
            if(hm.get(pos)==null)
            {
                path.add(pos);
                hm.put(pos,path.size());
            }
            else {l=hm.get(pos); break;}
        }
        if(k<path.size()) {System.out.print(a[path.get((int)(k-1))]); return;}
        l--;
        k-=l;
        k%=(path.size()-l);
        k--;
        if(k==-1) k=path.size()-l-1;
        System.out.print(a[path.get((int)(l+k))]);
    }
}


Measured memory_bytes: 72124
n,m,x=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
ans=10**18
for i in range(2**n):
  flag=format(i,'b')
  flag='0'*(n-len(flag))+flag
  tmp=0
  check=[0]*(m)
  for j in range(n):
    if flag[j]=='0':
      continue
    tmp+=arr[j][0]
    for k in range(m):
      check[k]+=arr[j][k+1]
  for j in range(m):
    if check[j]<x:
      break
  else:
    ans=min(ans,tmp)
if ans==10**18:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 68444
# 0からの差が小さいもの（絶対値が0に近いもの）を選ぶ
n, l = map(int, input().split())
arr = [i + l for i in range(n)]
s = sum(arr)
idx = -1
mindif = 10 ** 9
for i, a in enumerate(arr):
    if mindif > abs(a):
        mindif = abs(a)
        idx = i
print(s - arr[idx])


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

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> h(N);
  for(int i=0;i<N;i++){
    cin>>h.at(i);
  }
  sort(h.begin(),h.end());
  reverse(h.begin(),h.end());
  int i=0;
  while(h.at(i)>=K){
    i++;
    if(i==N){
      break;
    }
  }
  cout<<i<<endl;
}

Measured memory_bytes: 640
def sosu(n):
    s = [1] * (n+1)
    s[0] = s[1] = 0
    
    end = int(n ** 0.5) + 1
    for i in range(2,end+1):
        if s[i] == 0:continue
        j = i+i
        while j <= n:
            s[j] = 0
            j += i

    return s

S = sosu(123456*2)

while 1:
    n = int(input())
    if not n:break
    print(len([v for v in S[n+1:n*2+1] if v == 1]))

Measured memory_bytes: 10388
x,n = gets.split.map(&:to_i)
a = (0..101).map(&:to_i)
gets.split.map(&:to_i).each{|p| a.delete(p)}
min = 1000
ans = x - a[0]
a.each do |aa|
  if min > (x-aa).abs
    min = (x-aa).abs
    ans = aa
  else
    break
  end
end
puts ans


Measured memory_bytes: 14288
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll s,w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe\n";
    }else{
        cout<<"safe\n";
    }
}

int main(ll argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;

#define vi vector<int>
#define vii vector<vector<int>>
#define ll long long int

void testcase(){
    int a,b;
    cin>>a>>b;
    if(a <= 8 && b <= 8){
        cout << "Yay!";
    }    
    else{
        cout << ":(";
    }
}

int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    testcase();
    return 0;
}


Measured memory_bytes: 3572
A,B = map(int,input().split())
S = input()
L = list(map(str,list(range(10))))
flag = True
for i in range(A+B+1):
    if ( i == A ):
        if (S[i] != "-"):
            flag = False
    else:
        if (not (S[i] in L)):
            flag = False
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M;
  cin >> N >> M;
  
  if(N>=2 && M>=2) {
    cout << N*(N-1)/2+M*(M-1)/2 << endl;}
  
  else if (N>=2 && M<2) {
    cout << N*(N-1)/2 << endl;}
  
  else if(N<2 && M>=2) {
    cout << M*(M-1)/2 << endl;}
  
  else if(N<2 && M<2) {
    cout << 0 << endl;}
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  string s;
  cin >> s;
  map<char, int > m;
  REP(i,s.size()){
    m[s[i]]++;
  }
  cout << ((m.size() == s.size())?"yes":"no") << endl;
} 

Measured memory_bytes: 256
import heapq

K = int(input())

Q = [1,2,3,4,5,6,7,8,9]
heapq.heapify(Q)

for i in range(K-1):
    x = heapq.heappop(Q)
    if x % 10 != 0:
        heapq.heappush(Q,10*x+x%10-1)
    heapq.heappush(Q,10*x+x%10)
    if x % 10 != 9:
        heapq.heappush(Q,10*x+x%10+1)

print(heapq.heappop(Q))

Measured memory_bytes: 11748
#include<iostream>
#include<vector>
int main() {
	int n;
	int count=0;
	int a;
	bool flag = true;
	std::cin >> n;
	std::vector<int> array(n);
	for (int i = 0; i < n; i++) {
		std::cin >> array[i];
	}
	while(flag == true) {
		for (int i = 0; i < n; i++) {
			if (array[i] % 2 == 1) {
				flag = false;
			}
			array[i] = array[i] / 2;
		}
			if(flag==true)count++;
	}
	std::cout << count;
	return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    
    
    long long H,W;
    
    cin>>H>>W;
    long long mult = H*W;
    
    if(H != 1 && W != 1){
	    if(mult% 2 == 0)
	    	cout<<mult/2;
	    
	    else
	    	cout<<(mult/2)+1;
    }
    else 
    	cout<<1;
    
	
	return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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


int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int N, K;
    cin >> N >> K;
    
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    cout << (N-2) / (K-1) + 1 << endl;


    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
const int MOD=2019;
typedef long long ll;
int main()
{
    int L,R;
    int ans=2018;
    cin>>L>>R;
    if((R-L)>2019)
        ans=0;
    L=L%2019;
    R=R%2019;
    if(R<=L)
    {
        int t;
        t=R;
        R=L;
        L=t;
    }
    for(int i=L;i<=R;i++)
    {
        for(int j=i+1;j<=R;j++)
        {
            ans=min(ans,(i*j)%2019);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
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;
}

//////////////////////////


int main(){fastio
    map<ll,ll>mp;
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=0;
    rep(i,0,n-1){
        ans+=mp[a[i]-i];
        mp[-i-a[i]]++;
    }
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 27880
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <assert.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

ll mod;
const int N = 6000;
ll fact[N], invf[N], two[N];

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

ll nPr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(fact[n], invf[n-r]);
}

ll nCr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(mul(fact[n], invf[r]), invf[n-r]);
}

int main() {
    int n, x;
    cin >> n >> x;
    int mi = 1e9;
    REP(i,n){
        int m;
        cin >> m;
        mi = min(mi, m);
        x -= m;
    }
    cout << n + x / mi << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    vector <bool> p;
    p.resize(26,0);
    for(int i=0;i<s.length();i++)
        p[s[i]-97]=1;
    bool f=0;
    char c;
    for(int i=0;i<26;i++)
        if(!p[i])
        {
            c=i+97;
            f=1;
            break;
        }
    if(!f)
        cout<<"None\n";
    else
        cout<<c<<endl;
    
    
    return 0;   
}




 
 


Measured memory_bytes: 512
import numpy as np
from itertools import combinations
from itertools import permutations
from math import factorial


N = int(input())
xy = np.array([list(map(int, input().split())) for _ in range(N)])
cnt = 0

for i in xy:
    for j in xy:
        cnt += np.linalg.norm(i - j)
print(cnt / N)

Measured memory_bytes: 27136
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
int i, n, m, k, ans;
int a[1000];

int main() {
    scanf(" %d", &n);
    rep(0,n) printf("ACL");
    printf("\n");
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> L(M), R(M);
  for(int i=0;i<M;i++) cin >> L.at(i) >> R.at(i);
  int Lmax = 0, Rmin = 100000;
  for(int i=0;i<M;i++){
    Lmax = max(Lmax, L.at(i));
    Rmin = min(Rmin, R.at(i));
  }
  if(Lmax > Rmin) cout << "0" <<endl;
  else cout << Rmin - Lmax + 1 <<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n,t,f1[3005][3005],f2[3005][3005],ans,mx,v1[3005],v2[3005];pii d[3005];
bool cmp(pii x,pii y){
    if(x.fi!=y.fi) return x.fi<y.fi;
    return x.se<y.se;
}
int main(){
    scanf("%d%d",&n,&t);
    rep(i,1,n) scanf("%d%d",&d[i].fi,&d[i].se),mx=max(mx,d[i].fi);
    sort(d+1,d+n+1,cmp);
    rep(i,1,n) {
        rep(j,0,t) {
            f1[i][j]=f1[i-1][j];
            if(j>=d[i].fi) f1[i][j]=max(f1[i][j],f1[i-1][j-d[i].fi]+d[i].se);
        }
    }
    per(i,n,1) {
        rep(j,0,t) {
            f2[i][j]=f2[i+1][j];
            if(j>=d[i].fi) f2[i][j]=max(f2[i][j],f2[i+1][j-d[i].fi]+d[i].se);
        }
    }
    rep(i,1,n){
        rep(j,0,t) v1[j]=f1[i-1][j],v2[j]=f2[i+1][j];
        rep(j,0,t-1) ans=max(ans,v1[j]+v2[t-1-j]+d[i].se);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    ll A;
    ll ans=0;
    string B;
    cin >> A >> B;
    B.erase(1, 1);
    ans = A * stoi(B) / 100;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
N,M = list(map(int,input().split()))
PS = [input().split() for _ in range(M)]
status = {i[0]:[False,0] for i in PS}
countac = 0
countwa = 0
for ps in PS:
    if ps[1] == 'AC':
        if status[ps[0]][0] == False:
            status[ps[0]][0] = True
            countac += 1
            countwa += status[ps[0]][1]
    else:
        if status[ps[0]][0] == False:
            status[ps[0]][1] += 1
print(str(countac)+' '+str(countwa))

Measured memory_bytes: 49612
#include <cstdio>

int main()
{
    short a, b;
    scanf("%d %d", &a, &b);
    if(a < b)
    {
        printf("a < b\n");
    }
    else if(a > b)
    {
        printf("a > b\n");
    }
    else
    {
        printf("a == b\n");
    }
}


Measured memory_bytes: 2612
#include<cstdio>
int main(){
    int n,l,sum,a;
    scanf("%d%d",&n,&l);
    a=l+n-1;
    sum=n*(a+l)/2;
    if(l>0)sum-=l;
    else if(a<0)sum-=a;
    printf("%d\n",sum);
}

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

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 105;
const int maxl = 20;
vector<int>graph[maxn];
int up[maxn][maxl];

int n, lo;

int timer;
int in[maxn], out[maxn];

void dfs(int v, int p)
{
    in[v] = ++timer;
    up[v][0] = p;
    for (int i = 1; i <= lo; ++i)
        up[v][i] = up[up[v][i-1]][i-1];

    for (int u : graph[v]) {
        if (u != p)
            dfs(u, v);
    }

    out[v] = ++timer;
}

bool is_ancestor(int u, int v)
{
    return in[u] <= in[v] && out[u] >= out[v];
}

int lca(int u, int v)
{
    if (is_ancestor(u, v))
        return u;
    if (is_ancestor(v, u))
        return v;
    for (int i = lo; i >= 0; --i) {
        if (!is_ancestor(up[u][i], v))
            u = up[u][i];
    }
    return up[u][0];
}

void preprocess(int root) 
{
    timer = 0;
    lo = ceil(log2(n)) + 1;
    dfs(root, root);
}

int l[maxn], r[maxn];

int pref[maxn];

void dfs1(int u, int p)
{
  for(const auto &v : graph[u])
  {
    if(p == v)
      continue;
    dfs1(v, u);
  }
  pref[p] += pref[u];
}

int main()
{
  ios::sync_with_stdio(false);
  cin >> n;
  for(int i = 1; i < n ; i++)
  {
    int u,v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  int m;
  cin >> m;
  preprocess(1);
  for(int i = 0; i < m ; i++)
  {
    cin >> l[i] >> r[i];
  }

  ll ans = 0;

  for(int mask = 0; mask < (1 << m); mask++)
  {
    MSET(pref, 0);
    for(int i = 0; i < m; i++)
    {
      if(mask & (1 << i))
      {
        pref[l[i]]++;
        pref[r[i]]++;
        pref[lca(l[i], r[i])]--;
        pref[lca(l[i], r[i])]--;
      }
    }
    dfs1(1, 0);
    int x = 0;
    int sz = __builtin_popcount(mask);
    for(int i = 1 ; i <= n ; i++)
    {
      if(pref[i] > 0)
        x++;
    }
    if(sz % 2 == 0)
      ans += (1LL << (n - 1 - x));
    else
      ans -= (1LL << (n - 1 - x));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n;
  cin>>n;
  long long ans=1;
  rep(i,n){
    ans*=(i+1);
    ans%=MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
	char s[1005],t[1005];
	scanf("%s%s",s,t);
	int i,j,k,len=strlen(s),min=10000,cnt;
	for(i=0;i<len-strlen(t)+1;i++){
		cnt=0;
		for(j=0,k=i;j<strlen(t);j++,k++){
			if(s[k]!=t[j])
				cnt++;
		}
		if(min>cnt)
			min=cnt;
	}
	printf("%d\n",min); 
}

Measured memory_bytes: 1712
/*
 ============================================================================
 Name        : alds1_5_A_ExhaustiveSearch.c
 Author      : lovesaemi
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

int n, A[50];

int solve(int i, int m) {
	if (m == 0)
		return 1;
	if (i >= n)
		return 0;
	int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}

int main(void) {
	int q, M, i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &M);
		if (solve(0, M))
			printf("yes\n");
		else
			printf("no\n");
	}
	return EXIT_SUCCESS;
}



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

#define ll long long
#define mx  40005
#define mod 1000000009
#define lim 10000000
#define inf 2000000000
#define N 18
#define eps 100000
#define PI acos(-1)

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int a,b;cin>>a>>b;

	if(a&1 && b&1)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}


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

string f(string s)
{
  for (int i = 0; i < s.length() - 1; ++i) {
    if (s[i] != s[i + 1]) {
      s.erase(i, 2);
      break;
    }
  }
  return s;
}

int main()
{
  string s;
  cin >> s;
  int cnt = 0;
  for (;;) {
    string t = f(s);
    if (t.length() == s.length()) break;
    ++cnt;
    s = t;
  }
  cout << (cnt * 2) << endl;

  return 0;
}


Measured memory_bytes: 628
"use strict"

function main(input) {

    let ary = input.split('\n')
    let nums = ary[1].split(' ')
    nums = nums.map(x => +x)
    console.log(Math.max.apply(null, nums) - Math.min.apply(null, nums))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,cnt=0,k=0,ar[100];
  bool f=false ;
  cin>>n;
     for(int i=1;i<=9;i++){
       for(int j=1;j<=9;j++){
     {
         ar[k]=i*j;k++;}
       }
       }
       for(int i=0;i<k;i++){
           if(ar[i]%n==0) {f=true;break;}
           }

            if(f) cout<<"Yes"<<endl;
          else
             cout<<"No"<<endl;





return 0;}


Measured memory_bytes: 256