akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
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; }


void solve(){
    ll n;
    ll a[100];
    cin>>n;
    rep(i,n) cin>>a[i];
    ll b[100]={};
    b[n-1]=a[n-1];
    for(ll i=n-2;i>=0;i--){
        b[i]=max(a[i],b[i+1]);
    }
    ll dp[100]={};
    dp[0]=1000;
    rep(i,n){
        if(i>0)chmax(dp[i],dp[i-1]);
        rep(x,i){
            chmax(dp[i],dp[x]%a[x]+dp[x]/a[x]*a[i]);
        }
    }
    cout<<dp[n-1]<<endl; 

}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    
     

    solve(); 


    return 0;
}


Measured memory_bytes: 3552
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
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; }
//#define int long long

//連続部分列は累積的構造で考えるとよし！！！！！！！！！！！！

void solve() {
	string s, t; cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<int> S(n + 1, 0), T(m + 1, 0);
    rep(i, n) {
        if(s[i] == 'A') {
            S[i + 1] = S[i] + 2;
        } else {
            S[i + 1] = S[i] + 1;
        }
    }
    rep(i, m) {
        if(t[i] == 'A') {
            T[i + 1] = T[i] + 2;
        } else {
            T[i + 1] = T[i] + 1;
        }
    }
    int q; cin >> q;
    while(q--) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        --a; --c;
        if((S[b] - S[a]) % 3 == (T[d] - T[c]) % 3) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 1744
from itertools import accumulate
N = int(input())

M = [[0] * 20 for _ in range(20)]

As = []
for _ in range(N):
    a = input()
    if '.' not in a:
        a += '.0'
    big, small = a.split('.')
    big = int(big)
    small = int((small + '000000000')[:9])
    A = big * 10 ** 9 + small

    bai2 = 0
    while A % 2 == 0:
        bai2 += 1
        A //= 2
        if bai2 >= 18:
            break
    bai5 = 0
    while A % 5 == 0:
        bai5 += 1
        A //= 5
        if bai5 >= 18:
            break
    As.append((bai2, bai5))
    M[0][0] += 1
    M[0][bai5+1] -= 1
    M[bai2+1][0] -= 1
    M[bai2+1][bai5+1] += 1

# imosu hou
M2 = map(lambda row: list(accumulate(row)), M)
M3 = map(lambda col: list(accumulate(col)), zip(*M2))
M4 = list(zip(*M3))

ans = 0
for bai2, bai5 in As:
    ans += M4[18-bai2][18-bai5]
    if bai2 >= 9 and bai5 >= 9:
        ans -= 1
print(ans // 2)


Measured memory_bytes: 95152
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
using namespace std;
using ll = long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
ll func(ll x,ll y){
  if(y == 0){return x;}
  return func(y,x%y);
}
int main(){
  ll n;
  cin >> n;
  ll a[n];
  ll sum;
  rep(i,n){
    cin >> a[i];
    if(i == 0){
      sum = a[i];
    }else{
      sum = sum > a[i] ? func(sum,a[i]) : func(a[i],sum);
    }
  }
  cout << sum;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin>>S;
int count=0;
for(int i=0; i<4; i++){
    if(S.at(i)=='+'){
        count++;
    }
    else
    {
        count--;
    }
}
cout<<count<<endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=9999999999;
ll dp[2000][2000];

int main(){
    int H,W;
    cin>>H>>W;
    for(int h=0;h<=H;h++) dp[h][0]=0;
    for(int w=0;w<=W;w++) dp[0][w]=0;
    vector<string> s(H+3);
    for(int h=0;h<H;h++) cin>>s[h];
    for(int h=1;h<=H;h++){
        for(int w=1;w<=W;w++){
            if(s[h-1][w-1]=='#'){
                dp[h][w]=0;
            }else if(h==1 && w==1){
                dp[1][1]=1;
            }else{
                dp[h][w]=(dp[h-1][w]+dp[h][w-1])%MOD;
            }
        }
    }
    cout<<dp[H][W]<<endl;
    return 0;
}

Measured memory_bytes: 17152
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

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 V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
#pragma endregion

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> h(n);
	int ma = -1;
	int cnt = 0;
	for(int i = 0; i < n; ++i){
		cin >> h[i];
		if(ma <= h[i]) cnt++;
		ma = max(ma, h[i]);
	}
	cout << cnt << endl;
}

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

int main()
{
    string s;
    cin >> s;
    for(int i=0; i < s.length() ; i++)
    {
        if( s[i] == ','){
             s[i] = ' ';

        }

    }
cout << s;





    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <utility>
#define INF 9999999999
using namespace std;
typedef long long int ll;

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

	int num = b- a - 1;
	cout << num*(num + 1) / 2 - a<< endl;
	
	// a(a+1)-(a+1)(a+2) / 2
	// a^2+a - a^2 - 3a - 2
	// -2a - 2 
	// -a-1
	// a+1

	return 0;
}


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

int
main(int argc,char *argv[])
{
  string s;
  cin >> s;
  
  int n = s.size();
  
  for(int i = 0; i < n; i++){
    if(s[i] == '1'){
      s[i] = '9';
    }
    else{
      s[i] = '1';
    }
  }
  
  cout << s << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){

    long int A,B;
    scanf("%ld %ld",&A,&B);
    long int kbsa,kbsb;
    for(int i=1;kbsa<=A*B;i++){
        kbsa = A*i;
      if(kbsa%B==0){
      	break;
      }
    }
    printf("%ld",kbsa);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
vector <int> g[N];
ll a[N],b[N];
map <int,int> mp;
ll vis[N];
ll ts=0;
void dfs(ll v){
    vis[v]=1;
    for (auto u : g[v]){
        if (!vis[u]) dfs(u);
    }
    return ;
}
int32_t main(){
    sync;
    ll n;
    cin >> n;
    ll x=0;
    vector <int> c,d;
    for (int i=1;i<=n;i++){
        cin >> a[i];
        x ^= a[i];
        c.pb(a[i]);
    }
    a[n+1]=x;
    c.pb(x);
    x=0;
    for (int i=1;i<=n;i++){
        cin >> b[i];
        x ^= b[i];
        d.pb(b[i]);
    }
    b[n+1]=x;
    n++;
    d.pb(x);
    sort(c.begin(),c.end());
    sort(d.begin(),d.end());
    for (int i=0;i<n;i++) if (c[i]!=d[i]) kill(-1);
    for (int i=0;i<n;i++) mp[c[i]]=i+1;
    for (int i=1;i<=n;i++) a[i]=mp[a[i]],b[i]=mp[b[i]];
    for (int i=1;i<n;i++){
        if (a[i]==b[i]) continue;
        g[b[i]].pb(a[i]);
        g[a[i]].pb(b[i]);
        ts++;
    }
    ts++;
    g[a[n]].pb(b[n]);
    g[b[n]].pb(a[n]);
    ll cnt=0;
    for (int i=1;i<=n;i++){
        if (g[i].size() && !vis[i]) dfs(i),cnt++;
    }
   // cout << cnt << endl;
    cnt--;
    ll ans=cnt+ts-1;
    if (ans==-1) ans=0;
    cout << ans << endl;


}


Measured memory_bytes: 25872
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int n, k;
vector<int> h;
long long dp[301][301][301];

long long dfs(int now, int cnt, short p){
    if(n < now){
        return 0;
    }
    if(~dp[now][cnt][p]) return dp[now][cnt][p];
    dp[now][cnt][p] = dfs(now + 1, cnt, now) + max(0, h[now] - h[p]);
    if(cnt < k){
        dp[now][cnt][p] = min(dp[now][cnt][p], dfs(now + 1, cnt + 1, p));
    }
    return dp[now][cnt][p];
}

int main(){
    cin >> n >> k;
    h.resize(n + 2);
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    memset(dp, -1, sizeof dp);
    cout << dfs(1, 0, 0) << "\n";
}

Measured memory_bytes: 213376
N=int(input())
def num2alpha(num):
	if num<=26:
		return chr(64+num)
	elif num%26==0:
		return num2alpha(num//26-1)+chr(90)
	else:
		return num2alpha(num//26)+chr(64+num%26)
S=num2alpha(N)
s=S.lower()
print(s)

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

int main() {
  int n;
  cin >> n;
  map<string, int> kinds;
  for(int i=0;i<n;i++) {
    string s;
    cin >> s;
    kinds[s]++;
  }
  cout << kinds.size() << "\n";
}


Measured memory_bytes: 19228
/*input
6 3
2 3
4 5
5 6
*/
 
#include <unordered_map>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<long long, long long> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
 
int visited[100010];
vector<int> adj[100010];
int n;
int dp[100010];
void dfs(int node){
	visited[node] = 1;
	for(int u:adj[node]){
		if(visited[u]==0){
			dfs(u);
		}
		dp[node] = max(dp[node],dp[u]+1);
	}

}
 
 
int main() {
	godspeed;
	memset(visited,0,sizeof(visited));
	cin>>n;
	int m;
	cin>>m;
	memset(dp,0,sizeof(dp));
	rep(i,m){
		int a;
		int b;
		cin>>a>>b;
		adj[a].push_back(b);
	}
	for(int i = 1; i<=n;i++){
		if(visited[i]==0){
			dfs(i);
		}
	}
	int ma = 0;
	rep(i,n+1){
		ma = max(ma,dp[i]);
	}
	cout<<ma<<endl;



}

Measured memory_bytes: 12484
import java.util.Scanner;

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

        while (sc.hasNext()) {
            String input = sc.next();
            input = input.toLowerCase();
            for (int i = 0; i < input.length(); i++) {
                for (int j = 0; j < 26; j++) {
                    if ((j+'a') == input.charAt(i)) {
                        cnt[j] += 1;
                    }
                }
            }
        }
        for (int i = 0; i < 26; i++) {
            System.out.println((char)('a'+i) + " : " + cnt[i]);
        }
    }
}


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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<int> sa(n-1);
  rep(i, n-1) {
    sa[i] = h[i] - h[i+1];
  }
  int cnt = 0;
  int ans = 0;
  rep(i, n-1) {
    if(sa[i] >= 0) ++cnt;
    else {
      cnt = 0;
    }
    ans = max(ans, cnt);
  }
  
  cout << ans << endl;
  return 0;
}
    

Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
 
int nth_bit(int num, int n){
    return (num >> n) & 1;
}
 
int main(){
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    for(int i=0; i<N; i++){
        cin >> C[i];
        for(int j=0; j<M; j++) cin >> A[i][j];
    }
 
    int ans = 1e9;
    for(int b=0; b<(1<<N); b++){
        vector<int> sum(M);
        int cost = 0;
        for(int i=0; i<N; i++) if(nth_bit(b, i)){
            cost += C[i];
            for(int j=0; j<M; j++) sum[j] += A[i][j];
        }
        if(*min_element(sum.begin(), sum.end()) >= X) ans = min(ans, cost);
    }
    if(ans == 1e9) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(){
	while(1){
	int n;
	scanf("%d", &n);
	if(n==0) break;	

	int i;
	int x,y;
	x = y = 0;
	for(i=0;i<n;i++){
		int a,b;
		scanf("%d%d", &a, &b);

		if(a>b) x+=a+b;
		else if(a==b) x+=a,y+=b;
		else y+= a+b;
	}
	printf("%d %d\n", x, y);
	}
}

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

using namespace std;

int main() {
  int pasta[3];
  int juice[2];
  cin >> pasta[0];
  cin >> pasta[1];
  cin >> pasta[2];
  cin >> juice[0];
  cin >> juice[1];
  int m = 100000;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 2; j++) {
      m = min(m, pasta[i] + juice[j]);
    }
  }
  cout << m - 50 << endl;

  return 0;
}

Measured memory_bytes: 0
# DPL_3_A: Largest Square

import sys
H, W = map(int, sys.stdin.readline().strip().split())
dp = [[0] * (W + 1) for _ in range(H + 1)]

for h in range(1, H + 1):
    c = list(map(int, sys.stdin.readline().strip().split()))
    dirty = [i for i, x in enumerate(c) if x == 1]
    for w in dirty:
        dp[h][w + 1] = 'dirty'

ans = 0
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if dp[h][w] == 'dirty':
            dp[h][w] =0
            continue
        dp[h][w] = min(dp[h][w - 1], dp[h - 1][w - 1], dp[h - 1][w]) + 1
        ans = max(dp[h][w], ans)

print(ans ** 2)



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

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

    int l, r;
    l = X-(K-1);
    r = X+(K+1);

    for(int i=1;i<2*K; i++){
        cout << l << " ";
        l++;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC160E
int compare_lli(const void *a, const void *b) {
  long long *A=(long long *) a, *B=(long long *) b;
  if(*A>*B) return 1;
  if(*A<*B) return -1;
  return 0;
}

int main(void) {
  long long x, y, a, b, c, m, k, i, cou=0;
  scanf(" %lld %lld %lld %lld %lld", &x, &y, &a, &b, &c);
  long long p[a], q[b], r[c];
  for(i=0; i<a; i++)
    scanf(" %lld", &p[i]);
  for(i=0; i<b; i++)
    scanf(" %lld", &q[i]);
  for(i=0; i<c; i++)
    scanf(" %lld", &r[i]);

  qsort(p, a, sizeof(long long), compare_lli); //sort
  qsort(q, b, sizeof(long long), compare_lli); //sort
  qsort(r, c, sizeof(long long), compare_lli); //sort

  i=a-x, k=b-y, m=c-1;
  while((p[i]<r[m]||q[k]<r[m])&&m>=0){
    if(p[i]<q[k]) p[i]=r[m], m--,i=i+1>=a ? i : i+1;
    else q[k]=r[m], m--, k=k+1>=b ? k : k+1;
  }
  for(i=a-x; i<a; i++)
    cou+=p[i];
  for(i=b-y; i<b; i++)
    cou+=q[i];
  printf("%lld", cou);
}

Measured memory_bytes: 3324
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
a=(t.count("r"))*p+(t.count("s"))*r+(t.count("p"))*s
for i in range(n-k):
    if t[i]==t[i+k]:
        if t[i]=="r":
            a-=p
        elif t[i]=="s":
            a-=r
        elif t[i]=="p":
            a-=s
        t[i+k]=i
print(a)


Measured memory_bytes: 5528
import numpy as np
i8 = np.int64
i4 = np.int32


def solve(a, b, N):
    ans = 0
    nmax = 2 ** N - 1
    for n in range(nmax, 0, -1):
        d = n
        count = 0
        for i in range(N - 1, -1, -1):
            if d & 1:
                count += 1
                if n & a[i] > 0 or n | b[i] < nmax:
                    break
            d >>= 1
        else:
            ans = max(ans, count)
    return ans


def main2():
    stdin = open('/dev/stdin')
    N = int(stdin.readline())
    x = np.empty((N, N), i8)
    x.fill(-1)
    for i in range(N):
        A = int(stdin.readline())
        for _ in range(A):
            a, y = map(int, stdin.readline().split())
            x[i, a - 1] = y
    a = np.zeros(N, i8)
    b = np.zeros(N, i8)
    for i in range(N):
        for j in range(N):
            a[i] <<= 1
            b[i] <<= 1
            if x[i, j] == 0:
                a[i] += 1
                b[i] += 1
            elif x[i, j] == -1:
                b[i] += 1
    ans = solve(a, b, N)
    print(ans)


main2()

Measured memory_bytes: 12508
x1,y1,x2,y2 = map(int,input().split())
x_vec = x2 - x1
y_vec = y2 - y1
x4,y4 = x1-y_vec, y1+x_vec
x3,y3 = x4+x_vec, y4+y_vec
print(x3,y3,x4,y4)

Measured memory_bytes: 2940
w,h,n=map(int,input().split())
x,y=0,0
for i in range(n):
  a,b,c=map(int,input().split())
  if c==1:
    x=max(x,a)
  elif c==2:
    w=min(w,a)
  elif c==3:
    y=max(y,b)
  else:
    h=min(h,b)
print(max((w-x),0)*max((h-y),0))

Measured memory_bytes: 3064
#include <stdio.h>
#include <vector>
#include <iostream>
using namespace std;

#define MAX 1000001

int main(){
    int n;
    int ans_odd[MAX], ans[MAX];
    int tmp, i = 1, j;
    vector<int> odd, normal;

    for(j = 0; j < MAX; j++){
        ans_odd[j] = j;
        ans[j] = j;
    }

    while(tmp < MAX){
        tmp = i * (i + 1) * (i + 2) / 6;
        normal.push_back(tmp);
        if (tmp % 2 == 1) odd.push_back(tmp);
        i++;
    }

    ans_odd[0] = 0;
    ans[0] = 0;
    for(i = 1; i < MAX; i++){
        for(j = 0; j < normal.size(); j++){
            if(normal[j] > i) break;
            ans[i] = min(ans[i], ans[i - normal[j]] + 1);
        }
    }

    for(i = 1; i < MAX; i++){
        ans_odd[i] = i;
        for(j = 0; j < odd.size(); j++){
            if(odd[j] > i) break;
            ans_odd[i] = min(ans_odd[i], ans_odd[i - odd[j]] + 1);
        }
    }

    while(true){
        cin >> n;
        if(n == 0) break;
        printf("%d %d\n", ans[n], ans_odd[n]);
    }

    return 0;
}



Measured memory_bytes: 10864
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 200000
using namespace std;
char str[MAXN+5];
int N,A,B,C,D;
int main()
{
	scanf("%d %d %d %d %d",&N,&A,&B,&C,&D);
	scanf("%s",str+1);
	bool legal=true;
	for(int i=A;i<C&&legal;i++)
		if(str[i]==str[i+1]&&str[i]=='#')
			legal=false;
	for(int i=B;i<D&&legal;i++)
		if(str[i]==str[i+1]&&str[i]=='#')
			legal=false;
	if(legal==false)
	{
		printf("No\n");
		return 0;
	}
	if(C<D)
	{
		printf("Yes\n");
		return 0;
	}
	for(int i=B;i<=D;i++)
		if(str[i-1]=='.'&&str[i]=='.'&&str[i+1]=='.')
		{
			printf("Yes\n");
			return 0;
		}
	printf("No\n");
	return 0;
}

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

const int MAXN = 1e5 + 10;

int n, k, a[MAXN], ans;

int main() {
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= k; ++i) ans += a[i];
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int N,T,A,ans=0;
double dif = 1e9;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> T >> A;
	REP(i,N){
		int tmp;
		cin >> tmp;
		if(dif > fabs(A - (T - tmp * 0.006))){
          dif =  fabs(A - (T - tmp * 0.006));
          ans = i + 1;
        }
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
	int r, g, b;
	int n;
	cin >> r >> g >> b;
	
	n = r * 100 + g * 10 + b;
	
	if (n % 4 == 0) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
var
	a, b, c, d : integer;
	e : boolean;

begin
	e := false;
	readln(a, b, c, d);
    while (a > 0) and (c > 0) do
    begin
    	if e then
        	a := a - d
        else
        	c := c - b;
        e := not e;
    end;
    if c <= 0 then
    	writeln('Yes')
   	else
    	writeln('No');
end.

Measured memory_bytes: 1368
#include <fstream>
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;
int N;
struct punct{
 int x,y;
}v[10];
double Dist(punct A, punct B){
 return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
int Fact(int x){
   int val=1;
   for(int i=1;i<=x;i++)
      val*=i;
    return val;
  }
double S;
int main()
{//ifstream fin("length.in");
 //fin>>N;
 cin>>N;
 for(int i=1;i<=N;i++){
   cin>>v[i].x>>v[i].y;
  }
 for(int i=1;i<=N;i++)
   for(int j=1;j<=N;j++)
      {double D;
       if(i!=j)
         {D=Dist(v[i],v[j]);
          S+=(D*(double)Fact(N-1));
         }
      }
      S=S/Fact(N);
 cout<<fixed<<setprecision(6)<<S;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const LL MOD=1e9+7;

int main(){
    int A,P;
    cin>>A>>P;
    int res=(A*3+P)/2;
    cout<<res<<endl;
    return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> data(H, vector<char>(W));
  
  /*
  for(int h = 0; h<H; h++){
    for(int w = 0; w<W; w++){
      cin >> data.at(h).at(w);//データ取得 ↓でやることにした(trueとかfalseのとこ)
    }
  }
  */
  /*取得したデータを表示
  for(int h = 0; h<H; h++){
    for(int w = 0; w<W; w++){
      cout << data.at(h).at(w);
      if(w == W-1) cout<<endl;
    }
  }
  */
  
  vector<bool> row(H, false);//すべてfalseで初期化して，下で#がある行はtrueにする
  vector<bool> col(W, false);//すべてfalseで初期化して，下で#がある列はtrueにする
  
  for(int h=0; h<H; h++){
    for(int w=0; w<W; w++){
      cin >> data.at(h).at(w);//データ取得
      if(data.at(h).at(w) == '#'){
        row.at(h) = true;
        col.at(w) = true;
      }
    }
  }
    
  int num_col = 0;//表示すべき最終列がいくつかを今から求める
  for(int w = 0; w<W ; w++){
    if(col.at(w) == true) num_col = w+1;
  }
  //cout << "num_col: " << num_col<< endl;
    
  for(int h=0; h<H; h++){
    if(row.at(h) == false) continue;
    
    for(int w=0; w<num_col; w++){
      if(col.at(w) == false) continue;
      
      cout << data.at(h).at(w);
      if(w==num_col-1) cout<<endl;
    }
  }
    
        
  
  
  /*
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
  }

  vector<vector<char>> data(N, vector<char>(N));
  
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      data.at(i).at(j) = '-';
    }
  }
  
  //cout <<N<<" " << A.size()<<" "<<B.size()<<endl;
  
  for(int m=0; m<M; m++)
  {
    data.at(A.at(m)-1).at(B.at(m)-1) = 'o';
    data.at(B.at(m)-1).at(A.at(m)-1) = 'x';
  }
  
   
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      cout << data.at(i).at(j);
      if(j==N-1) cout<<endl;
      else  cout<<' ';
    }
  }
  */
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
        return modinv


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()

    comb = Combination(n_max=10 ** 5)
    ans = 0
    for i in range(N - K + 1):
        ans -= comb(N - 1 - i, K - 1) * A[i] % MOD
        ans += comb(N - 1 - i, K - 1) * A[N - i - 1] % MOD
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 20328
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(4100000)
  
n,m = map(int, readline().split())
g = [[]*n for i in range(n)]
for i in range(m):
    u,v = map(int,readline().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
    
q = int(readline())
chk = []
for i in range(q):
  V,D,C = map(int,readline().split())
  chk.append((V,D,C))
  

memo = [[0]*11 for _ in range(n)]

def f(v,d,c):
  if memo[v][d] != 0:
    return
  else:
    memo[v][d] = c
    if d > 0:
      f(v,d-1,c)
      for nxt in g[v]:
        f(nxt,d-1,c)
    else:
      return

for V,D,C in chk[::-1]:
    f(V-1,D,C)

for v in range(n):
    print(memo[v][0])

Measured memory_bytes: 113920
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define var(n) int n; scn(n)
#define F first
#define S second 
#define pb push_back
const int N=309;
// const ll M = 998244353;
const ll M=1e9+7;
const ll inf=1e18;

double dp[N][N][N];

int main()
{
	var(n);
	int fre[4]={0};
	rep(i,0,n)
	{
		var(x);	
		fre[x]++;
	}


	for(int c = 0;c<=n;c++)
	{
		for(int b = 0;b<=n;b++)
		{
			for(int a = 0;a<=n;a++)
			{
				double vc = c>0? (double)c/n * dp[a][b+1][c-1] : 0;
				double vb = b>0? (double)b/n * dp[a+1][b-1][c] : 0;
				double va = a>0? (double)a/n * dp[a-1][b][c] : 0;

				if(a+b+c>0) 
					dp[a][b][c] = (n * (va+vb+vc+1))/(a+b+c);

			}
		}
	}
	printf("%.10f\n",dp[fre[1]][fre[2]][fre[3]]);

}

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

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

#define MAXX 500005
#define INF INT_MAX

#define PI   3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll 	 long long

#define mod  1000000007



int main()
{
	FAST;
	int n;
	cin >> n;
	ll a[n + 6];
	ll x = 0;
	for(int i = 0; i < n; i ++){
		cin >> a[i];
		x += a[i];
	}
	
	ll ans = 0;
	for(int i = 0; i < n-1; i ++){
		x -= a[i];
		ans += (x%mod)*a[i];
		ans %= mod;
		
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 5212
#include <iostream>

using namespace std;

int main()
{
	int second;
	cin >> second;
	int hour, minite, remain_sec, remain_min;
	remain_sec = second % 60;
	minite = second / 60;
	remain_min = minite % 60;
	hour = minite / 60;
	cout << hour << ":" << remain_min <<":"<< remain_sec << endl;

	return 0;
}




Measured memory_bytes: 3076
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String line;

		char bracket[][] = {{'(', ')'}, {'[', ']'}};
		int stack[] = new int[100];
		int index;

		while (true){
			line = sc.nextLine();
			if (line.equals(".")){
				break;
			}

			index = 0;

			out: for (int i = 0; i < line.length(); i++){
				char c = line.charAt(i);
				for (int j = 0; j < bracket.length; j++){
					if (c == bracket[j][0]){
						stack[index] = j;
						index++;
					}else if (c == bracket[j][1]){
						index--;
						if (index < 0 || j != stack[index]){
							index = -1;
							break out;
						}
					}
				}
			}

			if (index == 0){
				System.out.println("yes");
			}else{
				System.out.println("no");
			}
		}
	}

}

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

int main()
{
  int N,K;
  cin >> N >> K;
  
  vector<int> l(N);
  for(int i = 0; i < N; i++){
    cin >> l.at(i);
  }
  
  sort(l.rbegin(),l.rend());
  
  int sum = 0;
  for(int i = 0; i < K; i++){
    sum += l.at(i);
  }
  
  cout << sum << endl;
}

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n;

void read() {
  cin >> n;
}

int solve(ll x, ll p) {
  if (x > n) {
    return 0;
  }
  int nr = x;
  bool a, b, c;
  a = b = c = 0;
  while (nr && (!a || !b || !c)) {
    int digit = nr % 10;
    nr /= 10;
    if (digit == 3)
      a = 1;
    else if (digit == 5)
      b = 1;
    else c = 1;
  }
  if (a && b && c)
    nr = 1;
  else nr = 0;
  return nr + solve(p * 3 + x, p * 10) + solve(p * 5 + x, p * 10) + solve(p * 7 + x, p * 10);
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
//  cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    cout << solve(0, 1);
  }
  return 0;
}


Measured memory_bytes: 256
from collections import deque

h, w = map(int, input().split())
a = ['#' + input() +  '#' for _ in range(h)]
b = ['#' * (w + 1)] * 2
r = 0
for i in range(1, h + 1):
  for j in range(1, w + 1):
    if a[i - 1][j] == '.':
      b[1: -1] = map(list, a)
      q = deque()
      b[i][j] = 0
      q.append((i, j))
      while(q):
        i, j = q.popleft()
        r = max(r, b[i][j])
        d = 0
        for i1 in range(i - 1, i + 2):
          for j1 in range(j - d, j + 2, 2):                
            if b[i1][j1] == '.':
              b[i1][j1] = b[i][j] + 1
              q.append((i1, j1))
          d ^= 1
print(r)


Measured memory_bytes: 3316
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        Y = X[i]
        Z = X[j]
        d2 = sum((y - z) ** 2 for y, z in zip(Y, Z))
        for k in range(1, d2 + 1):
            if k * k == d2:
                ans += 1
print(ans)

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

#define lli long long int
#define pb push_back
#define in insert
#define pi pair<int, int>
#define pd pair<double, int>
#define pib pair<pi, bool>
#define mp make_pair
#define fir first
#define sec second
#define MAXN 200001
#define MAXL 1000001
#define mod 1000000007

signed main()
{
  int n, k;
  cin >> n >> k;
  set<int> s;
  for (int i = 0; i < k; i++)
  {
    int kk;
    cin >> kk;
    while (kk--)
    {
      int a;
      cin >> a;
      s.insert(a);
    }
  }
  cout << n - s.size() << endl;
  return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input_1 = Console.ReadLine().Split(" ");
            int N = int.Parse(input_1[0]);
            int K = int.Parse(input_1[1]);

            string[] input_2 = Console.ReadLine().Split(" ");
            List<int> price = new List<int>();
            foreach (string element in input_2)
            {
                price.Add(int.Parse(element));
            }

            price.Sort();

            int ans = 0;
            for (int i = 0; i < K; i++)
            {
                ans += price[i];
            }

            Console.WriteLine(ans.ToString());
        }
    }
}


Measured memory_bytes: 28172
import collections

n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

counter_s = collections.Counter(s)
ans = 0
for k, v in counter_s.items():
    ans = max(ans, v - t.count(k))
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
int main()
{
	int n, l;
	std::cin>>n>>l;
	
	std::string s;
	std::vector<std::string> sa;
	for (int i = 0; i < n; i++)
	{
		std::cin >> s;
		sa.push_back(s);
	}
	std::sort(sa.begin(), sa.end());
	for (unsigned int i = 0; i < sa.size(); i++)
	{
		std::cout << sa[i];
	}
	std::cout<<"\n";

    return 0;
}



Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  string n;
  cin >> n;

  ll keta = sz(n);
  bool flg = true;
  for(int i = 1; i < keta; ++i)
  {
    if(n[i] != '9')
    {
      flg = false;
      break;
    }
  }

  ll ans;
  if(flg)
  {
    ans = n[0] - 48 + 9 * (keta - 1);
  }
  else
  {
    ans = n[0] - 48 + 9 * (keta - 1) - 1;
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

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

int main()
{
	string S;
	cin >> S;
	int count = 0;
	for(int i = 1; i < S.length(); i++){
		if(S[i] != S[i - 1]){
			count++;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 512
function main()
  n=parse(Int,readline())
  m=fill(-1,n,n)
  for i=1:n
    for j=1:parse(Int,readline())
      a,b=parse.(split(readline()))
      m[i,a]=b
    end
  end
  ans=0
  for i=[[i+1 for i=0:n if b&(1<<i)!=0] for b=0:(1<<n)-1]
    flag=true
    for j=i
      for k=1:n
        if m[j,k] == -1
          continue
        elseif m[j,k] != (k∈i)
          flag=false
        end
      end
    end
    flag ? ans=max(ans,length(i)) : 0
  end
  print(ans)
end
main()

Measured memory_bytes: 155764
/*why so serious?*/
#include<bits/stdc++.h>
using namespace std;
#define   int      long long
#define   fast()   ios_base::sync_with_stdio(0);cin.tie(0)
#define   all(x)   x.begin(),x.end()
#define   pb       push_back
#define   F        first
#define   S        second

int32_t main()
{int n,m,i,cost=0;
 cin>>n>>m;
 vector<pair<int,int>> v(n);
 for(i=0;i<n;++i)
 cin>>v[i].F>>v[i].S;
 sort(all(v));
 for(i=0;i<n;++i)
 {cost+=v[i].F*min(v[i].S,m);
  m-=min(v[i].S,m);
  if(!m)
  break;
 }
 cout<<cost;
}






Measured memory_bytes: 1792
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll a(n);
  rep(i, n){
    cin >> a[i];
  }
  ll ans = a[0]-1;
  ll cur = 1;
  repr(i, 1, n){
    if(a[i] == cur+1) cur++;
    else ans += (a[i]-1)/(cur+1);
    dump(i, a[i], cur, (a[i]-1)/(cur+1));
  }
  print(ans);
}


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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void solve() {
    ll n;
    cin >> n;
    cout << ((n + 1000 - 1) / 1000) * 1000 - n << endl;
}

int main() {
    IOS;
    //io_set();
    ll tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define ll unsigned long long

int main(){
	int W, H, x, y; // W = total x // H = total y // x = cut x // y = cut y
	cin >> W >> H >> x >> y;
	double ans1 = 0;
	int ans2 = -1;
	ans1 = (double)W * H / 2;
	if(W - x != x or H - y != y){
		ans2 = 0;
	}
	else{
		ans2 = 1;
	}
	cout << fixed << setprecision(6) << ans1 << " " << ans2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
main()
{
	int n;
	cin>>n;
	map<string,int>M;
	for(int i=0;i<n;i++)
	{
		string s;int a;cin>>s>>a;M[s]+=a;
	}
	vector<pair<string,int> >a;
	for(pair<string,int>it:M)
	{
		a.push_back(it);
	}
	sort(a.begin(),a.end(),[](const pair<string,int>&a,const pair<string,int>&b){
		if(a.first.size()!=b.first.size())return a.first.size()<b.first.size();
		else return a.first<b.first;
	});
	for(int i=0;i<a.size();i++)cout<<a[i].first<<" "<<a[i].second<<endl;
}



Measured memory_bytes: 3180
#include <iostream>
#include <cstdio>
#define N 105
using namespace std;

typedef long long ll;
ll n, s, g, a;
long long ans;
ll f(ll p, ll q) {
	if (p % q == 0) return q;
	f(q, p % q);
}

int main()
{
	ll i, j, k;
	cin >> n;
	ans = 1;
	for (i = 0; i < n; i++) {
		scanf ("%lld", &a);
		ans *= a / f(ans, a);
	}
	cout << ans;
    return 0;
}



Measured memory_bytes: 256
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(input())
H=[]
W=[]
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            H.append(i)
            W.append(j)
H=set(H)
W=set(W)
for j in H:
    ans=[]
    for i in W:
        ans.append(a[j][i])
    print("".join(ans))
    


Measured memory_bytes: 3316
N, K = map(int, input().split())
dice = 0
score = 0
percent = 0
cnt = 0
ans = 0

for dice in range(1,N+1):
  score = dice
  cnt = 0
  percent = 0
  while score < K:
    score = score * 2
    cnt += 1
  percent = (1/N) * (0.5 ** cnt)
  ans += percent

print(round(ans, 12))

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	float n,m;
	int t,s;
scanf("%f %f",&n,&m);
s=(n+m)/2.0*10;
if(s%10>=5)
t=(n+m)/2+1;
else
t=(n+m)/2;
printf("%d",t);
return 0; 
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
	int N,M,Q;
	cin >> N >> M >> Q;
	int tr[N+1][N+1];
	for (int i = 0;i < N+1;i++) {
		for (int j = 0;j < N+1;j++) {
			tr[i][j] = 0;
		}
	}
	for (int i = 0;i < M;i++) {
		int l, r; cin >> l >> r;
		tr[l][r] += 1;
	}
	for (int i = 1;i < N + 1;i++) {
		for (int j = 1;j < N + 1;j++) {
			tr[i][j] += tr[i][j-1];
		}
	}
	for (int i = 1;i < N + 1;i++) {
		for (int j = 1;j < N + 1;j++) {
			tr[i][j] += tr[i-1][j];
		}
	}
	for (int i = 0;i < Q;i++) {
		int l,r; cin >> l >> r;
		cout << tr[r][r] - tr[l-1][r] - tr[r][l-1] + tr[l-1][l-1] << endl;
	}
	
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
	std::ios::sync_with_stdio(false);
	int n,sum=0;
	cin>>n;
	for(int i=1;i<=n*2;i++)
	cin>>a[i];
	sort(a+1,a+n*2+1);
	//for(int i=1;i<=n*2;i++) cout<<a[i]<<endl;
	for(int i=1;i<=n*2;i+=2)
	sum+=a[i];
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256