akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n, m, a, b, c, d, ans;
string str;
int main(void)
{

	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n >> str;
	int len = str.length();
	for (int i = 0; i < len; i++)
	{
		cout << ((((int)str[i] + n) > 90) ? (char)((int)str[i] + n - 26) : (char)((int)str[i] + n));
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cctype>
#include<cmath>
#define ll  long long
#define inf 99999999
using namespace std;
int flag[11];
int c[101];
int n;
void add_flag(){
    int carry=1;
    for(int i=1;i<=10;i++){
        if(flag[i]==0 && carry ==1){
            flag[i]=1;
            return;
        }else{
            flag[i]=0;
        }
    }
}

bool check(){
    for(int i=1;i<=10;i++){
        if(flag[i]==0){
            return false;
        }
    }
    return true;
}

void clear_c(){
    for(int i=1;i<=n;i++){
        c[i]=0;
    }
}
int main()
{

    cin>>n;
    int f[n+1][11];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=10;j++){
            scanf("%d",&f[i][j]);
        }

    }

    int p[n+1][11];
    for(int i=1;i<=n;i++){
        c[i]=0;
        for(int j=0;j<11;j++){
            scanf("%d",&p[i][j]);
        }
    }
    ll res=-99999999999999;
    while (!check()){
        add_flag();
        clear_c();
        for(int i=1;i<=n;i++){
            for(int j=1;j<=10;j++){
                if(f[i][j] ==1 && flag[j]==1){
                    ++c[i];
                }
            }
        }
        ll temp_res=0;
        for(int i=1;i<=n;i++){
            temp_res+=(ll)(p[i][c[i]]);
        }
        if(temp_res>res){
            res=temp_res;
        }

    }
    cout<<res<<endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll s; cin>>s;
	ll h = s/3600; s %= 3600;
	ll m = s/60; s %= 60;
	cout << h << ":" << m << ":" << s << "\n"; 
	return 0;
}


