akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

  

int main() {
  Cinint(a);
  Cinint(b);
  Cinint(c);
  Cinint(d);
  rep(i, 100) {
    c -= b;
    if (c <= 0) {
      coYes;
      break;
    }
    a -= d;
    if (a <= 0) {
      coNo;
      break;
    }
  }
}
 

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w, m; cin >> h >> w >> m;
  vector<int> H(m), W(m);
  map<int, int> cntH, cntW;
  set<pair<int, int>> st;
  rep(i, m) {
    cin >> H[i] >> W[i];
    H[i]--; W[i]--;
    st.insert({H[i], W[i]});
    cntH[H[i]]++;
    cntW[W[i]]++;
  }
  int mxH = 0, mxW = 0;
  vector<int> mxi, mxj;
  for(auto ele: cntH) {
    if(ele.second > mxH) {
      mxi.clear();
      mxi.push_back(ele.first);
    } else if(ele.second == mxH) {
      mxi.push_back(ele.first);
    }
    chmax(mxH, ele.second);
  }
  for(auto ele: cntW) {
    if(ele.second > mxW) {
      mxj.clear();
      mxj.push_back(ele.first);
    } else if(ele.second == mxW) {
      mxj.push_back(ele.first);
    }
    chmax(mxW, ele.second);
  }
  ll ans = mxH + mxW;
  for(int i: mxi) {
    for(int j: mxj) {
      if(!st.count({i, j})) {
        cout << ans << endk;
        return 0;
      }
    }
  }
  cout << ans-1 << endk;
  return 0;
}


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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
 
////////////////////////////////////////////////////////////////////

const int N = 5e1 + 5;

int A[N], B[N], P[N][N];
bool M[N];

bool DFS(int v, int u) {
	if (P[v][u] != -1) return P[v][u];
	if (v == u) return P[v][u] = 1;
	for (int i = 1; i <= v; i++) if (!M[i] && DFS(v % i, u)) return P[v][u] = 1;
	return P[v][u] = 0;
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));
	
	memset(P, -1, sizeof P);
	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i];
	for (int i = 0; i < n; i++) cin >> B[i];
	for (int i = 0; i < n; i++) if (!DFS(A[i], B[i])) die(-1);
	ll ans = 0;
	for (int i = N - 1; i > 0; i--) {
		memset(P, -1, sizeof P);
		bool f = M[i] = true;
		for (int j = 0; j < n; j++) f &= DFS(A[j], B[j]);
		if (!f) M[i] = false, ans += (1LL << i);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
x,y,z,k = map(int, input().split())
aa = sorted(list(map(int, input().split())))
bb = sorted(list(map(int, input().split())))
cc = sorted(list(map(int, input().split())))
 
ab = sorted(a+b for a in aa for b in bb)[:-k-1:-1]
abc = sorted(s+c for s in ab[:k] for c in cc)[:-k-1:-1]
print(*abc, sep='\n')

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

int main() {
  	long long int H1, M1, H2, M2, K;
  	cin >> H1 >> M1 >> H2 >> M2 >> K;
  	if (H2 * 60 + M2 - H1 * 60 - M1 - K >= 0)cout << H2 * 60 + M2 - H1 * 60 - M1 - K << endl;
  	else cout << 0 << endl;
}

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

int a, b, c, d;

int main() {
    cin >> a >> b >> c >> d;
    while (a > 0){
        c -= b;
        if (c <= 0){
            cout << "Yes";
            exit(0);
        }
        a -= d;
    }
    cout << "No";
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, Ans="Good";
  cin >> S;
  for (int i=0; i<3; i++){
    if(S.at(i)==S.at(i+1)){
      Ans = "Bad";
      break;
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int a,b,c,d,s_1,s_2,s_3;

    scanf("%d %d %d %d",&a,&b,&c,&d);

    s_1=abs(a-c);
    s_2=abs(a-b);
    s_3=abs(b-c);

    if(s_1<=d || (s_2<=d) && (s_3<=d))
    {
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }



    return 0;
}

Measured memory_bytes: 1628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC060A___Shiritori
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            char lastChar = input.First().First();
            bool isShiritorable = true;

            foreach (string sentence in input)
            {
                if(lastChar != sentence.First())
                {
                    isShiritorable = false;
                }

                lastChar = sentence.Last();
            }

            string result = "NO";

            if (isShiritorable)
            {
                result = "YES";
            }

            Console.WriteLine(result);

        }
    }
}


