akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);  
//*s.find_by_order(p)   returns the value of pth largest starting from 0 
//s.order_of_key(p)   returns no. of items that are strictly < p 
//string bin = bitset<64>(m).to_string();     convert decimal m to binary
int main()
{
	fast;ll t;t=1;
	while(t--)
	{
		ll n,i,tr,tw,a,b,ans=10e15;
		cin>>n;
		string s;
		ll x[n+2]={0},y[n+2]={0};
		cin>>s;
		for(i=0;i<n;i++){
			if(s[i]=='R'){x[i]=1;y[i]=0;}
			else{x[i]=0;y[i]=1;}
		}
		for(i=1;i<n;i++){
			x[i]=x[i-1]+x[i];
			y[i]=y[i-1]+y[i];
		}
		tr=x[n-1];
		if(tr==0){cout<<"0\n";continue;}
		for(i=0;i<n;i++)
		{
			a=y[i];
			b=tr-x[i];
			ans=min(ans,max(a,b));
		}
		cout<<ans<<"\n";
	}
}

Measured memory_bytes: 6856
import sys
import decimal # 10進法に変換，正確な計算

def input():
    return sys.stdin.readline().strip()

def main():
    a = int(input())
    b = int(input())
    if a + b == 3:
        print(3)
        return
    elif a + b == 4:
        print(2)
        return
    print(1)
    
    
main()

Measured memory_bytes: 5076
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=100010;
struct edge{int u,v,w,next;};
edge e[maxn*2];
int g[maxn];
int vis[maxn];
int d[maxn];
int n;
int bfs(int u){
	memset(d,0,sizeof(d));
	memset(vis,0,sizeof(vis)); 
	queue<int>q;
	vis[u]=1;
	q.push(u);
	d[u]=0;
	while(!q.empty()){
		int x=q.front();q.pop();
		for(int i=g[x];i>0;i=e[i].next){
			int v=e[i].v,w=e[i].w;
			if(vis[v]==0){
				d[v]=d[x]+w;
				q.push(v);
				vis[v]=1;			
			}        
		}
	} 
	int ans=0;
	int v1=0;
	for(int i=0;i<n;i++){
		if(d[i]>ans){
			ans=d[i];
			v1=i;
		}		
	}
	return v1;
}