Measured memory_bytes: 3120
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for(ll i=0;i<(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n;cin>>n;
    V<ll>a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    ll m;cin>>m;
    V<ll>b(m);
    for(ll i=0;i<m;i++){
        cin>>b[i];
    }
    string s1="",s2="";
    for(ll i=0;i<n;i++)s1+=to_string(a[i]);
    for(ll i=0;i<m;i++)s2+=to_string(b[i]);
    if(a>=b){cout<<0<<endl;}
else cout<<1<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------













































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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};

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

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

int h,w;
int g[10][10];

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

	cin>>h>>w;
	REP(i,10) {
		REP(j,10) {
			cin>>g[i][j];
		}
	}

	REP(i,10) REP(j,10) REP(k,10) g[j][k]=min(g[j][k],g[j][i]+g[i][k]);

	ll sum=0;
	REP(i,h) {
		REP(j,w) {
			int m; cin>>m;
			if(m!=-1) sum+=g[m][1];
		}
	}
	cout<<sum<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if( x + r > W || x - r < 0 || y + r > H || y - r < 0){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;
}



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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl ;
#define Yes cout << "Yes" << endl ;
#define NO cout << "NO" << endl ;
#define No cout << "No" << endl ;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio

    lli num , cnte = 0 , cnto = 0 ;
    cin >> num ;


    for (lli i = 1 ; i <= num ; i++)
    {
        if (i % 2 == 0)
            cnte ++ ;
        else
            cnto ++ ;
    }
    cout << cnto * cnte ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int N;
	cin >> N;
	int a = N / 100;
	int b = N - 100 * a;
	if (a == 0 || 12 < a) {
		if (b == 0 || 12 < b) {
			cout << "NA" << endl;
		}
		else {
			cout << "YYMM" << endl;
		}
	}
	else {
		if (b == 0 || 12 < b) {
			cout << "MMYY" << endl;
		}
		else {
			cout << "AMBIGUOUS" << endl;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n[4];
    rep(i, 4) cin >> n[i];
    sort(n, n + 4);
    
    if ((n[0] == 1) && (n[1] == 4) && (n[2] == 7) && (n[3] == 9)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    
    return 0;
}


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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main(){
  int x,a,b;
  cin >> x >> a >> b;

  if(a >= b){
    printf("delicious\n");
  }
  else if(x >= b-a){
    printf("safe\n");    
  }
  else printf("dangerous\n");

  return 0;
}

Measured memory_bytes: 256
N = int(input())
ans = 0
for i in range(N):
    n = int(input())
    if n==2:ans+=1
    elif n%2==0:continue
    for j in range(3,n+1,2):
        if j**2 > n:
            ans+=1
            break
        if n%j==0:break
print(ans)


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

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

long long lcm(long long a, long long b){
    long long g = gcd(a,b);
    return a/g * b;
}

int main() 
{
    int N;
    cin >> N;
    
    long long ans = 1LL;
    for (int i = 0; i < N; i++) {
        long long a;
        cin >> a;
        ans = lcm(ans, a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.10lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[6] = {-1,-1,0,0,1,1};
int dy[6] = {-1,0,-1,1,0,1};

const int N = 8e3+5;

int a[N];

int main()
{
    string s,t;
    cin>>s>>t;
    for(int i=0;i<sz(s);++i){
        if(s[i]!=t[i]){
            return cout<<"No"<<endl,0;
        }
    } 
    cout<<"Yes"<<endl;
	return 0;
}

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

int gcd(int a,int b){
  int r;

  if(a<b) swap(a,b);
  if(b==0) return a;

  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);

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

  vector<int> left(n+1);
  for (int i = 0; i < n; i++)
  {
    left[i+1]=gcd(left[i],a[i]);
  }

  vector<int> right(n+1);
  for (int i = n; i > 0; i--)
  {
    right[i-1]=gcd(right[i],a[i-1]);
  }

  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    ans=max(gcd(left[i],right[i+1]),ans);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main()
{
	int a,c,d;
	char b;
	scanf("%d %c %d",&a,&b,&c);
	if(b=='+'){
		d=a+c;
		printf("%d\n",d);
	}
	if(b=='-'){
		d=a-c;
		printf("%d\n",d);
	}	
	return 0;
}

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

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

	sort(q.begin(),q.end());

	int flag = 0;
	for (int i = 0; i < N; i++) {
		if (p[i] != q[i]) flag++;
	}

	if (flag == 2 || flag == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
}	

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
void q_sort(int array[], int begin, int end);

void q_sort(int array[], int begin, int end){
    int i = begin;
    int k = end;
    int pivot;
    int temp;
    pivot = array[(begin + end) / 2];
    while (1) {
        while (array[i] < pivot) {
            ++i;
        }
        while (pivot < array[k]) {
            k--;
        }
        if (i >= k) {
            break;
        }
        temp = array[i];
        array[i] = array[k];
        array[k] = temp;
        i++;
        k--; //check
    }
    if (begin < i - 1) {
        q_sort(array, begin, i - 1);
    }
    if (k + 1 < end) {
        q_sort(array, k + 1, end);
    }
}
int main(int argc, const char * argv[])
{
    int mt[10];
    for (int i = 0; i < 10; i++) {
        cin >> mt[i];
    }
    q_sort(mt, 0, 9);
    for (int i = 9; 6 < i; i--) {
        cout << mt[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a,b;
    char s[51];
    cin>>a>>b;
    cin>>s;
    if('A'<=s[b-1]&&s[b-1]<='Z')
        s[b-1]-='Z'-'z';
    cout<<s<<endl;
}

Measured memory_bytes: 256
class Array
  def sum; inject(:+) end # v2.5
end
def min(a,b); a < b ? a : b end

h,w,k = gets.to_s.split.map(&:to_i)
a = Array.new(h){ gets.to_s.chomp.bytes }

ans = (h-1) * (w-1)
[0, 1].repeated_permutation(h-1) do |bit|
  div  = [0] * h
  t    = 0
  able = true
  (0...h-1).each do |i|
    t += 1 if bit[i] == 1
    div[i+1] = t
  end
  wc = [0] * (t+1)
  cut = bit.sum
  w.times do |j|
    over = false
    h.times do |i|
      wc[div[i]] += 1 if a[i][j] == 49
      if wc[div[i]] > k
        over = true
        break
      end
    end
    if over
      (t+1).times{|k| wc[k] = 0 }
      cut += 1
      h.times do |i|
        wc[div[i]] += 1 if a[i][j] == 49
        if wc[div[i]] > k
          able = false
          break
        end
      end
    end
    
    break if not able
  end
  ans = min(ans, cut) if able
end

p ans


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n, m;
int s[2000];
ll dp[2000];

int main() {
    cin >> n >> m;
    rep(i,n) cin >> s[i];
    rep(i,m) {
        int x; cin >> x;
        ll sum = 0;
        rep(j,n) {
            ll t = (sum + dp[j])%MOD;
            if (x == s[j]) {
                (dp[j] += sum+1) %= MOD;
            }
            sum = t;
        }
    }
    ll ans = 1;
    rep(i,n) ans += dp[i];
    cout << ans%MOD << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 100000000
using namespace std;
using ll = long long;
using p = pair <int, int>;

int		main(void){
	string		sd, t;
	cin >> sd >> t;
	int			lensd, lent;
	int			i, j;
	lensd = sd.length();
	lent = t.length();
	i = lensd - 1;
	j = lent - 1;
	while (i >= 0){
		if (sd[i] == t[j] || sd[i] == '?'){
			j--;
			i--;
		} else{
			i = i + (lent - j) - 2;
			j = lent - 1;
		}
		if (j < 0)
			break ;
	}
	if (j >= 0){
		cout << "UNRESTORABLE\n";
		return (0);
	}
	i++;
	j++;
	while (j < lent)
		sd[i++] = t[j++];
	i = 0;
	while (i < lensd){
		if (sd[i] == '?')
			sd[i] = 'a';
		i++;
	}
	cout << sd;
}


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

typedef long long ll;

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

    string s; cin >> s;
    for(int i=0;i<s.size();i++) cout << 'x';
    cout << endl;
    return 0;
}

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

int main()
{
    int a, b;
    while(1){
        cin >> a >> b;
        if(a==0 && b==0)break;
        for (int i = 0; i < a; i++){
            for (int j = 0; j < b; j++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc159b
{
    class Program
    {
        static void Main(string[] args)
        {
            //1) input
            string input1 = Console.ReadLine();
            //==========================================================================================================================




            //2) output
            string output = "No";

            int n = input1.Length;
            string a = input1.Substring(0, (n - 1) / 2);
            string b = input1.Substring((n - 1) / 2 + 1, (n - 1) / 2);
            bool isPalindrome = a == string.Join("", b.Reverse());


            int nA = a.Length;
            int sizeA = 0;
            int indexA = 0;
            int tmpA = 0;
            if (nA % 2 == 0)
            {
                tmpA = nA;
                sizeA = tmpA / 2;
                indexA = tmpA / 2;

            }
            else
            {
                tmpA = nA - 1;
                sizeA = tmpA / 2;
                indexA = tmpA / 2 + 1;

            }

            string aA = a.Substring(0, sizeA);           
            string bA = a.Substring(indexA, sizeA);
            bool isPalindromeA = aA == string.Join("", bA.Reverse());


            int nB = a.Length;
            int sizeB = 0;
            int indexB = 0;
            int tmpB = 0;
            if (nA % 2 == 0)
            {
                tmpB = nB;
                sizeB = tmpB / 2;
                indexB = tmpB / 2;

            }
            else
            {
                tmpB = nB - 1;
                sizeB = tmpB / 2;
                indexB = tmpB / 2 + 1;

            }

            string aB = b.Substring(0, sizeB);
            string bB = b.Substring(indexB, sizeB);
            bool isPalindromeB = aB == string.Join("", bB.Reverse());



            if (isPalindrome && isPalindromeA && isPalindromeB)
            {
                output = "Yes";
            }


            Console.WriteLine(output);
        }
    }
}


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

#define ll long long
int we[100009];
ll dp[101][100009], va[105];


ll call(int pos, int w){
        if(w == 0 || pos <= 0)return 0;
        if(w < 0)return LLONG_MIN;
        ll &ret = dp[pos][w];
        if(ret != -1)return ret;
        ret = call(pos - 1, w);
        if(w >= we[pos])ret = max(ret, va[pos] + call(pos - 1, w - we[pos]));
        return ret;
}


int main(){


        int n, w; scanf("%d %d", &n, &w);
        for(int i = 1; i <= n; i++){
                scanf("%d %lld", we + i, va + i);

        }

        memset(dp, -1, sizeof dp);
        printf("%lld\n", call(n, w));
        return 0;
}


Measured memory_bytes: 79104
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		long[][] nums = new long[n][];
    for(int i = 0; i < n; i++)
    {
      nums[i] = new long[2];
      nums[i][0] = long.Parse(Console.ReadLine());
      nums[i][1] = i;
    }
    Array.Sort(nums, (a, b) => b[0].CompareTo(a[0]));
    long[] answers = new long[n];

    for(int i = 0; i < n; i++)
    {
      if(i != nums[0][1]) answers[i] = nums[0][0];
      else answers[i] = nums[1][0];
    }

    var answerText = new StringBuilder();
    for(long i = 0; i < answers.Length; i++)
    {
      answerText.AppendLine(answers[i].ToString());
    }
    Console.Write(answerText);
	}
}

Measured memory_bytes: 38728
S = int(input())
f = [0]*(S+1)
f[0] = 1
if S >= 3: f[3] = 1
if S >= 4: f[4] = 1
if S >= 5: f[5] = 1
for i in range(6, S+1):
    f[i] = sum(f[i-j] for j in range(3, i+1))%(10**9+7)
print(f[S])


Measured memory_bytes: 68168
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
const int M=2e5+10;
int a[M],n,k;
bool check(int x)
{
    int cnt=0;
    for(int i=0;i<n;i++)
        cnt+=(a[i]-1)/x;
    //printf("%d %d\n",x,cnt);
    return cnt<=k;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    int l=1,r=1e9+10,ans=0;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(check(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 4592
using System;
using System.Linq;

namespace AtCoderTutorial
{
    public class AtCoder176
    {
        public static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long[] AN = Console.ReadLine().Split(' ').Select(_ => long.Parse(_)).ToArray();

            long modNum = (long) Math.Pow(10, 9) + 7;
            long result = 0;

            long ANtotal = 0;
            for (int i = 0; i < N; i++)
            {
                ANtotal = (ANtotal + AN[i]) % modNum;
            }

//            Console.WriteLine($"init ANtotal = {ANtotal}");


            for (int i = 0; i < N - 1; i++)
            {
//                for (int j = i + 1; j < AN.Length; j++)
//                {
                ANtotal = ANtotal - (AN[i] % modNum);
                if (ANtotal < 0)
                {
                    ANtotal += modNum;
                }

//                Console.WriteLine($"count={i} ANTotal={ANtotal}");
                result += AN[i] * (ANtotal % modNum);
//                Console.WriteLine($"result = {result}");
                result = result % modNum;
//                }
            }


            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 47852
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define vi vector<int>
#define vvi vector<vi >
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	
	vvi vec(m);
	REP(i,m){
		int k;
		cin>>k;
		vec[i].resize(k);
		REP(j,k){
			cin>>vec[i][j];
			vec[i][j]--;
		}
	}
	
	vi p(m);
	REP(i,m) cin>>p[i];
	
	int ans=0;
	for(int i=0;i<(1<<n);++i){//スイッチの付き方全通り試す.
		bool ok=true;
		for(int j=0;j<m;++j){//全ての電球を試す.
			int cnt=0;
			for(int id:vec[j]){
				if((i>>id)&1) cnt++;
			}
			if((cnt%2)!=p[j]) ok=false;
		}
		if(ok) ans++;
	}
	
	cout<<ans<<endl;
}//解説参考.bit全探索.


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #define test
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
LL sh[maxn],tem[maxn];

int main(){
	int A,B,Q;
	scanf("%d%d%d",&A,&B,&Q);
	for(int i = 0 ; i < A ; ++i) scanf("%lld",sh+i);
	for(int i = 0 ; i < B ; ++i) scanf("%lld",tem+i);
#ifdef test
	cout<<"Data"<<endl;
	for(int i = 0 ; i < A; ++i)
		cout<<sh[i]<<" ";
	cout<<endl;
	for(int i = 0 ; i < B; ++i)
		cout<<tem[i]<<" ";
	cout<<endl;
	cout<<endl;
#endif
	while(Q--){
		LL loc;
		scanf("%lld",&loc);
		int pos1 = lower_bound(sh,sh+A,loc) - sh;
		int pos2 = lower_bound(tem,tem+B,loc) - tem;
		int a1[2],a2[2],p1 = 0,p2 = 0;

		if(pos1 != A) a1[p1++] = pos1;
		if(pos1 != 0) a1[p1++] = pos1-1;

		if(pos2 != 0) a2[p2++] = pos2-1;
		if(pos2 != B) a2[p2++] = pos2;
#ifdef test
		cout<<"pos"<<endl;
		for(int i = 0 ; i < p1 ; ++i){
			cout<<a1[i]<<" ";
		}
		cout<<endl;
		for(int i = 0 ; i < p2 ; ++i){
			cout<<a2[i]<<" ";
		}
		cout<<endl;
#endif
		LL res = 0x3f3f3f3f3f3f3f3fll;
		for(int i = 0 ; i < p1 ; ++i){
			for(int j = 0 ; j < p2 ; ++j){
				LL how1 = sh[a1[i]],how2 = tem[a2[j]];
#ifdef test
				cout<<"how1 = "<<how1<<" how2 = "<<how2<<endl;
#endif
				how1 -= loc; how2 -= loc;
				LL sig = (how1/abs(how1))*(how2/abs(how2));
				if(sig > 0){
					res = min(res,max(abs(how1),abs(how2)));
				}else{
					res = min(res,min(2*abs(how1) + abs(how2),abs(how1) + abs(how2)*2));
				}
#ifdef test
				cout<<"res = "<<res<<endl;
#endif
			}
		}
		// puts("==");
		printf("%lld\n",res);
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

ll n;

int solve(ll num)
{
  if (num > n)
  {
    return 0;
  }

  bool is_753 = true;
  string num_str = to_string(num);
  string s = "753";
  for (int i = 0; i < 3; i++)
  {
    if (count(num_str.begin(), num_str.end(), s[i]) == 0)
    {
      is_753 = false;
      break;
    }
  }

  int res;
  if (is_753)
  {
    res = 1;
  }
  else
  {
    res = 0;
  }

  for (ll i : {7, 5, 3})
  {
    res += solve(num * 10 + i);
  }

  return res;
}

int main()
{
  cin >> n;

  cout << solve(0) << endl;
}


Measured memory_bytes: 256
# Wrote in Mar 4, 2020 18:45 by reetok
require 'time'
require 'prime'
require 'bigdecimal'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=:to_i)
  t = []
  n.times do
    t.push(eval("gets.chomp.#{datatype.to_s}"))
  end
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
class Integer
  def divisor_list
    devisors = [1]
    2.upto(self/2) do |i|
      devisors << i if self%i == 0
    end
    devisors << self
    return devisors.uniq.sort
  end
end
class Array
  def upper(a) #aより上
    self.sort.select{|n|n>=a}
  end
  def downer(a) #aより下
    self.sort.select{|n|n<=a}
  end
end

#---------------

a,b = inp

puts [a/b,a%b,sprintf("%.10f",a.to_f/b)].join(" ")


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

ll N;
vector<vector<ll>> A, path;

ll dfs(ll x, ll y) {
    if(y > 1 || x > N - 1) return 0;
    if(path[y][x] >= 0) return path[y][x];
    path[y][x] = max(dfs(x + 1, y), dfs(x, y + 1)) + A[y][x];
    return path[y][x];
}

int main(void) {
    cin >> N;
    A.resize(2, vector<ll>(N));
    path.resize(2, vector<ll>(N, -1));
    for(ll i = 0;i < N;i++) cin >> A[0][i];
    for(ll i = 0;i < N;i++) cin >> A[1][i];
    cout << dfs(0, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	int a,b,c,d;cin>>a>>b>>c>>d;
	int x=max(a,c),y=min(b,d);
	if(y>x) cout<<y-x<<endl;else cout<<0<<endl;
}


Measured memory_bytes: 256
N = int(input())

cost = [int(i) for i in input().split()]

dp = [0]*N

dp[1] = abs(cost[0] - cost[1])

for i in range(2,N):
  dp[i] = min (dp[i-1] + abs(cost[i] - cost[i-1]), dp[i-2] + abs(cost[i-2] - cost[i]))
  
print(dp[-1])

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

int main(){
	int N;
	cin >> N;
	ll A[310][310];
	bool B[310][310];
	rep(i,N){
		rep(j,N){
			B[i][j] = true;
		}
	}
	rep(i,N){
		rep(j,N){
			cin >> A[i][j];
		}
	}
	
	rep(k,N){
		rep(i,N){
			rep(j,N){
				if(A[i][j] > A[i][k] + A[k][j]){
					cout << -1 << endl;
					return 0;
				}
				if(i == k || j == k) continue;
				if(A[i][j] == A[i][k] + A[j][k]){
					B[i][j] = false;
				}
			}
		}
	}
	
	ll ans = 0;
	rep(i,N){
		rep(j,i){
			if(B[i][j]) ans += A[i][j];
		}
	}
	
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c=0;
	cin>>a;
	for(int i=1;i<=a;i++){
		cin>>b;
		if(b!=i)
			c++;
	}
	if(c==0||c==2)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
  int a,b,c;
  std::cin >> a >> b >> c;
  
  if(a==b || b==c || c==a){
    if(a==b && b==c){
      std::cout << 1 << std::endl;
      return 0;
    }
    else{
      std::cout << 2 << std::endl;
      return 0;
    }
  }
  std::cout << 3 << std::endl;
  
  return 0;
}


Measured memory_bytes: 3588
N, T = gets.split.map{|i|i.to_i}
A = gets.split.map{|i|i.to_i}
min = A[0]
max_benefit = 0
max_count = 0
(1...(A.size)).each{|i|
    if A[i] < min
        min = A[i]
    end
    if A[i] - min == max_benefit
        max_count += 1
    end
    if A[i] - min > max_benefit
        max_benefit = A[i] - min
        max_count = 1
    end
}
puts max_count


Measured memory_bytes: 10636
n = int(input())

f = []
for i in range(n):
    f.append(list(map(int, input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))

ans = -10**18
for ci in range(1, 2**10):
    score = 0
    for cn in range(n):
        cnt = 0
        for cj in range(10):
            x = ci >> cj & 1
            if x and f[cn][cj]:
                cnt += 1
        score += p[cn][cnt]
    ans = max(ans, score)
print(ans)


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

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
};

int main() {
  int n, d, a;
  cin >> n >> d >> a;
  vector<P> p(n);
  rep(i,n) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());

  ll ans = 0;
  BIT<ll> bit(n+1);
  rep(i,n) {
    ll x = p[i].first;
    ll h = p[i].second;
    h -= bit.sum(i);
    if (h <= 0) continue;
    ll num = (h+a-1)/a;
    ans += num;
    ll damage = num*a;
    bit.add(i, damage);
    int rx = min(x+d*2, 1001001001ll);
    int j = upper_bound(p.begin(), p.end(), P(rx+1,-1)) - p.begin();
    bit.add(j, -damage);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int N, M, P;
    cin >> N >> M >> P;
    if (N == 0 && M == 0 && P == 0){
      break;
    }
    vector<int> X(N);
    for (int i = 0; i < N; i++){
      cin >> X[i];
    }
    if (X[M - 1] == 0){
      cout << 0 << endl;
    } else {
      int sum = 0;
      for (int i = 0; i < N; i++){
        sum += X[i];
      }
      cout << sum * 100 * (100 - P) / 100 / X[M - 1] << endl;
    }
  }
}


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

using namespace std;

int main()
{
    string s1;
    cin>>s1;
    stack<char>s;
    int n=s1.length();
    int a=0;
   for(int i=0;i<n;)
   {
       if((i<n-1)&&((s1[i]=='0'&&s1[i+1]=='1')||(s1[i]=='1'&&s1[i+1]=='0')))
       {
           a+=2;
           i+=2;
       }
       else
       {
           if((!s.empty())&&((s1[i]=='0'&&s.top()=='1')||(s1[i]=='1'&&s.top()=='0')))
           {
               a+=2;
               s.pop();
               i++;

           }
           else{
                s.push(s1[i]);
                i++;
                }

       }
   }
cout<<a<<endl;
}


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

const ll maxi  = 100005;

ll dp[4][maxi];



int main()
{

ll n;
cin>>n;
for(int j =1;j<=n;j++)
for(int i=0;i<3;i++)
cin>>dp[i][j];

for(int i=n-1;i>=1;i--)
{
	for(int j =0;j<3;j++)
	{
			dp[j][i]+=max(dp[(j+1)%3][i+1],dp[(j+2)%3][i+1]);
			
	}
	
}
	cout<<max(max(dp[0][1],dp[1][1]),dp[2][1])<<endl;
}

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

int main()
{
    ll N;
    cin >> N;
    int a;
    ll ans = 0;
    rep(0, i, N)
    {
        cin >> a;
        a--;
        ans += a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/*input
1
*/
#include <bits/stdc++.h>
#define db(x) cout<<#x<<"="<<(x)<<" "
#define el cout<<endl
using namespace std;
const int MXN = 1e5 + 10;

int N;
long long ans;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> N; // n = N;
    for (int m = 1; m * (m + 1) <= N * 2; ++m)
    {
        if (m * (m + 1) == N * 2) {
            int cnt = 0;
            puts("Yes");
            printf("%d\n", m + 1);
            std::vector<std::vector<int>> ans(m + 1, vector<int>(m, 0));
            for (int i = 0; i <= m; ++i)
            {
                for (int j = 0; j < i; ++j)
                    ans[i][j] = (ans[j][i - 1]);
                for (int j = i; j < m; ++j)
                    ans[i][j] = (++cnt);
                printf("%d", m);
                for (int j = 0; j < m; ++j)
                    printf(" %d", ans[i][j]);
                printf("\n");
            }
            return 0;
        }
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 2176
import collections
n = int(input())
s = [''] + list(input())
cnt_1 = collections.Counter(s)
 
sub = 0
for j in range(1, (n+1)//2):
    for i in range(1, n-2*j+1):
        tmp = s[i] + s[i+j] + s[i+j*2]
        cnt_2 = collections.Counter(tmp)
        if max(cnt_2.values()) == 1:
            sub += 1
 
print((cnt_1['R']*cnt_1['G']*cnt_1['B'])-sub)

Measured memory_bytes: 81872
#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;

#ifndef MDEBUG
#define NDEBUG
#endif

#define x first
#define y second
#define ll long long
#define d double
#define ld long double
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define pss pair<string,string>
#define psi pair<string,int>
#define pis pair<int,string>
#define psl pair<string,ll>
#define pls pair<ll,string>
#define wh(x) (x).begin(),(x).end()
#define ri(x) int x;cin>>x;
#define rii(x,y) int x,y;cin>>x>>y;
#define rl(x) ll x;cin>>x;
#define rv(v) for(auto&_cinv:v) cin>>_cinv;
#define wv(v) for(auto&_coutv:v) cout << _coutv << ' '; cout << endl;
#define ev(v) for(auto&_cerrv:v) cerr << _cerrv << ' '; cerr << endl;
#define MOD 1000000007

namespace std { 
template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
// auto fraclt = [](auto&a,auto&b) { return (ll)a.x * b.y < (ll)b.x * a.y; };
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }
template<typename T> void fracn(pair<T,T>&a) {auto g=gcd(a.x,a.y);a.x/=g;a.y/=g;}
template<typename T> struct Index { int operator[](const T&t){auto i=m.find(t);return i!=m.end()?i->y:m[t]=m.size();}int s(){return m.size();} unordered_map<T,int> m; };

vector<vector<int>> E;
vector<bool> V;

int bfs(int v, int K, int N) {
    vector<int> Q(N);
    vector<int> P(N);
    vector<int> C(N,0);
    fill(V.begin(),V.end(),false);
    V[v] = true; Q[0] = v; P[0] = -1;
    int cnt = 1;
    int b = 0; int e = 1;
    for (int i = 0; i < K/2; i++) {
        for(int j = b; j < e; ++j) {
            int q = Q[j];
            for (int w: E[q]) {
                if (!V[w]) {
                    V[w] = true;
                    Q[cnt] = w;
                    P[cnt] = P[j] == -1 ? w : P[j];
                    cnt++;
                }
            }
        }
        b = e; e = cnt;
    }
    if (K&1) {
        int m = 0;
        for(int j = b; j < e; ++j) {
            int q = Q[j];
            m = max(m, C[P[j]] += E[q].size() - 1);
        }

        cnt += *max_element(C.begin(),C.end());
    }


    return cnt;
}

int main(int,char**) {
    ios_base::sync_with_stdio(false);

    ri(N);ri(K);
    E.resize(N);
    V.resize(N);
    for (int i = 0; i < N-1; i++) {
       ri(A);ri(B);
       E[A-1].push_back(B-1);
       E[B-1].push_back(A-1);
    }

    if (K==1) {
        cout << N-2 << endl;
        return 0;
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, bfs(i,K,N));
    }
    cout << N - ans << endl;


}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long 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;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

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

int main() {
	ll N,ans=0;
	ll tmp;
	cin >> N;
	for (ll i = 1; i <= N;i++) {
		tmp = N / i;
		ans += i * (tmp)*(tmp+1)/2;
	}
	cout << ans;
}
	

Measured memory_bytes: 3196
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin>>N;
    cin>>K;
    int a=0;
    
    while(N>=K){
       N=N/K;
       a=(a+1);
    }
    int ans=a+1;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
H, W, k = gets.split.map(&:to_i)
c = H.times.map {|_| gets.chomp.split("")}

ans = 0
(0...H).each do |h|
  (0...H).to_a.combination(h).to_a.each do |columns|
    cc = Marshal.load(Marshal.dump(c))
    columns.each do |i|
      (0...W).each do |j|
        cc[i][j] = "r"
      end
    end
    (0...W).each do |w|
      (0...W).to_a.combination(w).to_a.each do |rows|
        ccc = Marshal.load(Marshal.dump(cc))
        rows.each do |j|
          (0...H).each do |i|
            ccc[i][j] = "r"
          end
        end
        ans += 1 if ccc.flatten.grep(/#/).length == k
      end
    end
  end
end

p ans

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

vector<ll_ll> prime_factor(ll n) {
  vector<ll_ll> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i) continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }

  if (n != 1) res.emplace_back(n, 1);
  return res;
}

int main(int argc, char* argv[]) {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  set<ll> s;

  ll g = gcd(A, B);
  auto v = prime_factor(g);
  put(sz(v) + 1);

  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

ll gcd(ll x, ll y)
{
  if (x % y == 0)
  {
    return y;
  }
  return gcd(y, x % y);
}

int main()
{
  ll a, b, h;
  cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long
vector<pair<int, int>>v;
signed main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		v.push_back(make_pair(a, 0));
	}
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		v.push_back(make_pair(a, 1));
	}
	sort(v.begin(), v.end());
	int c0 = 0, c1 = 0;
	int ans = 1;
	for (int i = 0; i < v.size(); i++) {
		if (v[i].second == 1) {
			if (c0 == 0)c1++;
			else {
				ans *= c0;
				c0--;
				ans %= 1000000007;
			}
		}
		else {
			if (c1 == 0)c0++;
			else {
				ans *= c1;
				c1--;
				ans %= 1000000007;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5872
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		 int s=scn.nextInt();
		 HashMap<Integer, Integer> hmap= new HashMap<>();
		 System.out.println(func(hmap,s,1));
	}

	public static int solve(int i, int a) {
		if(i==1) {
			return a;
		}
		if(a%2==0) {
			return a/2;
		}else {
			return 3*a+1;
		}
	}
	
	public static int func(HashMap<Integer, Integer> hmap, int a, int i) {
		if(hmap.containsKey(a)) {
			return i;
		}
		hmap.put(a, i);
		return func(hmap,solve(i+1,a),i+1);
	}
}


Measured memory_bytes: 21844