Measured memory_bytes: 13268
import sys
import math
x = int(input())
li = [1]
for i in range(2,32):
    tmp = 2
    while (i ** tmp <= 1000):
        li.append(i ** tmp)
        tmp += 1
for i in range(x, 0, -1):
    if (i in li):
        print(i)
        sys.exit()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,INF=0x3f3f3f3f;
int a[N],fa[N],vis[N],mi[N];
pair<int,int>t;
priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > >Q;
int find(int x)
{
    return x==fa[x]?x:(fa[x]=find(fa[x]));
}
int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    for(int i=0; i<n; i++)
        cin>>a[i],fa[i]=i,mi[i]=INF;
    for(int i=0,u,v; i<m; i++)
    {
        cin>>u>>v,u=find(u),v=find(v);
        if(u!=v)fa[u]=v;
    }
    for(int i=0; i<n; i++)find(i);
    for(int i=0; i<n; i++)
        mi[fa[i]]=min(a[i],mi[fa[i]]),Q.push(make_pair(a[i],fa[i]));
    sort(fa,fa+n);
    int tn=unique(fa,fa+n)-fa;
    if(tn==1)
        cout<<0;
    else
    {
        long long s=0;
        for(int i=0; i<tn; i++)
            s+=mi[fa[i]];
        while(!Q.empty())
        {
            if(tn==2)break;
            t=Q.top();
            Q.pop();
            if(!vis[t.second])
            {
                vis[t.second]=1;
                continue;
            }
            s+=t.first,--tn;

        }
        if(tn==2)cout<<s;
        else cout<<"Impossible";
    }
    return 0;
}


Measured memory_bytes: 2676
// インクルード
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>

// 名前空間省略
using namespace std;

// メイン
int main()
{
	// 入出力の高速化
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// 表示精度変更
	cout << fixed << setprecision(16);

	int n,k;
	bool d[10];
	for(int i=0;i<10;i++) d[i] = false;

	cin >> n >> k;
	for(int i=0;i<k;i++){
		int x;
		cin >> x;
		d[x] = true;
	}

	bool flag = false;
	while(1){
		string s = to_string(n);
		for(int i=0;i<s.length();i++){
			if(d[s[i]-'0'] == true){
				break;
			}
			if(i==s.length()-1){
				cout << n << endl;
				return 0;
			}
		}
		n++;
	}
}

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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    rep(i, sz(v)) cout << v[i] << ",";
    cout << "]";
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N, M;
int A[2001], B[2001];
ll dp[2001][2001];
int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N >> M;
    repp(i, 1, N+1) cin >> A[i];
    repp(i, 1, M+1) cin >> B[i];

    rep(i, 2001) dp[i][0] = dp[0][i] = 1;
    repp(i, 1, N+1) repp(j, 1, M+1) {
        dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
        if (A[i] == B[j]) dp[i][j] += dp[i-1][j-1];
        dp[i][j] = (dp[i][j]+MOD)%MOD;
    }

    cout << dp[N][M] << endl;
}


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

int main() {
  int N;
  string S;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if (i+1 < N)
      continue;
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 3612
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

double expValue(int val){
    double ans = 0;
    for(int i = 0; i <= val; i++) ans += i;
    return ans / val;
}

int main()
{
    int n, k;
    cin >> n >> k;
    long double tot = 0;
    vector<double> table(200005);
    for(int i = 1; i <= n; i++){
        int a;
        cin >> a;
        table[i] = expValue(a);
    } 
    for(int i = 1; i <= k; i++) tot += table[i];
    long double max = tot;
    for(int i = 1; i + k <= n; i++){
        tot -= table[i];
        tot += table[i+k];
        if(max < tot) max = tot;
    }
    printf("%Lf", max);
}

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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 1001001001;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n), l(n), r(n);
    rep(i, n) {
        cin >> a[i];
    }

    l[0] = a[0];
    r[n-1] = a[n-1];
    frep(i, 1, n-1) {
        l[i] = my_gcd(l[i-1], a[i]);
        r[n-1-i] = my_gcd(r[n-i], a[n-1-i]);
    }
    ll ans = 0;
    rep(i, n) {
        if(i==0) {
            if(r[1] > ans) ans = r[1];
        }
        else if(i==n-1) {
            if(l[n-2] > ans) ans = l[n-2];
        }
        else {
            ll tmp = my_gcd(l[i-1], r[i+1]);
            if(ans < tmp) ans = tmp;
        }
    }
    cout << ans << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        ret %= MOD;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count))%MOD;
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}



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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    for (int i=0;i<N;i++) cin >> a[i];
    ll ans = 0;
    if (a[0] > x) {
        int p = a[0] - x;
        a[0] -= p;
        ans += p;
    }
    for (int i=1;i<N;i++){
        if (a[i-1]+a[i]>x) {
            int p = a[i-1]+a[i]-x;
            a[i] -= p;
            ans += p;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()) {
	    int w = kbd.nextInt();
	    if(w!=-1){
		System.out.println(4280-solve(w));
	    }
	}
    }

    static int solve(int w) {
	int r = 0;
	int bill = 0;
	while(w>=0){
	    bill += cost(w, r);
	    w -= 10;
	    r ++;
	    //System.out.println("p");
	}
	return bill;
    }

    static int cost(int w, int r){
	if(r==0){ return 1150; }
	else if(r==1){ 
	    if(w>=10) return 125*10;
	    else return 125*w;
	}
	else if(r==2){
	    if(w>=10) return 140*10;
	    else return 140*w;
	}
	else if(r>2){
	    if(w>=10) return 160*10;
	    else return 160*w;
	}
	else return 0;
    }
}

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

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

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

  int n;
  cin >> n;

  if (n % 2 == 0) {
    cout << n << endl;
  } else {
    cout << n * 2 << endl;
  }
  return 0;
}


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