int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		int u,v,w;
		cin>>u>>v>>w;
		e[i*2-1]=(edge){u,v,w,g[u]};g[u]=i*2-1;
		e[i*2]=(edge){v,u,w,g[v]};g[v]=i*2;
	}
	int v1=bfs(1);
	int v2=bfs(v1); 
	cout<<d[v2]<<endl;
	return 0;
} 

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

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

    int wa = 0;
    int nn = n;

    do {
        wa += nn % 10;
    } while (nn /= 10);

    cout << (n % wa == 0 ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdlib>
#include <cmath>

#define INF 100000000
template<class T> inline bool chmax(T& a, T b)
{ if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b)
{ if (a > b) { a = b; return 1; } return 0; }

using namespace std;

int main(){
  int i,j,k,n,d,a[100],x,y,z=1,ans=0;

  cin >>x>>y;
  for(i=0;i<21;i++){

    if(i==1)a[i]=x;
    else{
      a[i]=(x*i)-(i-1);
    }
  }

  for(i=0;i<21;i++){
    if(y<=a[i])break;
  }

  cout << i <<endl;

  return 0;
}

Measured memory_bytes: 256
for i in range(int(raw_input())):
    train = ''
    move = raw_input()
    train = train + move[0]
    move = move[1:]
    while move:
        if move[2] not in train:
            if move[:2] == "<-":
                train = move[2] + train
            else:
                train = train + move[2]
        move = move[3:]
    print train

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

#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
const int MOD=1e9+7;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
signed main(){
	string l;
	cin>>l;
	int dp[2][100010];
	dp[0][0]=2;
	dp[1][0]=1;
	int n=l.size();
	rep(i,1,n){
		if(l[i]=='1'){
			dp[0][i]=dp[0][i-1]*2;
			dp[1][i]=dp[0][i-1]+dp[1][i-1]*3;
		}else{
			dp[0][i]=dp[0][i-1];
			dp[1][i]=dp[1][i-1]*3;
		}
		dp[0][i]%=MOD;
		dp[1][i]%=MOD;
	}
	cout<<(dp[0][n-1]+dp[1][n-1])%MOD<<endl;
}


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

int main() {
    const long long X_MAX=400000000;
    int N, M;
    cin >> N >> M;
    vector <vector<long long>> gakusei(N, vector<long long> (2, 0));
    vector <vector<long long>> point(M, vector<long long> (2, 0));
    for (int i=0; i<N; i++) {
        cin >> gakusei.at(i).at(0) >> gakusei.at(i).at(1);
    }
    for (int i=0; i<M; i++) {
        cin >> point.at(i).at(0) >> point.at(i).at(1);
    }
    vector <vector<long long>> res(N, vector<long long> (2, X_MAX));
    for (int i=0; i<N; i++) {
        for (int j=0; j<M; j++) {
            long long new_dist = abs(gakusei.at(i).at(0)-point.at(j).at(0))+abs(gakusei.at(i).at(1)-point.at(j).at(1));
            if (new_dist<res.at(i).at(0)) {
                res.at(i).at(0) = new_dist;
                res.at(i).at(1) = j+1;
            }
        }
    }
    for (int i=0; i<N; i++) {
        cout << res.at(i).at(1) << "\n";
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{

  int N;
  cin >> N;

  int cnt = 0;
  for(int i = 1; i <=N; i++){
    if(i%2 == 1) cnt++;
  }

  cout << (float)cnt/(float)N << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob
int a,b;
string str;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> str;
	a=10*(str[0]-'0')+(str[1]-'0'),b=10*(str[2]-'0')+(str[3]-'0');
	if(1<=a&&a<=12&&1<=b&&b<=12) print1("AMBIGUOUS");
	else if(1<=a&&a<=12) print1("MMYY");
	else if(1<=b&&b<=12) print1("YYMM");
	else print1("NA");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 


using namespace std;

int main(){

    int n;
    cin >> n;

    int ans = 0;

    for(int i = 1; i <= n; i = i + 2){

        int count = 0;

        for(int j = 1; j <= i; j++){
            if(i % j == 0) count++;
        }

        if(count == 8) ans++;

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int i, n, t, C[10001];
    unsigned short A[2000001], B[2000001], a_max = 0;
    
    cin >> n;
    for(i = 0; i < n; i++) cin >> A[i];
    for(i = 0; i < n; i++) if(a_max < A[i]) a_max = A[i];
    for(i = 0; i < a_max + 1; i++) C[i] = 0;
    for(i = 0; i < n; i++) C[A[i]]++;
    t = 0;
    for(i = 0; i < a_max + 1; i++){
        C[i] += t;
        t = C[i];
    }
    for(i = n - 1; i >= 0; i--){
        t = C[A[i]];
        B[t - 1] = A[i];
        C[A[i]]--;
    }
    for(i = 0; i < n; i++){
        if(i > 0) cout << " ";
        cout << B[i];
    }
    cout << endl;
    return 0;
}



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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int ceil(int a, int b) {
	return (a + b - 1) / b;
}
int main() {
	int n, k;
	while (cin >> n >> k)
		cout << ceil(n, k) - n / k << endl;

	return 0;
}



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

public class GFG
{

    public static void Main()
    {
        var ii = Console.ReadLine().ToCharArray();

        if (Char.IsUpper(ii[0]))
        {
            Console.Write("A");
        }
        else
            Console.Write("a");

    }
    
}




Measured memory_bytes: 17440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// #define debug(a) cout << "["; rep(i,a.size()) cout << a[i] << ", "; cout<<"]"<< endl;

const ll mod = 1000000007;

int main() {
    int x; cin >> x;
    int ans;
    if(x>=1800){
        ans = 1;
    } else if(x>= 1600){
        ans = 2;
    } else if(x>= 1400){
        ans = 3;
    } else if(x>= 1200){
        ans = 4;
    } else if(x>= 1000){
        ans = 5;
    } else if(x>= 800){
        ans = 6;
    } else if(x>= 600){
        ans = 7;
    } else if(x>= 400){
        ans = 8;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;//105,165,135,195
  int cnt = 0, cntt = 0;
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= N; j = j + 2){
      if( i % j == 0) cntt++;
    }
    if(cntt == 8) cnt++;
    cntt = 0;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int L[100001],R[100001];
int main(){
    int n;
    cin>>n;
    int l,r;
    rep(i,n){
        cin>>l>>r;
        L[i]=l;
        R[i]=r;
    }
    sort(L,L+n,greater<int>());
    sort(R,R+n);
    ll mx=0;
    ll sum=0;
    rep(i,n){
        mx=max(mx,sum+max(L[i],-R[i]));
        sum+=L[i]-R[i];
        mx=max(mx,sum);
    }
    cout<<mx*2<<endl;
    return 0;
}

Measured memory_bytes: 1024
import Foundation

extension String {
    @inlinable
    func wordsMap<T>(_ f: (Substring) -> T?) -> [T] {
        return self.split(separator: " ").compactMap(f)
    }
}

@inlinable
func readWords<T>(_ f: (Substring) -> T?) -> [T] {
    return readLine()!.wordsMap(f)
}

extension Optional {
    @inlinable
    func pleaseAC(){
        print(self!)
    }
}

readLine().map { line -> Any in 
    let nh = line.wordsMap { Int($0) }
    let n = nh[0]
    let h = nh[1]

    var maxA = 0
    let weapons = (1...n).map { _ -> Int in
        let ab = readWords { Int($0) }
        let a = ab[0]
        let b = ab[1]
        maxA = max(a, maxA)
        return b
    }

    let niceB = weapons.filter { $0 > maxA }.sorted(by: >)

    var total = 0
    var ans = 0
    for b in niceB {
        total += b
        ans += 1
        if total >= h {
            return ans
        }
    }

    let rest = h - total

    return (rest % maxA == 0 ? 0 : 1) + rest / maxA + ans

}
.pleaseAC()


Measured memory_bytes: 15772
n = int(input())
d = [list(map(int,input().split())) for i in range(n)]
for i in range(n-2):
    if d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]:
        print('Yes')
        exit()
print('No')
    

Measured memory_bytes: 9168
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long[][] memo = new long[n][n];
		boolean[][] memoed = new boolean[n][n];
		long[] a = new long[n];
		for (int i=0;i<n;i++) {
			a[i]=sc.nextLong();
		}
		System.out.println(taro(0,n-1,memo,memoed,a));
		System.out.println();
	}
	
	static long taro(int start, int end, long[][] memo, boolean[][] memoed, long[] a) {
		if (memoed[start][end]) {
			return memo[start][end];
		} else if (start == end) {
			memoed[start][end]=true;
			memo[start][end]=a[start];
			return a[start];
		} else {
			long ret = Math.max(jiro(start,end-1,memo,memoed,a)+a[end], jiro(start+1,end,memo,memoed,a)+a[start]);
			memoed[start][end]=true;
			memo[start][end]=ret;
			return ret;
		}
	}
	
	static long jiro(int start, int end, long[][] memo, boolean[][] memoed, long[] a) {
		if (memoed[start][end]) {
			return memo[start][end];
		} else if (start == end) {
			memoed[start][end]=true;
			memo[start][end]=-a[start];
			return -a[start];
		} else {
			long ret=Math.min(taro(start,end-1,memo,memoed,a)-a[end], taro(start+1,end,memo,memoed,a)-a[start]);
			memoed[start][end]=true;
			memo[start][end]=ret;
			return ret;
		}
	}

}


Measured memory_bytes: 151512
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N;
vector<int> G[100010];

void recdist(int p, vector<int> &dst, int prev=-1) {
    for(auto to : G[p]) {
        if(to == prev) continue;
        dst[to] = dst[p] + 1;
        recdist(to, dst, p);
    }
}

void paintvt(int p, int prev, int col, vector<int> &v) {
    v[p] = col;
    for(auto to : G[p]) {
        if(to == prev) continue;
        paintvt(to, p, col, v);
    }
}

signed main() {
    cin >> N;
    rep(i,0,N-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> dsta(N), dstb(N);
    recdist(0, dsta); recdist(N-1, dstb);

    int s = 0, t = 0;
    rep(i,0,N) for(auto to : G[i]) {
        if(dsta[i] <= dstb[i] && dsta[to] > dstb[to]) {
            s = i, t = to;
        }
    }

    vector<int> bh(N);
    paintvt(s, t, 0, bh); paintvt(t, s, 1, bh);

    int cntb = 0, cntw = 0;
    rep(i,0,N) (bh[i] ? cntw : cntb)++;
    cout << (cntb > cntw ? "Fennec" : "Snuke") << endl;
    return 0;
}

Measured memory_bytes: 14336
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 200010
#define pa(a, b) (aa){a, b}
using namespace std;
struct aa{int x, id;}a[4][N];
int n, R, C, x, y, len[4], cl, d[N], l, sum[N], flag[N], b[N];
inline void ins(int x, int y, int i){
	if(!x&&y<C)a[0][++len[0]]=pa(y, i);
	if(y==C&&x<R)a[1][++len[1]]=pa(x, i);
	if(x==R&&y)a[2][++len[2]]=pa(y, i);
	if(!y&&x)a[3][++len[3]]=pa(x, i);
}
inline bool cmp1(aa a, aa b){return a.x<b.x;}
inline bool cmp2(aa a, aa b){return a.x>b.x;}
int main(){
	scanf("%d%d%d", &R, &C, &n);
	memset(len, 0, sizeof(len));
	for(int i=1; i<=n; i++){
		scanf("%d%d", &x, &y); ins(x, y, i);
		scanf("%d%d", &x, &y); ins(x, y, i);
	}
	sort(a[0]+1, a[0]+1+len[0], cmp1);
	sort(a[1]+1, a[1]+1+len[1], cmp1);
	sort(a[2]+1, a[2]+1+len[2], cmp2);
	sort(a[3]+1, a[3]+1+len[3], cmp2);
	l=0;
	for(int i=0; i<=3; i++)
		for(int j=1; j<=len[i]; j++)b[++l]=a[i][j].id;
	memset(sum, 0, sizeof(sum)); memset(flag, 0, sizeof(flag));
	for(int i=1; i<=l; i++)sum[b[i]]++;
	cl=0;
	for(int i=1; i<=l; i++)if(sum[b[i]]==2){
		if(!flag[b[i]]){flag[b[i]]=1; d[++cl]=b[i];}
		else{
			if(d[cl]!=b[i]){printf("NO"); return 0;}
			cl--;
		}
	}
	printf("YES");
	return 0;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define pii pair<int,int>
#define mk make_pair
#define ff first
#define ss second
#define mod 1000000007
int dp[101][100001];
bool cmp(pii a, pii b){
    if(a.ss<b.ss)return false;
    else if(a.ss==b.ss){
        if(a.ff<b.ff)return false;
    }
    return true;
}
int32_t main(){
	int n,w,x,y;
	cin>>n>>w;
	vector<pii>v;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		v.pb(mk(x,y));
	}
	sort(v.begin(),v.end(),cmp);
/*	for(int i=0;i<n;i++){
	    cout<<v[i].ff<<" "<<v[i].ss<<endl;
	}*/
	memset(dp,0,sizeof dp);
	int mx=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<100001;j++){
			if(v[i-1].ss>j){
				dp[i][j]=dp[i-1][j];
			}
			else if(v[i-1].ss==j){
				if(dp[i-1][j]==0)dp[i][j]=v[i-1].ff;
				else dp[i][j]=min (dp[i-1][j-v[i-1].ss]+v[i-1].ff,dp[i-1][j]);
			}
			else{
				if(dp[i-1][j-v[i-1].ss]!=0){
					if(dp[i-1][j]==0)dp[i][j]=dp[i-1][j-v[i-1].ss]+v[i-1].ff;
					else dp[i][j]=min(dp[i-1][j-v[i-1].ss]+v[i-1].ff,dp[i-1][j]);
				}
				else{
					dp[i][j]=dp[i-1][j];
				}
			}
			if(dp[i][j]<=w&&dp[i][j]!=0)mx=max(mx,j);
		}
	}
	cout<<mx;
	/*for(int i=0;i<=n;i++){
	    for(int j=0;j<40;j++){
	        cout<<dp[i][j]<<" ";
	    }
	    cout<<endl;
	}*/
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N, H;
  cin >> N >> H;
  vector<pair<int, int>> katana;
  int maxA = 0;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    if (a > maxA) {
      maxA = a;
    }
    katana.emplace_back(b, a);
  }
  sort(katana.begin(), katana.end());
  reverse(katana.begin(), katana.end());
  int ans = 0;
  for (auto x : katana) {
    if(H <= 0){
      cout << ans <<endl;
      return 0;
    }
    int b = x.first;
    if (b <= maxA) {
      break;
    }
    H -= b;
    ans++;
  }
  ans += ceil((long double)H / maxA);
  cout << ans << endl;
}

Measured memory_bytes: 4192
#include <iostream>
#include <algorithm>

#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <stack>
#include <unordered_map>
#include <map>
#include <set>
#include <deque>
#include <bitset>

#include <cmath>
#include <functional>

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for(int i = int(a); i < int(b); ++i)
#define RFOR(i, a, b) for(int i = int(b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define IN(a, x ,b) (a<_x && x < b)
template<class T> inline T CHMAX(T& a, const T b) {return a=(a<b)?b:a;}
template<class T> inline T CHMIN(T& a, const T b){return a=(a>b)?b:a;}

using ll = long long;

using std::vector;
using std::cout;
using std::endl;
using std::cin;
using std::pair;
using std::unordered_multimap;
using std::set;
using std::map;

int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  REP(i, n) cin >> a[i] >> b[i];

  int sz = 0;
  { // zaatsu
    map<int, int> mp;
    REP(i, n) mp[a[i]], mp[b[i]];
    for(auto& p : mp) p.second = sz++;
    REP(i, n) a[i] = mp[a[i]], b[i] = mp[b[i]];
  }

  vector<vector<int>> LR(sz), RL(sz);
  REP(i, n) {
    LR[a[i]].emplace_back(b[i]);
    RL[b[i]].emplace_back(a[i]);
  }

  { // s1
    int res = 0;
    vector<int> L;
    REP(i, n) L.emplace_back(a[i]);
    sort(ALL(L));
    int sum = 0;
    REP(i, sz) {
      for(int l : RL[i]) --sum;
      for(int r : LR[i]) {
        int cnt = std::lower_bound(ALL(L), r) - L.begin() - i;
        CHMAX(res, cnt + sum);
      }
      ++sum;
    }

    cout << res << " ";
  }

  { // s2
    int res = 0;
    int cnt = 0;
    REP(i, sz) {
      for(int l : RL[i]) --cnt;
      for(int r : LR[i]) ++cnt;
      CHMAX(res, cnt);
    }
    cout << res << endl;
  }

  return 0;
}



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

