akhauriyash/Code-Regression huggingface dataset:
// B-Acrostic_20170707.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cstdlib>

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

using namespace std;

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

    string s;
    int w;
    string sumString;

    cin >> s;
    cin >> w;

    for (int i = 0; i < s.length(); i++)
    {
        if (i % w == 0) sumString += s[i];
    }
    cout << sumString << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# INF = float('inf')
# N = int(input())
# A = [int(x) for x in input().split()]
# A = [int(input()) for _ in range(N)]
# dp = [[0] * 100 for _ in range(100)]
# dp = defaultdict(lambda: float('inf'))

N, W = [int(x) for x in input().split()]

dp = defaultdict(lambda: float('inf'))
dp[0] = 0

for i in range(N):
    w, v = [int(x) for x in input().split()]

    add = defaultdict(lambda: float('inf'))
    for vv in list(dp.keys()):
        if dp[vv + v] > dp[vv] + w:
            add[vv + v] = dp[vv] + w
    dp.update(add)

print('hoge', file=sys.stderr)

print(max(filter(lambda i: i[1] <= W, dp.items()), key=lambda x:x[0])[0])


Measured memory_bytes: 19032
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N,K;
    long double sum = 0;
    cin >> N >> K;
    std::vector<long long> P(N) ;
    std::vector<double> p(N) ;
    
    for (int i = 0; i < N; i++){
        cin >> P[i];
        p[i] = P[i] /2.0 + 0.5;
    }
    
    for (int i = 0; i < K; i++){
        sum += p[i];
    }
    
    long double ans = sum;
    int count = 0;
    
    for (int i = K; i < N; i++){
        sum += p[i] - p[count];
        count++;
        ans =max(ans,sum);
    }
    
    cout << fixed << setprecision(12);
    cout << ans << endl;
}


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

signed main(void)
{
	string s, tmp;
	bool ok;

	cin >> s;
	ok = false;
	rep(i, s.size())
	{
		for(int j = 0; i + j <= s.size(); j++)
		{
			tmp = "";
			tmp += s.substr(0, i); 
			tmp += s.substr(i + j, s.size() - j);
			if (tmp == "keyence")
				ok = true;
		}
	}
	if (ok)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    vector< string> in(n);
    for (int i = 0; i < n; i++) cin >> in[i];

    cout << "AC x " << count(begin(in), end(in), "AC") << endl;
    cout << "WA x " << count(begin(in), end(in), "WA") << endl;
    cout << "TLE x " << count(begin(in), end(in), "TLE") << endl;
    cout << "RE x " << count(begin(in), end(in), "RE") << endl;
}

Measured memory_bytes: 6336
#include <iostream>
#include <string>

using namespace std;

class Dice
{
    int top;    //1
    int front;  //2
    int right;  //3
    int left;   //4
    int back;   //5
    int bottom; //6
public:
    void diceroll(const char *dir);
    Dice(int top, int front, int right, int left, int back, int bottom);
    int show_top();
};

void Dice ::diceroll(const char *dir)
{
    while (*dir)
    {
        int tmp;
        switch (*dir)
        {
        case 'E':
        {
            tmp = top;
            top = left;
            left = bottom;
            bottom = right;
            right = tmp;
            break;
        }
        case 'N':
        {
            tmp = top;
            top = front;
            front = bottom;
            bottom = back;
            back = tmp;
            break;
        }
        case 'S':
        {
            tmp = top;
            top = back;
            back = bottom;
            bottom = front;
            front = tmp;
            break;
        }
        case 'W':
        {
            tmp = top;
            top = right;
            right = bottom;
            bottom = left;
            left = tmp;
            break;
        }
        }
        dir++;
    }
}

Dice ::Dice(int top, int front, int right, int left, int back, int bottom)
{
    this->top = top;
    this->front = front;
    this->right = right;
    this->left = left;
    this->back = back;
    this->bottom = bottom;
}

int Dice ::show_top()
{
    return top;
}

int main()
{
    char direction[101]; //方位
    int top, front, right, left, back, bottom;
    cin >> top >> front >> right >> left >> back >> bottom;
    cin >> direction;
    Dice d(top, front, right, left, back, bottom);
    d.diceroll(direction);
    cout << d.show_top() << endl;
}



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


int main() {
  
  long N,K;
  cin>>N>>K;
  
  
  long sw;
  long res;
  
  if(N>=K){
    sw=N%K;
    if(K%2==0){
      if(sw>=K/2){
        res=K-sw;
      }else{
        res=sw;
      }
    }else if(sw>=K/2+1){
      res=K-sw;
    }else{
      res=sw;
    }
  }else{
    if(K%2==0){
      if(N>=K/2){
        res=K-N;
      }else{
        res=N;
      }
    }else if(N>=K/2+1){
      res=K-N;
    }else{
      res=N;
    }
  }
  
  cout<<res<<endl;
  
  
    
}



  

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

long long g(long long n) {
    return n * (n + 1) / 2;
}

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

    long long ans = 0;
    for (int i = 1; i <= N; i++) {
        long long x = N / i;
        ans += g(x) * i;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18 
 
using namespace std;

signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int n;
    cin>>n;
    map<string,int> m;
    while(n--)
    {
        string s;
        cin>>s;
        m[s]++;
    }
    cout<<"AC x "<<m["AC"]<<endl;
    cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<endl;
    cout<<"RE x "<<m["RE"]<<endl;
}

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

typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<pair<int,int> > a(N);
  REP(i,N) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  ll ans = 0;

  multiset<int> s;
  s.emplace(-1);
  s.emplace(-1);
  s.emplace(N);
  s.emplace(N);

