akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }


/*
<url:https://onlinejudge.u-aizu.ac.jp/services/room.html#RitsCamp18Day1/problems/A>
問題文============================================================
 N  個の相違なる自然数 ai が与えられる。与えられた自然数から相違なる自然数を選び、ペアを作ることにした。
 作ることができるペアのうち、値の差が N−1 の倍数であるペアを一つ出力せよ。
 
 なお、そのようなペアは必ず存在する。
=================================================================

解説=============================================================

 N^2 試すだけ
 
================================================================
*/
void solve(){
    ll N; cin >> N;
    vector<ll> a(N); for(auto& in:a) cin >> in;
    [&]{
        for(int i = 0; i < N;i++){
            for(int j = i+1; j < N;j++){
                if(a[i] == a[j]) continue;
                if(abs(a[i] - a[j])%(N-1) == 0){
                    cout << a[i] << " " << a[j] << endl;
                    return;
                }
            }
        }
        return;
    }();
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    solve();
	return 0;
}



Measured memory_bytes: 3232
N,A,B = map(int,input().split())

if (N >= A+B):
  a = N // (A+B)
  b = N % (A+B)
  if (b >= A):
    print(A*a + A)
  else:
    print(A*a + b)
else:
  if (N >= A):
    print(A)
  else:
    print(N)


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,n;
    t = 1;
    while(t--) {
     cin >> n;
     if(n < 1000)
      cout << "ABC" << endl;
     else
      cout << "ABD" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,a[100000],flg=0,i,w,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
	    scanf("%d",&a[i]);
	}
	w=0;
	j=1;
	while(1){
	    j=a[j];
		w++;
		if(j==2) break;
		if(w>n){
		    w=-1;
			break;
		}
	}
	printf("%d\n",w);
	return 0;
}

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