int main() {
	int a, b, N, s, f;
	cin >> a >> b >> N;
	vector<int> tmp(1001);
	for (int i = a; i < b; ++i) ++tmp[i];
	for (int i = 0; i < N; ++i) {
		cin >> s >> f;
		for (int j = s; j < f; ++j) ++tmp[j];
	}
	int i;
	for (i = 0; i < 1001; ++i) {
		if (tmp[i] > 1) break;
	}
	if (i == 1001) cout << 0;
	else cout << 1;
	cout << endl;
}


Measured memory_bytes: 3124
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

using namespace std;

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

    const int INF = INT_MAX;
    vector<vector<int>> happiness(n, vector<int>(3, INF));

    const int SEA = 0;
    const int MOUNTAIN = 1;
    const int HOME = 2;
    for (int i = 0; i < n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;

        if (i == 0) {
            happiness[i][SEA] = a;
            happiness[i][MOUNTAIN] = b;
            happiness[i][HOME] = c;
        } else {
            happiness[i][SEA] =
                max(happiness[i - 1][MOUNTAIN] + a, happiness[i - 1][HOME] + a);
            happiness[i][MOUNTAIN] =
                max(happiness[i - 1][SEA] + b, happiness[i - 1][HOME] + b);
            happiness[i][HOME] =
                max(happiness[i - 1][SEA] + c, happiness[i - 1][MOUNTAIN] + c);
        }
    }

    int max_happiness = happiness[n - 1][SEA];
    max_happiness = max(max_happiness, happiness[n - 1][MOUNTAIN]);
    max_happiness = max(max_happiness, happiness[n - 1][HOME]);
    cout << max_happiness << '\n';
}


