akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll,int> P;
const ll INF=1000000000000LL;

int main(){
    int n,l;
    cin>>n>>l;
    ll a[100001];
    bool used[100001];
    fill(used,used+100001,false);
    for(int i = 0; i < n; i++)
        cin>>a[i];
    priority_queue<P> pq;
    for(int i = 0; i < n; i++){
        if(i==0){
            if(a[i+1]<a[i]){
                pq.push(P(a[i],i));
                used[i]=true;
            }
        }
        else if(i==n-1){
            if(a[i]>a[i-1]){
                pq.push(P(a[i],i));
                used[i]=true;
            }
        }
        else{
            if(a[i]>a[i-1]&&a[i]>a[i+1]){
                used[i]=true;
                pq.push(P(a[i],i));
            }
        }
    }
    ll diff=0;
    while(pq.size()){
        // ÅÉàÁÆàå«¢àÌðæèo·
        ll length=0;
        vector<int> nums;
        while(pq.size()){
            if(length==0||length==pq.top().first){
                if(length==0)
                    diff+=l-pq.top().first;
                l=pq.top().first;
                length=l;
                // Ôði[
                nums.push_back(pq.top().second);
                a[pq.top().second]=-INF;
                pq.pop();
            }
            else
                break;
        }
        // æèoµ½àÌÌ¶EÉ évfªðð½·æ¤ÉÈÁ½©²×é
        for(int i = 0; i < nums.size(); i++){
            // ¶EÌvfð`FbN
            int left=nums[i]-1;
            int right=nums[i]+1;
            // ðð½µ½çA élªZ­µ½àÌð}ü
            if(left>=0&&!used[left]){
                if(left==0){
                    if(a[left+1]<a[left]){
                        pq.push(P(a[left]-diff,left));
                        used[left]=true;
                    }
                }
                else if(left==n-1){
                    if(a[left]>a[left-1]){
                        pq.push(P(a[left]-diff,left));
                        used[left]=true;
                    }
                }
                else{
                    if(a[left]>a[left-1]&&a[left]>a[left+1]){
                        used[left]=true;
                        pq.push(P(a[left]-diff,left));
                    }
                }
            }
            if(right<n&&!used[right]){
                if(right==0){
                    if(a[right+1]<a[right]){
                        pq.push(P(a[right]-diff,right));
                        used[right]=true;
                    }
                }
                else if(right==n-1){
                    if(a[right]>a[right-1]){
                        pq.push(P(a[right]-diff,right));
                        used[right]=true;
                    }
                }
                else{
                    if(a[right]>a[right-1]&&a[right]>a[right+1]){
                        used[right]=true;
                        pq.push(P(a[right]-diff,right));
                    }
                }
            }
        }
    }
    cout<<diff<<endl;

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second
typedef long long ll;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define all(con) con.begin(),con.end()
#define w(x) int x; cin>>x; while(x--)
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cout<<fixed<<setprecision(8);
    string s;
    cin>>s;
    int ans = 0;
    rep(i,0,(int)s.length()-1)
    {
    	if(s[i] == s[i+1] && s[i] == '0')
    	{
    		s[i+1] = '1';
    		ans++;
    	}
    	else if(s[i] == s[i+1] && s[i]== '1')
    	{
    		s[i+1] = '0';
    		ans++;
    	}
    }
    cout<<ans<<endl;
    return 0;
}

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

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

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

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> A(N);
    REP(i, N)cin >> A[i];
    vector<pair<ll, ll>> bc(M);
    REP(i, M)cin >> bc[i].first >> bc[i].second;

    sort(ALL(A));
    sort(ALL(bc), [](auto a, auto b) {return a.second > b.second; });

    int index = 0;
    int cnt = 0;
    REP(i, N) {
        if (A[i] < bc[index].second) {
            cnt++;
            A[i] = bc[index].second;
            if (cnt >= bc[index].first) {
                cnt = 0;
                index++;
            }
            if (index >= M ) {
                break;
            }
        }
        else {
            break;
        }
    }

    ll ans = accumulate(ALL(A), 0LL);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int s,w;
    cin>>s>>w;
    if(s<=w)
    {
        cout<<"unsafe";
    }
    else
    {
        cout<<"safe";
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

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

    int n;
    cin>>n;
    vector<pair<int,int>>v(n-1);
    for(auto &i:v){
      int x,y;
      cin>>x>>y;
      i.first = min(x,y);
      i.second = max(x,y);
    }
    int ans = 0;
    for(int i=0;i<n;i++)
      ans += (i+1)*(n-i);

    for(auto i:v)
      ans -= (n-i.second+1)*(i.first);

    cout<<ans;


}    