int main() {
	int data;
  
  	cin >> data;
  
  	int ans = 0;
    while (data > 0) {
      if (data % 2 == 1) ans++;
      data /= 10;
    }
  
  	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define int long long
int main(){
	char s1[1005],s2[1005];
	cin>>s1;
	cin>>s2;
	int ans=0;
	for(int i=0;i<=strlen(s1)-strlen(s2);i++){
		int num=0;
		for(int j=0;j<strlen(s2);j++)
		if(s1[i+j]==s2[j])num++;
		ans=max(ans,num); 
	}
	cout<<strlen(s2)-ans<<endl;
	return 0;
} 

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sct(tc) scanf("%lld",&tc)
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define scs(ch) scanf("%s", ch)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
int main()
{
	ll m,n,ans,r;
	scll(n,m);
	r=n%m;
	ans=min(r,abs(r-m));
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
import * as fs from 'fs';

namespace AtCoder.abc101 {
    class ProgramA {
        args: string[];

        // +-++
        // 2
        constructor(args: string[]) {
            this.args = args;
        }

        main(): void {
            const s: string = args[0];
            let ans: number = 0;

            s.split('').forEach(x => {
                if (x === '+') ans++;
                if (x === '-') ans--;
            });
            console.log(ans);
        }
    }

    const args: string[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
    const func: ProgramA = new ProgramA(args);
    func.main();
}

Measured memory_bytes: 7372
/******************
*  Author: BD747  *
******************/
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
using namespace std;

int n;
string s1,s2,s3;
int ans;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	cin>>s1;
	cin>>s2;
	cin>>s3;
	for(int i=0;i<n;i++){
		if(s1[i]!=s2[i]&&s2[i]!=s3[i]&&s1[i]!=s3[i]){
			ans+=2;
		}else{
			if(s1[i]==s2[i]&&s2[i]==s3[i]){
				ans+=0;
			}else{
				ans+=1;
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; scanf("%d", &x); return x;}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool link(int x, int y) { //新たな併合を行うとtrue
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  int root(int x) { // 代表元を返す
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) { // 要素xが含まれる集合の大きさ
    return -data[root(x)];
  }
  bool same(int x, int y) { // 同じ集合ならtrue
    return root(x) == root(y);
  }
  int num() { // 異なる集合の数
    int res = 0;
    REP(i, data.size()) res += root(i) == i;
    return res;
  }
};

struct Edge {
  int a, b, w;
};

const int MAX_N = 100000 + 10;
struct P {
  int id, x, y;
};
P p[MAX_N];

int main2() {
  int N = nextInt();
  REP(i, N) {
    p[i].id = i;
    p[i].x = nextInt();
    p[i].y = nextInt();
  }
  
  vector<Edge> es;
  sort(p, p + N, [](const P& a, const P& b) -> bool {
    if (a.x != b.x) return a.x < b.x;
    return a.y < b.y;
  });
  for (int i = 0; i + 1 < N; i++) {
    es.push_back( (Edge){p[i].id, p[i+1].id, p[i+1].x - p[i].x } );
  }
  sort(p, p + N, [](const P& a, const P& b) -> bool {
    if (a.y != b.y) return a.y < b.y;
    return a.x < b.x;
  });
  for (int i = 0; i + 1 < N; i++) {
    es.emplace_back( (Edge){p[i].id, p[i+1].id, p[i+1].y - p[i].y} );
  }

  sort(es.begin(), es.end(), [](const Edge& a, const Edge& b) -> bool {
    return a.w < b.w;
  });
  UnionFind uf(N);

  ll ans = 0;
  for (Edge e : es) {
    if (!uf.same(e.a, e.b)) {
      uf.link(e.a, e.b);
      ans += e.w;
    }
  }
  cout << ans << endl;

  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 6004
#include <iostream>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	int x[] = {a, b, c};
	int temp;
	if (x[0] > x[1]) {
		temp = x[0];
		x[0] = x[1];
		x[1] = temp;
	}
	if (x[1] > x[2]) {
		temp = x[1];
		x[1] = x[2];
		x[2] = temp;
	}
	if (x[0] > x[1]) {
		temp = x[0];
		x[0] = x[1];
		x[1] = temp;
	}
	for (int i = 0; i < 3; ++i) {
		cout << x[i];
		if (i != 2) {
			cout << " ";
		}
		else {
			cout << "\n";
		}
	}
}



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


int main() {
  long long k  ;
  cin >> k ;
  long long a=100;

  for(int i=1;i<10000000;i++){
    a=a*1.01;
    a=a/1;
    if(a>=k){
      cout << i << endl;
      break;
    }
  }
    
    
  
  
  
    
}

Measured memory_bytes: 3620
#include <cfenv>
#include <cmath>
#include<iostream>
using namespace std;

int main()
{  
	int N,M,All=0;
	cin >>N>>M;

	int A[N],m=0;
	bool YesFlag=false;

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

	for(int i=0;i<N;i++){
      	float P =ceil((float)All/(4*M));
		if(A[i]>=P){m++;}
		if(m>=M){YesFlag=true;break;}
	}

	if(YesFlag){cout<<"Yes"<<endl;}
	else{cout<<"No"<<endl;}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
 int a, b;
 
 cin >> a >> b;
 if ( a < b ){cout << "a < b";}
 if ( a > b ){cout << "a > b";}
 if ( a == b ) {cout << "a == b";}
 
 cout << endl;
 
  return 0;
}



Measured memory_bytes: 3044
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
int n;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	while(n){
		if(n%10==7) return puts("Yes"),0;
		n/=10;
	}
	puts("No");
	return 0;
}

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

int main(){
	int x1,y1,x2,y2,x3,y3,x4,y4;
	cin>>x1>>y1>>x2>>y2;
	int a=x2-x1;
	int b=y2-y1;
	x3=x2-b;
	y3=y2+a;
	x4=x3-a;
	y4=y3-b;
	cout << x3 << " " << y3<< " " << x4 << " " <<y4;
	return 0;
}


Measured memory_bytes: 256
def main(k, a, b):
    for n in range(a, b + 1):
        if n % k == 0:
            return 'OK'
    else:
        return 'NG'


if __name__ == '__main__':
    k = int(input())
    a, b = map(int, input().split(' '))
    print(main(k, a, b))


Measured memory_bytes: 9172
#include"bits/stdc++.h"
#define INFLL        1e18
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
using ull=unsigned long long;
template<typename T>using pqg=priority_queue<T,vector<T>,greater<T>>;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

ll calc(const string&s)
{
    ll ret=0;
    auto itr=s.begin();
    while(true){
        auto pl=find(itr,s.end(),'+');
        ret+=stoll(string(itr,pl));
        if(pl==s.end())break;
        itr=pl+1;
    }
    return ret;
}
int main()
{
    string s;cin>>s;
    ll ret=0;
    REP(i,1<<(s.length()-1)){
        ll ic=i;auto sc=s;
        for(ll j=s.length()-1;ic!=0;--j,ic>>=1){
            if(ic&1){
                sc.insert(j,"+");
            }
        }
        ret+=calc(sc);
    }
    cout<<ret<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long K, A, B;
	cin >> K >> A >> B;
	auto r = K+1;
	auto t = (K-(A-1))/2;
	if (B-A >= 2 && t > 0) {
		r = max(r, 1 + (K-2*t) + (B-A)*t);
	}
	cout << r << endl;
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int left = a + b;
    int right = c + d;

    if (left == right) {
        cout << "Balanced" << endl;
    } else if (left < right) {
        cout << "Right" << endl;
    } else {
        cout << "Left" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
def main(n,s):
    c = Counter(s)
    maxVal = max(c.values())
    res = sorted([k for k,v in c.items() if v == maxVal])
    return res

n = int(input())
s = [input() for _ in range(n)]
for i in main(n,s):
    print(i)

Measured memory_bytes: 35564
import math

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

PI = math.pi

A_rad = PI * (60*H + M)/360
B_rad = PI * M/30

cosine = math.cos(A_rad - B_rad)

ans = math.sqrt(A*A + B*B - 2*A*B*cosine)

print(ans)


Measured memory_bytes: 9424
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    if(N%K==0)prt(0);
    else prt(1);

    return 0;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    int N = s.size() + 1;
    vector<int> r(N, 0), l(N, 0);
    rep(1, i, N)
    {
        if (s.at(i - 1) == '<')
        {
            r.at(i) = r.at(i - 1) + 1;
        }
        else
        {
            r.at(i) = 0;
        }
    }

    reverse(all(s));
    rep(1, i, N)
    {
        if (s.at(i - 1) == '>')
        {
            l.at(i) = l.at(i - 1) + 1;
        }
        else
        {
            l.at(i) = 0;
        }
    }
    reverse(all(l));

    ll ans = 0;
    rep(0, i, N)
    {
        ans += max(r.at(i), l.at(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4740
import collections

n = int(input())
a = list(map(int,input().split()))

l = [0 for _ in range(n)]

for i in range(n):
	l[i] = a[i]-i-1

count = collections.Counter(l)
#print(l)
#print(count)
ans = 0
for i in range(n):
	ans += count[-i-1-a[i]]

print(ans)


Measured memory_bytes: 42800
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;


public class Main{

    static long[][] maxknap;
    static ArrayList<Integer> values;
    static ArrayList<Integer> weights;
    static int N;
    static int reqd_weight;

    static void table(){
        for(int i=1;i<=N;i++){

            for(int j=1;j<=reqd_weight;j++){

                if(weights.get(i-1)>j){
                    maxknap[i][j] = maxknap[i-1][j];
                }
                else{
                    maxknap[i][j] = max(maxknap[i-1][j],values.get(i-1)+maxknap[i-1][j-weights.get(i-1)]);
                }
            }

        }
    }

    static long max(long a, long b){
        if(a>b){
            return a;
        }
        else{
            return b;
        }
    }

    public static void main(String[] args) throws IOException {



        BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
        String[] nk = inp.readLine().split(" ");

        N = Integer.parseInt(nk[0]);
        reqd_weight = Integer.parseInt(nk[1]);

        weights = new ArrayList();
        values = new ArrayList<>();

        maxknap = new long[N+1][reqd_weight+1];


        for(int i=0;i<N;i++){
            String[] wv = inp.readLine().split(" ");

            int index = Collections.binarySearch(weights,Integer.parseInt(wv[0]));
            if(index>=0){
                weights.add(index,Integer.parseInt(wv[0]));
                values.add(index,Integer.parseInt(wv[1]));
            }
            else{
                index = -index - 1;
                weights.add(index,Integer.parseInt(wv[0]));
                values.add(index,Integer.parseInt(wv[1]));
            }
        }

        table();

//        for(int i=0;i<=N;i++){
//            for(int j=0;j<=reqd_weight;j++){
//                System.out.print(maxknap[i][j]+ " ");
//            }
//            System.out.println("");
//        }

        System.out.println(maxknap[N][reqd_weight]);

    }
}


Measured memory_bytes: 127696
#include <bits/stdc++.h>
using namespace std;
 
const int DIM = 1e2 + 5;
 
vector<int> lst[4];
pair<int, int> arr[DIM];
 
int main( void ) {
    
    int n, w;
    cin >> n >> w;
    
    fill( lst, lst + 4, vector<int>(1, 0) );
    
    for( int i = 1; i <= n; i ++ ) {
        cin >> arr[i].first >> arr[i].second;
        lst[arr[i].first - arr[1].first].push_back( arr[i].second );
    }
    
    for( int i = 0; i <= 3; i ++ ) {
        sort( lst[i].begin() + 1, lst[i].end(), greater<int>() );
        
        for( int j = 1; j < lst[i].size(); j ++ )
            lst[i][j] += lst[i][j - 1];
    }
    
    int ans = 0;
    for( int i = 0; i < lst[0].size(); i ++ ) {
    for( int j = 0; j < lst[1].size(); j ++ ) {
    for( int k = 0; k < lst[2].size(); k ++ ) {
        int p = min( (long long)( lst[3].size() ) - 1, ( 1LL * w - 1LL * i * ( arr[1].first + 0 )
                                                                 - 1LL * j * ( arr[1].first + 1 )
                                                                 - 1LL * k * ( arr[1].first + 2 ) ) / ( arr[1].first + 3 ) );
        
        if( 1LL * i * ( arr[1].first + 0 ) + 1LL * j * ( arr[1].first + 1 ) + 1LL * k * ( arr[1].first + 2 ) <= 1LL * w )
            ans = max( ans, lst[0][i] + lst[1][j] + lst[2][k] + lst[3][p] );
    } } }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define EPS 1e-10
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


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

    ll A,B,C; cin >> A >> B >> C;
    swap(A,B);
    swap(A,C);
    
    cout << A << " " << B << " " << C << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
int n;

void depth(vector<int> child[],int d[], int i, int de){
	d[i] = de;
	vector<int> temp = child[i];
	for(int k = 0; k<temp.size(); k++){
		depth(child, d, temp.at(k),de+1);
	}
}
int height(vector<int> child[],int h[],int i,int degree[]){
	if(degree[i] == 0){
		h[i] =0;
		return 0;
	}
	vector<int> temp = child[i];
	int max = 0;
	for(int k = 0; k<temp.size(); k++){
		 int te = height(child, h, temp.at(k),degree)+1;
		 //if(i==4) printf("te:%d ",te);
		 if(te>max)
		 max = te;
	}
	//if(i==4) printf("max:%d ",max);
	h[i] = max;
	return h[i];	
}

int main(){
	scanf("%d",&n);
	int tree[n]; //store parent
	int sib[n];
	int degree[n];
	int d[n];
	int type[n];
	int h[n];
	for(int i = 0; i<n; i++){
		tree[i] = -1;
		sib[i] = -1;
		degree[i] = 0;
		d[i] = 0;
		type[i] = 0;//0:internal node
		h[i] = -1;
	}
	vector<int> child[n];
	for(int i = 0; i<n; i++){
		int p;
		int l,r;
		int count = 0; // count the degree
		scanf("%d %d %d",&p,&l,&r);
		vector<int> temp;
		if(l!=-1){
			tree[l] = p;temp.push_back(l);
			sib[l] = r;
			count++;
		}
		if(r!=-1)
		{
			tree[r] = p;temp.push_back(r);
			sib[r] = l;
			count++;
		}
		child[p] = temp;
		degree[p] = count;	
		if(count==0) type[p] = 1; // leaf
	}
	int root;
	for(int i = 0; i<n; i++){
		if(tree[i] == -1){
			root = i;break;
		}
	}
	//printf("root:%d\n",root);
	depth(child,d, root, 0);
	height(child, h, root,degree);
	for(int i = 0; i<n; i++){
		printf("node %d: ",i);
		printf("parent = %d, ", tree[i]);
		printf("sibling = %d, ", sib[i]);
		printf("degree = %d, ", degree[i]);
		printf("depth = %d, ", d[i]);
		printf("height = %d, ", h[i]);
		
		//type
		if(tree[i]==-1){
			printf("root");
		}else{
			if(type[i]==1) printf("leaf");
			else printf("internal node");
		}
		
		printf("\n");
	}
	
	
	
	return 0;
}


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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 305;

int mod;

void add(int &a,int b)  {
    a += b;
    if (a >= mod)
        a -= mod;
}
void sub(int &a,int b)  {
    a -= b;
    if (a <  0)
        a += mod;
}
int mul(int a,int b)    {
    return  1ll * a * b % mod;
}
int Pow(int a,int b)    {
    int ans = 1;
    while (b)   {
        if(b & 1)   ans = mul(ans,a);
        a = mul(a,a);   b >>= 1;
    }
    return  ans;
}
int inv(int a,int p)    {
    return  a == 1 ? 1 : p - 1ll * p * inv(p % a,a) / a;
}

typedef pair<int,int>   ii;

int f[N][N][N];

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

    int n;  cin >> n;
    int k;  cin >> k >> mod;

    if (k % 2 == 0) {
        k /= 2;
        vector<int> f(n + 1,0);
        vector<int> g(n + 1,0);

        g[0] = 1;

        for(int i = 1 ; i <= n ; ++i)   {
            add(g[i],f[i - 1]);
            add(g[i],g[i - 1]);

            for(int j = 1 ; j <= k ; ++j)   if (j <= i)
                add(f[i],g[i - j]);
        }
        for(int i = 0 ; i <= n ; ++i)
            add(f[i],g[i]);

        cout << mul(f[n / 2],f[n - n / 2]) << endl;
        return  0;
    }
    f[0][0][0] = 1;

    for(int i = 2 ; i <= n + k ; i += 2)    {
        for(int j = 0 ; j <= n ; ++j)
        for(int t = 0 ; t <= k + 1 ; ++t)
            add(f[i][0][0],f[i - 2][j][t]);

        if (i <= n) {
            for(int j = 0 ; j <= n ; ++j)
            for(int t = 0 ; t <= k + 1 ; ++t)
                add(f[i][j + 1][0],f[i - 2][j][t]);
        }
        if (i >  k) {
            for(int j = 0 ; j <= n ; add(f[i][0][0],f[i - 2][j++][0]))
            for(int t = 1 ; t <= k ; ++t)
                add(f[i][0][t + 1],f[i - 2][j][t]);
        }
        if (i <= n && i > k)    {
            for(int j = 0 ; j <= n ; ++j)   if (j < k)
            for(int t = 0 ; t <= k ; ++t)
                add(f[i][j + 1][max(j + 2,t + 1)],f[i - 2][j][t]);
        }
    }
    int ans = 0;

    for(int i = 0 ; i <= n ; ++i)
    for(int j = 0 ; j <= k + 1 ; ++j)
        add(ans,f[(n + k) / 2 * 2][i][j]);

    cout << ans << endl;
}

Measured memory_bytes: 107136
function Main(input) {
  var input = input.split("\n");
  var ary = input[0].split("");
  var even = ary.filter(function(e, i){
    return i%2 == 0 ? e : false;
  });
  var odd = ary.filter(function(e, i){
    return i%2 != 0 ? e : false;
  });

  var evenZero = even.filter(function(e){
    return e == 0;
  });

  var oddZero =  odd.filter(function(e){
    return e == 0;
  });

  var result = 0;
  if(evenZero.length > oddZero.length) {
    result = oddZero.length + (even.length - evenZero.length);
  } else {
    result = evenZero.length  + (odd.length - oddZero.length);
  }
  console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 15516
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int ans[n + 1][n + 1] = {};
    int u, k, v;
    for (int i = 0; i < n; ++i)
    {
        cin >> u >> k;
        for (int j = 0; j < k; ++j)
        {
            cin >> v;
            ans[u][v] = 1;
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            printf("%d", ans[i][j]);
            if (j < n)
                putchar(' ');
        }
        putchar('\n');
    }
}


Measured memory_bytes: 3216
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const long long MOD = 1000000007;


void solve(int N, std::vector<int> A){
    map<int,int> list;
    
    bool error = false;
    REP(i, N){
            list[A[i]]++;
    }
    if(N%2==0){ //even
        for(int i=1; i<N; i+=2) if(list[i]!=2){error=true;break;}
    }
    else{ //odd
        for(int i=2; i<N; i+=2)if(list[i]!=2){error=true;break;}
        if(list[0]!=1)error=true;
        
    }    
    if(error){
        cout<<0<<endl;
        return;
    }
    LL ans=1;
    REP(i,N/2){
      ans*=2;
      ans%=MOD;
    }
    cout<<ans<<endl;
    return;
}

int main(){
    int N;
    cin>>N;
    std::vector<int> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%d",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 3584
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
A=[0]*(len(T))
for i in range(len(T)):
 A[i]=T[i]
BR=[0]*K
BS=[0]*K
BP=[0]*K
for j in range(N):
 s=j%K
 f=int(j/K)
 if f==0:
  if A[j]=="r":
   BP[s]=P
  elif A[j]=="s":
   BR[s]=R
  else:
   BS[s]=S 
 else:
  if A[j]=="r":
   a=max(BS[s],BP[s])
   b=max(BR[s],BP[s])
   c=max(BR[s],BS[s])+P
   BR[s]=a
   BS[s]=b
   BP[s]=c
  elif A[j]=="s":
   a=max(BS[s],BP[s])+R
   b=max(BR[s],BP[s])
   c=max(BR[s],BS[s])
   BR[s]=a
   BS[s]=b
   BP[s]=c
  else:
   a=max(BS[s],BP[s])
   b=max(BR[s],BP[s])+S
   c=max(BR[s],BS[s])
   BR[s]=a
   BS[s]=b
   BP[s]=c
d=0
for k in range(K):
 d+=max(BR[k],BS[k],BP[k])
print(d)

Measured memory_bytes: 59236
#include <iostream>

using namespace std;

int main()
{
 string x;
    cin>>x;
    int a=0;
    for(int i=0;i<4;i++){
            for(int r=i+1;r<4;r++){
            if(x.at(i)==x.at(r)){
                a++;
            }}
    }
    if(a==2){
        cout<<"Yes";
    }
    else{cout<<"No";}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int a, b;
	cin >> a >> b;

	int c = a*b;

	if (c % 2 == 0) std::cout << "Even"<< std::endl;
	else std::cout << "Odd"<< std::endl;
}

Measured memory_bytes: 256
#include<stdio.h>

typedef struct {int num[6];}dice;

int comparison(dice A[]){
    if (A[0].num[0] == A[1].num[0] && A[0].num[1] == A[1].num[1]){
            return 1;
        }
    else return 0;
}

int simulation(dice A[]){ 
    int i, j, k, u, v, w;
    for(i = 0; i < 4; i++){
        u = A[0].num[0];
        A[0].num[0] = A[0].num[1];
        A[0].num[1] = A[0].num[5];
        A[0].num[5] = A[0].num[4];
        A[0].num[4] = u;
        for(j = 0; j < 4; j++){
            v = A[0].num[0];
            A[0].num[0] = A[0].num[2];
            A[0].num[2] = A[0].num[5];
            A[0].num[5] = A[0].num[3];
            A[0].num[3] = v;
            for(k = 0; k < 4; k++){
                w = A[0].num[1];
                A[0].num[1] = A[0].num[2];
                A[0].num[2] = A[0].num[4];
                A[0].num[4] = A[0].num[3];
                A[0].num[3] = w;
                if(comparison(A)){
                    return A[0].num[2];
                }
            }
        }
    }
}

int main(){
    dice A[2] = {};
    int i, j, q, ans;
    for(i = 0; i < 6; i++) scanf("%d", &A[0].num[i]);
    scanf("%d", &q);
    for(i = 1; i <= q; i++){
        for(j = 0; j < 2; j++){
            scanf("%d", &A[1].num[j]);    
        }
        ans = simulation(A);
        printf("%d\n", ans);
    }    
    return 0;
}


Measured memory_bytes: 2080
#include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

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

	vi cnt(101);

	int n, ma = 0;
	while (cin >> n) {
		if (n == 0) break;
		cnt[n]++;
		ma = max(ma, cnt[n]);
	}

	for (int i = 0; i < 101; i++) {
		if (cnt[i] == ma) {
			cout << i << endl;
		}
	}
	return 0;
}

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

 
using namespace std;
int main(void){
    string s;
    cin >> s;
    int start_point = 0, flag = 1;
    // cout << s.length() << endl;
    // cout << s.substr(start_point, 5) << endl;
    while(1) {
        if(s.length() == start_point){break;}
        else if(s.length() - start_point < 5){
            flag = 0;
            break;
        }
        //dreamがつく場合
        else if(s.substr(start_point, 5) == "dream"){
            //dream単体だと判定
            if(s.substr(start_point+5, 2) != "er" || s.substr(start_point+5, 5) == "erase" ){
                start_point += 5;
            }
            //dreamer単体だと判定
            else if(s.substr(start_point+5, 2) == "er" && s.substr(start_point+5, 5) != "erase"){
                start_point += 7;
            }
        }
        //eraseがつく場合
        else if(s.substr(start_point, 5) == "erase"){
            //erase単体だと判定
            if(s.substr(start_point+5, 1) != "r"){
                start_point += 5;
            }
            //eraser単体だと判定
            else if(s.substr(start_point+5, 1) == "r"){
                start_point += 6;
            }
        }
        else{
            flag = 0;
            break;
        }
    }

    if(flag == 1){cout << "YES" << endl;}
    else{cout << "NO" << endl;}
  return 0;
}

Measured memory_bytes: 3728
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL a, b;

int main()
{
	in >>a >> b;
	if (a + b == 15) out << "+" << std::endl;
	else if (a*b == 15) out << "*" << std::endl;
	else out << "x" << std::endl;
	return 0;
}


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

int main(){
  int X,d;
  cin >> X;
  for(int i=0;i<X;i++){
    cin >> d;
    auto result = find(kind.begin(),kind.end(),d);
    if(result == kind.end())kind.push_back(d);
  }
  cout << kind.size() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(i);
// sort(arr, arr+n, greater<int>());
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	int r;
	cin>>r;
	long double ans=0;
	ans = 2*r*3.141592653589793238462643383279502884197169399375105820974944592307816406286;
	cout<<fixed<<setprecision(2)<<ans<<endl;
}

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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(a*n,b) << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<int>> x(n,vector<int>(0)),y(n,vector<int>(0));
  int i,j;
  for(i=0;i<n;i++){
    cin >> a.at(i);
    for(j=0;j<a.at(i);j++){
      int k,l;
      cin >> k >> l;
      x.at(i).push_back(k);
      y.at(i).push_back(l);
      x.at(i).at(j)--;
    }
  }
  
  int s=1;
  for(i=0;i<n;i++){
    s *= 2;
  }
  
  int max=0;
  vector<int> bit(n,0);
  for(i=0;i<s;i++){
    int p=i;
    int count=0;
    for(j=0;j<n;j++){
      bit.at(j)=p%2;
      count += bit.at(j);
      p /= 2;
    }
    
    bool judge=true;
    for(j=0;j<n;j++){
      if(bit.at(j)==1){
        int k;
        for(k=0;k<a.at(j);k++){
          if(bit.at(x.at(j).at(k))!=y.at(j).at(k)){
            judge=false;
          }
        }
      }
    }
    if(judge){
      if(max<count){
        max=count;
      }
    }
  }
  
  cout << max << endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/

ll ex(ll a){
    if(a==1)return 1;
    return a+ex(a-1);
}

int main(){
    ll n;
    cin>>n;
    for(int i=1;i<100000;i++){
        if(ex(i)>=abs(n)){
            
                op(i);
                return 0;
            
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());




int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    int a,b;
    cin >> a >> b;
    if(b >= a)cout << "unsafe\n";
    else cout << "safe\n";
    return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>

long long min(long long a,long long b){
    return(a>b)?b:a;
}

int main(void){
    int n,m,Q;
    long long L;
    scanf("%d%d%lld",&n,&m,&L);
    int a[m],b[m];
    long long c[m];
    for(int i=0;i<m;i++){
        scanf("%d%d%lld",&a[i],&b[i],&c[i]);
    }
    scanf("%d",&Q);
    int s[Q],t[Q];
    for(int i=0;i<Q;i++){
        scanf("%d%d",&s[i],&t[i]);
    }
    long long d[n][n];
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)d[i][j]=(i!=j?10000000000:0);
    for(int i=0;i<m;i++){
        d[a[i]-1][b[i]-1]=d[b[i]-1][a[i]-1]=c[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
            }
        }
    }
    long long fuel[n][n];
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)fuel[i][j]=(i==j?0:10000000000);
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(d[i][j]<L+1)fuel[i][j]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                fuel[j][k]=min(fuel[j][k],fuel[j][i]+fuel[i][k]);
            }
        }
    }
    for(int i=0;i<Q;i++){
        if(fuel[s[i]-1][t[i]-1]<10000000000)printf("%lld\n",fuel[s[i]-1][t[i]-1]-1);
        else printf("-1\n");
    }
    return 0;
}
    



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/
int n, k;
vector<int> a;
/**********************************************/

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    a.resize(n);
    REP(i, n) cin >> a[i];
    
    vector<int> ruiseki1(n), ruiseki2(n);
    ruiseki1[0] = a[0];
    REP(i, n-1){
        ruiseki1[i+1] = ruiseki1[i] + a[i+1];
    }
    ruiseki2[0] = max(0LL, a[0]);
    REP(i, n-1){
        ruiseki2[i+1] = ruiseki2[i] + max(0LL, a[i+1]);
    }
    
    int ans = -INFL;
    REP(i, n-k+1){
        int range1 = max(0LL, ruiseki1[i+k-1] - (i == 0 ? 0 : ruiseki1[i-1]));
        int range2 = (i == 0 ? 0 : ruiseki2[i-1]);
        int range3 = (i == n-k ? 0 : ruiseki2[n-1] - ruiseki2[i+k-1]);
        ans = max(ans, range1 + range2 + range3);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
require 'complex'

require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

# 44094532945393573773964662553787022455836724127102591670765486080000


def eratosthenes(n)
	is_p = Array.new(n+1){true}
	is_p[0] = false
	is_p[1] = false
	2.upto(N){|i|
		if(is_p[i])
			j = i+i
			while(j<=N)
				is_p[j]=false
				j+=i
			end
		end
	}
	is_p
end
def prime_decomp(n,is_p)
	h = {}
	if(is_p[n])
		h[n] = 1
		return h
	end
	q = n
	for d in 2..(Math.sqrt(n).to_i)
		if(is_p[d])
			dcnt = 0
			while(q%d==0)
				q /= d
				dcnt += 1
			end
			dcnt != 0 ? h[d] = dcnt : 1
		end
	end
	q != 1 ? h[q] = 1 : 1
	dpp h
	h
end

N,_=gets.chomp.split(' ').map{|n| n.to_i}
if(N==1)
	puts 1
	exit(0)
end
is_p = eratosthenes(N)
h = {}
2.upto(N){|i|
	h.merge!(prime_decomp(i,is_p)){|k, oldv, newv| oldv + newv}
}
dpp h
puts h.to_a.inject(1){|sum,kv| sum*(kv[1]+1)} % (10**9+7)


Measured memory_bytes: 2300
l, r = map(int, input().split())
if r - l >= 2019:
    print(0)
else:
    lm = l % 2019
    rm = r % 2019
    if lm >= rm:
        print(0)
    else:
        m = 2019
        for i in range(lm, rm):
            for j in range(i+1, rm+1):
                m = min(i * j % 2019, m)
        print(m)

Measured memory_bytes: 3060
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    map<ll, ll, greater<ll>> m;
    REP(i, N) {
        ll A;
        cin >> A;
        m[A]++;
    }
    REP(i, M) {
        ll B, C;
        cin >> B >> C;
        m[C] += B;
    }
    ll res = 0;
    int cnt = 0;
    for (auto x : m) {
        if (cnt == N) {
            break;
        }
        ll d = N - cnt;
        res += x.first * min(x.second, d);
        cnt += min(x.second, d);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std; 
long long n,m;
long long a[200010],b[200010];
long long ans=0;
long long cost[20100];
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i];
	}
	memset(cost,9999999,sizeof(cost));
	cost[0]=0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<m;j++){
			cost[i+a[j]]=min(cost[i+a[j]],cost[i]+b[j]);
		}
	}
	//for(int i=0;i<n+1;i++)cout<<cost[i]<<' ';
	for(int i=10010;i>=0;i--)cost[i]=min(cost[i],cost[i+1]);
	cout<<cost[n]<<endl;
    return 0; 
}/*
*/

Measured memory_bytes: 384
import numpy as np

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    if sum(a) >= k:
        a.sort()
        L, R = -1, n-1
        while L+1 < R:
            P = (L+R+1)//2
            if k <= a[P]:
                R = P
                continue
            dp = np.zeros((k+1), dtype=np.bool)
            dp[0] = True
            for j in range(n):
                if k <= a[j] or j == P:
                    continue
                dp[a[j]:] |= dp[:-a[j]]
            f = False
            for j in range(k-a[P], k):
                f |= dp[j]
            if f:
                R = P
            else:
                L = P
        print(R)
    else:
        print(n)

if __name__ == "__main__":
    main()

Measured memory_bytes: 27376
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
a.sort()
b = sorted(list(set(a)))
c = Counter(a)
ans = 0
for i in b:
    ans += c[i] - 1
if ans % 2 == 1:
    ans += 1
print(n - ans)

Measured memory_bytes: 83812
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())

    vec = list(range(1, 10))
    for i in range(K):
        tail = vec[i] % 10
        if tail == 0:
            vec.append(vec[i] * 10 + tail)
            vec.append(vec[i] * 10 + tail + 1)
        elif tail == 9:
            vec.append(vec[i] * 10 + tail - 1)
            vec.append(vec[i] * 10 + tail)
        else:
            vec.append(vec[i] * 10 + tail - 1)
            vec.append(vec[i] * 10 + tail)
            vec.append(vec[i] * 10 + tail + 1)

        if len(vec) == K:
            break

    print(vec[K - 1])
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 86684