Measured memory_bytes: 5760
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main() {
	int n, x;
	cin >> n >> x;
	vector<ll>a(n),surplus(n-1);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n - 1) {
		surplus[i] =(a[i] + a[i + 1])-x;
	}
	ll count = 0;
	ll tmp = 0;
	rep(i, n - 1) {
		//tmp burden[i-1](max a[i])からの繰り越し
		ll burden = surplus[i] - tmp; 
		//a[i]a[i+1]の負担から
		   //前回a[i]が負担した分を引いたもの
		count += max(burden,(ll) 0);
		if (burden > 0) {
			tmp = min(surplus[i] - tmp,a[i+1]);
		//持ち越せるのはa[i+1]まで
		}
		else {
			tmp = 0;
		}
		//cout << count << endl;
	}
	cout << count << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
int main() {
	int N,n;
	std::cin >> N >> n;
	N -= 1;
	std::vector<int> x(n), y(n),ans(n);
	for (int i = 0; i < n; i += 1){
		std::cin >> x[i] >> y[i];
		x[i] -= 1, y[i] -= 1;
		if (x[i] < y[i]) {
			if (x[i] + y[i] > N)
				ans[i] = (N - y[i]) % 3 + 1;
			else
			ans[i] = x[i] % 3 + 1;
		}
		else {
			if (x[i] + y[i] > N)
				ans[i] = (N - x[i]) % 3 + 1;
			else
				ans[i] = y[i] % 3 + 1;
		}
	}
	for (int i = 0; i < n; i += 1)
		std::cout << ans[i] << std::endl;
	return 0;
}