int main()
{
    string a;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='0')
        {
            a.push_back(s[i]);
        }
        else if(s[i]=='1')
        {
            a.push_back(s[i]);
        }
        else if(s[i]=='B')
        {
            if(!a.empty())
            {
                a.pop_back();
            }
            
        }
    }
    
    cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 256
use io::*;

fn main() {
    let con = read_string();
    let mut sc = Scanner::new(&con);

    let a: i64 = sc.next();
    let b: i64 = sc.next();
    let c: i64 = sc.next();
    let k: i64 = sc.next();

    let ans = if k % 2 == 0 { a - b } else { b - a };

    println!("{}", ans);

    // let m: Mat = [[0, 1, 1], [1, 0, 1], [1, 1, 0]];

    // for i in 0..100 {
    //     println!("{}: {:?}", i, mpow(&m, i));
    // }

    // let mm = mpow(&m, k);

    // let ma = mm[0][0] * a + mm[0][1] * b + mm[0][2] * c;
    // let mb = mm[1][0] * a + mm[1][1] * b + mm[1][2] * c;
    // let ans = ma - mb;

    // if ans.abs() > 1000_000_000_000_000_000 {
    //     println!("Unfair");
    // } else {
    //     println!("{}", ans);
    // }
}

type Mat = [[i64; 3]; 3];