Measured memory_bytes: 6304
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        String ans = "No";

        if(A%2 == 1 && B % 2 == 1){
            ans = "Yes";
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();
		if(a + b == c || a + c == b || b + c == a) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


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

int main(){
	int i;
	int j;

	for(i = 1; i <= 9; i++){
		for(j = 1; j <= 9; j++){
			cout << i << "x" << j << "=" << i * j << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1116
#include<iostream>
#include<vector>
#include<map>
#include<stack>
#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()
using namespace std;
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(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}
using AdjList = vector<vector<int>>;
using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

// Recieve edge(=(int,int)) as an adj list.
vector<vector<int>> getadj(int N, int M){
	// Initialize all lists of the graph as a empty vector.
	vector<int> init;
	vector<vector<int>> graph(N,init);

	rep(i,M){
		int a, b;
		cin >> a >> b;
		graph[a-1].emplace_back(b-1);
		graph[b-1].emplace_back(a-1);
	}
// rep(i,N)
// 	putv(graph[i]);
	return graph;
}

#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
using namespace std;

int main(){
	int W,H,N;
	cin >> W >> H >> N;
	int  rect[W][H] = {};
// rep(i,W){
// 	rep(j,H)
// 		cout << rect[i][j] << " ";
// 	cout << endl;
// }
	int x,y,a;
	rep(i,N){
		cin >> x >> y >> a;
		if(a==1)
			for(int i=0; i<x; ++i)
				for(int j=0; j<H; ++j)
					rect[i][j] = -1;
		else if(a==2)
			for(int i=x; i<W; ++i)
				for(int j=0; j<H; ++j)
					rect[i][j] = -1;
		else if(a==3)
			for(int i=0; i<W; ++i)
				for(int j=0; j<y; ++j)
					rect[i][j] = -1;
		else if(a==4)
			for(int i=0; i<W; ++i)
				for(int j=y; j<H; ++j)
					rect[i][j] = -1;
		else cout << "unexpected value a" << endl;
	}
// cout << endl;
// rep(i,W){
// 	rep(j,H)
// 		cout << rect[i][j] << " ";
// 	cout << endl;
// }
	int ans = 0;
	rep(i,W)
		rep(j,H)
			ans += rect[i][j]+1;
	cout << ans << endl;
}

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

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    long long int n,i,j,k;
    cin>>n;
    long long int a[n][3],dp[n][3];
    for(i=0;i<n;i++)
        for(j=0;j<3;j++)
            cin>>a[i][j];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(i=1;i<n;i++)
    {
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


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

int main(){
   int a,b,c;
   cin >> a >> b >> c;
   if(a < b && b < c){
      cout << "Yes" << endl;
   }
   if(a > b && b > c ){
      cout << "No" << endl;
   }
   if(a > b && b < c ){
      cout << "No" << endl;
   }
   if(a < b && b > c ){
      cout << "No" << endl;
   }
   if(a == b && b == c ){
      cout << "No" << endl;
   }
   if(a == b && b > c ){
      cout << "No" << endl;
   }
   if(a == b && b < c ){
      cout << "No" << endl;
   }
   if(a < b && b == c ){
      cout << "No" << endl;
   }
   if(a > b && b == c ){
      cout << "No" << endl;
   }
   return 0;
}

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

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

    int count = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'o'){
            count++;
        }
    }

    if(s.size()==15){
        if(count >= 8){
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
    }
    else if(s.size() < 15){
        if(15-s.size()+count >= 8){
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>

int main(){
   int N;
   std::cin >> N;
   int B[N];
   for(int i=0; i<N-1; ++i)
      std::cin >> B[i];
   B[N-1] = 100000;

   long long ans = B[0];
   for(int i=0; i<N-1; ++i){
      ans += std::min(B[i],B[i+1]);
   }
   std::cout << ans << std::endl;
   return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

int n,k;
vector<int> inten;
vector<int> updater;
vector<int> deleter;

int main() 
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {  
        int tmp;
        cin >> tmp;
        inten.push_back(tmp);
        updater.push_back(0);
        deleter.push_back(0);
    }

    for (int i = 0; i < k; i++) 
    {
        bool update = false;
        for (int i = 0; i < n; i++) 
        {
            int d = inten[i];
            int l_idx = (i - d) >= 0 ? i - d : 0;
            int r_idx = (i + d) < n ? i + d : n-1;
            updater[l_idx]++;
            deleter[r_idx]++;
        }

        int update_val = 0;

        for (int i = 0; i < n; i++)
        {
            update_val += updater[i];
            if (update_val != inten[i]) update = true;
            inten[i] = update_val;
            update_val -= deleter[i];
            updater[i] = 0; deleter[i] = 0;
        }

        if (!update) break;
    }

    for(int i = 0; i < n; i++) 
    {
        if(i == n-1) cout << inten[i];
        else cout << inten[i] << " ";
    }

    return 0;
}


Measured memory_bytes: 5848
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int a,b,c;
    cin >> a >> b >> c;
    //処理
    //出力
  	if(a<=c && c<=b) cout << "Yes" << ENT;
  	else cout << "No" << ENT;
    return 0;
}

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


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

int main() {
    int bingo[3][3];

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> bingo[i][j];
        }
    }

    int N;
    cin >> N;

    for (int i = 0; i < N; ++i) {
        int b;
        cin >> b;

        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (bingo[j][k] == b)
                    bingo[j][k] = -1;
            }
        }
    }

    bool ok = false;

    for (int i = 0; i < 3; ++i) {
        bool fail = false;

        for (int j = 0; j < 3; ++j) {
            if (bingo[i][j] != -1) fail = true;
        }

        if (!fail) ok = true;
    }

    for (int i = 0; i < 3; ++i) {
        bool fail = false;

        for (int j = 0; j < 3; ++j) {
            if (bingo[j][i] != -1) fail = true;
        }

        if (!fail) ok = true;
    }
    
    {
        bool fail = false;
        for (int i = 0; i < 3; ++i) {
            if (bingo[i][i] != -1) fail = true;
        }
        if (!fail) ok = true;
    }
    
    {
        bool fail = false;
        for (int i = 0; i < 3; ++i) {
            if (bingo[2 - i][i] != -1) fail = true;
        }
        if (!fail) ok = true;
    }

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
typedef pair<int,int> P;
int n,w;
int a[114],b[114];
int dp[114][114514];//[どこまで見たか][価値]=重さの最小値;
signed main(){
	cin>>n>>w;
	rep(i,n)cin>>a[i]>>b[i];
	
	rep(i,n){
		rep(j,114514){
			dp[i][j]=1000000001;
		}
	}
	dp[0][b[0]]=a[0];
	dp[0][0]=0;
	for(int i=1;i<n;i++){
		for(int j=0;j<=100000;j++){
			dp[i][j]=min(dp[i-1][j],dp[i][j]);
			dp[i][j+b[i]]=min(dp[i][j+b[i]],dp[i-1][j]+a[i]);
		}
	}
	for(int j=114513;j>=0;j--){
		if(dp[n-1][j]<=w){
			cout<<j<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 90368
import itertools
def main():
    N = int(input())
    xyz = itertools.product(range(1, 101), repeat=3)

    ans = [0] * (N + 1)
    for (x, y, z) in xyz:
        # print(x, y, z)
        f = x*x + y*y + z*z + x*y + y*z + z*x
        if f <= N:
            ans[f] += 1

    ans = ans[1:]
    print(*ans, sep='\n')

if __name__ == '__main__':
    main()

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

#define all(a)  (a).begin(),(a).end()
#define MOD 1000000007;

typedef long long ll;

int main(){
    ll ans=0,sum=0;
    int n,count=0;
    string s,t;

    map<char,int> ms;
    map<char,vector<int>> msi;
    map<char,int> mt;
    cin >>s>>t;

    int slen=(int)s.length();
    int tlen=(int)t.length();
    for (int i = 0; i < slen; i++){
        ms[s[i]]++;
        msi[s[i]].push_back(i+1);
    }

    for (int i = 0; i < tlen; i++){
        mt[t[i]]++;
    }
    
    for(auto p : mt){
        if(ms[p.first] < 1){
            cout << "-1" << '\n';
            return 0;
        }
    }

    int ansinner=ans%slen;

    for (int i = 0; i < tlen; i++){

        int num=msi[t[i]].size();
        int j = (upper_bound(all(msi[t[i]]),ansinner))-(msi[t[i]].begin());

        if(j >= num){
            count++;
            ansinner=msi[t[i]][0];
        }else{
            ansinner=msi[t[i]][j];
        }

        ans = (ll)(ansinner + (ll)slen*count);
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n;
    cin>>n;
    vector <ll> a(n);
    vector <ll> dp(n, INT_MAX);
    for(auto &it : a){
        cin>>it;
    }
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j <= i + 2; j++){
            if(j < n){
                dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
            }
        }
    }
    cout<<dp[n - 1]<<endl;
    return 0;
}


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

map<char,string> e;
map<string,char> d;

void init(){
	e[' ']="101";
	e['\'']="000000";
	e[',']="000011";
	e['-']="10010001";
	e['.']="010001";
	e['?']="000001";
	e['A']="100101";
	e['B']="10011010";
	e['C']="0101";
	e['D']="0001";
	e['E']="110";
	e['F']="01001";
	e['G']="10011011";
	e['H']="010000";
	e['I']="0111";
	e['J']="10011000";
	e['K']="0110";
	e['L']="00100";
	e['M']="10011001";
	e['N']="10011110";
	e['O']="00101";
	e['P']="111";
	e['Q']="10011111";
	e['R']="1000";
	e['S']="00110";
	e['T']="00111";
	e['U']="10011100";
	e['V']="10011101";
	e['W']="000010";
	e['X']="10010010";
	e['Y']="10010011";
	e['Z']="10010000";
	d["00000"]='A';
	d["00001"]='B';
	d["00010"]='C';
	d["00011"]='D';
	d["00100"]='E';
	d["00101"]='F';
	d["00110"]='G';
	d["00111"]='H';
	d["01000"]='I';
	d["01001"]='J';
	d["01010"]='K';
	d["01011"]='L';
	d["01100"]='M';
	d["01101"]='N';
	d["01110"]='O';
	d["01111"]='P';
	d["10000"]='Q';
	d["10001"]='R';
	d["10010"]='S';
	d["10011"]='T';
	d["10100"]='U';
	d["10101"]='V';
	d["10110"]='W';
	d["10111"]='X';
	d["11000"]='Y';
	d["11001"]='Z';
	d["11010"]=' ';
	d["11011"]='.';
	d["11100"]=',';
	d["11101"]='-';
	d["11110"]='\'';
	d["11111"]='?';
}

int main(void){
	string s;
	init();
	while(1){
		getline(cin,s);
		if(cin.eof())break;
		string encode="";
		rep(i,s.size()) encode+=e[s[i]];
		string decode="";
		for(int i=0;i<encode.size();i+=5){
			string tmp=encode.substr(i,5);
			while(tmp.size()<5) tmp+="0";
			decode+=d[tmp];
		}
		//cout << encode << endl;
		cout << decode << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int x;
	cin >> x;
	if (x == 3 || x == 5 || x == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,j;
   long long int N,K;
    scanf("%lld%lld",&N,&K);
    long long int a[N-1];
    for(i=0; i<N; i++)
    {
        scanf("%lld",&a[i]);
    }

    int temp,sum=0;
    for(i=0; i<N; i++)
    {
        for(j=i+1; j<N; j++)
        {
            if(a[i]>a[j])
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    for(i=0; i<K; i=i+1)
    {
        sum=sum+a[i];
    }
    printf("%d\n",sum);



    return 0;
}


Measured memory_bytes: 1704
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <stdio.h>
#include <deque>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define REV(v) for (auto itr = v.rbegin(); itr != v.rend(); itr++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a));
#define MINUS(a) memset(a,-1,sizeof(a));
#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 pi pair<int, int>
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define VL(v,n) vector<ll> v(n);
#define Read_VL(v,n) vector<ll> v(n);REP(i,0,n)cin>>v[i];
#define sumV(v,n) Vl(acm,n) REP(i,0,n) acm[i] = v[i] + ( i == 0 ? 0 : acm[i - 1]);
#define EPS (1e-10)
#define INF 1000000000000LL

void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}


template<class T=ll>struct Graph{
	int n;
	vector<vector<tuple<ll,T>>>edge;
	Graph(int N=1):n(N){edge.resize(n);}
	void add(ll f,ll t,T c,bool d=false){
		edge[f].emplace_back(t,c);
		if(!d)edge[t].emplace_back(f,c);
	}
	void view(){
		REP(i,0,n)for(auto&e:edge[i])
			puta(i,"=>",get<0>(e),", cost :",get<1>(e));
	}
};


bool length_cmp( string &a, string &b ){
  return a.size() < b.size();
}

ll StoLL( string s )
{
	ll num=0;
  REP( i, 0, s.size() ){
    num = num * 10 + ( s[i] ^ 48 );
  }
  return num;
}

ll CtoLL( char c )
{
	if( 'a' <= c && c <= 'z'){
		return (ll)( c ^ 96 ) ;
	}
	else if( 'A' <= c && c <= 'Z'){
		return (ll)( c ^ 64 );
	}
  return 0;
}


ll mod=1000000007;
ll dx[4] = { 1, 0, -1, 0 };
ll dy[4] = { 0, 1, 0, -1 };
//I ASCII code: '0' = 48; 'A' = 65; 'a' = 97


struct person{
	string name;
	ll height;
};

bool p_operator( person &a, person &b ){
	return a.name < b.name;
}

#include <chrono>
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);


		set< char > a[256],b[256];
		SIN(s) SIN(t)
		REP( i, 0, s.size() ){
			a[ s[i] ].insert( t[i] );
			b[ t[i] ].insert( s[i] );
		}

		//
		REP( i, 0, 256 ){
			if( a[i].size() > 1 ){
				puta( "No\n");
				return 0;
			}
			if( b[i].size() > 1 ){
				puta( "No\n");
				return 0;
			}
		}
		puta( "Yes\n" );
    return 0;
}


Measured memory_bytes: 916
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define pb push_back
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-8;
const ll MOD = 1e9+7;
const int MAXN = 1e5+5;

int main()
{
    int n, k, t = 0;
    cin >> n >> k;
    while (n){
            t++;
        n /= k;
    }
    cout << t << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
flg = False

if n%4 == 0:
    flg = True
elif n%7 ==0:
    flg = True
else:
    for i in range(0,n//7 + 1):
        if (n - 7*i)%4 == 0:
            flg = True
            break

print('Yes' if flg else 'No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int res = a*x + b*y;
    rep1(i, max(x, y)+1){
        int ab = i*2;
        int cand = c*ab + a*max(0, x-i) + b*max(0, y-i);

        res = min(res, cand);
    }

    cout << res << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define REP(i, n) for(int i=0; i<n; i++)
#define RER(i, n) for(int i=n-1; i>=0; i--)
#define ALL(v) v.begin() v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
bool dp[101];

signed main(){
	cin >> n;
	dp[0] = true;
	for (int i = 1; i < 101; ++i){
		dp[i] = false;
		if(i >= 4) dp[i] |= dp[i-4];
		if(i >= 7) dp[i] |= dp[i-7];
	}
	if(dp[n]) cout << "Yes" << endl;
	else cout << "No" << endl;
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long double A;
    long double B;
    cin>>A>>B;
    long double ans=A*B;
    long long int rounded_ans=trunc(ans);
    cout<<rounded_ans<<"\n";
	return 0;
}

Measured memory_bytes: 3736
line = gets.split(' ').map(&:to_i)
a=line[1]
b=line[2]
if ((a-b).abs)%2==0 then
  p ((a-b).abs)/2
elsif ((a-b).abs)%2!=0 then
  if (a-b).abs==1 then
    p [[a,b].max-1,line[0]-[a,b].min].min
  else
    p [[a,b].min-1,line[0]-[a,b].max].min+(((a-b).abs)/2)+1
  end
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
	if(b==0) return a;
	else return gcd(b,a%b);
}
ll lm(ll a,ll b)
{
	return a*b/gcd(a,b);
}
int main()
{
	ll a,b;
	cin>>a>>b;
	cout<<lm(a,b)<<endl;
	return 0;
}

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

int main()
{
	int N;
	cin >> N;
	vector<int> a( N );
	for( int i = 0; i < N; i++ )  {
		cin >> a[i];
	}

	int ans = 0;
	int n = 1;
	for( int i = 0; i < N; i++ ) {
		if( a[i] != n ) ans++;
		else n++;
	}

	if( ans >= N ) ans = -1;
	cout << ans << endl;
}


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

#define all(x) (x).begin(),(x).end()
#define ll long long
#define ld long double
#define pb push_back
#define FR first
#define SC second
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector< vl >
#define vb vector<bool>
#define vbb vector< vb >
#define vpl vector<pll>
#define vpll vector< vpl >

void solve()
{
	ll n, m ,k;
	cin>>n;
	vl a(n), factor(MAX, 0);
	for(ll i = 0; i < n; i++){
	    cin>>a[i];
	    factor[a[i]]++;
	}
	ll gcd = a[0];
	for(ll i = 1; i < n; i++)
	    gcd = __gcd(gcd, a[i]);
	if(gcd != 1)
	{
	    cout<<"not coprime";
	    return;
    }
    bool set_coprime = false;
    for(ll i = 2; i < MAX; i++)
    {
        ll count = 0;
        for(ll j = i; j <= MAX; j += i)
        {
            if(factor[j] != 0)
                count++;
        }
        if(count > 1)
        {
            //cout<<i<<" "<<count<<"\n";
            set_coprime = true;
            break;
        }
    }
    if(set_coprime)
        cout<<"setwise coprime";
    else
        cout<<"pairwise coprime";
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t = 1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


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

int main(){
    string s;
    cin>>s;
    int sz = s.size();
    int ans=0;
    for(int i=0; i<sz; i++){
        int cnt=0;
        for(int j=i; j<sz; j++){
            if(s[j]=='A'||s[j]=='C'||s[j]=='G'||s[j]=='T')cnt++;
            else break;
        }
        ans=max(ans,cnt);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
/// Find the maximum product of subsequences  of size k
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
using namespace std;
int main()
{
    ll i,j,k,n,s=0;
    cin>>n;
    cin>>k;
    ll K=k;
    vector<ll>neg,pos,zero;
    vector<pair<ll,ll> >vec;
    ll arr[n];
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
        if(arr[i]>0)
        {
            pos.pb(arr[i]);
            s=1;
        }
        else if(arr[i]<0)
        {
            neg.pb(abs(arr[i]));
            s=-1;
        }
        else
        {
            zero.pb(arr[i]);
            s=1;
        }
        vec.pb(make_pair(abs(arr[i]),s));
    }
    ll idp=pos.size()-1;
    ll idn=neg.size()-1;
    sort(pos.begin(),pos.end());
    sort(neg.begin(),neg.end());
    sort(vec.begin(),vec.end());
    ll ans=1;
    if(k%2)
    {
        if(pos.size()>0)
        {
            ans=((ans*pos[idp])%mod+mod)%mod;
            idp--;
            k--;
        }
    }
    /// as k is even so k will be zero if enough positive or negative pair is present here
    while(k&& (idp>0||idn>0))
    {
        ll a=-inf;
        ll b=-inf;
        if(idp>=1)
            a=pos[idp]*pos[idp-1];
        if(idn>=1)
            b=neg[idn]*neg[idn-1];
        if(a>b)
        {
            ans=((a+mod)%mod*(ans+mod)%mod)%mod;
            idp=idp-2;
            k=k-2;
        }
        else
        {
            ans=((b+mod)%mod*(ans+mod)%mod)%mod;
            idn=idn-2;
            k=k-2;
        }
    }
    if(k)
    {
        if(zero.size())
            ans=0;
        else
        {
            ans=1;
            for(i=0; i<K; i++)
                ans=((ans%mod*((vec[i].first*vec[i].second)%mod))%mod+mod)%mod;
        }
    }
    cout<<ans;
return 0;

}


Measured memory_bytes: 10976
n = int(input())
A = list(map(int, input().split()))

ai = max(A)
A.remove(ai)

aj = A[0]
delta_j = abs(ai/2 - aj)

for a in A:
    delta = abs(ai/2 - a)
    if delta < delta_j:
        aj = a
        delta_j = delta

print(ai, aj)

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

int g[15][15];//正直者かどうか

int main(){
  int n;
  cin >> n;
  rep(i,n) rep(j,n) g[i][j] = -1;//何も証言していない：－１
  rep(i,n){
    int m;
    cin >> m;//証言の個数
    rep(j,m){
      int a,x;
      cin >> a >> x;
      --a;//0-origin
      g[i][a] = x;
    }
  }

  int ans = 0;
  //solve
  rep(i,1 << n) { //
    vector<int> d(n);
    rep(j,n) if(i>>j&1) {
      d[j] = 1;//嘘つきと正直者の割り当て
    }
    bool ok = true;
    rep(j,n){
      if(d[j]) {
        rep(k,n){
          //証言のチェック
          if(g[j][k] == -1) continue;
          if(g[j][k] != d[k]) ok = false;
        }
      }
    }
    if(ok) ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int W,H,x,y,R;
    cin >> W >> H >> x >> y >> R;
    
    int l,r,t,b;
    l = x - R;
    r = x + R;
    b = y - R;
    t = y + R;

    
    if(l < 0) {
        cout << "No" << endl;
        return 0;
    }
    
    if(r > W) {
        cout << "No" << endl;
        return 0;
    }
    
    if(b < 0) {
        cout << "No" << endl;
        return 0;
    }
    
    if( t > H) {
        cout << "No" << endl;
        return 0;
    }
    
    cout << "Yes" << endl;
    

}


Measured memory_bytes: 3116
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int N,M,K; cin >> N >> M >> K;
    rep(i,N+1)rep(j,M+1){
        int d = i*M-i*j+(N-i)*j;
        if(d == K){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}



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

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

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
ab = []
cd = []
for _ in range(N):
    ab.append([int(x) for x in input().split()])
for _ in range(N):
    cd.append([int(x) for x in input().split()])
ab_x = sorted(ab, reverse=True, key=lambda x:x[0])
ab_y = sorted(ab, reverse=True, key=lambda x:x[1])
cd_x = sorted(cd, key=lambda x:x[0])
cd_y = sorted(cd, key=lambda x:x[1])
ans = 0
for i in ab_x:
    for j in cd_x:
        if i[0] < j[0] and i[1] < j[1]:
            ans += 1
            cd_x.remove(j)
            break
cnt = 0
for i in ab_y:
    for j in cd_y:
        if i[0] < j[0] and i[1] < j[1]:
            cnt += 1
            cd_y.remove(j)
            break
temp = max(ans, cnt)
ab_x = sorted(ab, reverse=True, key=lambda x:x[0])
ab_y = sorted(ab, reverse=True, key=lambda x:x[1])
cd_x = sorted(cd, key=lambda x:x[0])
cd_y = sorted(cd, key=lambda x:x[1])
ans = 0
for i in ab_x:
    for j in cd_y:
        if i[0] < j[0] and i[1] < j[1]:
            ans += 1
            cd_y.remove(j)
            break
cnt = 0
for i in ab_y:
    for j in cd_x:
        if i[0] < j[0] and i[1] < j[1]:
            cnt += 1
            cd_x.remove(j)
            break
print(max(temp, ans, cnt))



Measured memory_bytes: 41180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  if(n<1000) cout << "ABC" << endl;
  else cout << "ABD" << endl;
  return 0;
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  vi c(n,0);
  c[0] = 3;
  mint ans = 1;
  rep(i,n){
    if(c[a[i]] == 0){
      cout<<"0"<<endl;
      return 0;
    }
    ans*=c[a[i]];
    c[a[i]]--;
    c[a[i]+1]++;
  }
  cout<<ans.x<<endl;
  return 0; 
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <ctime>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int N = 2010;
const int mod = 1e9 + 7;
int f[2][N * 2][2], s[2][N * 2];

int main()
{
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	f[0][0][0] = 1;
	Rep0(i, n) s[0][i] = 1;
	LL ans = 0;
	Rep(i, max(n, m) * 2) {
		Rep0(j, n){
			f[i & 1][j][0] = (f[(i - 1) & 1][j][0] + f[(i - 1) & 1][j][1]) % mod;
			if (j){
				if (j - k >= 0) f[i & 1][j][1] = (s[(i - 1) & 1][j - 1] - s[(i - 1) & 1][j - k] + mod) % mod;
				else f[i & 1][j][1] = s[(i - 1) & 1][j - 1];
			}
			s[i & 1][j] = (f[i & 1][j][0] + f[i & 1][j][1]) % mod;
			if (j) s[i & 1][j] = (s[i & 1][j] + s[i & 1][j - 1]) % mod;
		}
		Rep(j, n) if (j % (k - 1) == n % (k - 1) && ((k - 1) * i - j + 1) <= m && ((k - 1) * i - j + 1) % (k - 1) == m % (k - 1)){
			ans = (ans + f[i & 1][j][1]) % mod;}
	}
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

template <typename T>
T pow(T a, ll n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= a; 
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <ll mod>
class ModInt {
private:
    ll num;
public:
    ModInt() {};
    ModInt(ll n) { num = n % mod; }
    ModInt inv() const { return pow(*this, mod-2); }
    explicit operator ll() const { return num; }

    ModInt& operator+=(const ModInt& a) {
        num += a.num; 
        if (num >= mod) num -= mod; 
        return *this;
    }
    ModInt& operator-=(const ModInt& a) {
        if (num < a.num) num += mod;
        num -= a.num;
        return *this;
    }
    ModInt& operator*=(const ModInt& a) {
        num = num * a.num % mod;
        return *this;
    }
    ModInt& operator/=(const ModInt& a) { return *this *= a.inv(); }
    friend ModInt operator+(const ModInt& a, const ModInt& b) { return ModInt(a) += b; }
    friend ModInt operator-(const ModInt& a, const ModInt& b) { return ModInt(a) -= b; }
    friend ModInt operator*(const ModInt& a, const ModInt& b) { return ModInt(a) *= b; }
    friend ModInt operator/(const ModInt& a, const ModInt& b) { return ModInt(a) /= b; }

    friend ostream& operator<<(ostream& os, const ModInt& a) { return os << a.num; }
    friend istream& operator>>(istream& is, ModInt& a) {
        ll tmp;
        is >> tmp;
        a.num = tmp % mod;
        return is;
    }
};
using mint = ModInt<998244353>;

mint dp[301][90001];
mint dp2[301][90001];

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e: a) cin >> e;
    ll sum = accumulate(a.begin(), a.end(), 0LL);

    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= sum; ++j) {
            dp[i+1][j+a[i]] += dp[i][j];
            dp[i+1][j] += dp[i][j] * 2;
        }
    }

    mint ans = pow<mint>(3, n) - 3 * accumulate(dp[n] + (sum+1)/2, dp[n] + sum+1, (mint)0);
    if (sum % 2 == 0) {
        dp2[0][0] = 1;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j <= sum; ++j) {
                dp2[i+1][j+a[i]] += dp2[i][j];
                dp2[i+1][j] += dp2[i][j];
            }
        }
        ans += dp2[n][sum/2] * 3;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 422784
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i = (a) ; i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i!= (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end)

#define pb push_back
#define mp makek_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

const int N = 1<<20;

bool c[N] = {};
int sp[N] = {};
int lp[N] = {};

void gen()
{
    for (int i = 2; i < N; ++i) {
	if (!c[i]) {
	    for (int j = i; j < N; j += i) {
		c[j] = true;
		sp[j] += i;
		lp[j] = max(lp[j], i);
	    }
	}
    }
}

int key(int n)
{
    return 2 * lp[n] - sp[n];
}

int main()
{
    gen();

    int a, b;
    while (cin >> a >> b && a)
	cout << (key(a) > key(b) ? "a" : "b") << endl;

    return 0;
}

Measured memory_bytes: 10368
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        for(int i=0;i<n;i++){
            p[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int res = 0;
        for(int i=1;i<n-1;i++){
            if((p[i] > p[i-1] && p[i] < p[i+1]) || (p[i] > p[i+1] && p[i] < p[i-1])){
                res++;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 22100
def m():
 e=input
 a=''
 for _ in[0]*int(e()):
  X,z=e(),[]
  for y in e():
   s=i=0
   for k in z:
    t=X.find(y,s)+1
    if t<1:break
    if t<k:z[i]=t
    s=k;i+=1
   else:
    t=X.find(y,s)+1
    if t:z+=[t]
  a+=f'\n{len(z)}'
 print(a[1:])
if'__main__'==__name__:m()


Measured memory_bytes: 5624
while 1 do
  n = gets().to_i
  if n!=0 then
    a=0
    b=0
    n.times{
      log = gets().chomp.split(" ").map(&:to_i)
      if log[0]==log[1] then
        a+=log[0]
        b+=log[1]
      elsif log[0]>log[1] then
        a+=log[0]+log[1]
      else
        b+=log[0]+log[1]
      end
    }
    puts "#{a} #{b}"
  else
    break
  end
end

Measured memory_bytes: 8808
#include<bits/stdc++.h>
#define INF 2000000000
#define int long long int
#define MOD 1000000007
#define pb push_back
#define cin1(n) (cin >> n)
#define cin2(a,b) (cin >> a >> b)
#define cin3(a,b,c) (cin >> a >> b >> c)
#define cout(n) (cout << n << endl)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define fr first 
#define sc second 
#define EPS (1e-10)

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<string> vs;
typedef vector<vector<string>> vss;
typedef pair<int,int> pii;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int a,b;
int p,q;


int dfs(int P, int Q,int t,int N) {
		if (p*Q == q*P) return 1;
		if (N == n) return 0;
		if (p*Q < q*P) return 0;

		int ret = 0;

		for (int i = t; i*Q <= a; i++) {
			ret += dfs(P*i+Q,i*Q,i,N+1);
		}

		return ret;	
}

signed main() {
	while(cin >> p >> q >> a >> n) {
		if (p+q+a+n == 0) break;
		cout << dfs(0,1,1,0) << endl;
	}


	return 0;
}

Measured memory_bytes: 3052
#include <iostream>
#include <vector>
#include <memory.h>
using namespace std;

vector<int>adj[200001];
int counter[200001];
bool isVisit[200001];

void DFS(int u, int counterSum)
{
	isVisit[u] = true;
	for (int v : adj[u])
	{
		if (isVisit[v] == false)
			DFS(v, counterSum + counter[u]);
	}
	counter[u] += counterSum;
}


int main()
{
	memset(isVisit, false, sizeof(isVisit));
	int n, m;
	cin >> n >> m;

	for (int i = 0; i < n-1; i++)
	{
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	for (int i = 0; i < m; i++)
	{
		int u, c;
		scanf("%d %d", &u, &c);
		counter[u] += c;
	}

	DFS(1, 0);
	for (int i = 1; i <= n; i++)
	{
		printf("%d ", counter[i]);
	}
}

Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long  x, a=0, b=0;
  bool flag=0;
  cin >> x;
  for(long long i=-1000;i<1000;i++){
    for(long long j=-1000;j<1000;j++){
      if(i*i*i*i*i-j*j*j*j*j==x){
        a=i;
        b=j;
        flag=1;
        break;
      }
      if(flag){
        break;
      }
    }
  }
  
  cout << a<<" " <<b<<endl;
}


Measured memory_bytes: 3628