Measured memory_bytes: 3128
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define sz 200008
map <pair<int,int>,int> mm;
vector <int> adj[sz];
int vis[sz];
int sum = 0;
    void dfs(int src){
        vis[src] = 1;
        sum++;
        int i,len,child;
        len = adj[src].size();
        for(i = 0;i<len;i++){
            child = adj[src][i];
            if(!vis[child]) dfs(child);
        }
        return;
    }
int main(){
    
    int i,j,n,p,q,m,mx = 0;
    
    cin >> n >> m;
    
    for(i = 0;i<m;i++){
        cin >> p >> q;
        if(mm[{p,q}] == 0){
            mm[{p,q}] = 1;
            mm[{q,p}] = 1;
            adj[p].push_back(q);
            adj[q].push_back(p);
        }
    }
    
      for(i = 1;i<=n;i++){
          if(!vis[i]){
              dfs(i);
              mx = max(mx,sum);
              sum = 0;
          }
      }
        cout << mx << endl;
    return 0;
}


Measured memory_bytes: 49524
# 奇数はかんたん 偶数ならkで割ってk/2あまるやつと割り切れるやつのそれぞれ組み合わせしたやつを加算
n, k = gets.chomp.split.map(&:to_i)
ans = 0
if k.odd?
  ans = (n/k).floor ** 3
else
  s = 0
  t = 0
  (1..n).each do |x|
    if x % k  == k / 2
      t += 1
    elsif  x % k == 0
      s += 1
    end
  end
  ans = t ** 3 + s ** 3

end
puts ans


Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;