fn mpow(a: &Mat, n: i64) -> Mat {
    if n == 0 {
        [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
    } else {
        let t = mpow(&mmul(a, a), n / 2);
        if n % 2 == 0 {
            t
        } else {
            mmul(&t, a)
        }
    }
}

fn mmul(a: &Mat, b: &Mat) -> Mat {
    let mut c: Mat = [[0; 3]; 3];

    for i in 0..3 {
        for j in 0..3 {
            for k in 0..3 {
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }

    c
}

//-----

pub mod io {
    use std;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T>(&mut self) -> T
        where
            T: std::str::FromStr,
            <T as std::str::FromStr>::Err: std::fmt::Debug,
        {
            let s = self.iter.next().unwrap();
            s.parse::<T>().unwrap()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 4352
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int a = int.Parse(Console.ReadLine());
    int b = int.Parse(Console.ReadLine());

		Console.WriteLine(6-a-b);
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN=1e5+10,MAXM=1e6+10;
const int INF=~(1<<31),MOD=1e9+7;
int a[MAXN];

int main()
{
    int n,m,q;
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=q;i++)
    {
        int temp;
        scanf("%d",&temp);
        a[temp]++;
    }
    for(int i=1;i<=n;i++)
        if(a[i]+m-q>0)
        puts("Yes");
    else puts("No");
	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
string s;
int sum1,sum2,sum;
int main()
{
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++)
    {
        if(s[i]=='S') sum2++;
        else if(sum2) sum1++;
        if(sum2>=sum1)
        {
            sum+=min(sum2,sum1)*2;
            sum2-=min(sum2,sum1);
            sum1=0;
        }
    }
    cout<<n-sum<<endl;
    return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
struct BIT {
	int n;
	std::vector<int> data;
	BIT (int n) : n(n) {
		data.resize(n + 1);
	}
	void add(int i, int val) {
		for (i++; i <= n; i += i & -i) data[i] += val;
	}
	int sum(int r) {
		int res = 0;
		for (; r; r -= r & -r) res += data[r];
		return res;
	}
};

int main() {
	int n = ri();
	int q = ri();
	int a[n];
	for (auto &i : a) i = ri();
	
	std::vector<std::pair<int, int> > index(n);
	for (int i = 0; i < n; i++) index[i] = {a[i], i};
	std::sort(index.begin(), index.end());
	
	struct Info {
		int l;
		int r;
		int val;
	};
	std::vector<Info> add[n + 1];
	
	int all = 0;
	for (int i = 0; i < n; ) {
		int j = i;
		while (j < n && index[j].first == index[i].first) j++;
		
		int last = 0;
		for (int k = i; k <= j; k++) {
			int cur = k == j ? n : index[k].second;
			add[last].push_back({last, cur, 1});
			add[cur].push_back({last, cur, -1});
			last = cur + 1;
		}
		i = j;
		all++;
	}
	
	std::vector<std::pair<int, int> > qs[n];
	for (int i = 0; i < q; i++) {
		int l = ri() - 1;
		int r = ri() - 1;
		qs[l].push_back({r, i});
	}
	BIT tree(n + 1);
	int res[q];
	for (int i = 0; i < n; i++) {
		for (auto j : add[i]) {
			tree.add(j.l, j.val);
			tree.add(j.r, -j.val);
		}
		for (auto j : qs[i]) res[j.second] = all - tree.sum(j.first + 1);
	}
	for (auto i : res) printf("%d\n", i);
	
	return 0;
}


Measured memory_bytes: 74228
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int h,w;
  cin>>h>>w;
  char a[h + 2][w + 2];
  rep(i,h + 2) {
    rep(j, w + 2) {
      a[i][j] = '#';
    }
  }
  FOR(i,1,h + 1) {
    FOR(j, 1, w + 1) {
      cin>>a[i][j];
    }
  }
  rep(i,h + 2) {
    rep(j, w + 2) {
      cout << a[i][j];
    }
    cout << endl;
  }

  return 0;
}


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

vector<int> ans;
int main(){
	int N,A,B; scanf("%d %d %d",&N,&A,&B);
	if(N<A) return !printf("-1");
	for(int i=N-A+1;i<=N;i++) if(i>0){
		ans.push_back(i);
	}
	N-=A;
	B--;
	if(B){
		int k=(N+B-1)/B;
		int r=N%B;
		if(!r) r=B;
		if(k>A || !k) return !printf("-1");
		while(B--){
			int gap=k-(r>0 ? 0:1);
			if(!gap) return !printf("-1");
			for(int i=N-gap+1;i<=N;i++) if(i>0){
				ans.push_back(i);
			}
			N-=gap;
			r--;
		}
	}
	if(N>0) return !printf("-1");
	for(int x : ans) printf("%d ",x);
}

Measured memory_bytes: 3440
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    cin >> n;
    vector<long> a(n);
    long yen = 1000;
    for (int i = 0; i < n; i++) cin >> a[i];
    int l = 0;
    int r = 0;
    for (int i = 1; i < n; i++) {
        if (a[i - 1] < a[i]) {
            l = i - 1;
            r = i;
        } else {
            l = i;
            r = i;
        }
        long stock = yen / a[l];
        yen -= stock * a[l];
        yen += stock * a[r];
    }
    cout << yen << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
typedef long long ll;
using namespace std;

int main(void){
  int x,a;
	cin>>x>>a;
	if(x<a){
		cout<<0<<endl;
	}
	else{
		cout<<10<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int x; cin>>x;
	if(x>=30) Yes();
	else No();


    return 0;
}



Measured memory_bytes: 3584
/*
	DSL: domain-specific language
	http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_D
	12/5/2017
	TLE: 17/22 10^10 must change the data structure--> binary tree
	update the data: set the priority
	WA 2/22
*/

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 131072 //100000
#define MAXVAL ((long int) ((unsigned long) (1 << 31) - 1))
typedef struct Node{
	int val;
	int priority;
}node;
void find(int i);
void add(int s,int t, int x,int i);
node array[2*N+100];      //the size of array, for present the tree
//BEGIN FROM 1;
int main(){
	int n = 0, q = 0;
	int a,b,c;
	//FILE *fp;
	//fp = fopen("in.txt","r");
	scanf("%d %d",&n,&q);
	
	//how to calculate the beginning index (the last layer of the tree)
	int count = 0;
	int temp = n;
	while(n!=1){
		n = n/2;
		count++;  
	}
	if(pow(2,count)!=temp) count++;
	//printf("count:%d",count);
	int B = pow(2,count)-1;
	n = temp;
	for(int i = 0; i<=B;i++){ //special case forn==1, need i = 0;
		array[i].val =  MAXVAL;
		array[i].priority = 0;
	}
	for(int i = 1; i<=n; i++){
		array[i+B].val = MAXVAL;	//e.g.begin from 8 (the last element of previous layer is 7)
		array[i+B].priority = 0;
	}//printf("%d\n", array[B].val);
	B = B+1;
	for(int i = 1; i <= q; i++){
		int temp = 0;
		scanf("%d",&temp);
		if(temp==0){
			scanf("%d %d %d",&a,&b,&c);
			add(a+B,b+B,c,i);
		}
		else if(temp==1){
			scanf("%d",&a);
			find(a+B);
		}
	}
	return 0;
}
//add elements
//s means: left pointer
//t means : right pointer
void add(int s,int t, int x,int i){
	//signle node
	if(s==t) {
		array[s].val = x;
		array[s].priority = i;
		return;
	}
	//range update
	//check the left pointer
	while(s<t){
		//printf("inside loop:s%d,t%d,s%d\n",s,t,x);
		if(s%2==0){ //left child, level up
			s = s/2;
		}else{ //right child: mark and level up + 1
			array[s].val = x;
			array[s].priority = i;
			s = s/2;
			s++;
		}
		
		if(t%2==0){//left child: 
			array[t].val = x;
			array[t].priority = i;
			t = t/2;
			t--;
		} else { //right child
			t/= 2; 	
		}
		if(s==t) {
			array[s].val =x;
			array[s].priority = i;
		}// works for 1-4,1-3, 1-5
		//printf("inside loop:s%d,t%d,s%d\n",s,t,x);
	}
	
	//test for 
	/*for(int i = 1; i<20; i++){
		printf("%2d ", i);
	}printf("\n");
	for(int i = 1; i<20; i++){
		printf("%2d ", array[i]);
	}*/
	
}

void find(int i) {//the index of the tree
	int res = array[i].val;
	int max = 0; //the priority
	//printf("%d\n", array[i].val);
	while(i>=1){
		if(array[i].priority>max){
			res=array[i].val;
			//printf("array:%d",res);
			max = array[i].priority;	
		}
		i = i/2;
	}
	
	printf("%d\n", res);
}

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

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

	int i;
	int a[num];
	for(i=0; i<num; i++){
		cin>>a[i];
	}
	int tmp;
	for(i=0;i<num/2;i++){
		tmp=a[i];
		a[i]=a[num-1-i];
		a[num-1-i]=tmp;
	}
	cout << a[0];
	for(i=1;i<num;i++){
		cout<<" "<< a[i];
	}
	cout<<endl;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  vi A(m);for(auto &a:A)cin>>a;
  if(n>=m)cout<<0<<endl;
  else{
    sort(ALL(A));
    priority_queue<ll>que;
    for(int i=0;i<m-1;i++)
      que.push(A[i+1]-A[i]);
    ll ans=A[m-1]-A[0];
    for(int i=0;i<n-1;i++){
      ans-=que.top();
     
      que.pop();
    }
    cout<<ans<<endl;
  }
  return 0;
}
  

Measured memory_bytes: 2168
/*
    Author : DemonStar
*/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define loop(i, n) for(ll i = 0; i < n; i++)
#define pl pair<ll, ll>
#define vl vector<ll>
#define endl '\n'
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");}

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

#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};


template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

ll modpow(ll n, ll p) {
    ll ans = 1;
    while (p) {
        if (p  & 1) (ans *= n) %= mod;
        (n *= n) %= mod, p /= 2;
    }
    return ans;
}

int main()
{

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    fast;
    vl v(5);
    cin >> v;
    cout << find(all(v), 0) - v.begin() + 1 << endl;


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s";
#endif

    return 0;
}

Measured memory_bytes: 3640
from collections import defaultdict
N=int(input())
if N==1 or N==2:
    print(0)
    quit()
def prime_factor(n):
    i = 2
    table = defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            table[i]+=1
        i += 1
    if n > 1:
        table[n]+=1
    return table
table=prime_factor(N)
list=[1]
for fact,num in table.items():
    list_=[]
    for k in range(num+1):
        list_.extend([i*fact**k for i in list])
    list=list_
list.sort()
ans=0
for i in range(len(list)):
    if i==0:
        continue
    if list[i-1]+1==list[i]:
        continue
    m=list[i]-1
    if N//m==N%m:
        ans+=list[i]-1
print(ans)


Measured memory_bytes: 39280
#include<bits/stdc++.h>
/*
CE 头文件 
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>

*/
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(a,b) memset(a,b,sizeof (a))
#define ios std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
// ios和scanf,printf不能混用.即用ios必须全部cin,cout. 
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;

ll ksm(ll a,ll b){ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int n,m,k;
const int N=2e5+10;
ll a[N];
bool cmp(ll a,ll b){
	return a>b;
}
int main(){
	scanf("%d",&n);
	rep(i,0,n-1){
		scanf("%lld",&a[i]);
	}
	sort(a,a+n,cmp);
	ll ans=0,cnt=1,k=0;
	rep(i,1,n-1){
		cnt++;
		ans+=a[k];
		if(cnt==2){
			k++;
			cnt=0;
		}
	}
	printf("%lld\n",ans);
    return 0;
}


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

int main() {
  int N,k,s=0;
  cin>>N;
  int a[N],b[N]={};
  bool flag=false;
  for(int i=1;i<=N;i++)  cin>>a[i];
  k=1;
  b[0]=1;
  while(true){
    k=a[k];
    s++;
    if(k==2) break;
    if(b[a[k]-1]==1) {flag=true; break;}
    b[a[k]-1]=1;
    if(k==2) break;
  }
  if(flag==false) cout<<s<<endl;
  else cout<<-1<<endl;
}
              
    

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	//quotinet_dは整数型の商、quotinet_fは実数型の商、remainderは剰余
	int input_a, input_b;
	int quotinet_d;
	double quotinet_f;
	int remainder;

	//データを取得
	scanf("%d %d", &input_a, &input_b);

	quotinet_d = input_a / input_b;
	quotinet_f = (double)input_a / (double)input_b;
	remainder = input_a % input_b;

	//結果を出力
	printf("%d %d %f\n", quotinet_d, remainder, quotinet_f);
	
	return 0;
}


Measured memory_bytes: 2044
using namespace std;
using ll=long long;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#define out(S) cout<<(S)<<endl;


int main()
{
	string S;
	cin >> S;
	//後ろから3文字目で判断
	while (S.size()>=5)
	{
		int index = S.size();
		string s = S;
		if (s.substr(index-5,index) == "dream") {
			//dream
			S.erase(index - 5, index);
		}
		else if (index>=7&&s.substr(index-7,index)=="dreamer") {
			//dreamer
			S.erase(index-7, index);
		}
		else if (s.substr(index-5,index)=="erase") {
			//erase
			S.erase(index - 5, index);
		}
		else if (index>=6&&s.substr(index-6,index)=="eraser") {
			//eraser
			S.erase(index - 6, index);
		}
		else {
			break;
		}
	}
	if (S.size() == 0) {
		out("YES");
	}
	else {
		out("NO");
	}
	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll n,k;
vector<ll> a, d, res;
vector<ll> divisor(ll n) {
    vector<ll> res;
    for (ll i=1; i*i<=n; i++){
        if (n%i==0){
            res.push_back(i);
            if (i!=n/i) res.push_back(n/i);
        }
    }
    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    a.resize(n); res.resize(n);
    ll sum=0;
    rep(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    d=divisor(sum);
    sor(d); rev(d);
    for(auto &e: d){
        ll temp=0;
        rep(i,0,n){
            res[i]=a[i]%e;
            temp+=a[i]/e;
        }
        sor(res);
        temp=sum/e-temp;
        ll x=0;
        rep(i,0,n-temp){
            x+=res[i];
        }
        if(x<=k){
            cout <<e<<"\n";
            return 0;
        }
    }
}

Measured memory_bytes: 256
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut ans: usize = 0;
    for i in 1..=n {
        if i % 3 != 0 && i % 5 != 0 {
            ans += i;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2116
#include <stdio.h>
int main(void)
{
    int S;
    int h,m,s;
    
    scanf("%d",&S);

    h=S/3600;
    S=S-(h*3600);
    m=S/60;
    s=S%60;
    

    printf("%d:%d:%d\n",h,m,s);

    return 0;
}


Measured memory_bytes: 2036
#include<bits/stdc++.h> 
//compiling code: g++ test.cpp(file) -o script(output) -std=c++11(version) -O2(make it 2x faster)
using namespace std;
long long n, k, h;
priority_queue<int> pq;

int main(){
    cin >> n >> k;
    for(int i=0; i<n; i++){
        cin >> h;
        pq.push(h);
    }
    
    long long ans = 0;
    for(int i=0; i<n; i++){
        if (k > 0){
            pq.pop(); 
            k -= 1;
        } else{
            ans += pq.top();
            pq.pop();   
        }
    }

    cout << ans << "\n";

}

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

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend()) 
#define mp(x, y) make_pair(x, y)
#define INF 1000000000
#define MOD 1000000007
#define F(i, a, n) for(i=a;i<n;i++)
#define B(i, a, n) for(i=n-1;i>=0;i--)
#define SI(x) cin>>x
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z
#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<< "\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

    

int main(void)
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ll i, j;
    ll n;
    SI(n);
    SO(n * (n - 1) / 2);    
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<string> w(n);
    REP(i, n) cin >> w[i];
    bool flag = true;
    REP(i, n - 1) {
        if(w[i].back() != w[i + 1].front()) flag = false;
    }
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(w[i] == w[j]) flag = false;
        }
    }
    cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int a,b,c,d,tk,ao;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  tk=c/b;
  if((c%b)!=0)
    tk++;
  ao=a/d;
  if((a%d)!=0)
    ao++;
  if(tk<=ao)
    printf("Yes");
  else
    printf("No");
  
  return 0;
}

Measured memory_bytes: 1736
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.nextLine();
		scan.close();
		if(S.length()==1) {
			System.out.println(S);
			return;
		}
		int[] N = new int[S.length()];

		int patternCount = 1;
		String tmpBit = "";
		for(int i=0; i<N.length; i++) {
			N[i] = Integer.parseInt(String.valueOf(S.charAt(i)));
			if(i>0) {
				patternCount*=2;
				tmpBit = tmpBit + "1";
			}
		}

		long sum=0;
		for(int i=0; i<patternCount; i++) {
			String bin = Integer.toBinaryString(i);
			while(bin.length()<tmpBit.length()) {
				bin = "0" + bin;
			}
			String add = String.valueOf(N[0]);
			for(int j=0; j<bin.length(); j++) {
				if(bin.charAt(j)=='1') {
					sum+=Integer.parseInt(add);
					add = "";
				}
				add = add + N[j+1];
			}
			if(add.length()>0) {
				sum+=Long.parseLong(add);
			}
		}
		System.out.println(sum);

	}

}


Measured memory_bytes: 23892
n=int(input())
a=list(map(int,input().split()))

minans=0
miniro=[0]*8
count=0

for i in range(n):
    tmp=a[i]//400
    if tmp<8 and miniro[tmp]==0:
        miniro[tmp]=1
    elif tmp>=8:
        count+=1

print("{0} {1}".format(max(sum(miniro),1), count+sum(miniro)))

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

using namespace std;

typedef long long ll;

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

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

	ll x, k, d;
	cin >> x >> k >> d;

	if(x < 0) x = -x;

	ll ans = 1e17;
	if(k % 2 == 0){
		chmin(ans, x);
		ll y = x / (2 * d);
		chmin(ans, abs(x - min(y, k / 2) * 2 * d));
		chmin(ans, abs(x - min(y + 1, k / 2) * 2 * d));
	}else{
		ll y = x / d;
		if(y == 0){
			chmin(ans, abs(x - d));
		}else{
			if(y % 2 == 0) y--;
			chmin(ans, abs(x - min(y, k) * d));
			chmin(ans, abs(x - min(y + 2, k) * d));
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3640
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional;

void main(){
    auto nk=readln().split.array;
    auto n=nk[0].to!int;
    string[] ds=readln().split.array;


    bool isSafe(int cur){
        string str=cur.to!string;
        return ds.all!(d=>!str.canFind(d));
    }

    foreach(current;n..100000){
        if(isSafe(current)){
            writeln(current);
            return;
        }
    }
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=55;
int p[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  cin>>n;
  rep(i,1,n+1)
    cin>>p[i];
  bool ok=false;
  rep(i,1,n+1)
    rep(j,1,n+1)
    {
      vi v;
      rep(k,0,n) v.pb(p[k+1]);
      swap(v[i-1],v[j-1]);
      vi v2(v);
      sort(all(v2));
      ok|=(v==v2);
    }
  if(ok) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[1005];
int main()
{
    ll n;
    cin >> n;
    for(ll i = 0; i < n; i ++)
    {
        cin >> a[i];
    }
    sort(a,a+n);
    cout<<abs(a[0] - a[n-1]);
}



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

long long nc2(long long a) {
    return a * (a - 1) / 2;
}

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

    vector<string> arr(n);
    map<string, long long> mp;
    for (long long i = 0; i < n; i++) {
        cin >> arr[i];
        sort(arr[i].begin(), arr[i].end());
        mp[arr[i]]++;
    }

    long long ans = 0;
    for (auto it = mp.begin(); it != mp.end(); it++) {
        ans = ans + nc2(it->second);
    }

    cout << ans << endl;
}

Measured memory_bytes: 14072
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
	string S, num;
	vector<int> vc;
	bool flag = false;
	while( getline( cin, S ) )
	{
		REP( i, (int) S.size() )
		{
			if( isdigit( S[ i ] ) )
			{
				flag = true;
				num += S[ i ];
				continue;
			}
			if( flag ){
				vc.emplace_back( stoi( num ) );
				flag = false;
				num.clear();
			}
		}
	}
	cout << accumulate( ALL( vc ), 0 ) << endl;
	return 0;
}

Measured memory_bytes: 3232
#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;

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

    int d;
    cin >> d;

    cout << "Christmas";
    rep(i, 25-d) cout << " Eve";
    cout << endl;

    return 0;
}

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

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int d = A[0];
    for (int i = 1; i < N; i++) {
        d = gcd(d, A[i]);
    }

    cout << d << endl;
    return 0;
}

Measured memory_bytes: 3764
#include <vector>
#include <set>
#include <cstdio>
using namespace std;

int main(){
	int N;
	long long W,tV=0,tW=0,x=0;
	scanf("%d%lld",&N,&W);
	vector<pair<int,int> >v(N);
	for(int i=0;i<N;i++)scanf("%d%d",&v[i].first,&v[i].second),tV+=v[i].first,tW+=v[i].second;
	if(W>tW)W=tW;
	if(tW<2000000){
		vector<long long>bag(tW+1);
		bag[0]=1;
		for(auto &e:v){
			x+=e.second;
			for(int j=x;j>=e.second;j--)if(bag[j-e.second]&&bag[j]<bag[j-e.second]+e.first)
				bag[j]=bag[j-e.second]+e.first;
		}
		for(int i=0;i<W;i++)bag[i+1]=max(bag[i+1],bag[i]);
		printf("%lld\n",bag[W]-1);
	}else if(tV<2000000){
		vector<long long>bag(tV+1);
		bag[0]=1;
		for(auto &e:v){
			x+=e.first;
			for(int j=x;j>=e.first;j--)if(bag[j-e.first]&&(!bag[j]||bag[j]>bag[j-e.first]+e.second))
				bag[j]=bag[j-e.first]+e.second;
		}
		int i=0,mi;
		for(;i<=tV;i++)if(bag[i]&&bag[i]-1<=W)mi=i;
		printf("%d\n",mi);
	}else{
		return 1;
	}
}

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

int main(){
	long x;
	cin>>x;
    int k=floor(sqrt(x<<1));
    long r=k*(k+1)/2;
    if(x>r)cout<<(k+1)<<endl;
    else cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    s, t = input().split()
    a, b = list(map(int,sys.stdin.readline().split()))
    u = input()
    if u == s:
        a -= 1
    else: b -= 1
    print(a,b)
    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
class UF:
    def __init__(self, N):
        self.uf = [-1]*N
        self.n = N

    def find(self, x):
        if self.uf[x]<0: return x
        self.uf[x] = self.find(self.uf[x])
        return self.uf[x]

    def size(self, x):
        return -self.uf[self.find(x)]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x==y: return
        if self.size(x) > self.size(y): x, y = y, x
        self.uf[y] += self.uf[x]
        self.uf[x] = y
        self.n -= 1

N = int(input())
XYI = sorted([(*map(int, input().split()), i) for i in range(N)])

uf = UF(N)

pi = None
py = N+1
for x, y, i in XYI:
    if y>py: uf.union(i, pi)
    else:
        pi = i
        py = y

pi = None
py = 0
for x, y, i in reversed(XYI):
    if y<py: uf.union(i, pi)
    else:
        pi = i
        py = y

XYI = [(y, x, i) for x, y, i in XYI]
XYI.sort()

pi = None
py = N+1
for x, y, i in XYI:
    if y>py: uf.union(i, pi)
    else:
        pi = i
        py = y

pi = None
py = 0
for x, y, i in reversed(XYI):
    if y<py: uf.union(i, pi)
    else:
        pi = i
        py = y

for i in range(N):
    print(uf.size(i))


Measured memory_bytes: 132400
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    int tak = c%b?c/b+1:c/b;
    int aok = a%d?a/d+1:a/d;
    if(tak<=aok)cout<<"Yes"<<endl;
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3632