akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<bool>> check(M+1, vector<bool>(N+1, false));
  for(int i=1; i<=M; i++){
    int k;
    cin >> k;
    for(int j=1; j<=k; j++){
      int l;
      cin >> l;
      check[i][l]=true;
    }
  }
  //p
  vector<int> P(M+1, 0);
  for(int i=1; i<=M; i++){
    int p;
    cin >> p;
    P[i]=p;
  }
  
  int ans=0;
  for(int i=0; i<(1<<N); i++){
    bool finish=false;
    int k=i;
    vector<int> temp(N+1, 0);
    for(int j=1; j<=N; j++){
      if(1 & k>>j-1) temp[j]=1;
    }
    for(int x=1; x<=M; x++){
      int count=0;
      for(int y=1; y<=N; y++){
        if(check[x][y]==true && temp[y]==1) count++;
      }
      if(count%2 != P[x]) {
        finish=true;
        break;
      }
    }
    if(finish) continue;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n=(input())
#n='765'
n2=int(n[-1])
#print(n2)

pr='bon'
if n2==3:
    pr='bon'
elif n2==2 or n2==4 or n2==5 or n2==7 or n2==9:
    pr='hon'
else:
    pr='pon'
print(pr)

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

int main() {
  int n, a, b, c, d, flag = 0;
  string s;

  cin >> n >> a >> b >> c >> d >> s;
  a--;
  b--;
  c--;
  d--;

  for (int i = a + 2; i < d; i++) {
    if (s[i] == '#' && s[i - 1] == '#') {
      cout << "No";
      return 0;
    }
  }

  if (c > d) {
    for (int i = b - 1; i < d && i + 2 < n; i++)
      if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') flag = 1;
  } else {
    flag = 1;
  }

  if (flag) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>

using namespace std;

int m, n;
int main(){
    cin >> m >> n;
    int a[m + 2][n + 2];
    memset(a,0,sizeof(a));
    for(int i = 1; i <= m; ++i){
        int sum = 0;
        for(int j = 1; j <= n; ++j){
            cin >> a[i][j];
            sum += a[i][j];
            a[m + 1][j] += a[i][j];
        }
        a[i][n + 1] = sum;
        a[m + 1][n + 1] += sum;
    }
    for(int i = 1; i <= m + 1; ++i){
        for(int j = 1; j <= n; ++j){
            cout << a[i][j] << " ";
        }
        cout << a[i][n + 1] << endl;
    }
}


Measured memory_bytes: 3144
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
				Scanner s = new Scanner(System.in);
		String A = s.next();
		
		String AA = A.toUpperCase();
		
		if(AA.equals(A)) {
			System.out.println('A');
		}else {
			System.out.println('a');
		}
	}
}

Measured memory_bytes: 35744
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define ff          first
#define ss          second
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          1000000007
#define pi          acos(-1.0)

ll a[200010], b[200], c[200];
map<ll,ll>m;
vector<ll>v;
string s,q;

int main()
{
   ll t,n,i,j,k,l,mn=0, mx=0, f=0;
   sl(t);
   loop(t)
   {
       sl2(b[i], c[i]);
   }

   loop(t)
   {
       if(b[i]==c[i])
        f++;
       else f=0;
       if(f>=3)
       {
           cout<<"Yes"<<endl;
           return 0;
       }
   }

   cout<<"No";

}



Measured memory_bytes: 3684
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MAX_N 5001
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int a, b;
int n;