void solve(){
    string s, t;
    cin >> s >> t;
    sort(all(s));
    sort(all(t));
    reverse(t.begin(), t.end());
    cout << ((t > s) ? "Yes": "No");
}
int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char *argv[]){
    unsigned int N;
    std::cin >> N;
    unsigned int A[N];
    for(auto &a : A){
        std::cin >> a;
    }

    int X[N];
    int i;
    X[N-1] = A[N-1];
    for(i=0; i<N-1; ++i){
        X[N-1] += (2*(i&1)-1)*A[i];
    }

    X[N-1] /= 2;

    for(i=N-2; i>=0; --i){
        X[i] = A[i] - X[i+1];
    }
    
    for(auto &x : X){
        std::cout << 2*x << " ";
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 2048
from math import factorial


def modpow(a, n, p):
    if n == 0:
        return 1
    elif n == 1:
        return a % p
    if n % 2 == 1:
        return (a * modpow(a, n-1, p)) % p
    tmp = modpow(a, n//2, p)
    return (tmp * tmp) % p


def main():
    mod = 10 ** 9 + 7
    n, a, b = map(int, input().split())

    # まずは繰り返し2乗法によって全部の組み合わせを求める
    # すべての組み合わせは、花を選ぶ/選ばないで組み合わせを決めれる

    ans = (modpow(2, n, mod) - 1) % mod

    # a本選んだときの数を引く
    c_a = 1
    for i in range(n, n-a, -1):
        c_a *= i
        c_a %= mod
    c_a *= modpow(factorial(a), mod-2, mod)
    ans -= c_a
    ans %= mod

    # b本選んだときの数を引く
    c_b = 1
    for i in range(n, n-b, -1):
        c_b *= i
        c_b %= mod
    c_b *= modpow(factorial(b), mod-2, mod)
    ans -= c_b
    ans %= mod

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5400
import sys
readline = sys.stdin.readline

ans = 0
def scomp(S):
    L = 1+max(S)
    table = [0]*L
    for s in S:
        table[s] += 1
    it = [None]*L
    cnt = 0
    for i in range(L):
        it[i] = cnt
        if table[i]:
            cnt += 1
    return it

import sys
readline = sys.stdin.readline

class Node:
    def __init__(self, sigma, depth):
        self.end = False
        self.child = [None] * sigma
        self.depth = depth
        self.count = [0]*sigma
        self.par = None
    def __setitem__(self, i, x):
        self.child[i] = x
    def __getitem__(self, i):
        return self.child[i]

class Trie():
    def __init__(self, sigma):
        self.sigma = sigma
        self.root = Node(sigma, 0)
    
    def add(self, S):
        vn = self.root
        for cs in S:
            if vn[cs] is None:
                vn[cs] = Node(self.sigma, vn.depth + 1)
                vn[cs].par = vn
            vn = vn[cs]
        vn.end = True
    
    def up(self, S):
        vn = self.root
        for cs in S:
            if vn[cs] is None:
                vn[cs] = Node(self.sigma, vn.depth + 1)
            vn = vn[cs]

        k = [0]*self.sigma
        ls = len(S)
        for i in range(ls-1, -1, -1):
            vn = vn.par
            s = S[i]
            k[s] = 1
            for i in range(self.sigma):
                vn.count[i] += k[i]
    
    def count(self, S, ss):
        vn = self.root
        for cs in S:
            if vn[cs] is None:
                vn[cs] = Node(self.sigma, vn.depth + 1)
            vn = vn[cs]
        
        global ans
        ans += vn.count[ss]

ans = 0



N = int(readline())
A = [list(map(lambda x: ord(x)-97, readline().strip()))[::-1] for _ in range(N)]

T = Trie(26)

for a in A:
    T.add(a)
for a in A:
    T.up(a)
for a in A:
    s = a[:-1]
    t = a[-1]
    T.count(s, t)

print(ans-N)

Measured memory_bytes: 795284
/*
 * main.c
 *
 *  Created on: 2019/12/29
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;

int main()
{
	int N = 0, M = 0;
	scanf("%d %d", &N, &M);
	if (N == M) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
#define SZ(x) ((int)(x).size())

using namespace std;



string zero_fill(int number, int n) {

	stringstream ss;
	ss << setw(n) << setfill('0') << number;
	return ss.str();
}

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

	vector<pair<pair<int, int>,int>> P(M); //pair<pair<prefecture, year>, index>
	for (int i = 0; i < M; i++)
	{
		cin >> P[i].first.first >> P[i].first.second;
		P[i].second = i;
	}
	sort(P.begin(), P.end()); //昇順ソート(左側にある要素を優先してソートしてくれる)

	//for (int i = 0; i < M; i++)
	//{
	//	printf("[p, y, i] = [%d, %d, %d]\n", P[i].first.first, P[i].first.second, P[i].second);
	//}

	vector<string> ans(M); 
	int previous_prefecture = P[0].first.first; //前回処理した県の初期値
	int number = 1; //市が誕生した順番の初期値
	for (int i = 0; i < M; i++)
	{
		int prefecture = P[i].first.first;
		//printf("[now, prev] = [%d, %d]\n",prefecture, previous_prefecture);

		//前回処理した県とこれから処理する県が異なるときは市が誕生した順番を初期化
		if (prefecture != previous_prefecture) {
			number = 1;
		}

		//0埋め
		string first = zero_fill(prefecture, 6);
		string last  = zero_fill(number    , 6);

		//答えの配列にIDを入れる
		int index = P[i].second; //ソート前のインデックスを取得
		ans[index] = first + last;

		//次の処理のために更新
		number++; //市が誕生した順番
		previous_prefecture = prefecture; //県の番号
	}


	for (int i = 0; i < M; i++)
	{
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 8192
#include <stdio.h>
#include<string.h>

int main(void) {
	int n,i;
	char t[1300];
	gets(t);
	n=strlen(t);
	for(i=0;i<n;i++){
		if(islower(t[i])){
			printf("%c",toupper(t[i]));
		}
		else if(isupper(t[i])){
			printf("%c",tolower(t[i]));
		}
		else{
			printf("%c",t[i]);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
def main():
    K, A, B = (int(i) for i in input().split())
    ans = 1
    K -= (A-ans)
    ans = A
    if B-A > 2:
        ans += (B-A)*(K // 2)
        if K & 1:
            ans += 1
    else:
        ans += 1*K
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
 
using namespace std;

signed main()
{
    fast;
    int x,y;
    cin>>x>>y;

    int m = x % y;
    
    cout<<min(m,y-m)<<endl;
    return 0;
}

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

struct Node{int p,l,r;};

Node T[100000];
int n,D[100000];

void print(int u){
    int i=0,c;
    cout<<"node "<<u<<": ";
    cout<<"parent = "<<T[u].p<<", ";
    cout<<"depth = "<<D[u]<<", ";
    
    if(T[u].p==-1)cout<<"root, ";
    else if(T[u].l==-1)cout<<"leaf, ";
    else cout<<"internal node, ";
    
    cout<<"[";
    
    for(c=T[u].l;c!=-1;c=T[c].r){
        if(i)cout<<", ";i++;
        cout<<c;
    }
    cout<<"]"<<endl;
}

void rec(int u,int p){
    D[u]=p;
    if(T[u].r!=-1)rec(T[u].r,p);
    if(T[u].l!=-1)rec(T[u].l,p+1);
}

int main(){
    int i,j,d,v,c,l,r;
    cin>>n;
    for(i=0;i<n;i++)T[i].p=T[i].l=T[i].r=-1;
    
    for(i=0;i<n;i++){
        cin>>v>>d;
        for(j=0;j<d;j++){
            cin>>c;
            if(j==0)T[v].l=c;
            else T[l].r=c;
            l=c;
            T[c].p=v;
        }
    }
    
    for(i=0;i<n;i++){
        if(T[i].p==-1)r=i;
    }
    
    rec(r,0);
    
    for(i=0;i<n;i++)print(i);
    
    return 0;
}


Measured memory_bytes: 7704
n = int(input())
p = list(map(int, input().split()))

p_sort = sorted(p)
key = [x-y for x,y in zip(p,p_sort)]
cnt = 0
for w in key:
    if w != 0:
        cnt += 1
        if cnt > 2:
            break
if cnt > 2:
  print('NO')
else:
    print('YES')

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N = sc.nextInt();
	static long[] A = new long[N];
	static long[] B = new long[N];
	static long[] D = new long[N];
	static {
		Arrays.setAll(A, i -> sc.nextLong());
		Arrays.setAll(B, i -> sc.nextLong());
		Arrays.setAll(D, i -> A[i] - B[i]);
	}
	public static void main(String[] args) {
		long[] shortages = Arrays.stream(D).filter(i -> i < 0).toArray();
		long shortage = Arrays.stream(shortages).sum();
		// B-A > 0なテストは絶対に変えなければならない
		int ans = shortages.length;
		long[] remains = Arrays.stream(D).filter(i -> i > 0).sorted().toArray();
		for (int i = remains.length - 1; i >= 0; i--) {
			// 不足分が補われたら抜ける
			if (shortage >= 0) break;
			shortage += remains[i];
			ans++;
		}
		// 余剰分を充当してなお不足分が補われていなかったら -1
		if (shortage < 0) {
			ans = -1;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 91604
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
multiset<string>s;
int main(){
    scanf("%d%d%d",&a,&b,&c);
    for(int i=1;i<=a;++i)s.insert("a");
    for(int i=1;i<=b;++i)s.insert("b");
    for(int i=1;i<=c;++i)s.insert("c");
    while(s.size()>1){
        string ss=*s.begin()+*--s.end();
        s.erase(s.begin());
        s.erase(--s.end());
        s.insert(ss);
    }
    cout<<*s.begin();
    return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,m,a;
	cin >> m >> n;
	int sum = 0;
	for(int i=0;i<n;i++){
		cin >> a;
		sum += a;
	}
	if(sum > m) cout << "-1\n";
	else cout << m-sum << '\n';
}

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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N=2e5+5;
const ll MOD=1e9 +7;
ll arr[N];

void solve(){
	int n,k;
	scanf("%d %d",&n,&k);
	fr(i,0,n){
		scanf("%lld",arr+i);
	}
	if(k==n){
		ll prod=1;
		int ncnt=0;
		fr(i,0,n){
			if(arr[i]<0)
				ncnt++;
			prod=(prod* abs(arr[i]))%MOD;
		}
		if(ncnt%2){
			prod=(MOD-prod)%MOD;
		}
		printf("%lld",prod);
		return;
	}
	vll pos,neg;
	neg.reserve(n);
	pos.reserve(n);
	fr(i,0,n){
		if(arr[i]<0)
			neg.pb(abs(arr[i]));
		else
			pos.pb(arr[i]);
	}
	sort(neg.rbegin(),neg.rend());
	sort(pos.rbegin(),pos.rend());
	ll ns=neg.size(),ps=pos.size();
	if(ns==n && (k%2)){
		ll prod=1;
		reverse(all(neg));
		fr(i,0,k){
			prod=(prod*neg[i])%MOD;
		}
		prod=(MOD-prod)%MOD;
		printf("%lld",prod);
	}
	else{
		vll final;
		final.reserve(n);
		ll prod=1;
		if(k%2)
			prod=pos[0];
		fr(i,k%2,ps){
			final.pb(pos[i]*pos[i+1]);
			i++;
		}
		fr(i,0,ns){
			final.pb(neg[i]*neg[i+1]);
			i++;
		}
		sort(final.rbegin(),final.rend());
		fr(i,0,k/2){
			prod=((prod) * ((final[i])%MOD))%MOD;
		}
		printf("%lld",prod);
	}
	return;
}

int main()
{
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}

Measured memory_bytes: 7168
try:
    while 1:
        lv = list(map(int, input().split(',')))
        l = lv[:-2]
        v1, v2 = lv[-2:]

        s = sum(l) / (v1 + v2) * v1
        spam = 0
        for i in range(10):
            spam += l[i]
            if spam >= s:
                print(i + 1)
                break
except:
    pass

Measured memory_bytes: 7576
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    vector<int> A(N+1);
    for (int i = 1; i <= N; ++i) {
        cin >> A[i];
    }

    vector<vector<int>> C(H, vector<int>(W, 0));

    int color = 1;
    for (int i = 0; i < H; ++i) {
        if (i & 1) {
            // backward
            for (int j = W-1; j >= 0; --j) {
                if (A[color] > 0) {
                    C[i][j] = color;
                    A[color]--;
                } else {
                    if (color <= N) {
                        color++;
                        C[i][j] = color;
                        A[color]--;
                    } else {
                        break;
                    }
                }
            }
        } else {
            // forward
            for (int j = 0; j < W; ++j) {
                if (A[color] > 0) {
                    C[i][j] = color;
                    A[color]--;
                } else {
                    if (color <= N) {
                        color++;
                        C[i][j] = color;
                        A[color]--;
                    } else {
                        break;
                    }
                }
            }
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cout << C[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3672
import sys

# import bisect
from collections import Counter, deque, defaultdict

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
from operator import attrgetter, itemgetter

# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    xyh = [list(map(int, readline().split())) for _ in range(n)]

    hbase = 0
    idx = 0

    while hbase == 0:
        xbase = xyh[idx][0]
        ybase = xyh[idx][1]
        hbase = xyh[idx][2]
        idx += 1

    for x in range(101):
        for y in range(101):
            h = hbase + (abs(xbase - x) + abs(ybase - y))
            for i in range(n):
                htemp = max((h - (abs(xyh[i][0] - x) + abs(xyh[i][1] - y)), 0))
                if htemp != xyh[i][2]:
                    break
            else:
                print(x, y, h)
                sys.exit()


if __name__ == '__main__':
    main()


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

int main() {
 int a,b;
  cin >> a >> b;
  if (a % 2 == 0 || b % 2 == 0){
  cout << "Even" << endl;
  }
  else {
  cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll D, T, S; cin >> D >> T >> S;
    if(D > T*S) cout << "No\n";
    else cout << "Yes\n";
}


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

#define ll long long

int main(void){

    int num[4]={0};
    int a[3],b[3];
    for(int i=0;i<3;i++){
        cin>>a[i]>>b[i];
        num[a[i]-1]++;
        num[b[i]-1]++;
    }
    int flag1=0,flag2=0;
    for(int i=0;i<4;i++){
        if(num[i]==1)flag1++;
        if(num[i]==2)flag2++;
    }
    if(flag1==flag2&&flag1==2)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

string s, t;
int n, m, nm, nxt[500009], cnt, ans;
vector<int> vec[500009];
int ind[500009], ld[500009];

void fun()
{
	nxt[0] = 0;
	nxt[1] = 0;
	for (int i = 2, j  = 0; i <= m; i++) {
		while (j > 0 && t[i - 1] != t[j])
			j = nxt[j];
		if (t[i - 1] == t[j]) {
			j++;
			nxt[i] = j;
		}
	}
}

void gun(int cur, int v)
{
	cnt++;
	ld[cur] = max(ld[cur], v);
	ans = max(ans, ld[cur]);
	if (ind[cur] == 0) {
		for (int i = 0; i < (int)vec[cur].size(); i++) {
			ind[vec[cur][i]]--;
			gun(vec[cur][i], ld[cur] + 1);
		}
	}
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s >> t;
	n = s.length();
	m = t.length();
	nm = n + m;
	fun();
	for (int i = 0, j = 0; i < nm - 1; i++) {
		while (j > 0 && s[i%n] != t[j]) {
			j = nxt[j];
		}
		if (s[i%n] == t[j]) j++;
		if (j == m) {
			vec[(i + 1 - m) % n].pb((i + 1)%n);
			ind[(i + 1)%n]++;
			j = nxt[j];
		}
	}
	for (int i = 0; i < n; i++) {
		if (ind[i] == 0)
			gun(i, 0);
	}
	if (cnt < n)
		cout << -1 << E;
	else {
		cout << ans << E;
	}
	//system("pause");
	return 0;
}


Measured memory_bytes: 56220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
 string S;
 cin >> S;
 if((S.at(2) == S.at(3)) && ( S.at(4) == S.at(5))) {
 	cout << "Yes" << endl;
 }else{
 	cout << "No" << endl;
 }
}

Measured memory_bytes: 3616
#pragma GCC optimize("Ofast")
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
long long sum;
int n,a[100005];
bool b;
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
		if (a[i]%2!=0)
		   b=true;
	}
	if (!b && sum%2==0)
	   cout<<"second\n";
	else
	   cout<<"first\n";
    return 0;
}

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

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

    int R[N];
    for (int i = 0; i < N; i++) cin >> R[i];

    int maxv = R[1] - R[0];
    int minv = R[0];
    for (int i = 1; i < N; i++){
        maxv = max(maxv,R[i] - minv);
        minv = min(minv,R[i]);
    }
    cout << maxv << endl;
}



Measured memory_bytes: 3876
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;
int n, k;
llong T[MAX];

int check(llong P) {
	int i = 0;
	for (int j = 0;j < k;j++) {
		llong s = 0;
		while (s + T[i] <= P) {
			s = s + T[i];
			i++;
			if (i == n) return n;
		}
	}
	return i;
}

llong solve() {
	llong left = 0;
	llong right = 10000 * 100000;
	llong mid;
	while (right - left > 1) {
		mid = (left + right) / 2;
		int v = check(mid);
		if (v >= n) right = mid;
		else left = mid;
	}
	return right;
}

int main() {
	cin >> n >> k;
	for (int i = 0;i < n; i++) { cin >> T[i]; }
	llong ans = solve();
	cout << ans << endl;

}

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

#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define TC int tc; cin >> tc; while(tc--)

using namespace std;

const int INF = 1e9 + 7;


int main(void)
{
	int x; cin >> x;
	cout << (x >= 30 ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 3624