akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

int main() {
    string S;
    cin >> S;
    int l = S.length();
    int mid;
    if(l % 2 == 0) {
        mid = l / 2;
    } else {
        mid = l / 2;
    }
    ll cnt = 0;
    for(int i = 0; i < mid; i++) {
        if(S[i] != S[l - 1 - i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  string ans = "No";
  for (int i = 0; i < n.length(); i++) {
    if (n[i] == '7') ans = "Yes";
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for(int i = 0;i < n;i++)
#define IINF 2e9
#define MOD 1e9+7

int main(void){

    string s;
    cin >> s;

    for(int i = 0; i < s.size();i++){
        if(s[i] == '?') cout << 'D';
        else cout << s[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3764
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N,M,Q;
    cin>>N>>M>>Q;
    vector<int> back(N),front(N);
    vector<char> Good(N,true);
    for(int i=0;i<N;++i){
        front[i]=(i+1)%N;
        back[i]=i==0?N-1:i-1;
    }
    int place=0;
    for(int i=0;i<M;++i){
        int num;
        cin>>num;
        if(num%2==0){
            for(int j=0;j<num;++j){
                place=front[place];
            }
        }else{
            for(int j=0;j<num;++j){
                place=back[place];
            }
        }
        Good[place]=false;
        front[back[place]]=front[place];
        back[front[place]]=back[place];
        place=front[place];
    }
    for(int i=0;i<Q;++i){
        int num;
        cin>>num;
        cout<<(Good[num]?1:0)<<endl;
    }
}

Measured memory_bytes: 4648
#include<stdio.h>

int main(){
  int a, b;
  scanf("%d %d", &a, &b);

  
  if(a < b){
    printf("a < b\n");
  }
  else if(a > b){
    printf("a > b\n");
  }
  else{
    printf("a == b\n");
  }

  return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  for(int i=0; i<n; i++){
    cin >> l.at(i);
  }
  vector<int> d(n+1);
  d.at(0)=0;
  int count=1;
  for(int i=1; i<n+1; i++){
    d.at(i) = d.at(i-1) + l.at(i-1);
    if(d.at(i) <= x){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
//substr
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];

int main(){
    int n, m = 1, sum = 0;
    cin >> n;
    int a[n];
    rep(i, n){
        cin >> a[i];
        sum += a[i] - 1;
    }
    cout << sum << endl;
    return 0;
}

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

int main()
{
	int b,r,g,c,s,t;
	while(cin >> b >> r >> g >> c >> s >> t){
		if(b==0 && r==0)
			break;
		int medal = 100;
		int bonus = 0;
		bonus += b*5;
		medal += b*15;
		bonus += r*3;
		medal += r*15;
		medal += g*7;
		medal += c*2;
		t -= s;
		t -= bonus;
		medal += bonus*13;
		medal -= 3*t;
		cout << medal << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
  ll a,b,n,f=0;
  cin>>a>>b;
  string s;
  cin>>s;
  n=s.length();
  for(int i=0;i<a;i++)
  {
    if(s[i]=='-')
      f=1;
  }
  if(s[a]=='-')
  {
    for(int i=a+1;i<n;i++)
    {
      if(s[i]-'0'>9||s[i]-'0'<0)
      {
        f=1;
        break;
      }

    }
    if(f)
      No
    else
      Yes
  }
  else
  {
    No
  }
    
}
return 0;
}

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

const static ll MOD = (1e+9)+7;

int main(){
    //全探索で余裕じゃないか...
    int n,m;cin>>n>>m;
    vector<vector<bool>> A(n,vector<bool>(n,0));
    vector<vector<bool>> B(m,vector<bool>(m,0));
    rep(i,n){
        rep(j,n){
            char s;cin>>s;
            if(s == '#'){
                A[i][j]=1;
            }
        }
    }
    rep(i,m){
        rep(j,m){
            char s;cin>>s;
            if(s == '#'){
                B[i][j]=1;
            }
        }
    }
    for(int i = 0; i<= n-m;i++){
        for(int j = 0; j<=n-m;j++){
            bool flg = 0;
            for(int a = 0; a < m;a++){
                for(int b = 0; b < m;b++){
                    if(A[i+a][j+b] != B[a][b])flg = 1;
                }
            }
            if(flg == 0){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

using namespace std;
#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

int main ()
{
  string S;
  int num[4],sum;
  string res;

  cin >> S;
  REPI(4)
    num[i] = S[i] - '0';

  REPI (8)
  {
    sum = num[0];
    REPJ (3)
    {
      if (i & (int)pow (2,j))
        sum += num[j+1];
      else
        sum -= num[j+1];      
    }

    if (sum == 7)
    {
      res = to_string (num[0]);
      REPJ (3)
      {
        if (i & (int)pow (2,j))
          res += '+';
        else
          res += '-';
        res += to_string (num[j+1]);
      }
      res += "=7";
    }
  }
  cout << res << endl;
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  string S; cin >> S;
  int s1 = stoi(S.substr(0, 2));
  int s2 = stoi(S.substr(2, 2));

  bool yymm = false, mmyy = false;
  if ((0 <= s1 && s1 <= 99) && (1 <= s2 && s2 <= 12)) {
    yymm = true;
  }

  if ((0 <= s2 && s2 <= 99) && (1 <= s1 && s1 <= 12)) {
    mmyy = true;
  }

  if (yymm && mmyy) {
    cout << "AMBIGUOUS" << endl;
  } else if (yymm) {
    cout << "YYMM" << endl;
  } else if (mmyy) {
    cout << "MMYY" << endl;
  } else {
    cout << "NA" << endl;
  }
}

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

t = l-1
cnt = 1

edge = []

while t > 0:
    if t % 2 == 0:
        edge.append((cnt, -1, t))
        t -= 1

    k = (t+1)//2
    edge.append((cnt, cnt+1, 0))
    edge.append((cnt, cnt+1, k))
    t = k-1
    cnt += 1

print(cnt, len(edge))

for u, v, w in edge:
    if v == -1:
        v = cnt
    print(u, v, w)


Measured memory_bytes: 38384
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
C = Counter(S)
l = []
max = C.most_common(1)[0][1]
for c in C.most_common():
    if max == c[1]:
        l.append(c[0])
    else:
        break
l.sort()
print("\n".join(l))

Measured memory_bytes: 45040
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int main() {

    ll N;
    cin >> N;
    vector<int> A, B;
    ll Asum = 0;
    ll Bsum = 0;
    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        A.push_back(a);
        Asum += a;
    }
    for (int i = 0; i < N; ++i) {
        ll b;
        cin >> b;
        B.push_back(b);
        Bsum += b;
    }

    //総和が負けてる場合は構築できない
    if (Bsum > Asum) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> Plus, Minus;
    ll MinusSum = 0;

    for (int i = 0; i < N; ++i) {
        ll x = A[i] - B[i];
        if(x < 0){
            Minus.push_back(x);
            MinusSum += x;
        }else if (x > 0){
            Plus.push_back(x);
        }
    }
    if(MinusSum == 0){
        cout << 0 << endl;
        return 0;
    }
    sort(Plus.begin(),Plus.end(),greater<ll>());
    ll c = 0;
    for (int i = 0; i < Plus.size(); ++i) {
        ll p = Plus[i];
        MinusSum += p;
        if(MinusSum >= 0){
            c=i+1;
            break;
        }
    }

    cout << Minus.size() + c << endl;

    return 0;
}

Measured memory_bytes: 1784
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut x: i64 = read();
    let k: i64 = read();
    let d: i64 = read();
    let mut ans = 0;
    if x < 0 {
        x *= -1;
    }
    let div = x / d;
    let modulo = x % d;

    if div > k {
        ans = x - k * d;
    }

    if k >= div {
        if (k - div) % 2 == 0 {
            ans = modulo;
        } else {
            ans = d - modulo;
        }
    }

    print!("{}", ans)
}


Measured memory_bytes: 2132
#include<stdio.h>
int buble(int a, int b[200]){
   int j,i,tmp;
  for(i=0;i<a;i++){
 	 for(j=0;j<a;j++){
   		 if(b[i]>b[j]){
  	   	   tmp=b[i];
   		   b[i]=b[j];
   		   b[j]=tmp;    
		  }
 	 }
  }
   return b;
  }
int main(){
  int N=0,L[200]={},p=0,q=0,d=0,e=0,f=0,count=0;
  scanf("%d",&N);
  for(p=0;p<=N;p++){
  scanf("%d",&L[p]);
  }
  L[200]=buble(N,L);
//  printf("%d\n",N);
//  for(p=0;p<N;p++){
//    printf("%d ",L[p]);
//  }
  q=(N*N*N-3*N*N+2*N)/6;
  for(d=0;d<N;d++){
    for(e=d+1;e<N;e++){
      for(f=e+1;f<N;f++){
  if(L[d]>=L[e]+L[f]||L[d]==L[e]||L[e]==L[f]||L[f]==L[e]){
    count++;
  }
      }
    }
  }
  count=q-count;
  printf("%d",count);
  return 0;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int n, h;
    cin >> n >> h;

    vector<int> v;
    int mx = 0;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;

        mx = max(mx, a);
        v.push_back(b);
    }
    sort(v.rbegin(), v.rend());
    int ct = 0;
    for (auto x: v) {
        if (h <= 0)break;
        if (mx >= x)break;
        ct++;
        h -= x;
    }
    if (h > 0)
        ct += h / mx + (h % mx > 0);
    cout << ct << endl;
}

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

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

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


int main(){
    
    int arr[3][3];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> arr[i][j];
        }
    }
    
    int diff[3][3];
    
    for(int i = 0; i < 3; i++){
        diff[i][0] = arr[i][0] - arr[i][2];
        diff[i][1] = arr[i][0] - arr[i][1];
        diff[i][2] = arr[i][1] - arr[i][2];
    }
    
    
    bool check = true;
    for(int i = 0; i < 3; i++){
        if(diff[0][i] != diff[1][i] || diff[1][i] != diff[2][i] || diff[2][i] != diff[0][i]){
            check = false;
            break;
        }
    }
    
    if(check){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    
}


Measured memory_bytes: 3632
// "header" {{{
#pragma GCC optimize("Ofast")

#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define int int64_t
#define double long double
#define Fixed fixed << setprecision(10)
#define moke_pair make_pair

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int64_t mod1 = 1000000007;
constexpr int64_t mod2 = 998244353;

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

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class T,class U> using umap = unordered_map<T,U>;

inline int64_t updiv(int64_t n,int64_t d){ return ((n + d -1) / d); }
inline int square(int a){ return a * a; }

int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
// }}}

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int a,b,k;
    cin >> a >> b >> k;

    int cnt = 0;
    for(int i = max(a,b);i >= 1;--i){
        cnt += (a % i == 0 && b % i == 0);
        if(cnt == k) return cout << i << '\n',0;
    }

    return 0;
}

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

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

    int n;
    std::cin >> n;
    double loan = 100000;
    for(int i=0; i<n; ++i){
        loan *= 1.05;
        loan = std::ceil(loan/1000)*1000;
    }
    std::cout << std::fixed << std::setprecision(0) << loan << "\n";
    return 0;
}

Measured memory_bytes: 3204
#include <stdio.h>

void countInput(int count[],int town){
	++count[town - 1];
}

int main(int argc, char const *argv[])
{
	int count[4] = {0,0,0,0};
	int a,b,one = 0,two = 0;
	for (int i = 0; i < 3; ++i)
	{
		scanf("%d%d",&a,&b);
		countInput(count,a);
		countInput(count,b);
	}
	for (int i = 0; i < 4; ++i)
	{
		if(count[i] == 1)	++one;
		else ++two;
	}
	if(one == 2 && two == 2)	printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

#define rep(i, n) for (int i = 0; i < (n); ++i)

typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<pair<int, int> > pairs(n);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        pairs[i] = make_pair(b, a);
    }
    sort(pairs.begin(), pairs.end());

    int total_time = 0;

    rep(i, n) {
        int time_limit = pairs[i].first;
        total_time += pairs[i].second;
        if (time_limit < total_time) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1792
def main():
    antidote, antidote_delicious, poison = map(int, input().split())
    answer = antidote_delicious + poison
    if antidote + antidote_delicious < poison and antidote_delicious < poison - antidote:
        answer = antidote + 2 * antidote_delicious + 1
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
using namespace std;
typedef long long ll;
const int maxn = 105;

int n,a[maxn];
int f[maxn][2];

int main() {
#ifdef suiyuan2009
  freopen("in.cpp","r",stdin);
#endif // suiyuan2009
  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i];
  f[0][0]=1;
  for(int i=1;i<=n;i++){
    f[i][0]=f[i-1][0]*(a[i]%2==0?2:1);
    f[i][1]=f[i-1][1]*3+f[i-1][0]*(a[i]%2==0?1:2);
  }
  cout<<f[n][1]<<endl;
  return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N;
  cin >> N;
  
  long sum=0;
  for(long i=1; i<N+1; i++){
    if(i%3==0) continue;
    if(i%5==0) continue;
    sum = sum + i;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int A, B, C, D;
int main() {
	cin >> A >> B >> C >> D;
	cout << max(0, min(B, D) - max(C,A)) << endl;
	return 0;
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  ios_base::sync_with_stdio(false);

  int x;
  cin >> x;

  cout << (x >= 30 ? "Yes" : "No") << '\n';
  return 0;
}

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

int N, M;

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

  priority_queue<int> pq;
  rep(i, N) {
    int A;
    cin >> A;
    pq.push(A);
  }
  rep(i, M) {
    int A = pq.top();
    pq.pop();
    pq.push(A / 2);
  }
  ll ans = 0;
  while (!pq.empty()) {
    ans += pq.top();
    pq.pop();
  }

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


Measured memory_bytes: 892
a, b, m = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)

ans = as.min + bs.min

m.times do
  x, y, c = gets.split.map(&:to_i)
  d = as[x - 1] + bs[y - 1] - c

  ans = d if d <= ans
end

puts ans


Measured memory_bytes: 18700
n = gets.to_i
hs = gets.chomp.split.map(&:to_i).reverse
ans = "Yes"
present = hs[0]
hs.each do |h|
  if h - present > 1
    ans = "No"
    break
  end
  if h - present == 1
    present = h-1
  else
    present = h
  end
end
puts ans

Measured memory_bytes: 10500
import java.util.*;
class Main{
	private static Scanner sc= new Scanner(System.in);;
	private static String str="";
	static int n=0;
	static Map<Integer,Set<String>>map=new TreeMap<Integer,Set<String>>();
	public static void main(String[] args){
		for(;!(str=sc.next()).equals("0,0");){
			args=str.split(",");
			if(!map.containsKey(n=new Integer(args[1])))map.put(n,new HashSet<String>());
			map.get(n).add(args[0]);
		}
		
		
		
		ans();
		

	}
	static void ans(){
		for(int i=0;sc.hasNext();System.out.println(i)){
			str=sc.next();i=map.size();
			for(int k:map.keySet()){
				if(map.get(k).contains(str))break;--i;
			}
		}
		
	}
}

Measured memory_bytes: 17240
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(){
  int i,j,k,N;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d ",&A[i]);
    A[i] -= (i+1);
  }
  qsort(A,N,sizeof(int),compare_int);
  int b;
  long ans=0;
  if(N%2 == 1){
    b = A[N/2];
    for(i=0;i<N;i++)
      ans+=labs(A[i]-b);
  }
  else{
    b=A[N/2 -1];
    for(i=0;i<N;i++)
      ans+=labs(A[i]-b);
    b=A[N/2];
    long anss=0;
    for(i=0;i<N;i++)
      anss+=labs(A[i]-b);
    if(anss < ans)
      ans = anss;
  }
  printf("%ld\n",ans);
  return 0;
}

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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; }

int a;
std::string s;

int main()
{
  std::cin >> a >> s;

  if( a >= 3200 )
    std::cout << s << std::endl;
  else
    std::cout << "red" << std::endl;

  return 0;
}

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

using namespace std;

#define endl '\n'

pair<int, int> join(pair<int, int> a, const pair<int, int> &b)
{
    for (int x : {b.first, b.second})
    {
        if (a.first < x) swap(a.first, x);
        if (a.second < x) swap(a.second, x);
    }
    return a;
}

int main()
{
#ifdef jcg
    assert(freopen("input.in", "r", stdin));
//    assert(freopen("output.out", "w", stdout));
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;

    N = 1 << N;

    vector<pair<int, int>> a(N);
    for (auto &p : a)
        cin >> p.first;

    for (int m, mh = 1; (m = mh << 1) <= N; mh = m)
        for (int i = 0; i < N; i += m)
            for (int j = i; j < i + mh; ++j)
                a[j + mh] = join(a[j + mh], a[j]);

    int best = 0;
    for (int i = 1; i < N; ++i)
        cout << (best = max(best, a[i].first + a[i].second)) << endl;

    return 0;
}


Measured memory_bytes: 5120
#include <stdio.h>

int main(){
	int N = 100000;
	scanf("%d\n", &N);
	int usagi[100000];
	int flag[100000] = {0};
	for (size_t i = 0; i < N; i++) {
		scanf("%d", &usagi[i]);
	}
	int count = 0;
	for (size_t i = 0; i < N; i++) {
		if (flag[i]) {
			continue;
		}
		if (usagi[usagi[i]-1]-1 == i) {
			count++;
			flag[usagi[i]-1] = 1;
		}
	}
	printf("%d\n", count);
	return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int solve(vector<int> weights, vector<int> values, int capacity)
{
  vector<int> dp(capacity + 1, 0);
  int n = weights.size();
  for (int w = 1; w <= capacity; ++w) {
    for (int i = 0; i < n; ++i) {
      if (weights[i] <= w) {
        dp[w] = max(dp[w], dp[w - weights[i]] + values[i]);
      }
    }
  }
  return dp[capacity];
}

int main()
{
  int nkinds, max_weight;
  fscanf(stdin, "%d %d", &nkinds, &max_weight);
  vector<int> weights(nkinds, 0), values(nkinds, 0);
  for (int i = 0; i < nkinds; ++i) {
    fscanf(stdin, "%d %d", &values[i], &weights[i]);
  }
  int ans = solve(weights, values, max_weight);
  fprintf(stdout, "%d", ans);
  fprintf(stdout, "\n");
  return 0;
}

Measured memory_bytes: 1252
import java.util.*;


public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n = sc.nextInt();
    static boolean[] visited = new boolean[n];
    static int[] value = new int[n];
    static List<Integer>[] edge = new ArrayList[n];



    public static void main(String[] args){
//        Scanner sc = new Scanner(System.in);
//        int n = sc.nextInt();
        int q = sc.nextInt();
//        int[] value = new int[n];
//        List<Integer>[] edge = new ArrayList[n];

        for (int i=0; i<n; i++){
            edge[i] = new ArrayList<>();
        }

        Node[] nodes = new Node[n];
        for (int i=0; i<n; i++) nodes[i] = new Node();

        for (int i=0; i<n-1; i++){
            int v = sc.nextInt()-1;
            int u = sc.nextInt()-1;
            edge[v].add(u);
            edge[u].add(v);
        }

        for (int i=0; i<q; i++){
            int s = sc.nextInt()-1;
            int v = sc.nextInt();
            value[s] += v;
        }

        dfs(0, 0l);



//        List<Integer> l = new ArrayList<>();
//        Queue<Integer> l = new ArrayDeque<>();

//        l.add(0);
//
//        while (!l.isEmpty()){
//            int a = ((ArrayDeque<Integer>) l).pollFirst();
//            for (int c: edge[a]){
//                value[c] += value[a];
//                l.add(c);
//            }
//        }

        for (int i=0; i<n; i++){
            System.out.print(value[i]+" ");
        }
    }

    private static void dfs(int u, long cnt){
        visited[u] = true;
        value[u] += cnt;
        for (int v: edge[u]){
            if (!visited[v]){
                dfs(v, value[u]);
            }
        }

    }

    public static class Node{
        static List<Node> adj = new ArrayList<>();
        static int offset;
        static int cnt;
    }

}


Measured memory_bytes: 223184
// C - Linear Approximation

// 中央値を求める解法

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int N;
ll B[200001];

ll err(int k) {
	ll result = 0;

	for (int i=1; i<=N; i++) {
		result += abs(B[i] - k);
	}

	return result;
}

int main() {
	cin >> N;

	for (int i=1; i<=N; i++) {
		int A;
		cin >> A;
		B[i] = A - i;
	}

	sort(B+1, B+N+1);

	ll ans = err(B[N/2 + 1]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5060
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;

int solve(){
    int n;
    cin>> n;
    vll x(n), y(n);
    rep(i, 0, n){
        ll xx, yy;
        cin>> xx>> yy;
        x[i] = xx + yy;
        y[i] = xx - yy;
    }
    sort(all(x));
    sort(all(y));
    ll a[2];
    a[0] = abs(x.back() - x[0]);
    a[1] = abs(y.back() - y[0]);
    ll ans = max(a[0], a[1]);
    cout<< ans<< "\n";
    return 0;
}
//Counting problems: Sometimes easier to find complement of the answer
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


Measured memory_bytes: 6332
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ans := make(map[int]int, n)
	for i := 2; i <= n; i++ {
		var temp int
		fmt.Scan(&temp)
		ans[temp]++
	}

	for i := 1; i <= n; i++ {
		fmt.Println(ans[i])
	}
}

Measured memory_bytes: 12004
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int>h(n);
	rep(i, n) cin >> h[i];
	h.pb(0);
	ll sum = 0;
	rep(i, n)if (h[i] > h[i + 1 ]) {
		sum += h[i] - h[i + 1];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}
import qualified Data.Array.MArray as MA
import Control.Monad
import Data.Ix
import Data.Array.IO
import Data.Functor

main::IO ()
main=do
  n <- read <$> getLine::IO Int
  let aryRange= (1,n)
  numList <- map read . words <$> getLine::IO [Int]
  ary <- MA.newListArray aryRange numList::IO (IOUArray Int Int)
  mapM_
    (\x->
      do
        insert aryRange x ary
        output <- unwords . map show <$> MA.getElems ary
        putStrLn output
    )
    [1..n]


change::(MA.MArray a e m, Ix i)=>i->i->a i e->m ()
change a b ary=do
  va <- MA.readArray ary a
  vb <- MA.readArray ary b
  MA.writeArray ary a vb
  MA.writeArray ary b va

insertSort::MA.MArray a Int m=>a Int Int ->m ()
insertSort ary=
  do
    (minI,maxI) <- MA.getBounds ary
    mapM_ (\n->insert (minI,maxI) n ary) [2..maxI]

insert::MA.MArray a Int m=>(Int,Int)->Int->a Int Int->m ()
insert (minI,maxI) begin ary=
  if begin > minI
    then
      do
        let back=begin-1
        forward<- MA.readArray ary back
        next<- MA.readArray ary begin
        when (forward > next)
          $ do
            change back begin ary
            when (minI < back) (insert (minI,maxI) back ary)
    else
      return ()

Measured memory_bytes: 4080
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll n,a;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>n>>a;
	if((n%500)<=a)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

#define int             long long
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define endl             '\n'
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr <<'}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i);cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



int string_to_int(string s){
	int ans = 0;
	int p=1;
	for(int i=s.size()-1;i>=0;i--){
		ans += (s[i]-'0')*p;
		 p *= 10;
	}
	return ans;
}

void t_c_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	int n; cin >> n;
	int arr[n];
	int sum = 0;
	int mx = INT_MIN;
	for(int i=0;i<n;i++){
		cin >> arr[i];
		if(arr[i]>mx){
			mx = arr[i];
		}
		sum += arr[i];
	}
	int pre[100001];
	memset(pre,0, sizeof pre);
	for(int i=0;i<n;i++){
		pre[arr[i]-1]++;
	}
	int q; cin >> q;
	while(q--){
		int cnt = 0;
		int a,b; cin >> a >> b;
		cnt = pre[a-1];
		sum -= cnt*a;
		sum += cnt*b;
		pre[a-1] = 0;
		pre[b-1] += cnt;
		cout << sum << endl;
	}
}

int32_t main()
{
	t_c_c();
	return 0;
}


Measured memory_bytes: 5224
class Node():
    def __init__(self, id):
        self.id = id
        self.left = None
        self.right = None
        self.parent = None
        self.marked = 0
    def setLeft(self, left):
        left.parent = self
        self.left = left
    def setRight(self, right):
        right.parent = self
        self.right = right
    def __str__(self):
        return str(self.id)


def preorder(arr, root, res):
    if root == None:
        return
    res.append(root)
    preorder(arr, root.left, res)
    preorder(arr, root.right, res)

def inorder(arr, root, res):
    if root == None:
        return
    inorder(arr, root.left, res)
    res.append(root)
    inorder(arr, root.right, res)

def postorder(arr, root, res):
    if root == None:
        return
    postorder(arr, root.left, res)
    postorder(arr, root.right, res)
    res.append(root)


def main():
    n = int(input())
    array = [Node(i) for i in range(n)]
    for node in array:
        i, l, r = list(map(int, input().split()))
        array[i].setLeft(array[l]) if l != -1 else None
        array[i].setRight(array[r]) if r != -1 else None
    
    root = None
    for node in array:
        if node.parent == None:
            root = node
            break

    res = []
    preorder(array, root, res)
    print("Preorder\n ", end="")
    print(*res) 
    res = [] 
    inorder(array, root, res)
    print("Inorder\n ", end="")
    print(*res)
    res = []
    postorder(array, root, res)
    print("Postorder\n ", end="")
    print(*res)
    
if __name__ == "__main__":
    main()

        

    



Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

int main(){
  string s; int n,k; 
  cin >> n >> s;
  k = s.size();
  
  for(int i=0; i<k; i++){
    s[i] += n;
    if(s[i]>90){s[i]-=26;}
  }
  cout << s <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <array>
#include <algorithm>
#include <set>

using namespace std;

#define int long long

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

    string a, s, d;

    cin >> a >> s;

    d = a + s;

    int x = std::atoi(d.c_str());

    for (int i = 1; i <= x; ++i)
    {
        if (i*i == x)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
#define MOD 998244353 //1000000007

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

    // solution comes here

    ll N;   cin >> N;
    vl h(N);
    rep(i, N) cin >> h[i];

    ll ans=h[N-1];
    rep(i, N-1) {
        if(h[i]>h[i+1]) ans -= h[i+1] - h[i];
    }
    cout << ans << nl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;
multimap<string, ll> mp;
int main(){
    int n, m;
    cin >> n;
    set<ll> a;
    rep(i,n){
        ll an; cin >> an;
        a.insert(an);
    }
    cin >> m;
    set<ll> b;
    rep(i,m){
        ll bn; cin >> bn;
        b.insert(bn);
    }

    vector<ll> c;
    set_intersection(all(a), all(b), back_inserter(c));
    rep(i,c.size())cout << c[i] << endl;
    return 0;
}


Measured memory_bytes: 22096
#include <iostream>
using namespace std;
int main(void){
   int a, b, c;
   cin >> a >> b >> c;
   
   int x = 0;
   for(int i = a;i <= b;i++){
       
       if(c%i == 0){
           x++;
       }
   }
   cout << x << endl;
    
}
//ITP1_3_D


Measured memory_bytes: 3088
# AOJ ITP1_10_C

import math

def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    while True:
        n = int(input())
        if n == 0: break
        data = intinput()
        sum_1 = 0  # 1乗の総和
        sum_2 = 0  # 2乗の総和
        for i in range(n):
            sum_1 += data[i]; sum_2 += data[i] ** 2
        # print('(%d, %d)' % (sum_1, sum_2))
        sigma = math.sqrt((sum_2 / n) - ((sum_1 / n) ** 2))
        print(sigma)

if __name__ == "__main__":
    main()


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

int main() {
    int n;
    string s, t;
    char ans[201];
    cin >> n >> s >> t;
    for (int i = 0; i < n; i++)
    {
        ans[i*2] = s[i];
        ans[(i*2) + 1] = t[i];
    }
    //文字列の終端を示すためにnull文字を挿入
    ans[2*n] = '\0';
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

int main() {
	long a[5], n;
	cin >> n;
	long m;
	cin >> a[0];
	m = a[0];
	for (int i = 1; i < 5; i++) {
		cin >> a[i];
		m = min(m, a[i]);
	}

	long c = n / m;
	if (n%m != 0) { c++; }
	cout << c + 4 << endl;

	return 0;
}

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

using namespace std;

int main(){
  string s,s1,s2;
  int Q;
  
  cin >> s;
  cin >> Q;
  int flag = 0;
  for(int i=0;i<Q;i++){
  int a;  cin >> a;
    if(a == 1){
      flag = 1-flag;
    }
    else{
  int b; char c; cin >> b >> c; b--;
      if(flag) b = 1- b;
      if(b == 0) s1 += c;
      else s2 += c;
    }
  }
    reverse(s1.begin(),s1.end());
  string  X = s1 + s + s2;
  
    if(flag) reverse(X.begin(),X.end());
  
    cout << X << endl;
    
  }
      
      
    


Measured memory_bytes: 1348
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

#define MAX_SIZE 100010
#define INF 1ll << 40
typedef long long ll;

int main() {
  vector<ll> P[2];
  P[0].reserve(MAX_SIZE);
  P[1].reserve(MAX_SIZE);
  for (int i = 0; i < MAX_SIZE; ++i) {
    P[0][i] = P[1][i] = INF;
  }
  P[0][0] = 0;
  P[1][0] = 0;

  int A, B, Q;

  cin >> A >> B >> Q;
  for (int i = 1; i <= A; ++i) {
    cin >> P[0][i];
  }

  for (int i = 1; i <= B; ++i) {
    cin >> P[1][i];
  }

  for (int q = 0; q < Q; ++q) {
    ll ans = INF;
    ll x;
    cin >> x;
    for (int i = 0; i < 2; ++i) {
      int pos = lower_bound(P[i].begin(), P[i].begin() + MAX_SIZE, x) - P[i].begin();
      for (int j = 0; j < 2; ++j) {
        ll target = P[i][pos-j];
        if (target == 0 || target == INF) continue;
        ll target_l = abs(target  - x);

        int pos2 = lower_bound(P[i^1].begin(), P[i^1].begin() + MAX_SIZE,target) - P[i^1].begin();
        for (int k = 0; k < 2; ++k) {
          ll target2 = P[i^1][pos2-k];
          if (target2 == 0 || target2 == INF) continue;
          ll target2_l = abs(target2 - target);
          ans = min(ans, target_l + target2_l);
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}



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

ans = 'No'
if n%4 == 0 or n%7 == 0 or n%11 == 0:
  ans = 'Yes'
else:
  for i in range(15):
    if (n - 7*i)%4 == 0 and (n - 7*i) >= 0:
      ans = 'Yes'
      break
      
print(ans)

Measured memory_bytes: 2940
d, g = [int(i) for i in input().split()]
p = [0] + [[int(i) for i in input().split()] for _ in range(d)]

def recursive(d, g):
    if d == 0:
        return 10 ** 9
    n = min(g // (100 * d), p[d][0])
    t = 100 * d * n
    # Full
    if n == p[d][0]:
        t += p[d][1]
    # Partial
    if t < g:
        n += recursive(d-1, g-t)
    return min(n, recursive(d-1, g))

def bit(d, g):
    ans = 10 ** 9
    for i in range(2 ** d):
        b = '-' + format(i, '0{}b'.format(d))
        last_zero_index = 0
        tmp_ans = 0
        total_score = 0
        for j in range(1, d+1):
            if b[j] == '1':
                total_score += p[j][0] * (100 * (j))
                total_score += p[j][1]
                tmp_ans += p[j][0]
            else:
                last_zero_index = j
        if total_score < g:
            diff = g - total_score
            q = diff // (100 * last_zero_index)
            r = diff % (100 * last_zero_index)
            if r != 0:
                q += 1
            if q > p[last_zero_index][0]:
                continue
            else:
                tmp_ans += q
        ans = min(ans, tmp_ans)
    return ans

#solve = recursive
solve = bit
print(solve(d, g))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define kmax 32
int n, m, k;
int a[kmax];

int main(){
    int idx = 0;
    scanf("%d%d", &n, &m);
    for(int i=0; i<n ; i++){
        scanf("%d", &k);
        for(int j=0; j<k; j++){
            scanf("%d", &idx);
            a[idx-1]++;
        }
    }
    int cnt=0; 
    for(int i=0; i<kmax; i++){
        if(a[i]==n){
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0; 
}


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

int main(){
	long long N,K;
	while(cin >> N >> K && N){
		N--;
		long long p = 9 , c = 0;
		while(N>=p*(c+1)){
			N -= p * (c+1);
			p *= 10; 
			c++;
		}
		long long r = N / (c+1);
		N -= r * (c+1);
		stringstream ss;
		long long ten = 1;
		for(int i = 0 ; i < c ; i++) ten *= 10;
		long long st = ten + r;
		
		while(ss.str().size() <= N+K)ss << st,st++;
		cout << ss.str().substr(N,K) << endl;
	}
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  string s;
  cin>>s;
  int min=1000000000;
  char x,y,z;

  r(i,s.size()-2){
    x=s.at(i)-'7';

    y=s.at(i+1)-'5';
    z=s.at(i+2)-'3';
    //int a=x,b=y,c=z;
    //cout<<a<<" "<<b<<" "<<c<<endl;

  if(min>=abs(x*100+y*10+z)){
    min=abs(x*100+y*10+z);
  }
  }
  cout<<min<<endl;


return 0;}


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

int n;

int main()
{
	cin >> n;
	int tmp = n;
	int res = 0;
	while(1){
		res += tmp % 10;
		tmp /= 10;
		if(tmp == 0){
			break;
		}
	}
	string msg ="";
	if(n % res == 0){
		msg ="Yes";
	}
	else {
		msg = "No";
	}
	cout << msg << endl;
}

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

using namespace std;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 1e5 + 10;

int n;
int a[N];
map <int, int> mp;

void run() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    mp[a[i]]++;
  }
  int ans = 0;
  for (auto kv : mp) {
    ans += kv.second >= kv.first ? (kv.second - kv.first) : kv.second;
  }
  printf("%d\n", ans);
}

int main() {
  run();
  return 0;
}


Measured memory_bytes: 5120
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, M, C = map(int, input().split())
    B = list(map(int, input().split()))

    ans = 0
    for _ in range(N):
        A = list(map(int, input().split()))
        val = C
        for i in range(M):
            val += A[i] * B[i]
        if val > 0: ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include<iostream>
using namespace std;
int n;
int main()
{
	cin>>n;
	if(n<10)cout<<n;
	else if(n<100)cout<<9;
	else if(n<1000)cout<<n-90;
	else if(n<10000)cout<<909;
	else if(n<100000)cout<<n-9090;
	else cout<<90909;
	return 0;
}

Measured memory_bytes: 256