int main(){
	while (cin >> a >> b >> n){
		int ans = 0;
		int num = a%b * 10;
		REP(i, n){
			ans += num / b;
			num = num%b * 10;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
from operator import itemgetter
import heapq
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key = itemgetter(0))
q = []
idx = 0
ans = 0
for i in range(1, m+1):
    while idx < n:
        a, b = ab[idx]
        if a <= i:
            heapq.heappush(q, -b)
            idx += 1
        else:
            break
    if len(q) > 0:
        b = heapq.heappop(q)
        ans -= b
print(ans)


Measured memory_bytes: 31912
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    int S;      //4桁の整数abcd
    cin >> S;

    int ab = S / 100;
    int cd = S % 100;  
 
    if(1 <= ab && ab <= 12) {
        if(1 <= cd && cd <= 12) {
            cout << "AMBIGUOUS";
        }
        else {
            cout << "MMYY";
        }
    }
    else {
        if(1 <= cd && cd <= 12) {
            cout << "YYMM";
        }
        else {
            cout << "NA";
        }
    }
    
    cout << endl;
    return 0;
}

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

int64_t ans = 0;
string A;
void divide(int64_t n,int64_t k,int64_t m){
    if (n < A.size()){
        divide(n+1,0,m + 10*k + (A[n-1]-'0'));
        divide(n+1,10*k + (A[n-1]-'0'),m);
    }
    else {
      ans += m + 10 * k  + (A[n-1]-'0');
    }
}

int main(){
    cin >> A;    
    divide(1,0,0);
    cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

void main()
{
    auto S = readln.chomp.to!(wchar[]);
    auto w = readln.chomp.to!size_t;
    size_t i;
    while (i < S.length) {
        write(S[i]);
        i += w;
    }
    writeln("");
}

Measured memory_bytes: 256
class Maximum
  def initialize
    @result = []

    while(@n = $stdin.gets.chomp.to_i)
      @max = -1000000
      if @n != 0
        calc  
      else 
        break
      end
    end
    render
  end

  def calc
    sum = 0
    @n.times do 
      val = $stdin.gets.chomp.to_i
      if val < 0
        sum += val
        if @max < sum
          @max = sum
        end
        if sum <= 0
          sum = 0
        end
      else
        sum += val
        if @max < sum
          @max = sum
        end
      end
    end
    @result.push(@max)
  end

  def render
    @result.each do |val|
      puts val
    end
  end
end

m = Maximum.new

Measured memory_bytes: 2820
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a,a+n);
    double sum =a[0];
    for(int i=1;i<n;i++){
        sum=(sum+a[i])/2;
    }
    cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

const int N_MAX = 100;

int main(){
    int N;
    int A[N_MAX];

    cin >> N;

    int max_n = 0;
    int min_n = 2000000000;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        max_n = max(A[i], max_n);
        min_n = min(A[i], min_n);
    }

    cout << max_n - min_n << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
int mod;
inline int add(int a,int b,int mod=mod){a+=b;return a>=mod?a-mod:a;}
inline int sub(int a,int b,int mod=mod){a-=b;return a<0?a+mod:a;}
inline int mul(int a,int b,int mod=mod){return (ll)a*b%mod;}
inline int qpow(int a,int b,int mod=mod){int ret=1;for(;b;b>>=1,a=mul(a,a,mod))if(b&1)ret=mul(ret,a,mod);return ret;}
/* math */
int n;
const int N = 310;
int l[N*2], r[N*2];
pii a[N*3];
int dp[N*2][N*2];

int main()
{
	cin >> n >> mod;
	for(int i=0;i<n<<1;i++){
		r[i]=min(2*n-1,(int)floor(sqrt(4*n*n-i*i)));
		if(i<n)l[i]=ceil(sqrt(n*n-i*i)),a[i]=pii(l[i]-1,-i);
		else a[i]=pii(r[i],-i);
	}
	sort(a,a+n*2);for(int i=0;i<n<<1;i++)a[i].second=-a[i].second;
	int ans=0;
	for(int cnt,k=0;k<=n;++k){
		memset(dp,0,sizeof(dp));cnt=0,dp[0][0]=1;
		for(int i=0;i<n<<1;i++){
			if(a[i].second<n)cnt++;
			for(int j=0,M=min(k,cnt);j<=M;j++){
				if(a[i].second<n){
					dp[i+1][j]=add(dp[i+1][j], mul(dp[i][j], r[a[i].second]+1-(2*n-1-a[i].second+k-j)));
					if(j)dp[i+1][j]=add(dp[i+1][j], mul(dp[i][j-1], a[i].first+1-((i-(cnt-j)))));
				}else{
					dp[i+1][j]=mul(dp[i][j], a[i].first+1-(i-(cnt-j)));
				}
			}
		}
		if(k&1)ans=sub(ans, dp[n*2][k]);
		else ans=add(ans, dp[n*2][k]);
	}
	cout << ans << endl;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n), b(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    b.at(a.at(i)) = i;
  }
  
  set<ll> s;
  s.insert(-1);
  s.insert(n);
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    auto it = s.lower_bound(b.at(i));
    it--;
    ans += i * (*s.upper_bound(b.at(i)) - b.at(i)) * (b.at(i) - *it);
    s.insert(b.at(i));
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    long long int happy = 0;
    FOR(i,1,n){
        if(s[i]==s[i-1]){
            happy++;
        }
    }
    cout << min(n - 1, happy + 2 * k) << endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

struct Card
{
	int value;
	char mark;
};

void BubbleSort(Card a[],int n)
{
	bool flag = true;
	for(int i = 0;flag;i++){
		flag = false;
		for(int j = n-1;j > i;j--){
			if(a[j].value < a[j-1].value){
				Card c = a[j];
				a[j] = a[j-1];
				a[j-1] = c;
				flag = true;
			}
		}
	}
}

void SelectionSort(Card a[],int n){
	int minj;
	for(int i = 0;i<n;i++){
		minj = i;
		for(int j=i;j<n;j++){
			if(a[minj].value>a[j].value)
				minj = j;
		}
		if(minj != i){
			Card c = a[i];
			a[i] = a[minj];
			a[minj] = c;
		}
	}
}

void Show(Card a[],int n){
	for(int i = 0;i<n;i++){
		if(i>0) cout << ' ';
		cout << a[i].mark << a[i].value ;
	}
	cout << endl;
}

int main(){
	int n;
	Card c1[100],c2[100];
	bool isStable = true;
	
	cin >>n;
	for(int i= 0;i<n;i++){
		cin >> c1[i].mark >> c1[i].value;
		c2[i] = c1[i];
	}
	
	BubbleSort(c1,n);
	SelectionSort(c2,n);
	
	Show(c1,n);
	
	cout<<"Stable"<<endl;
	Show(c2,n);
	for(int j=0;j<n;j++){
		if(c1[j].mark != c2[j].mark){
			cout << "Not stable" ;
			isStable = 0;
			break;
		}
	}
	if(isStable) cout << "Stable";
	cout <<endl;
	return 0;
}

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

int main() {
	
	//vector<int> a(n);  sort(a.begin(),a.end());
	//cout << "test" << "\n";
	cin.tie(0);
	ios::sync_with_stdio(false);
	//string ans="YES";
	
//////////////////////////////////////////////
	
	ll ans=-2;


	ll n;
	cin >> n;
	
	ll k=sqrt(n);
	
	for(int i=k;i>0;i--){
		if(n%i==0) {
			ans+=i+n/i;
			break;
		}
	}
	

	cout << ans << "\n";
	
	
	return 0;
}


//g++ -o a a.cpp

Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int X, Y, Z;
	std::cin >> X >> Y >> Z;
	
	int result = (X - Z) / (Y + Z);
	std::cout << result << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

bool check(char ch){
	if(ch=='A'||ch=='T'||ch=='C'||ch=='G')return true;
	else return false;
}

int main(){
	string s,res="",ans="";
	cin>>s;
	rep(i,s.size()){
		if(check(s[i])){
			res+=s[i];
			if(i==s.size()-1){
				if(ans.size()<=res.size()){
					ans=res;
				}
			}
		}else{
			if(ans.size()<=res.size()){
				ans=res;
			}
			res="";
		}
	}
	cout<<ans.size()<<endl;
	return 0;
}

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

using namespace std;

const string aiueo = "aiueo";
const string silent = "ksthp";

int main()
{
  string S;
  while(cin >> S, S != "#") {
    vector< string > token;
    string buff;
    for(int i = 0; i < S.size(); i++) {
      buff += S[i];
      if(aiueo.find(S[i]) != string::npos) {
        if(i + 1 < S.size() && (S[i + 1] == 'a' || S[i + 1] == 'i' || S[i + 1] == 'u')) buff += S[++i];
        token.push_back(buff);
        buff.clear();
      } else if(S[i] == '\'') {
        token.push_back(buff);
        buff.clear();
      } else if(S[i] == 'n' && (i + 1 == S.size() || (aiueo.find(S[i + 1]) == string::npos && S[i + 1] != 'y'))) {
        token.push_back(buff);
        buff.clear();
      }
    }

    bool latte = false;
    int sz = 0;

    for(string &a : token) {
      sz++;
      bool malta = !latte;
      if(malta) {
        malta = false;
        int proc = 0;
        for(auto c : a) proc += aiueo.find(c) != string::npos;
        if(silent.find(a[0]) != string::npos && proc == 1) {
          if(a.back() == 'i' || a.back() == 'u') {
            malta = token.size() == sz || silent.find(token[sz][0]) != string::npos;
          } else if(a.back() == 'a' || a.back() == 'o') {
            malta = sz < token.size() && silent.find(token[sz][0]) != string::npos && token[sz][(token[sz][1] == 'y') + 1] == a.back();
          }
        }
      }
      // cout << malta << endl;
      if(malta) {
        bool ok = false;
        for(int i = 0; i < a.size(); i++) {
          if(!ok && aiueo.find(a[i]) != string::npos) {
            cout << "(" << a[i] << ")";
            ok ^= 1;
          } else {
            cout << a[i];
          }
        }
      } else {
        cout << a;
      }
      latte = malta;
    }
    cout << endl;
  }
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main(){
  int N, T;
  cin >> N >> T;
  vector<int> D(N);
  for (int i = 0; i < N; i++){
    cin >> D[i];
  }
  sort(D.begin(), D.end());
  long long ans = 1;
  for (int i = 0; i < N; i++){
    ans *= D.begin() + i - lower_bound(D.begin(), D.end(), D[i] - T) + 1;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;

const ll MOD = 1000000007;

int N;
ll A[20][20];
ll dp[1<<16];
ll S[1<<16];

void solve() {
    cin >> N;
    REP(i, N) REP(j, N) cin >> A[i][j];
    REP(i, 1<<N) dp[i] = -(1LL << 59);
    dp[0] = 0;

    REP(mask, 1<<N) REP(i, N) REP2(j, i+1, N) if ((mask&(1<<i))&&(mask&(1<<j))) {
        S[mask] += A[i][j];
    }

    REP(mask, 1<<N) {
        for(int i=mask; i>=0; i--) {
            i&=mask;
            dp[mask] = max(dp[mask], dp[i] + S[mask&(~i)]);
        }
    }

    cout << dp[(1<<N)-1] << "\n";
}

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

    solve();
}


Measured memory_bytes: 1280
N,A=map(int,input().split())
x=list(map(int,input().split()))
cnt=x.count(A)
B=[]
for i in x:
  if i != A:
    B.append(i-A)
#print(cnt,B)

plus=[0]*2501
minus=[0]*2501

for i in B:
  if i>0:
    for j in range(2500,0,-1):
      if plus[j]>0 and j+i<=2500:
        plus[j+i]+=plus[j]
    plus[i]+=1
  if i<0:
    i=-i
    for j in range(2500,0,-1):
      if minus[j]>0 and j+i<=2500:
        minus[j+i]+=minus[j]
    minus[i]+=1

#print(plus[:100])
#print(minus[:100])
    
ans=0
for i in range(2501):
  ans+=plus[i]*minus[i] if plus[i]>0 and minus[i]>0 else 0
#print(ans)
ans*=2**cnt
ans+=2**cnt-1

print(ans)

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

using ll = long long;
constexpr ll inf = 1e18;

int main() {
    ll n, k; cin >> n >> k;
    ll zero_cnt = 0;
    vector<ll> neg, pos;
    for(int i = 0; i < n; ++i) {
        ll a; cin >> a;
        if(a == 0) {
            zero_cnt += 1;
        } else if(a < 0) {
            neg.push_back(-a);
        } else {
            pos.push_back(a);
        }
    }
    sort(neg.begin(), neg.end());
    sort(pos.begin(), pos.end());

    if(k <= (ll)neg.size() * (ll)pos.size()) {
        ll lb = 0, ub = inf + 1;
        while(ub - lb > 1) {
            const auto mid = (ub + lb) / 2;
            ll cnt = 0;
            for(auto const v : neg) {
                cnt += pos.end() - lower_bound(pos.begin(), pos.end(), (mid + v - 1) / v);
            }
            if(cnt < k) {
                ub = mid;
            } else {
                lb = mid;
            }
        }
        cout << -lb << endl;
    } else {
        k -= (ll)neg.size() * pos.size();
        if(k <= zero_cnt * (n - 1) - zero_cnt * (zero_cnt - 1) / 2) {
            cout << 0 << endl;
            return 0;
        }
        k -= zero_cnt * (n - 1) - zero_cnt * (zero_cnt - 1) / 2;

        ll lb = 0, ub = inf;
        while(ub - lb > 1) {
            const auto mid = (ub + lb) / 2;
            ll cnt = 0;
            for(int t = 0; t < 2; ++t) {
                const auto& vs = (t ? pos : neg);
                const int sz = vs.size();
                for(int i = 0; i < sz; ++i) {
                    const auto fst = vs.begin() + i + 1;
                    cnt += upper_bound(fst, vs.end(), mid / vs[i]) - fst;
                }
            }
            if(cnt < k) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        cout << ub << endl;
    }
}


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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size() / 2;
	int ans = 0;
	int j = s.size()-1;
	for(int i=0; i<n; i++){
		if(s[i] != s[j])
			ans++;
		j--;
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#define FILE_NAME "a"

const int MAXN = 1e5 + 10;

int n;
int a[3 * MAXN];

bool read() {
	if  (scanf("%d", &n) < 1) {
		return 0;
	}
	forn(i, 3 * n) {
		scanf("%d", &a[i]);
	}
	return 1;
}



ll solve() {
	sort(a, a + (3 * n));
	ll ans = 0;
	for (int i = n; i < 3 * n; i += 2) {
		ans += a[i];
	}
	return ans;
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		cout << solve() << endl;
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
  	cin>>a>>b;
  	if(a!=1&&b!=1){
    	cout<<1<<endl;
    }
  	else if(a!=2&&b!=2){
    	cout<<2<<endl;
    }
  	else{
    	cout<<3<<endl;
    }

}

Measured memory_bytes: 256
N,P = map(int,input().split())
#素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
X = factorization(P)
ans = 1
for i in X:
    ans *= max(1,i[0]**(i[1]//N))
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MONEY = 1e15;

int main() {
    ll n, m, sv, tv;
    cin >> n >> m >> sv >> tv;
    sv--;  tv--;
    
    vvpll G1(n), G2(n);  // G1 : 円のグラフ、 G2 : スヌークのグラフ
    rep(i, m) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;  v--;
        G1[u].pb(make_pair(v, a));
        G1[v].pb(make_pair(u, a));
        G2[u].pb(make_pair(v, b));
        G2[v].pb(make_pair(u, b));
    }
    
    // ダイクストラ法。計算量はO((V+E)*log(V))
    vl dist1(n, INF);  // dist1[v] : 頂点svから頂点vへの最短距離
    priority_queue<P, vector<P>, greater<P>> prQ1;
    dist1[sv] = 0;
    prQ1.push(make_pair(sv, 0));  // (頂点番号, 頂点svからの最短距離)
    while(!prQ1.empty()) {
        auto p1 = prQ1.top();
        prQ1.pop();
        ll v = p1.first;
        if(dist1[v] < p1.second) {
            continue;
        }
        for(auto p2 : G1[v]) {
            ll u = p2.first;
            ll cost = p2.second;
            if(dist1[u] > dist1[v] + cost) {
                dist1[u] = dist1[v] + cost;
                prQ1.push(make_pair(u, dist1[u]));
            }
        }
    }

    // ダイクストラ法。計算量はO((V+E)*log(V))
    vl dist2(n, INF);  // dist2[v] : 頂点tvから頂点vへの最短距離
    priority_queue<P, vector<P>, greater<P>> prQ2;
    dist2[tv] = 0;
    prQ2.push(make_pair(tv, 0));  // (頂点番号, 頂点tvからの最短距離)
    while(!prQ2.empty()) {
        auto p1 = prQ2.top();
        prQ2.pop();
        ll v = p1.first;
        if(dist2[v] < p1.second) {
            continue;
        }
        for(auto p2 : G2[v]) {
            ll u = p2.first;
            ll cost = p2.second;
            if(dist2[u] > dist2[v] + cost) {
                dist2[u] = dist2[v] + cost;
                prQ2.push(make_pair(u, dist2[u]));
            }
        }
    }

    vl cost(n);
    rep(v, n) {
        cost[v] = dist1[v] + dist2[v];
    }
    for(ll v = n-1; v >= 1; v--) {
        chmin(cost[v-1], cost[v]);
    }
    
    rep(i, n) {
        out(MONEY - cost[i]);
    }
    
    re0;
}

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

int main(){
  int N;
  cin >> N;
  for(int i = 1; i < 10; ++i){
    for(int j = 1; j < 10; ++j){
      if(i*j == N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(a == b ? a+b : Math.max(a,b)*2-1);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

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

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

	int N=in(),M=in();
	deque<int> A(M);
	REP(i,M) A[i] = in();

	for(int i=1;i<M;i++){
		if((A[i]-A[i-1])==1){
			cout << 0 << endl;
			return 0;
		}
	}

	int dp[100100];
	for(auto& x:dp) x = 0;
	dp[0] = 1;

	if(!A.empty() && A.front()==1){
		dp[1] = -1;
		A.pop_front();
	}
	else dp[1] = 1;

	for(int i=2;i<=N;i++){
		if(!A.empty() && A.front()==i){
			dp[i] = -1;
			A.pop_front();
		}
		else chmax(dp[i],(max(dp[i-1],0)+max(dp[i-2],0))%1000000007);
	}
	
	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 896
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, K = MAP()

if A >= K:
	print(K)
elif A+B >= K:
	print(A)
else:
	print(A-(K-(A+B)))


Measured memory_bytes: 10044
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)&&ch!='-')
		ch=getchar();
	if (ch=='-')
		f=-1,ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
int n;
vector <int> e[N];
int Log[N],ans=0,f[N];
void solve(int x,int pre){
	int t=0;
	for (auto y : e[x])
		if (y!=pre){
			solve(y,x);
			t|=f[x]&f[y];
			f[x]|=f[y];
		}
	int k=t?Log[t]+1:0;
	while (k<30&&(f[x]>>k&1))
		k++;
	ans=max(ans,k);
	f[x]|=1<<k;
	f[x]&=~((1<<k)-1);
}
int main(){
	n=read();
	for (int i=1;i<=n;i++)
		e[i].clear();
	for (int i=1;i<n;i++){
		int a=read(),b=read();
		e[a].push_back(b);
		e[b].push_back(a);
	}
	Log[1]=0;
	for (int i=2;i<=n;i++)
		Log[i]=Log[i>>1]+1;
	solve(1,0);
	cout << ans;
	return 0;
}

Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;

int h,w;
vector<vector<bool>> jud;
vector<vector<int>> dp;

int main(){
  cin>>h>>w;
  jud.assign(h+1,vector<bool>(w+1,true));
  dp.assign(h+1,vector<int>(w+1,0));
  for(int i=1;i<=h;i++)for(int j=1;j<=w;j++){
    char a;cin>>a;
    if(a=='#')jud[i][j]=false;
  }
  
  dp[1][1]=1;
  for(int i=1;i<=h;i++)for(int j=1;j<=w;j++){
    if(i==1&&j==1)continue;
    if(jud[i][j])dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
  }
  
  cout<<dp[h][w]<<endl;
}

Measured memory_bytes: 4352
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

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

    cout << (a + b + 1) / 2 << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
s = [0] * M
c = [0] * M
A = [0] * N
X = 0
for i in range(M):
    s[i], c[i] = map(int, input().split())
    if s[i] == 1:
        if c[i] == 0:
            if N != 1:
                X += 1
    for k in range(i):
        if s[k] == s[i]:
            if c[k] != c[i]:
                X += 1

    A[s[i]-1] = c[i]

if N != 1:
    if A[0] == 0:
        A[0] = 1


Y = map(str, A)
Z = ','.join(Y)


if X == 0:
    print(int(Z.replace(',', '')))
else:
    print(-1)


Measured memory_bytes: 3064
function main()
    S = readline()
    T = readline()

    length_S = lastindex(S)
    length_T = lastindex(T)

    min_diff = length_T
    for s in 1:(length_S - length_T + 1)
        diff = 0
        for t in 0:length_T - 1
            if S[s+t] != T[t+1]
                diff += 1
            end
        end
        if min_diff > diff
            min_diff = diff
        end
    end
    print(min_diff)
end

main()

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

class Main{
    static int n,m;
    static boolean isvisited[][];
    public static boolean check(int i,int j){
        if(i<1 || i>n)
            return false;
        if(j<1 || j>m)
            return false;
        return !isvisited[i][j];
    }
    public static void main(String args[])throws IOException{
        Scanner in=new Scanner(System.in);
        n=in.nextInt();
        m=in.nextInt();
        char arr[][]=new char[n+1][m+1];
        int i,j;
        isvisited=new boolean[n+1][m+1];
        Queue<Node> queue=new LinkedList<>();
        for(i=1;i<=n;i++){
            String s=in.next();
            for(j=1;j<=m;j++){
                arr[i][j]=s.charAt(j-1);
                if(arr[i][j]=='#'){
                    isvisited[i][j]=true;
                    queue.add(new Node(i,j));
                }

            }
        }
        int cost=0,x=queue.size(),p=0,l,r;
        Node n;
        int dir[][]={{-1,0},{1,0},{0,1},{0,-1}};
        //System.out.println("HYY");
        while(!queue.isEmpty()){
            n=queue.poll();
            for(i=0;i<4;i++){
                l=n.i+dir[i][0];
                r=n.j+dir[i][1];
                if(check(l,r)){
                    queue.add(new Node(l,r));
                    isvisited[l][r]=true;

                }
            }
            p++;
            //System.out.println(n.i+" "+n.j+" "+cost+" "+x+" "+p);
            if(p==x){
                cost++;
                p=0;
                x=queue.size();
            }


        }
        System.out.println(cost-1);



    }
}
class Node{
    int i, j;
    public Node(int i,int j){
        this.i=i;
        this.j=j;
    }
}

Measured memory_bytes: 77284
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

func main() {
	var cnt int
	var ans int64
	var m int64 = math.MaxInt64
	n := readInt()
	for i := 0; i < n; i++ {
		t := readInt64()
		if t < 0 {
			cnt++
		}
		ans += absInt64(t)
		m = minInt64(m, absInt64(t))
	}
	if cnt%2 == 0 {
		fmt.Println(ans)
	} else {
		fmt.Println(ans - 2*m)
	}
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

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

int n, m, r, q;

#define MAX_N 1001
#define MAX_M 10001

#define MAX_T 1261
int timeforcalc[MAX_M][MAX_T];

int main(void)
{
	while (cin >> n >> m, n|m) {
		memset(timeforcalc, 0, sizeof(timeforcalc));
		vector< vector<pii> > time_of_students = vector< vector<pii> >(m, vector<pii>());
		cin >> r;
		rep(t, r) {
			int tt, nn, mm, ss;
			cin >> tt >> nn >> mm >> ss;
			time_of_students[mm-1].push_back(pii(nn, tt));
		}

		rep(student, m) {
			sort(ALL(time_of_students[student]));
			bool f = true;
			for (int i = 0; i < time_of_students[student].size(); i+= 2) {
				int a = time_of_students[student][i].second;
				int b = time_of_students[student][i+1].second;
				fill(timeforcalc[student]+a, timeforcalc[student]+b, 1);
			}
		}

		cin >> q;
		rep(t, q) {
			int ts, te, mm;
			cin >> ts >> te >> mm;
			int sum = 0;
			REP(i, ts, te)
				sum += timeforcalc[mm-1][i];
			cout << sum << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 50708
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
const int N=1e6+5,MAX=3e7,MOD=1e9+7;
 
using namespace std;

int n,m,q;
vector<ll> a,b;
ll solve(ll x,bool got1,bool got2){
	if(got1 && got2)return 0;

	ll ret = 1e18;
	if(!got1){
		auto it = lower_bound(all(a),x);
		if(it!=a.end())ret=min(ret,solve(*it,1,got2)+(*it)-x);
		if(it!=a.begin()){
			it--;
			ret = min(ret,solve(*it,1,got2)+x-*it);
		}
	}
	if(!got2){
		auto it = lower_bound(all(b),x);
		if(it!=b.end())ret=min(ret,solve(*it,got1,1)+(*it)-x);
		if(it!=b.begin()){
			it--;
			ret = min(ret,solve(*it,got1,1)+x-(*it));
		}
	}
	return ret;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

      scanf("%d %d %d",&n,&m,&q);

      a.resize(n);
      b.resize(m);

      for(int i=0;i<n;i++)scanf("%lld",&a[i]);
      for(int i=0;i<m;i++)scanf("%lld",&b[i]);
      while(q--){
      	ll x;
      	scanf("%lld",&x);
      	printf("%lld\n",solve(x,0,0));
      }
 }

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N,K;
    cin >> N >> K;
    ll s = 0;
    ll t = N;
    ll ans = 0;
    
    reps(i,1,N+2){
        
        if(i >= K){
            ans += (t-s+1)%mod;
            ans %= mod;
        }
        
        s += (ll)i;
        t += (ll)(N-i);
        
    }
    
    cout << ans%mod << endl;
    
    

    return 0;
}


Measured memory_bytes: 3624
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int n, a, b;
    cin >> n >> a >> b;


    cout << min(a, b) << " ";

    if(a + b > n){
        cout << a + b - n << endl;
    } else {
        cout << 0 << endl;
    }
}

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

int main() {
  vector<int> vec(3);
  cin >> vec[0] >> vec[1] >> vec[2];
  
  sort(vec.begin(), vec.end());
  
  if (vec[0]==5 && vec[1]==5 && vec[2]==7){

  cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

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

int main() {
    int A, B, C, D;
    
    cin >> A >> B >> C >> D;
    
    string ans = "Balanced";
    
    if(A+B > C+D) ans = "Left";
    if(A+B < C+D) ans = "Right";
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
s=int(input())
list=[]
list.append(1)
list.append(1)
list.append(1)
list.append(2)
list.append(1)
list.append(2)
list.append(1)
list.append(5)
list.append(2)
list.append(2)
list.append(1)
list.append(5)
list.append(1)
list.append(2)
list.append(1)
list.append(14)
list.append(1)
list.append(5)
list.append(1)
list.append(5)
list.append(2)
list.append(2)
list.append(1)
list.append(15)
list.append(2)
list.append(2)
list.append(5)
list.append(4)
list.append(1)
list.append(4)
list.append(1)
list.append(51)
print(list[s-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 3e6 + 9;
const ll mod = 1e9 + 7;
typedef pair<ll,ll> LL;
ll n,cur = 7,cnt = 1;
bool dd[N];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n;
    while(cur%n != 0){
        if (dd[cur]){
            cout<<-1; return 0;
        }
        dd[cur] = 1;
        cur = (cur*10 + 7)%n;
        cnt++;
    }
    cout<<cnt;
}



Measured memory_bytes: 4636
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  if (n == 25)
    cout << "Christmas" << endl;
  else if (n == 24)
    cout << "Christmas Eve" << endl;
  else if (n == 23)
    cout << "Christmas Eve Eve" << endl;
  else
    cout << "Christmas Eve Eve Eve" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

void print(const std::vector<int>& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n; cin >> n;
  vector<int> hoge;
  vector<int> p(n);
  vector<int> q(n);
  rep_i(i, n){
    hoge.push_back(i + 1);
  }
  
  rep_i(i, n){
    cin >> p[i];
  }
  rep_i(i, n){
    cin >> q[i];
  }

  int a = 1;
  int b = 1;
  do {
    bool f_a = true;
    // print(hoge);
    // cout << endl;
    rep_i(i, n){
      if(hoge[i] != p[i]){
        // cout << "i:" << i << endl;
        f_a = false;
      }
    }

    if(f_a){
      break;
    }else{
      a += 1;
    }
  } while (std::next_permutation(hoge.begin(), hoge.end()));
  hoge.clear();
  rep_i(i, n){
    hoge.push_back(i + 1);
  }

  // cout << "aaaa" << endl;

  do {
    bool f_b = true;
    // print(hoge);
    rep_i(i, n){
      if(hoge[i] != q[i]){
        f_b = false;
      }
    }

    if(f_b){
      break;
    }else{
      b += 1;
    }
  } while (std::next_permutation(hoge.begin(), hoge.end()));
  // cout << a << endl;
  // cout << b << endl;

  say(abs(a - b));
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
def main():
    n = int(input())
    a = list(map(str, input().split()))
    b = deque([a[0]])
    for i in range(1,n):
        if i%2 == 0:
            b.append(a[i])
        else:
            b.appendleft(a[i])
    if n%2 == 1:
        print(" ".join(reversed(b)))
    else:
        print(" ".join(b))

if __name__ == '__main__':
    main()

Measured memory_bytes: 26548