//  for ( auto x: a)
//    cout << x.first << " " << x.second << endl;

  REP(i,N) {
    int idx = a[i].second;
    auto it = s.lower_bound(idx);
    ll r1 = *it; it++;
    ll r2 = *it;
    it--; it--;
    ll l1 = *it; it--;
    ll l2 = *it;
    ans += ((ll)((r2-r1) * (idx-l1)) + (ll)((r1-idx) * (l1-l2))) * (ll)a[i].first;
//    cout << idx << ":" << l2 << ", " << l1 << " - " << r1 <<  ", " << r2;
//    cout << " * " << a[i].first << " => " << ((ll)((r2-r1) * (idx-l1)) + (ll)((r1-idx) * (l1-l2))) * (ll)a[i].first << endl;
    s.emplace(idx);
  }
  cout << ans << endl;

}




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

using namespace std;

int main(){
  int su[1005]={};
  for(int i=1;i<500;++i){
    int j=i+1,tmp=i;
    while(j+tmp<=1000){
      su[j+tmp]++;
      tmp+=j; j++;
    }
  }
  int n;
  while(cin>>n && n){
    cout << su[n]<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3008
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1000000007;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
 
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

// 割り算の切り上げ処理
ll round_up(ll a, ll b) {
  return (a + b - 1) / b;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int n,m;
    cin >> n >> m;
    if(n == m){
      print("Yes");
    }else{
      print("No");
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
using ll = long long;
ll dp[525252];


int main() {
	int n;
	cin >> n;
	dp[0] = 0;
	for (int i=1; i<=n; i++) {
		ll a;
		cin >> a;
		dp[i] = dp[i-1] + a;
	}
	ll res = 1000000000000000000LL;
	for (int i=1; i<n; i++) {
		ll diff = abs(dp[i] - (dp[n]-dp[i]));
		res = min(res, diff);
	}
	cout << res << endl;
}

Measured memory_bytes: 1792
import Data.Char

ans :: String -> String
ans [] = []
ans (c:cs)
  | isUpper c  = (toLower c):(ans cs)
  | isLower c  = (toUpper c):(ans cs)
  | otherwise  = c:(ans cs)

main = do
  c <- getContents
  let i = lines c
      o = map ans i
  mapM_ putStrLn o
  

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n;cin >> n;
  vector<long long> vec(n,0);
  for (int i=0;i<n;i++) {
    long long a;cin >> a;
    vec[a-1]=i+1;
  }
  for (int i=0;i<n;i++) cout << vec[i] << endl;
  
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<iostream>
#define pb push_back
#define fi first
#define se second
#define sz(x)  x.size()
#define cl(x)  x.clear()
#define all(x)  x.begin() , x.end()
#define r(x)  scanf("%d", &x)
#define rr(x , y)  scanf("%d%d" , &x , &y)
#define rst(s)  scanf("%s" , s)
#define rl(x)  scanf("%lld" , &x)
#define rrl(x , y)  scanf("%lld%lld" , &x , &y)
#define w(x)  printf("%d" , x)
#define ww(x , y)  printf("%d %d" , x , y)
#define wl(x)  printf("%lld" , x)
#define wwl(x , y)  printf("%lld %lld" , x , y)
#define sp()  printf(" ")
#define en()  puts("")
#define rep(i , x , n)  for(int i = x ; i <= n ; i ++)
#define per(i , n , x)  for(int i = n ; i >= x ; i --)
#define mem0(x)  memset(x , 0 , sizeof(x))
#define mem_1(x)  memset(x , -1 , sizeof(x))
#define mem_inf(x)  memset(x , inf , sizeof(x))
#define mem__inf(x)  memset(x , -inf , sizeof(x))
#define p_queue priority_queue
#define debug(x)  cout << '*' << x << '\n'
#define ddebug(x , y)  cout << '*' << x << ' ' << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
using namespace std ;
//mt19937  rnd(chrono::high_resolution_clock::now().time_since_epoch().count()) ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef pair<int , ll> pil ;
typedef pair<ll , int> pli ;
typedef pair<double , double> pdd ;
const int inf = 0x3f3f3f3f ;
const ll mod = 1e9 + 7 ;
const int maxn = 1e5 + 5 ;
const int maxm = 30 ;
const double eps = 1e-6 ;
const double pi = acos(-1.0) ;
int n ;
int a[5] ;
char s[maxn][5] ;
vector<char> ans ;
void print()
{
	for(auto x : ans)  printf("%c\n" , x) ;
}
int main()
{
	r(n) ;
	rep(i , 0 , 2)  r(a[i]) ;
	bool flag = 0 ;
	rep(i , 1 , n)	rst(s[i]) ;
	rep(i , 1 , n)
	{
		int x = s[i][0] - 'A' , y = s[i][1] - 'A' ;
		if(a[y] == 0)  a[x] -- , a[y] ++ , ans.pb(s[i][1]) ;
		else if(a[x] == 0)  a[y] -- , a[x] ++ , ans.pb(s[i][0]) ;
		else
		{
			if(i == n)  a[x] -- , a[y] ++ , ans.pb(s[i][1]) ;
			else
			{
				if(y == s[i + 1][0] - 'A' || y == s[i + 1][1] - 'A')
				  a[x] -- , a[y] ++ , ans.pb(s[i][1]) ;
				else
				  a[y] -- , a[x] ++ , ans.pb(s[i][0]) ;
			}
		}
		if(a[x] < 0 || a[y] < 0)  flag = 1 ;
	} 
	if(!flag)  puts("Yes") , print() ;
	else  puts("No") ;
	return 0 ;
}

Measured memory_bytes: 4392
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  int N,k,i,j,d,max;
  int T[3];
  
  if (scanf("%d",&N)<1) exit(1);
  for (k=0;k<N;k++) {
    for (i=0;i<3;i++) {
      if (scanf("%d",&d)<1) exit(1);
      T[i] = d;
    }
    max = T[0];
    for (i=1;i<3;i++) if (max < T[i]) max = T[i];
    if (T[0]*T[0]+T[1]*T[1]+T[2]*T[2] == 2*max*max) printf("YES\n");
    else printf("NO\n");
  }
  
  return 0;
}

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

int main(){
	string s;
	cin>>s;
	int i,v,r=0;
	int n=s.size();
	for(i=0;i<n;i++){
		v = s[i]-'0';
		r = (r+v)%9;
	}
	if(r==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5+10;
int p[N];
set<pair<int,int>> s;
int main() {
	int n;
	cin >> n;
	for (int i=1;i<=n;i++) {
		int x;
		cin >> x;
		p[x] = i;
	}
	s.insert({1,n});
	ll ans = 0;
	for (int i=1;i<=n;i++) {
		auto c = --s.upper_bound({p[i],n+1});
		ans += 1ll*(p[i] - c->first + 1)*(c->second - p[i] + 1)*i;
		if (c->first != p[i]) s.insert({c->first,p[i]-1});
		if (c->second != p[i]) s.insert({p[i]+1,c->second});
		s.erase(c);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3328
a,b = map(int,input().split())

S  = (a-1)*(a-2)//2
def solve(x,y,s):
    print(a+s-y-1)
    for i in range(1,a):print(1,1+i)
    c = s-b
    for i in range(1,a):
        for I in range(i+1,a):
            if c > 0:
                print(i+1,I+1)
                c-=1
            else:exit()
# print(b,S)
if not 0<= b <= S:
    print(-1)
    exit()
else:
    solve(a,b,S)


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

public class P
{
    public int id { get; set; }
    public int s { get; set; }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var ps = new P[n];
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var a = Array.ConvertAll(line, int.Parse);
                ps[i] = new P { id = a[0], s = getScore(a) };
            }
            foreach (var x in ps.OrderByDescending(y => y.s).ThenBy(y => y.id))
                Console.WriteLine("{0} {1}", x.id, x.s);
        }
    }
    static int getScore(int[] a)
    {
        var p = 1; var s = 0;
        for (int i = 1; i <= 9; i++)
        {
            if (a[p] == 10) { s += 10 + a[p + 1] + a[p + 2]; p++; }
            else if (a[p] + a[p + 1] == 10) { s += 10 + a[p + 2]; p += 2; }
            else { s += a[p] + a[p + 1]; p += 2; }
        }
        for (int i = p; i < a.Length; i++) s += a[i];
        return s;
    }
}



Measured memory_bytes: 16288
#include<iostream>
#include<cmath>
using namespace std;
long long x,ys=1,sq,t,cnt,ans;
int check(long long y)
{
    long long u=x;
    while(u%y==0) u/=y;
    return u%y==1;
}
int main()
{
     long long i;
     cin>>x;
     sq=sqrt(x-1);
     t=x-1;
     ans=2;
     for(i=2;i<=sq;i++)
     {
         if(t==i*i) ans++;
         else if(t%i==0) ans+=2;
     }
     t=sqrt(x);
     for(i=2;i<=t;i++)
     {
          if(x%i==0&&check(i)==1) 
          {
              //cout<<i<<endl;
              ans+=check(i);
          }
     }
     if(x==2) ans=1;
     cout<<ans;
     cin>>i; 
}
     
             


Measured memory_bytes: 256
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
#define biggest(A,B) A=max(A,B)
#define smallest(A,B) A=min(A,B)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
const int MAXN=5e5+10;
vector<int> g[MAXN];
int n,m,low[MAXN],deep[MAXN];
bool vis[MAXN];
void dfs(int now,int pre=0,int depth=0){
	low[now]=deep[now]=depth;
	vis[now]=1;
	for(auto it:g[now]){
		if(it!=pre){
			if(vis[it]){
				low[now]=min(low[now],deep[it]);
			}
			else{
				dfs(it,now,depth+1);
				low[now]=min(low[now],low[it]);
			}
		} 
	}
}
int main(){
	fastio;
	R2(n,m);
	rb(i,1,m){
		int u,v;
		cin>>u>>v;
		g[u].PB(v);
		g[v].PB(u);
	} 
	dfs(1);
	int res=0;
	rb(i,1,n){
		res+=(low[i]==deep[i]);	
	}
	res--;
	cout<<res<<endl;
	return 0;
}
/*
INPUT:
7 7
1 3
3 4
4 5
5 6
6 4
6 7
7 2
OUTPUT:
4
*/

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

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

    vector<int> a(N);
    for(auto &x: a){
        cin >> x;
    }
    int sum  = 0;
    for(int i = 0; i < N; i++){
        if((i+1) % 2 == 1){
            if(a.at(i) % 2 == 1){
                sum++;
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
vector<bitset<50>> vec;
long long sum[1010] = { 0 };
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		long long a;
		cin >> a;
		sum[i] += a;
		sum[i] += sum[i - 1];
	}
	for (int i = 0; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			vec.emplace_back(sum[j] - sum[i]);
		}
	}
	long long ans = 0;
	for (int i = 49; i >= 0; i--) {
		int co = 0;
		vector<bitset<50>> vec1;
		for (int j = 0; j < vec.size(); j++) {
			if (vec[j][i]) {
				co++;
				vec1.emplace_back(vec[j]);
			}
		}
		if (co >= k) {
			vec = vec1;
			long long t = 1;
			for (int j = 0; j < i; j++) {
				t *= 2;
			}
			ans += t;
		}
	}
	cout << ans << endl;
}


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

#define ull unsigned ll
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (ll i = l; i < r; i++)
#define repb(i, r, l) for (ll i = r; i > l; i--)
#define sz(a) (ll)a.size()
#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll N = 100000;
const ll inf = (ll)1e9 + 1;
const ll big = (ll)1e18 + 1;
const ll P = 31;
const ll MOD = (ll)1e9 + 7;
const ll MOD1 = (ll)1e9 + 9;
const ll MAX_ll = (1 << 31) - 1;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("battleship.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    ll n;
    ll a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i, 0, n)
        cin >> x[i];
    ll a1[n], b1[n];
    a1[0] = 0; b1[0] = 0;
    rep(i, 1, n)
    {
        if (x[i]- x[i - 1] < a)
            a1[i] = 1;
        else
            a1[i] = 0;
        if (x[i] - x[i - 1] < b)
            b1[i] = 1;
        else
            b1[i] = 0;
        a1[i] += a1[i - 1];
        b1[i] += b1[i - 1];
    }
    ll dp[n][2];
    rep(i, 0, n)
        rep(j, 0, 2)
            dp[i][j] = 0;
    rep(i, 0, n)
    {
        ll p = upper_bound(x.begin(), x.end(), x[i] - a) - x.begin();
        if (p == i)
        {
            if (i == 0)
                dp[i][0] = 1;
            else
                dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
        }
        else
        {
            if (b1[i - 1] - b1[p] > 0)
                dp[i][0] = 0;
            else
                dp[i][0] = dp[p][1];
        }

        p = upper_bound(x.begin(), x.end(), x[i] - b) - x.begin();
        if (p == i)
        {
            if (i == 0)
                dp[i][1] = 1;
            else
                dp[i][1] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
        }
        else
        {
            if (a1[i - 1] - a1[p] > 0)
                dp[i][1] = 0;
            else
                dp[i][1] = dp[p][0];
        }
    }
    cout << (dp[n - 1][0] + dp[n - 1][1]) % MOD;
    return 0;
}


Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] A = new long[n];
        for (int i = 0; i < n; ++i) {
            A[i] = sc.nextLong();
        }

        long res = 0L;
        for (int i = 0; i < n; ++i) {
            res += A[i] / 2;
            A[i] %= 2L;

            if (A[i] > 0 && i + 1 < n && A[i + 1] > 0) {
                A[i + 1]--;
                A[i]--;
                res++;
            }
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 61792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B, p1, p2;
  cin >> N >> A >> B;
  p1 = N * A;
  p2 = B;
  
  if (p1 >= p2) {
    cout << p2 << endl;
  } else {
    cout << p1 << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char ss1[101],ss2[101];
int main()
{
    gets(ss1);
    gets(ss2);
    int n=strlen(ss1);
    int m=strlen(ss2);
    sort(ss1,ss1+n);
    sort(ss2,ss2+m);
    for(int i=0;i<fmax(n,m);i++)
    {
        if(ss1[i]<ss2[m-i-1])
        {
            printf("Yes\n");
            return 0;
        }
        if(ss1[i]>ss2[m-i-1])
            break;
    }
    printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>	// 入出力
#include<stdio.h>	// printf()が使える 小数は%fで
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか

using namespace std;

using ll = long long;


int main()
{
	int x, a, b;

	cin >> x >> a >> b;

	int s = abs(x - a), t = abs(x - b);
	
	cout << ((s < t) ? "A" : "B") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mxn = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    if(s[s.length()-1] == 's'){
        s += "es";
    }
    else{
        s += "s";
    }
    cout << s;
    return 0;
}


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

using namespace std;

using ll = long long;

const ll MAX_N = 2 * 100000 + 5;
const ll MOD = 1000000007;

vector<ll> fac(MAX_N), finv(MAX_N), inv(MAX_N);

void init(int N) {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i <= N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll combi(int n, int k) {
  if (n < k || n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

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

  init(N);

  K = min(N - 1, K);

  ll ans = 1;
  for (int k = 1; k <= K; k++) {
    ll c = (combi(N, k) * combi(N - 1, k)) % MOD;
    ans = (ans + c) % MOD;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
import itertools
N = list(map(int, list(str(input()))))

def f():
    for pm in itertools.product(range(2), repeat = 3):
        ans = N[0]
        lst = []
        for i in range(3):
            if pm[i] == 1:
                ans += N[i + 1]
                lst.append("+")
            else:
                ans -= N[i + 1]
                lst.append("-")
        if ans == 7:
            for i in range(3):
                print(N[i], end = "")
                print(lst[i], end = "")
            print(N[-1], end = "")
            print("=7")
            return 0

f()

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

int main() {
    long long int n, sum = 0;
    cin >> n;
    long long int a[n];
    map<long long int, long long> mp;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        sum ^= a[i];
    }
    for(int i = 0; i < n; ++i) {
        cout << (sum^a[i]) << ' ';
    }
    cout << '\n';

}


Measured memory_bytes: 5104
strings=[]

while(1):
    try:
        s=input()
    except:
        break
    
    strings.append(s)

pattern=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
ans=[0 for i in range(26)]

for string in strings:
    s=list(string.lower())
    for letter in s:
        try:
            #print(ord(letter))
            ans[ord(letter)-97]+=1
        except Exception:
            pass

for i in range(26):
    print(pattern[i]+" : "+str(ans[i]))





Measured memory_bytes: 5568
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

const int MAX_N = 200020;

ll modpow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = modpow(a, b/2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * modpow(a, b-1)) % MOD;
    }
}

ll fact[MAX_N], finv[MAX_N];
ll comb(int n, int r){
    if(n < r || r < 0) return 0;
    return fact[n] * finv[n-r] % MOD * finv[r] % MOD;
}

void calc(int n){
    fact[0] = finv[0] = 1;
    for(int i=1; i<=n; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        finv[i] = modpow(fact[i], MOD-2);
    }
}

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

    calc(200010);

    ll n, m, k; cin>>n>>m>>k;

    ll ans = 0;
    for(int i=1; i<n; i++){
        ans += i * (n - i) * m * m;
        ans %= MOD;
    }

    for(int i=1; i<m; i++){
        ans += i * (m - i) * n * n;
        ans %= MOD;
    }

    ans *= comb(n * m - 2, k - 2);
    ans %= MOD;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define vec vector<ll>
#define inf 10000000000000000
bool mark[100005];
vec adj[100005];
ll counter;
vec cnt;
vector<string> forsubs;
ll b=1000000000000;
ll a[100005];
ll ans=0;
ll n;

	

int main()
{    
 

	#ifdef APNA_IO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
		    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

ll a,b,c;
cin>>a>>b>>c;
ll path1=min(a,b);
ll path2;

if(path1==a)
	path2=min(b,c);
else
	path2=min(a,c);

cout<<path1+path2<<endl;

		
}		





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

using namespace std;

template <typename T>
struct SegmentTree {
private:
	size_t n;
	vector<T> node;
	T M0;

public:
	SegmentTree(const vector<T>& v, T m0) {
		M0 = m0;
		n = 1;
		while (n < v.size()) { n *= 2; }
		node.assign(2*n - 1, M0);

		for (int i = 0; i < v.size(); ++i) {
			node[n - 1 + i] = v[i];
		}
		for (int i = n - 2; i >= 0; --i) {
			node[i] = merge(node[2*i + 1], node[2*i + 2]);
		}
	}
	
	T merge(T a, T b) { return a + b; }

	void update(int x, T val) {
		x += (n - 1);
		node[x] = val;
		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = merge(node[2*x + 1], node[2*x + 2]);
		}
	}

	T query(int a, int b, int k=0, int l=0, int r=-1) {
		if (r < 0) { r = n; }
		if ((r <= a) || (b <= l)) { return M0; }
		if ((a <= l) && (r <= b)) { return node[k]; }

		T vl = query(a, b, 2*k + 1, l, (l + r) / 2);
		T vr = query(a, b, 2*k + 2, (l + r) / 2, r);
		return merge(vl, vr);
	}
};

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

	SegmentTree<int> sg(vector<int>(N, 0), 0);
	sg.update(idx[N], 1);

	Int ans = 0;
	for (Int i = N - 1; i > 0; --i) {
		int l1 = -1, l2 = -1, r1 = -1, r2 = -1;
		int ix = idx[i];
		if (ix > 0 && sg.query(0, ix) > 0) {
			int low = 0, high = ix;
			while (high - low > 1) {
				int mid = (low + high) / 2;
				if (sg.query(mid, ix) > 0) { low = mid; }
				else { high = mid; }
			}
			l1 = low;
		}
		if (ix > 0 && sg.query(0, ix) > 1) {
			int low = 0, high = ix;
			while (high - low > 1) {
				int mid = (low + high) / 2;
				if (sg.query(mid, ix) > 1) { low = mid; }
				else { high = mid; }
			}
			l2 = low;
		}
		if (ix+1 < N && sg.query(ix + 1, N) > 0) {
			int low = ix + 1, high = N;
			while (high - low > 1) {
				int mid = (high + low) / 2;
				if (sg.query(ix + 1, mid) > 0) { high = mid; }
				else { low = mid; }
			}
			r1 = low;
		}
		if (ix+1 < N && sg.query(ix + 1, N) > 1) {
			int low = ix + 1, high = N;
			while (high - low > 1) {
				int mid = (high + low) / 2;
				if (sg.query(ix + 1, mid) > 1) { high = mid; }
				else { low = mid; }
			}
			r2 = low;
		}
		// cerr << "ix = " << ix << endl;
		// cerr << "i, l1, l2, r1, r2 = " << i << " " << l1 << " " << l2 << " ";
		// cerr << r1 << " " << r2 << endl;
		if (l1 >= 0) {
			Int l = l1 - l2;
			Int r = (r1 < 0 ? N : r1) - ix;
			// cerr << "if1 : l, r = " << l << " " << r << endl;
			ans += i * l * r;
		}
		if (r1 >= 0) {
			Int r = (r2 < 0 ? N : r2) - r1;
			Int l = ix - l1;
			// cerr << "if2 : l, r = " << l << " " << r << endl;
			ans += i * l * r;
		}
		sg.update(ix, 1);
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
    int A,B,C;
    long long X,Y;
    cin >> A >> B >> C >> X >> Y;
    long long ans1=0;
    long long ans2=0;
    long long ans=0;

    if((A+B) > 2*C){
        ans1 = min(X,Y)*2*C + max(0LL,X-min(X,Y))*A +max(0LL,Y-min(X,Y))*B;
        ans2 = max(X,Y)*2*C;
        ans = min(ans1,ans2);
    } else {
        ans = A*X + B*Y;
    }
    cout << ans << endl;
}

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

#define MOD 1000000007

int isPrime(int x)
{
    if (x == 1)
    {
        return 0;
    }
    if (x == 2)
    {
        return 1;
    }
    for (int i = 2; i <= x / 2; i++)
    {
        if (x % i == 0)
        {
            return 0;
        }
    }
    return 1;
}
int calculeazaPutere(int nr, int prime)
{
    int P = prime;
    int sum = 0;
    while (nr >= P)
    {
        sum += nr / P;
        P = P * prime;
    }
    return sum;
}
int main()
{
    int n;
    cin >> n;
    long long nrDivs = 1;
    for (int i = 2; i <= n; i++)
    {
        if (isPrime(i) == 1)
        {
            nrDivs = ((nrDivs % MOD) * ((calculeazaPutere(n, i) + 1) % MOD)) % MOD;
        }
    }
    cout << nrDivs;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n, p[100], a, b, i, aa = 0, ab = 0, ac = 0, ans = 100;
  scanf("%d", &n);
  scanf("%d %d", &a, &b);
  for(i = 0; i < n; ++i) {
    scanf("%d", &p[i]);
    if(p[i] <= a) aa++;
    if(p[i] >= a + 1 && p[i] <= b) ab++;
    if(p[i] >= b + 1) ac++;
  }
  if(ans > aa) ans = aa;
  if(ans > ab) ans = ab;
  if(ans > ac) ans = ac;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
N,M=map(int,input().split())
COSTLIST=[list(map(int,input().split())) for i in range(M)]#aからbへのcostがx

#グラフの最短距離を全て求める（ワーシャル–フロイド法）

Distance=[[float("inf") for i in range(N+1)] for j in range(N+1)]

for i,j,t in COSTLIST:
    Distance[i][j]=Distance[j][i]=t#分かっている距離を書き込んでおく.

for k in range(1,N+1):#k個までの町を使ってのDisが知れているときに
    for i in range(1,N+1):#町iと
        for j in range(i,N+1):#町jとの最短距離は、
            length=Distance[i][k]+Distance[j][k]
            if Distance[i][j]>length:
                Distance[i][j]=Distance[j][i]=length
        

ANS=0
for i ,j,t in COSTLIST:
    if Distance[i][j]!=t:
        ANS+=1

print(ANS)

Measured memory_bytes: 3572
N = int(input())
count = 0
if N<105:
    print(0)
else:
    for i in range(105,N+1):
        yaku = 0
        if i%2 == 1:
            for j in range(1,i+1):
                if i%j == 0:
                    yaku += 1
            if yaku == 8:
                count += 1
    print(count)

Measured memory_bytes: 63120
#include <iostream>
#include <string>

int main(void)
{
	//
	int N;
	N = 0;
	std::cin >> N;
	//A
	int *A =new int[N]();
	int *B = new int[N]();
	int *C = new int[N]();
	for (int i = 1; i <= N; i++)
	{
		while (!(std::cin >> A[i])) {}
		//std::cout << A[i] << std::endl;
		//
	}
	//B
	int sum = 0;
	for (int i = 1; i <= N; i++)
	{
		while (!(std::cin >> B[i])) {}
	}
	//C
	for (int i = 1; i < N; i++)
	{
		sum += B[A[i]];
		//std::cout << B[A[i]] << std::endl;
		//std::cout << sum << std::endl;
		while (!(std::cin >> C[i])) {}
	}
	sum += B[A[N]];
	for (int i = 1; i < N; i++)
	{
		if (A[i] + 1 == A[i + 1])
		{
			sum += C[A[i]];
		}
		//std::cout << sum << std::endl;
	}
	//

	std::cout << sum << std::endl;
	return 0;
}


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

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

long long MOD = 10000000000 + 7;
template<class T>
using MaxHeap = std::priority_queue<T>;

int main(){
  cout << setprecision(10);
  int N,M; cin >> N >> M;

  MaxHeap<ll> h;
  for(int i = 0; i < N; i++){
    ll tmp; cin >> tmp;
    h.push(tmp);
  }
  
  while(M>0){
    ll now = h.top();
    h.pop();
    now /= 2;
    h.push(now);
    M--;
  }
  ll ans = 0;
  while(!h.empty()){
    ll now = h.top();
    ans += now;
    h.pop();
  }
  cout << ans << endl;


}


Measured memory_bytes: 4288
import java.util.ArrayList;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = scan.next();
		int n;
		int[] array; int[] box; int t;
		while (str.equals("-") == false) {
			n = scan.nextInt();
			array = new int[str.length()];
			box = new int[str.length()];
			for (int i = 0; i < str.length(); i++) {
				array[i] = i;
			}
			for (int i = 0; i < n; i++) {
				t = scan.nextInt();
				for (int j = 0; j < array.length; j++) {
					box[j] = array[(j + t) % array.length];
						
				}
				for (int j = 0; j < array.length; j++) {
					array = (int[])box.clone();
				}
				//System.out.println(box[0]+" "+box[1]+" "+box[2]+" "+box[3]+" "+box[4]);
			}
			for (int j = 0; j < str.length(); j++) {
				System.out.print(str.charAt(box[j]));
			}
			System.out.println();
			str = scan.next();
		}
	}

}

Measured memory_bytes: 42020
import sys


while True:
    j = 1
    h,w = map(int,raw_input().split())
    if h == 0 and w == 0:
        break
    while j <= h:
        i = 1
        if j % 2:
            while i <= w:
                if i % 2:
                    sys.stdout.write("#")
                elif not i % 2:
                    sys.stdout.write(".")
                if not i % w:
                    sys.stdout.write("\n")
                i +=1
        if not j % 2:
            while i <= w:
                if i % 2:
                    sys.stdout.write(".")
                elif not i % 2:
                    sys.stdout.write("#")
                if not i % w:
                    sys.stdout.write("\n")
                i +=1
        j += 1
    sys.stdout.write("\n")

Measured memory_bytes: 4236
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  long n, m; rd(n, m);

  if(n>m) swap(n, m);
  if((m-n)>=2){
    writeln(0);
    return;
  }
  long tot=1, mod=10^^9+7;
  for(int i=1; i<=n; i++) (tot*=i)%=mod;
  for(int i=1; i<=m; i++) (tot*=i)%=mod;
  if(n==m) (tot*=2)%=mod;
  writeln(tot);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


Measured memory_bytes: 256
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

count = 0

stack = set()
visited = []
visited_set = set()
endf = False

current = 0
while True:
    i = A[current]-1
    visited_set.add(current)
    visited.append(current)

    if not i in visited_set:
        current = i
        count += 1
    else:
        leng = len(visited_set)
        roop_len = leng - visited.index(i)
        header_len = leng - roop_len
        break

    if count >= K:
        endf = True
        print(i+1)
        break

if not endf:
    roop_ind = (K - header_len + 1) % roop_len
    if roop_ind == 0:
        print(visited[-1]+1)
    else:
        print(visited[header_len + roop_ind-1]+1)

Measured memory_bytes: 35448
#include <fstream>
#include <cmath>
#include <bitset>
#include <vector>
#include <iostream>

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 998244353
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= (a); i--)
#define RF0(i,b) RFO(i,0,b)
#define lli long long int
#define pii pair<int,int>
#define add(a,b) ((int) (((lli) (a) + (b))%MOD))
#define mul(a,b) ((int) (((lli) (a) * (b))%MOD))
#define PB emplace_back
#define F first
#define S second

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int H, W, K;
int psum [11][1001] = {{0}};

int mxw(vector<int>& inds, int st, int ed) { // not including st
    int ans = 0;
    F0R(i,inds.size()-1) {
        ans = max(ans, psum[inds[i+1]][ed] - psum[inds[i]][ed] - psum[inds[i+1]][st] + psum[inds[i]][st]);
    }
    return ans;
}

int sv(string bn) {
    int dp [1001];
    dp[0] = -1;
    vector<int> inds;

    // cout << bn << '\n';

    inds.PB(0);
    FOR(i,1,H) if (bn[9-H+i] == '1') inds.PB(i);
    inds.PB(H);

    // for (int x: inds) cout << x << ' ';
    // cout << '\n';

    int ind = 0;
    FOR(i,1,W+1) {
        while (mxw(inds, ind, i) > K) ind++;
        if (ind >= i) return 1000000000;
        // cout << "i: " << i << " ind: " << ind << " mxw: " << mxw(inds,ind,i) << '\n';
        dp[i] = dp[ind]+1;
    }
    // cout << "ret: " << dp[W] << '\n';
    return dp[W];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> H >> W >> K;
    FOR(i,1,H+1) FOR(j,1,W+1) {
        char a; cin >> a;
        psum[i][j] = a-'0';
        psum[i][j] += psum[i][j-1];
    }
    FOR(j,1,W+1) FOR(i,1,H+1) psum[i][j] += psum[i-1][j];

    // F0R(i,H+1) {
    //     F0R(j,W+1) cout << psum[i][j] << ' ';
    //     cout << '\n';
    // }

    int ans = 1000000000;
    const int sz = H-1;
    F0R(i,pow(2,H-1)) {
        ans = min(ans, __builtin_popcount(i) + sv(bitset<9>(i).to_string()));
    }
    cout << ans << '\n';
}

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

struct dsu {
  int cc;
  vector<int> p, sz;
  dsu(int n) : cc(n), p(n, -1), sz(n, 1) {}
  int root(int v) const {
    while (p[v] != -1) v = p[v];
    return v;
  }
  bool unite(int u, int v) {
    u = root(u), v = root(v);
    if (u == v) return false;
    --cc;
    if (sz[u] < sz[v]) swap(u, v);
    p[v] = u;
    sz[u] += sz[v];
    return true;
  }
  bool same(int u, int v) const { return root(u) == root(v); }
  int size(int v) const { return sz[root(v)]; }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, q;
  long long m;
  cin >> n >> m >> q;
  vector<int> a(q), b(q), c(q);
  dsu d(n);
  for (int i = 0; i < q; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    if (c[i] == 0) {
      d.unite(a[i], b[i]);
    }
  }
  for (int i = 0; i < q; ++i) {
    if (c[i] == 0) {
      continue;
    }
    if (d.same(a[i], b[i]) or d.cc < 3 or m == n - 1) {
      cout << "No\n";
      exit(0);
    }
  }
  if (m > (long long)d.cc * (d.cc - 1) / 2 + (n - d.cc)) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <set>
using ll = long long;
using namespace std;
#define INF 999999999

int main()
{
    int n;
    list<int> h;
    int tmp;
    cin >> n;
    int max_h = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> tmp;
        h.push_back(tmp);
        max_h = max(tmp, max_h);
    }
    int ans = 0;
    for (int i = 1; i <= max_h; i++)
    {
        int count = 0;
        bool s = false;
        for (auto v : h)
        {
            if (v < i)
                s = false;
            else
            {
                if (!s)
                    count++;
                s = true;
            }
        }
        //cout << count << endl;
        ans += count;
    }
    cout << ans << endl;
    return 0;
}

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

MAX_INT = 9999999999999999

N,x=gets.chomp.split(' ').map{|n| n.to_i}
A=gets.chomp.split(' ').map{|n| n.to_i}.sort
cnt = 0
sum = 0
for i in 0..(N-1)
	if(sum + A[i] > x)
		break
	end
	sum += A[i]
	cnt += 1
end
if(x > A.inject(0){|a,sum| sum + a})
	cnt -= 1
end
puts cnt

Measured memory_bytes: 2172
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <math.h>

using namespace std;

int main(){
    int n;
    string str;
    cin >> n >> str;
    if(n % 2 == 1) cout << "No" << endl;
    else{
        string s1 = "", s2 = "";
        for(int i = 0; i < n; i++){
            if(i < n/2) s1 += str[i];
            else s2 += str[i];
        }
        //cout << "s1: " << s1 << endl;
        //cout << "s2: " << s2 << endl;
        string ans = s1 == s2 ? "Yes": "No";
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
import sys
sys.setrecursionlimit(10000)

def nasu(A, B, L, D, M):
  if L == 1:
    return A
  ans = nasuA(A, L, D, M)
  ans = (ans + nasuB(1, L - 1, D, M) * B * D) % M
  return ans % M

def nasuB(B, L, D, M):
  if L == 1:
    return B
  ans = powB(1, L, D, M) % M
  return ans % M

def powB(B, L, D, M):
  if L == 1:
    return B
  k = 0
  t = D
  while T[k + 1] <= L:
    k += 1
    t = t * t % M
    if k + 1 == len(T):
      break
  ans = powB2(B, T[k], D, M) % M
  if L != T[k]:
    ans += nasu(T[k] + 1, 1, L - T[k], D, M) * t % M 
    #ans += powB(1, L - T[k], D, M) * t % M
    #ans += powA(-T[k], L - T[k], D, M) * t % M
  return ans % M
 
def powB2(B, L, D, M):
  if L == 1:
    return 1
  ans = powB2(B * 2, L // 2, D * D % M, M) * (D + 1) % M
  ans = ans + nasuA(1, L // 2, D * D % M, M) * B * D % M
  return ans

def nasuA(A, L, D, M):
  if L == 1:
    return A
  ans = powA(A, L, D, M) % M
  return ans % M

def powA(A, L, D, M):
  if L == 1:
    return A
  k = 0
  t = D
  while T[k + 1] <= L:
    k += 1
    t = t * t % M
    if k + 1 == len(T):
      break
  ans = powA2(A, T[k], D, M)
  if L != T[k]:
    ans +=  powA(A, L - T[k], D, M) * t % M
  return ans % M
 
def powA2(A, L, D, M):
  if L == 1:
    return A
  return powA2(A, L // 2, D * D % M, M) * (D + 1) % M

def powmod(a, n, M):
  ans = 1
  while n:
    if n & 1:
      ans = (ans * a) % M
    a = a * a % M
    n >>= 1
  return ans

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

N = math.ceil(math.log(A + 1, 10))
k = pow(10, N)
D = [[0, 0] for _ in range(20)]
while L > 0:
  n = min(L, (k - 1 - A) // B + 1)
  D[N - 1][0] = A
  D[N - 1][1] = n
  L -= n
  N += 1
  k *= 10
  A += n * B
T = [1]
while T[-1] < 10 ** 19:
  T.append(T[-1] * 2)
BI = (((B // M) + 1) * M - B) % M
ans = 0
for i in range(20):
  l = D[i][1]
  a = D[i][0] + (l - 1) * B
  if l == 0:
    continue
  ans = ans * powmod(pow(10, i + 1), l, M) % M
  ans = (ans + nasu(a, BI, l, pow(10, i + 1), M)) % M
print(ans)

Measured memory_bytes: 3572
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring> 

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;

long long mod_div(long long a, long long b) {
	if (a % b == 0)return a / b;
	long long tmp = MOD - 2, c = b, ret = 1;
	while (tmp > 0) {
		if (tmp & 1) {
			ret *= c; ret %= MOD;
		}
		c *= c; c %= MOD; tmp >>= 1;
	}
	return a*ret%MOD;
}

char str[100011];
int dp[4][100011];

int main() {

	scanf("%s",str);
	int len = strlen(str);

	ll tmp = 1;
	ll cou = 0;
	REP(i, len) {
		if (str[i] == '?')cou++;
	}
	REP(i, cou) {
		tmp *= 3;
		tmp %= MOD;
	}

	dp[0][0] = tmp;
	REP(i, len) {
		REP(j, 4) {
			if (dp[j][i]) {
				if (j < 3) {
					if (str[i] == 'A' + j) {
						dp[j + 1][i + 1] += dp[j][i];
						dp[j + 1][i + 1] %= MOD;
					}
					else if (str[i] == '?') {
						dp[j + 1][i + 1] += mod_div(dp[j][i], 3);
						dp[j + 1][i + 1] %= MOD;
					}
				}
				dp[j][i + 1] += dp[j][i];
				dp[j][i + 1] %= MOD;
			}
		}
	}

	printf("%d\n", dp[3][len]);

	return 0;
}


Measured memory_bytes: 1920
#include <cstring>
#include <cstdio>
using ll = long long;
char str[2000005];
int main()
{
	// freopen("AGC029-A.in", "r", stdin);
	scanf("%s", str);
	int n = strlen(str), cur = 0;
	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (str[i] == 'W')
			ans += i - cur++;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384