akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int n;
  cin >> n;
  int ans, p{};
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    if (p < a) {
      p = a;
      ans = a + b;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    string s, w[] = {"dream", "dreamer", "erase", "eraser"};
    cin >> s;

    int i = 0;
    while (i < s.size())
    {
        if (s[i] == 'd')
        {
            for (int j = 0; j < 5; j++)
            {
                if (s[i + j] != w[0][j])
                {
                    cout << "NO" << endl;
                    return 0;
                }
            }
            i += 5;

            if (s[i] == 'e' && s[i + 1] == 'r' && s[i + 2] != 'a')
            {
                i += 2;
            }
        }
        else if (s[i] == 'e')
        {
            for (int j = 0; j < 5; j++)
            {
                if (s[i + j] != w[2][j])
                {
                    cout << "NO" << endl;
                    return 0;
                }
            }
            i += 5;

            if (s[i] == 'r')
            {
                i += 1;
            }
        }
        else
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
int main()
{
    int n ,i ,ans=0 ,j ,cnt1 ,cnt2;
    bool lag[123];
    scanf("%d",&n);
    char a[n+1];
    scanf("%s",a);
    n--;
    for(i = 1; i < n; i++)
    {
        cnt1 = 0;
        memset(lag,true,sizeof(lag));
        for(j = 0; j < i; j++)
        {
            if(lag[a[j]])
            {
                lag[a[j]] = false;
                cnt1++;
            }
        }
        cnt2 = 0;
        //memset(lag,true,sizeof(lag));
        for(j = i; j <= n; j++)
        {
            if(! lag[a[j]])
            {
                cnt2++;
                lag[a[j]] = true;
            }
        }
        if(cnt2>ans)
            ans = cnt2;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 256
// test
#include <bits/stdc++.h>
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i = a; i <= b; i++)
typedef long long ll;
typedef double db;
const int N = 2*1e5+100;
const int M = 1e5+100;
const db EPS = 1e-9;
using namespace std;

ll n,k,a[N],vis[N],cnt,pos;
pair<ll,ll> mp[N];
vector<ll> v[N],ans;

int main()
{
    scanf("%lld%lld",&n,&k);
    memset(vis,-1,sizeof vis);
    rep(i,0,n-1){
        scanf("%lld",&a[i]);
        v[a[i]].push_back(i);
    }
    rep(i,1,((int)2*1e5)){
        if(!v[i].size()) continue;
        int len = v[i].size();
        rep(j,0,len-1){
            if(j != len-1){
                mp[v[i][j]].first = (v[i][j+1]+1)%n;
                mp[v[i][j]].second = v[i][j+1]+1-v[i][j];
            }
            else{
                mp[v[i][j]].first = (v[i][0]+1)%n;
                mp[v[i][j]].second = n-v[i][j]+v[i][0]+1;
            }
        }
    }
    cnt = 0; pos = 0;
    ll total = n*k-1ll;
    while(cnt+mp[pos].second <= total){
        if(vis[pos] != -1){
            ll K = cnt-vis[pos];
            ll hp = (n*k-vis[pos])%K;
            if(hp == 1ll){
                printf("\n");
                return 0;
            }
            if(hp == 0) hp = K-1ll;
            else hp--;
            total = vis[pos]+hp;
            cnt = vis[pos];
            break;
        }
        else vis[pos] = cnt;
        cnt += mp[pos].second;
        pos = mp[pos].first;
    }
    if(total == cnt+mp[pos].second-1ll){
        printf("\n");
        return 0;
    }
    while(cnt <= total){
        while(cnt+mp[pos].second <= total){
            cnt += mp[pos].second;
            pos = mp[pos].first;
        }
        if(cnt+mp[pos].second-1ll == total) break;
        else{
            ans.push_back(a[pos]);
            pos = (pos+1ll)%n;
            cnt++;
        }
    }
    int len = ans.size();
    if(len == 0) printf("\n");
    else{
        rep(i,0,len-1){
            printf("%lld",ans[i]);
            if(i != len-1) printf(" ");
            else printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 20600
//
//  211_d.cpp
//  test
//
//  Created by liuyuhan on 20/10/2018.
//  Copyright © 2018 liuyuhan. All rights reserved.
//

#include <iostream>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    int max_div = M / N;
    for (int i=max_div; i >=1; i--) {
        if (M % i == 0 && M / i >= N)
        {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 256
def show_result(arr1, arr2)
  result = 0
  arr1.size.times { |i| result += arr1[i] * arr2[i] }
  puts result
end

row = []
input = gets.chomp.split(' ').map(&:to_i)
input[0].times { |n| row.push(gets.chomp.split(' ').map(&:to_i)) }

column = []
input[1].times { column.push(gets.chomp.to_i) }

row.size.times { |i| show_result(row[i], column) }

Measured memory_bytes: 8856
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;

    if(s[2]!=s[3] || s[4]!=s[5] || s.size()<6)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }

}


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

int K;

int gcd(int a, int b, int c){
    for(int d = c; d > 0; d--){
        if(a%d == 0 and b%d == 0 and c%d == 0){
            return d;
        }
    }
}

int main(){
    int ans = 0;
    cin >> K;

    for(int a = 1; a < K + 1; a++){
        for(int b = 1; b < K + 1;b++){
            for(int c = 1; c < K + 1; c++){
                ans += gcd(a, b, c);
            }
        }
    }

    cout << ans << endl;
}

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

using namespace std;

char s[100][100];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%s", s[i]+1);
  int r = 1, c = 1;
  bool ok = true;
  while (1) {
    if (s[r][c] != '#') {
      ok = false;
      break;
    }
    s[r][c] = '.';
    if (r == n && c == m)
      break;
    if (s[r][c+1] == '#')
      c++;
    else
      r++;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      ok &= s[i][j] != '#';
    }
  puts(ok ? "Possible" : "Impossible");
  return 0;
}

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

// Union-Find
class DisjointSet {
public:
  vector<int> p, rank, size;
  int group_num;
  DisjointSet(int n) {
    p.assign(n, 0);
    rank.assign(n, 0);
    size.assign(n, 0);
    group_num = n;
    for (int i = 0; i < n; i++) {
      make_set(i);
    }
  }
 
  void make_set(int x) {
    p[x] = x;
    rank[x] = 0;
    size[x] = 1;
  }
 
  bool same(int x, int y) {
    return find_set(x) == find_set(y);;
  }
 
  int find_set(int x) {
    if (x != p[x]) {
      p[x] = find_set(p[x]);
    }
    return p[x];
  }
 
  int union_size(int x) {
    if (x != p[x]) {
      size[x] = union_size(find_set(x));
    }
    return size[x];
  }
 
  void link(int x, int y) {
    if(rank[x]  > rank[y]) {
      p[y] = x;
      size[x] = size[x] + size[y];
    }else if(rank[x] < rank[y]){
      p[x] = y;
      size[y] = size[x] + size[y];
    }else if(x != y) {
      p[y] = x;
      rank[x]++;
      size[x] = size[x] + size[y];
    }
  }
 
  void unite(int x, int y) {
    if (find_set(x) != find_set(y)) group_num--;
    link(find_set(x), find_set(y));
  }
};

int main() {
    int N, M;
    cin >> N >> M;
    int A[M], B[M];
    DisjointSet ds(N);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        ds.unite(A[i], B[i]);
    }
    int d = 0;
    for (int i = 0; i < N; i++) {
        d = max(d, ds.union_size(i));
    }
    cout << d << "\n";
    return 0;
}

Measured memory_bytes: 7136
import copy
n, w = map(int, input().split())
V = []
W = []
for i in range(n):
  vi, wi = map(int, input().split())
  V.append(vi)
  W.append(wi)
dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(n):
  for j in range(w+1):
    vi, wi = V[i], W[i]
    if j >= wi:
      dp[i+1][j] = max(dp[i][j - wi] + vi, dp[i][j])
    else:
      dp[i+1][j] = dp[i][j]
#print(dp)
print(dp[-1][-1])


Measured memory_bytes: 43108
#include <bits/stdc++.h>
using namespace std;
int a[110],b[110];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for(int i=0;i+2<n;i++){
		if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2]){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

const int MOD = 1000000007;
const int INF = 1000000000;
const double EPS = 1e-9;


int main() {

	cin.tie(0);

	int N;
	cin >> N;

	vector<int> H(N);
	FOR(i, 0, N) cin >> H[i];

	int ans = 1;

	FOR(i, 0, N) {
		FOR(j, 0, i) {
			if (H[j] > H[i]) break;
			if (j == i - 1) ans++;
		}
	}

	cout << ans;
	return 0;
}

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    char col[2*n];
    map<char, vector<int>> lol;
    int tp = -1;
    char st;
    string q;
    cout<<'?'<<" ";
    for(int i=0;i<n;i++) {
        cout<<i+1<<" ";
    }
    cout<<endl;
    cin>>q;
    st = q[0];
    char ot;
    if(st == 'R') ot = 'B';
    else ot = 'R';
    int ch = -1;
    int l = 0;
    int r = n;
    char lc = st;
    char rc = ot;
    while(l<r) {
        int mid = (l+r)/2;
        cout<<"? ";
        for(int j=0;j<n;j++) {
            cout<<mid+j+1<<" ";
        }
        cout<<endl;
        char c;
        cin>>q;
        c = q[0];
        if(c!=lc) {
            r=mid;
            ch = r;
        }
        else {
            l=mid+1;
            ch = l;
        }
    }
    // cout<<ch<<"\n";
    col[ch+n-1] = ot;
    lol[ot].pb(ch+n-1);

    for(int i=0;i<ch;i++) {
        cout<<"? ";
        for(int i = ch;i<ch+n-1;i++) {
            cout<<i+1<<" ";
        }
        cout<<i+1<<endl;
        char c;
        cin>>q;
        c = q[0];
        col[i]=c;
        lol[c].pb(i);
    }
    for(int i=ch+n;i<2*n;i++) {
        cout<<"? ";
        for(int i = ch;i<ch+n-1;i++) {
            cout<<i+1<<" ";
        }
        cout<<i+1<<endl;
        char c;
        cin>>q;
        c = q[0];
        col[i]=c;
        lol[c].pb(i);
    }

    for(int i=ch;i<ch+n-1;i++) {
        cout<<"? ";
        for(int i=0;i<n/2;i++) {
            cout<<lol['R'][i]+1<<" ";
        }
        for(int i=0;i<n/2;i++) {
            cout<<lol['B'][i]+1<<" ";
        }
        cout<<i+1<<endl;
        char c;
        cin>>q;
        c=q[0];
        col[i]=c;
        lol[c].pb(i);
    }   
    cout<<"! ";
    for(int i=0;i<2*n;i++) {
        cout<<col[i];
    }
    cout<<endl;



    return 0;
}

Measured memory_bytes: 3812
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a >= b&& c >= d) {
		cout << b + d << endl;
	}
	else if (a >= b&& d >= c) {
		cout << b + c << endl;
	}
	else if (b >= a&& c >= d) {
		cout << a + d << endl;
	}
	else cout << a + c << endl;
}

Measured memory_bytes: 256
//In the Name of God
//Let Our Voices Echo
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define X real()
#define Y imag()
typedef long long ll;
typedef double ld; 
typedef complex<ld> point;
const ld eps=1e-9;
const int MAX=1e5+9,MOD=1e9+7;
ll s,t;
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>s>>t;
	if (abs(s-t)<=1) cout<<"Brown\n";
	else cout<<"Alice\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define MODD 1000000007
#define ll long long
#define Inf 1000000000
using namespace std;
int H,W;

int dp[111][111][1111];

bool CanWin(int p,int q,int nummoves,int N) {
    
    
    if (nummoves >= 4)
        return false;
    
    if (dp[p][q][nummoves]!=-1)
        return dp[p][q][nummoves];
    
    bool canwin=false;
    for(int d=-1;d<=1;d+=2) {
        int np = p+d;
        if (np>=1 && np<=N && np != q) {
            canwin |= !CanWin(q,np,nummoves+1,N);
        }
    }
    
    
    return dp[p][q][nummoves]=canwin;
    
    
}



int main() {
    
    
    int N,A,B;
    cin>>N>>A>>B;
    
    if ((A+B)&1) {
        printf("Borys\n");
    } else {
        printf("Alice\n");
    }
    
    return 0;
    for(int i=0;i<111;i++)
        for(int j=0;j<111;j++)
            for(int k=0;k<1111;k++)
                dp[i][j][k]=-1;
    
    cout << CanWin(A,B,0,N) << endl;
    
}

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

struct Team {
  int time,correct,team_num;
};

int main(){
  Team data[51];
  int i,j,M,T,P,R,m,t,p,wrong[51][11];
  while(1){
     for( i = 0; i < 51; i++ ){
    for( j = 0; j < 51; j++ ){
    	wrong[i][j] = 0;
     }
      }
    cin >> M >> T >> P >> R;
    if ( M == 0 && T == 0 && P == 0 && R == 0 ) break;

    for( i = 1; i <= T; i++ ){
      data[i].time = 0;
      data[i].correct = 0;
      data[i].team_num = i;
    }
  
    for( i = 1; i <= R; i++ ){
      cin >> m >> t >> p >> j;
      if( j == 0 ){
	data[t].correct++;
	data[t].time += m + wrong[t][p] * 20;
      }else wrong[t][p]++; 
    }

    for( i = 1; i <= T; i++ ){
      for( j = 1; j < T; j++ ){
	if( data[j].team_num < data[j+1].team_num ) 
	  swap( data[j],data[j+1] );
      }
    }

    for( i = 1; i <= T; i++ ){
      for( j = 1; j < T; j++ ){
	if( data[j].time > data[j+1].time ) swap( data[j],data[j+1] );
      }
    }

    for( i = 1; i <= T; i++ ){
      for( j = 1; j < T; j++ ){
	if( data[j].correct < data[j+1].correct )
	  swap( data[j],data[j+1] );
      }
    }
   
    for( i = 1; i <= T-1; i++ ){
      cout << data[i].team_num;
      if( data[i].correct > data[i+1].correct )	cout << ",";
      else if( data[i].time < data[i+1].time ) cout <<  ",";
      else cout << "=";
      }
    cout << data[T].team_num << endl;

  }

  return 0;
}

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


int N;
set<int> s;

int main() {
    cin >> N;;

    rep(i, N) {
        int tmp;
        cin >> tmp;
        s.insert(tmp);
    }

    // cout << "ssssss" << endl;
    // set<int>::iterator ite;
    // for (ite = s.begin(); ite != s.end(); ite++) {
    //     cout << *ite << endl;
    // }
    cout << s.size() << endl;
}

Measured memory_bytes: 256
import heapq

x, y, z, k = [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
C = [int(i) for i in input().split(' ')]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

pq = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
s = {(0, 0, 0)}
res = []
while len(res) < k and len(pq) > 0:
    t = heapq.heappop(pq)
    res.append(str(-t[0]))
    idx = []
    if t[1] + 1 < len(A):
        idx.append(t[1] + 1)
    else:
        idx.append(t[1])
    if t[2] + 1 < len(B):
        idx.append(t[2] + 1)
    else:
        idx.append(t[2])
    if t[3] + 1 < len(C):
        idx.append(t[3] + 1)
    else:
        idx.append(t[3])
    flag = 0
    if (idx[0], t[2], t[3]) not in s:
        s.add((idx[0], t[2], t[3]))
        heapq.heappush(pq, (-(A[idx[0]] + B[t[2]] + C[t[3]]), idx[0], t[2], t[3]))
    if (t[1], idx[1], t[3]) not in s:
        s.add((t[1], idx[1], t[3]))
        heapq.heappush(pq, (-(A[t[1]] + B[idx[1]] + C[t[3]]), t[1], idx[1], t[3]))
    if (t[1], t[2], idx[2]) not in s:
        s.add((t[1], t[2], idx[2]))
        heapq.heappush(pq, (-(A[t[1]] + B[t[2]] + C[idx[2]]), t[1], t[2], idx[2]))

print('\n'.join(res))


Measured memory_bytes: 5096
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 100010
int n,x;
vector<pair<int,int> >v;

int main(){
  cin>>n;
  lol(i,n){cin>>x;v.push_back(make_pair(x,0));}
  lol(i,n){cin>>x;v.push_back(make_pair(x,1));}
  sort(v.begin(),v.end());
  ll ans=1,cnt=0;
  lol(i,v.size()){
    if(v[i].second==0){
      if(cnt>0)ans=ans*cnt%mod;
      cnt--;
    }
    if(v[i].second==1){
      if(-cnt>0)ans=ans*(-cnt)%mod;
      cnt++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2420
s=input()
ans=[0 for _ in range(len(s))]
rl=[]
for i in range(1,len(s)):
    if s[i-1]=='R' and s[i]=='L': rl.append(i)
ni=0
for i in range(len(s)):
    if rl[ni]<i and s[i]=='R': ni+=1
    if s[i]=='R':
        if (rl[ni]-i)%2==0:ans[rl[ni]]+=1
        else:ans[rl[ni]-1]+=1
    else:
        if (i-rl[ni])%2==0:ans[rl[ni]]+=1
        else:ans[rl[ni]-1]+=1
print(' '.join([str(_) for _ in ans]))

Measured memory_bytes: 12516
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SMALLPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
ll inf=1000000007;
const int MOD=998244353;
const int mod=998244353;
const int MAX=3001000;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit();
  ll x,y,n,a,b,k;cin>>n>>a>>b>>k;
  ll ans=0;
  ll i=0;
  while(i<=n){
		if((k-i*a)%b!=0){
          i++;
          continue;
        }
		ll j=(k-i*a)/b;
		ans+=COM(n,i)*COM(n,j)%mod;
    	ans%=mod;
    	i++;
  }
  cout<<ans<<endl;
}

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

using namespace std;

set <pair<int, int> > Map;
set <int> Set[210000];

int main() {
	int X, Y, n;
	scanf("%d%d%d", &X, &Y, &n);
	
	for (int i = 1; i <= Y; i++)
		Set[i].insert(X + 1);
	for (int i = 1; i <= n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		Map.insert(make_pair(x, y));
		Set[y].insert(x);
	}
	int ans = *Set[1].lower_bound(1) - 1;
	int nowX = 1;
	int nowY = 1;
	while (true) {
		nowX++;
		if (nowX > X || Map.count(make_pair(nowX, nowY)))
			break;
		if (!Map.count(make_pair(nowX, nowY + 1)) && nowY < Y)
			nowY++;
		ans = min(ans, *Set[nowY].lower_bound(nowX) - 1);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 38272
import math

n=int(input())
k=int(input())
x=list(map(int,input().split()))

l=0
for i in range(n):
    if(abs(x[i]-0) < abs(x[i]-k)):
        l+=2*abs(x[i]-0)
    else:
        l+=2*abs(x[i]-k)

print(l)

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

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

int main()
{
    int d,n;cin >> d >> n;

    if(d==0) printIf(n!=100,n,101)
    else if(d==1) printIf(n!=100,100*n,100*101)
    else if(d==2) printIf(n!=100,10000*n,10000*101)
}

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

namespace xmaho
{
inline namespace input
{
template<typename T>
T get_value(std::istream& is = std::cin);
template<typename C>
C get_container(std::istream& is = std::cin, typename C::size_type length = std::numeric_limits<typename C::size_type>::max());
}
}
using namespace xmaho;

int main()
{
  std::vector<char> is_ac(xmaho::get_value<std::size_t>(std::cin), 0);
  std::vector<unsigned int> miss(is_ac.size(), 0);
  for (auto _ {get_value<std::size_t>()}; _ != 0; --_) {
    const auto i {xmaho::get_value<std::size_t>(std::cin) - 1};
    const auto a {xmaho::get_value<std::string>(std::cin)};
    if (is_ac[i])
      continue;
    if (a == "AC") {
      is_ac[i] = 1;
    } else {
      ++miss[i];
    }
  }

  std::cout << std::accumulate(is_ac.cbegin(), is_ac.cend(), 0u) << ' ';
  auto res {0u};
  for (auto i {0u}; i < is_ac.size(); ++i)
    if (is_ac[i]) res += miss[i];
  std::cout << res << '\n';

  return 0;
}

class initalization
{
  class custom_numpunct: public std::numpunct<char>
  {
  public:
    using numpunct::numpunct;
  protected:
    std::string do_truename() const override { return "Yes"; }
    std::string do_falsename() const override { return "No"; }
  };

public:
  initalization()
  {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.imbue(std::locale(std::cout.getloc(), new custom_numpunct{}));
    std::cout << std::boolalpha << std::fixed << std::setprecision(15);
  }
} initalize;

template<typename T>
T xmaho::input::get_value(std::istream& is)
{ T v {}; is >> v; return v; }

template<typename C>
C xmaho::input::get_container(std::istream& is, typename C::size_type length)
{
  C v {};
  if (length != std::numeric_limits<typename C::size_type>::max())
    v.reserve(length);
  typename C::value_type e {};
  for (auto i {length}; i != 0 && is >> e; --i)
    v.push_back(std::move_if_noexcept(e));
  return v;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
#define MOD 1000000007ll // prime
// How to devide :
// ModInt a(6ll);
// ModInt b(2ll);
// a *= b.exp(MOD-2ll);  -> a/=b;  result: a = 3
struct ModInt{
	ll val;
	ModInt():val(0ll){}
	ModInt(ll v):val(((v%MOD)+MOD)%MOD){}
	ModInt exp(ll y)const{
		if(!y)return ModInt(1ll);
		ModInt a = exp(y/2ll);
		a *= a;
		if(y&1)a*=(*this);
		return a;
	}
	bool operator==(const ModInt& x)const{return val==x.val;}
	inline bool operator!=(const ModInt& x)const{return !(*this==x);}
	bool operator<(const ModInt& x)const{return val<x.val;}
	bool operator>(const ModInt& x)const{return val>x.val;}
	inline bool operator>=(const ModInt& x)const{return !(*this<x);}
	inline bool operator<=(const ModInt& x)const{return !(*this>x);}
	ModInt& operator+=(const ModInt& x){if((val+=x.val)>=MOD)val-=MOD;return *this;}
	ModInt& operator-=(const ModInt& x){if((val+=MOD-x.val)>=MOD)val-=MOD;return *this;}
	ModInt& operator*=(const ModInt& x){(val*=x.val)%=MOD;return *this;}
	ModInt operator+(const ModInt& x)const{return ModInt(*this)+=x;}
	ModInt operator-(const ModInt& x)const{return ModInt(*this)-=x;}
	ModInt operator*(const ModInt& x)const{return ModInt(*this)*=x;}
};
istream& operator>>(istream&i,ModInt&x){i>>x.val;return i;}
ostream& operator<<(ostream&o,const ModInt&x){o<<x.val;return o;}
ModInt pow(ModInt a,ll x){
	ModInt res = ModInt(1ll);
	while(x){
		if(x&1)res *= a;
		x >>= 1;
		a = a*a;
	}
	return res;
}
ModInt dp[42][1<<17];
bool ok[1<<17];
ModInt rui[42];
int N,X,Y,Z;
int main(){
	cin >> N >> X >> Y >> Z;
	int S = X+Y+Z;
	for(int i=0;i<(1<<S);i++){
		int a = ((i>>(X+Y+Z-1))&1);
		int b = ((i>>(Y+Z-1))&1);
		int c = ((i>>(Z-1))&1);
		if((a&b)&c)ok[i]=true;
	}
	dp[0][0]=ModInt(1ll);
	rui[0]=ModInt(1ll);
	int mask = (1<<S)-1;
	for(int i=1;i<=N;i++)rui[i]=rui[i-1]*ModInt(10ll);
	for(int i=0;i<N;i++){
		for(int j=0;j<(1<<S);j++){
			if(!ok[j]){
				for(int k=1;k<=10;k++){
					int nxt = (j<<k);
					nxt |= (1<<(k-1));
					dp[i+1][nxt&mask]+=dp[i][j];
				}
			}
		}
	}
	ModInt ans;
	for(int i=0;i<N;i++){
		for(int j=0;j<(1<<S);j++){
			if(ok[j]){
				ans += dp[i+1][j]*rui[N-1-i];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 43264
#include <stdio.h>
#include <math.h>
int main(){
	int H,W,i,j;
	while(1){
	scanf("%d %d",&H,&W);
		if(H ==0 && W==0){
			break;
		}
		for (i = 0; i < H; i++)
		{
			for (j = 0; j < W; j++)
			{
				printf("#");
			}
			printf("\n");
		}
			printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	bool a = false, b = false, c = true;
	if(s.front() == 'A') a = true;

	int cnt = 0;
	range(i,2,s.size() - 1){
		if(s[i] == 'C') cnt++;
	}
	if(cnt == 1) b = true;

	rep(i,s.size()){
		if(s[i] == 'A' or s[i] == 'C') continue;
		if(isupper(s[i])) c = false;
	}

	cout << (a and b and c ? "AC" : "WA") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,m;
    cin>>n>>m;
    vi mask(m);
    REP(i,m){
        int x;
        cin>>x;
        REP(j,x){
            int t;
            cin>>t;
            mask[i]^=1<<(t-1);
        }
    }
    vi vec(m);
    cin>>vec;
    int ans=0;
    REP(i,1<<n){
        bool f=true;
        REP(j,m){
            if(__builtin_popcount(mask[j]&i)%2!=vec[j]){
                f=false;
            }
        }
        if(f){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_D
 */
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>

using namespace std;

vector<int>
insersionsort(const vector<int> a, const int g, int &cnt)
{
    vector<int> work(a);
    for (int i = g; i < work.size(); i++) {
        int v = work[i];
        int j = i - g;
        while (j >= 0 && work[j] > v) {
            work[ j + g ] = work[j];
            j = j - g;
            cnt++;
        }
        work[ j + g ] = v;
    }
    return work;
}

void
shellsort(const vector<int> a)
{
    vector<int> work(a);
    int cnt = 0;
    int m = 1;
    vector<int> gs;
    while (pow(3, m) < 2 * a.size() + 2) { 
        gs.push_back((pow(3, m) - 1) / 2);
        m++;
    }

    cout << gs.size() << endl;

    for (auto it = gs.crbegin(); it != gs.crend(); it++) {
        if (it != gs.crbegin()) { cout << ' '; }

        vector<int> w = insersionsort(work, *it, cnt);
        cout << *it;
        work.swap(w);
    }
    cout << endl;
    cout << cnt << endl;

    for (auto it : work) {
        cout << it << endl;
    }
}

int
main()
{
    ios_base::sync_with_stdio(false);

    int N;
    cin >> N; cin.ignore();

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i]; cin.ignore();
    }
    shellsort(A);

    return 0;
}

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

using namespace std;

/*
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
typedef long long ll ;
const ll mk = 200054;
const ll logn  = 29;
const ll mod = 1e9 + 7;

#define endl             "\n"
#define IOS              ios::sync_with_stdio(0); cin.tie(0);
#define fi               first
#define se               second
#define pii              pair<ll,ll>
#define mp               make_pair
#define pq               priority_queue<int, std::vector<int>, std::greater<int> >
#define rep(i, n)        for(int i = 0 ; i < n ; i++)
#define push_back        pb
 
int n;
char ans[mk];
int cac[mk][26];
int f[mk], go[mk];
string s;
 
inline bool down(int &x, const int y) {return x > y ? x = y, 1 : 0;}
 
int main() {
	int i, j;
	cin >>s; n = s.length();
	fill(cac[n], cac[n] + 26, n);
	for (i = n - 1; i >= 0; --i) memcpy(cac[i], cac[i + 1], 104/*calculated*/), cac[i][s[i] - 97] = i;
	f[n] = 1;
	for (i = n - 1; i >= 0; --i) {
		f[i] = INT_MAX;
		for (j = 0; j < 26; ++j) if (down(f[i], f[ cac[i][j] + 1 ])) go[i] = j;
		++f[i];
	}
	for (j = i = 0; i <= n; i = cac[i][ go[i] ] + 1) ans[j++] = go[i] + 97;
	return puts(ans), 0;
}

Measured memory_bytes: 25604
#include<bits/stdc++.h>
#define MAX_V 100000
using namespace std;
int m,w[100001];
vector<int> vv[100001];
int S[100001];
int V;
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];
int C[100001],F[100001],U[100001],ans;
bool UU[100001];

void DFS(int p,int pr){
  if(S[p]++)return;
  for(int i=0;i<vv[p].size();i++){
    int np=vv[p][i];
    if(pr!=np){
      G[p].push_back(np);
      rG[np].push_back(p);
      DFS(np,p);
    }
  }
}

void dfs(int v){
  used[v]=true;
  for(int i=0;i<G[v].size();i++)if(!used[G[v][i]])dfs(G[v][i]);
  vs.push_back(v);
}

void rdfs(int v,int k){
  used[v]=true;
  cmp[v]=k;
  for(int i=0;i<rG[v].size();i++)if(!used[rG[v][i]])rdfs(rG[v][i],k);
}

int scc(){
  for(int v=0;v<V;v++)if(!used[v])dfs(v);
  memset(used,0,sizeof(used));
  int k=0;
  for(int i=vs.size()-1;i>=0;i--)if(!used[vs[i]])rdfs(vs[i],k++);
  return k;
}

bool DFS1(int p){
  if(U[p])return 0;
  U[p]=1;
  bool f=F[cmp[p]]>=2;
  for(int i=0;i<G[p].size();i++)
    f|=DFS1(G[p][i]);
  ans+=w[p]*f;
  return UU[p]=f;
}
bool UUU[100001];
int DFS2(int p){
  if(UUU[p])return 0;
  UUU[p]=1;
  int res=0;
  
  for(int i=0;i<G[p].size();i++)
    res=max(res,DFS2(G[p][i]));  
  return res+(UU[p]?0:w[p]);
}

int main(){
  cin>>V>>m;
  for(int i=0;i<V;i++)cin>>w[i];
  for(int j=0,a,b;j<m;j++){
    cin>>a>>b;a--,b--;
    vv[a].push_back(b),vv[b].push_back(a);
  }
  DFS(0,-1);
  int t=0;
  for(int i=0;i<V;i++)t+=w[i];
  scc();
  for(int i=0;i<V;i++)F[cmp[i]]++;
  DFS1(0);
  cout<<ans+DFS2(0)<<endl;
  return 0;
}

Measured memory_bytes: 28340
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

int main(){
ll N;
cin >> N; 
vector <string>  str(N);
for(int i = 0 ; i<N ; i++){
  cin >> str[i];
}
sort(str.begin(), str.end());
    int count = 1;
    for(int i = 0; i < N-1; i++){
        if(str[i] != str[i+1]){
            count++;
        }
    }
    cout << count;
}


Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
vector <string> v;
vector<int> num;
string s ;
int main(){
  int b;

  cin >>s>>b;

  for (int i = 0;i < (int)s.size();i++){
    string x;
    x = s[i];
    v.push_back(x);
    for(int j = i+1;j<min(i+b,(int)s.size());j++){
      x = x + s[j];
      v.push_back(x);
    }
  }
  sort(v.begin(),v.end());
  v.erase((unique(v.begin(),v.end())),v.end());

  cout << v[b-1]<<endl;
  return 0;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define LL long long


using namespace std;
const int maxn=1e5+5;
int gcd(int a , int b)
{
        return a%b==0? b:gcd(b,a%b);
}
inline LL quickread()
{
	LL X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}
int main()
{
    LL n;
    cin>>n;
    LL tmp;
    LL maxheight=0;
    LL ans=0;
    for(int i=0;i<n;i++)
     {
         tmp=quickread();
         if(tmp>=maxheight)
         {
             maxheight=tmp;
         }
         else
         {
             ans+=maxheight-tmp;
         }
     }
     cout<<ans<<endl;
}


Measured memory_bytes: 3632
import scala.io.StdIn

object Main {
  def SelectionSort(A: Array[Int]):(Int,Array[Int]) = {
    var count = 0
    def swap(i: Int, j: Int){
      if(i != j){
        count += 1
      }
      val tmp = A(i)
      A(i) = A(j)
      A(j) = tmp
    }

    for(i <- 0 to A.length - 1){
      var mini = i
      for(j <- i + 1 to A.length - 1){
        if (A(j) < A(mini)){
          mini = j
        }
      }
      swap(i,mini)
    }
    (count,A)
  }


  def main(args: Array[String]){
    val N = StdIn.readInt()
    val input = StdIn.readLine().split(" ").map(_.toInt).toArray

    assert(input.length == N, "input length must equal to N")

    val result = SelectionSort(input)
    println(result._2.mkString(" "))
    println(result._1)
  }
}

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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = 2147483647;
constexpr ll L_INF = 9223372036854775807LL;

//===




int main()
{
	int H, W;
	cin >> H >> W;
	vector<Vi> a(H, Vi(W));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> a[i][j];
		}
	}

	vector<tuple<int, int, int, int>> ansO;
	for (int i = 0; i < H; ++i) {
		if (i % 2 == 0) {
			for (int j = 0; j < W - 1; ++j) {
				if (a[i][j] % 2 == 1) {
					--a[i][j]; ++a[i][j + 1];
					ansO.emplace_back(i, j, i, j + 1);
				}
			}
			if (i != H - 1 && a[i][W - 1] % 2 == 1) {
				--a[i][W - 1]; ++a[i + 1][W - 1];
				ansO.emplace_back(i, W - 1, i + 1, W - 1);
			}
		}
		else {
			for (int j = W - 1; j >= 1; --j) {
				if (a[i][j] % 2 == 1) {
					--a[i][j]; ++a[i][j - 1];
					ansO.emplace_back(i, j, i, j - 1);
				}
			}
			if (i != H - 1 && a[i][0] % 2 == 1) {
				--a[i][0]; ++a[i + 1][0];
				ansO.emplace_back(i, 0, i + 1, 0);
			}
		}
	}

	cout << ansO.size() << endl;
	for (const auto& tup : ansO) {
		cout << get<0>(tup) + 1 << " " << get<1>(tup) + 1 << " " << get<2>(tup) + 1 << " " << get<3>(tup) + 1 << endl;
	}
	return 0;
}

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

int main() {
	int ans,sum,x=1;
	while(x!=0){
		int price=0;	
		cin>>sum;
		for(int i=0;i<9;i++){
			int a=0;
			cin>>a;
			price=price+a;
			x=a;
		}
		ans=sum-price;
		if(ans!=0){
			cout<<ans<<endl;
			}
	}
	
	
	return 0;
}

Measured memory_bytes: 1160
import collections
while True:
    w,h = map(int,input().split())
    if w==0 and h==0:
        break
    tile=[]
    tile.append(["#"]*(w+2))
    for _ in range(h):
        temp= list(input())
        temp=  ["#"]+ temp + ["#"]
        tile.append(temp)
    tile.append(["#"]*(w+2))

    route=[[[0,0,0,0] for i in range(w)] for j in range(h)]
    for i in range(1,h+1):
        for j in range(1,w+1):
            if tile[i+1][j] ==".":
                route[i-1][j-1][0]= 1
            if tile[i-1][j] ==".":
                route[i-1][j-1][1]= 1
            if tile[i][j+1] ==".":
                route[i-1][j-1][2]= 1
            if tile[i][j-1] ==".":
                route[i-1][j-1][3]= 1
            if tile[i][j]=="@":
                st=[i-1,j-1]

    dir= [[1,0],[-1,0],[0,1],[0,-1]]
    d=[[0]*w for i in range(h)]
    d[st[0]][st[1]]=1
    q= collections.deque()
    q.append(st)
    while len(q)> 0:
        cur = q.popleft()
        for i in range(4):
            if route[cur[0]][cur[1]][i]==1 and d[cur[0]+dir[i][0]][cur[1]+dir[i][1]]==0:
                d[cur[0]+dir[i][0]][cur[1]+dir[i][1]]=1
                q.append([cur[0]+dir[i][0],cur[1]+dir[i][1]])

    ans=0
    for i in range(h):
        for j in range(w):
            if d[i][j] == 1:
                ans+=1
    print(ans)


Measured memory_bytes: 6100
from fractions import gcd
A, B, C, D = map( int, input().split() )

# 方針
# 入力例1をよくみてみる。
# 1 2 3 4 5 6 7 8 9 10 11... に対して範囲[ 4, 9 ]の間で2の倍数を(),3の倍数を{}で示す
# 1 (2) {3} | (4) 5 {(6)} 7 (8) {9} | (10) 11.. となる。
# 範囲[1,9]の間の倍数で"ない"ものの個数と範囲[1,3]の間の倍数で"ない"ものの個数がわかれば良いことがわかる

# 範囲[ 1, upper ]の倍数で"ない"ものの個数
# Cの倍数とDの倍数を足してCDの最小公倍数を引く。それらが倍数で"ある"ものの個数。
# よって戻り値は全体から倍数で"ある"ものの個数を引く
def get_non_div_cnt_with_range( upper ):
  num_of_range_with_C  = ( upper // C )
  num_of_range_with_D  = ( upper // D )
  num_of_range_with_CD = ( upper // ( C * D // gcd( C, D ) ))
  return upper - ( num_of_range_with_C + num_of_range_with_D - num_of_range_with_CD )

upper_limit = B
lower_limit = A - 1
  
print( get_non_div_cnt_with_range( upper_limit ) - get_non_div_cnt_with_range( lower_limit ) )


Measured memory_bytes: 5048
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=1000000000000000003;
const int32_t LOG=21;
const int MOD=MOD2; 
int dp[40];
int comb[40];
int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {
          int n,m;
          cin>>n>>m;
          int a[n];
          rep(i,0,n)cin>>a[i];
          int sum=accumulate(a,a+n,0LL);
          int lim=sum/(4*m);
          int cnt=0;
          rep(i,0,n)
          {
             if(a[i]>lim)cnt++;
             else if(a[i]==lim && lim*4*m==sum)cnt++;
          }
          if(cnt>=m)cout<<"Yes"<<endl;
          else cout<<"No"<<endl;   
      }
      return 0;                         
}

/*
 TIPS(FOR ME):
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/


Measured memory_bytes: 256
import math
A, B, C=map(int,input().split())
x=C//(A*7+B)
y=C%(A*7+B)

z=math.ceil(y/A)
r=math.ceil(z/(A*7+B))
if z>=7:
    print(x*7+7*r)
else:
    print(x*7+z)



Measured memory_bytes: 5664
#include <iostream>
#include <map>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

map<int, int> p;

void prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			++p[i];
			n /= i;
		}
	}
	if (n != 1)p[n]++;
}

int main() {
	int n;
	cin >> n;
	for (int i = 2; i <= n; i++) {
		prime(i);
	}
	ll ans = 1;
	for (int i = 2; i <= n; i++) {
		ans *= 1 + p[i];
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int i=0;
  char a[20];
  while(1){
    scanf("%c",&a[i]);
    if(a[i]=='\n')break;
    i++;
  }
  for(i-=1;i>=0;i--){
    printf("%c",a[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 932
s = input()
a = s.count('a')
b = s.count('b')
c = s.count('c')

n = len(s)
if n%3 == 0:
    if a == b and b == c:
        print('YES')
    else:
        print('NO') 

elif n%3 == 1:
    v = [a,b,c]
    v.sort()
    if v[0] == v[1] and v[1]+1 == v[2]:
        print('YES')
    else:
        print('NO')


elif n%3 == 2:
    v = [a,b,c]
    v.sort()
    if v[0]+1 == v[1] and v[1] == v[2]:
        print('YES')
    else:
        print('NO')

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    REP(i, K) {
        if (A >= B)
            B *= 2LL;
        else if (B >= C)
            C *= 2LL;
    }

    if (A < B && B < C)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 3636
/**
 *    author:  otera    
**/
#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;

#define int long long
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)  cerr << #x << " = " << (x) << endl;
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() {
	int a, b, c, k; cin >> a >> b >> c >> k;
    if(k <= a) {
        cout << k << endl;
    } else if(k <= a + b) {
        cout << a << endl;
    } else {
        cout << a - (k - a - b) << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
const int MAXN=3010;
string s,dp[2][MAXN];
char x;
int sl,tl;

int main(){
	cin>>s,sl=s.size(),s=" "+s; cin.get();
	while(x=getchar()){
		if(x=='\n') break;
		++tl;
		for(register int j=1;j<=sl;++j){
			if(s[j]==x) dp[tl&1][j]=dp[(tl-1)&1][j-1]+x;
			else dp[tl&1][j]=(dp[(tl-1)&1][j].size()>dp[tl&1][j-1].size()?dp[(tl-1)&1][j]:dp[tl&1][j-1]);
		}
	}
	cout<<dp[tl&1][sl]<<endl;
	return 0;
}

Measured memory_bytes: 22200
#include<iostream>
#include<vector>

int main() {
  int town_n, road_n;
  std::cin >> town_n >> road_n;
  std::vector<int> data(town_n);
  for (int i=0; i<road_n; i++) {
    int temp_t1, temp_t2;
    std::cin >> temp_t1 >> temp_t2;
    data.at(temp_t1-1)++;
    data.at(temp_t2-1)++;
  }
  for (int i=0; i<town_n; i++) {
    std::cout << data.at(i) << std::endl;
  }
}


Measured memory_bytes: 256
<?php
$n = intval(fgets(STDIN));

$minRet = ask(0);
if($minRet == 0)exit;
$maxRet = ask($n-1);
if($maxRet == 0)exit;

$min = 0;
$max = $n-1;
while($min!=$max){
    $mid = intdiv($max+$min, 2);
    $ret = ask($mid);
    if($ret == 0){
        exit;
    }else{
        if(($ret != $minRet) <> ($mid - $min) % 2){
            $max = $mid;
            $maxRet = $ret;
        }else{
            $min = $mid;
            $minRet = $ret;
        }
    }
}

function ask($a){
    echo $a,"\n";
    flush();
    $in = trim(fgets(STDIN));
    if($in == "Vacant"){
        return 0;
    }elseif($in == "Male"){
        return 1;
    }else{
        return -1;
    }
}



Measured memory_bytes: 5200
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int c[][] = new int[10][10];
        int A[][] = new int[H][W];
        for(int i = 0; i < 10; i++) {
            for(int j = 0; j < 10; j++) {
                c[i][j] = sc.nextInt();
            }
        }
        
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        
        for( int k = 0; k < 10; k++ ) {
            for( int i = 0; i < 10; i++ ) {
                for( int j = 0; j < 10; j++ ) {
                    c[i][j] = Math.min( c[i][j], c[i][k] + c[k][j] );
                }
            }
        }
        
        int sum = 0;
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                if( A[i][j] == -1 ) continue;
                sum += c[A[i][j]][1];
            }
        }
        
        System.out.println(sum);
    }
}


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

class Program {
  static void Main() {
    var s = Console.ReadLine();
    if (s.Contains('N') == s.Contains('S') && s.Contains('E') == s.Contains('W')) {
      Console.WriteLine("Yes");
    } else {
      Console.WriteLine("No");
    }
  }
}

Measured memory_bytes: 13268
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    x,k = map(int, input().split())

    a = x % k
    res = min(a, k-a)
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <stdio.h>

int main(void) {
	// your code goes here
	
	int i,j,H,W;
	
	while(-1){
	    scanf("%d %d",&H,&W);
	    if(H == 0 && W==0) break;
	    
	    for(i=1;i<=H;i++){
	        for(j=1;j<=W;j++){
	            if(i==1 || i==H || j==1 || j==W){
	                printf("#");
	            }
	            else{
	                printf(".");
	            }
	           
	        }
	        printf("\n");
	        
	    }
	    printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2052