akhauriyash/Code-Regression huggingface dataset:
// finish date: 2018/06/21
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <functional>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define pii pair<int,int>
const int bigmod = 1000000007;
#define INF 1050000000


int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;
        vi p(n);
        rep(i, n) {
            cin >> p[i];
        }
        int maxDP = n * 1000;
        vector<pii > DP(maxDP, pii(-1, -1));
        DP[0] = pii(0, 0);
        vector<pii > newDP;
        rep(i, n) {
            newDP = vector<pii >(maxDP, pii(-1, -1));
            int otsuri = 1000 - p[i] % 1000;
            if (otsuri == 1000) otsuri = 0;
            for (int j = maxDP - 1; j >= 0; j--) {
                if (DP[j] == pii(-1, -1)) continue;
                bool con1 = newDP[j + otsuri].first < DP[j].first;
                bool con2 = newDP[j + otsuri].first == DP[j].first;
                bool con3 = newDP[j + otsuri].second > DP[j].second + p[i];
                if (con1 || (con2 && con3)) {
                    newDP[j + otsuri] = DP[j];
                    newDP[j + otsuri].second += p[i];
                }
            }
            rep(j, maxDP) {
                if (newDP[j] == pii(-1, -1)) continue;
                if (j >= 500) {
                    bool con1 = newDP[j - 500].first < newDP[j].first + 1;
                    bool con2 = newDP[j - 500].first == newDP[j].first + 1;
                    bool con3 = newDP[j - 500].second > newDP[j].second;
                    if (con1 || (con2 && con3)) {
                        newDP[j - 500] = newDP[j];
                        newDP[j - 500].first++;
                    }
                }
            }
            rep(j, maxDP) {
                if (DP[j].first > newDP[j].first || (DP[j].first == newDP[j].first && DP[j].second < newDP[j].second)) {
                    newDP[j] = DP[j];
                }
            }
            DP = newDP;
        }



        int ma = -1;
        int ansMoney = 0;
        rep(i, maxDP) {
            if (DP[i].first > ma || (DP[i].first == ma && DP[i].second < ansMoney)) {
                ma = DP[i].first;
                ansMoney = DP[i].second;
            }
        }
        cout << ma << " " << ansMoney << endl;

    }


    return 0;
}







Measured memory_bytes: 5220
import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		HashSet<Integer> set = new HashSet<>();
		set.add(sc.nextInt());
		set.add(sc.nextInt());
		set.add(sc.nextInt());
		System.out.println(set.size());
	}
}


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

#define oo 1e9
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))

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

int n,res,sum,a[100009],i;

int main(){
    IO;
    sum=0;
    res=0;
    cin>>n;
    for (i=1;i<=n;i++) {
        cin>>a[i];
        sum+=a[i];
    }
    //cout<<sum<<' '<<n<<' '<<sum/n<<' '<<sum/n;
    int mid=round((sum+0.0)/(n+0.0));
    for (i=1;i<=n;i++) {
        res+=(a[i]-mid)*(a[i]-mid);
    }
    cout<<res;
}

Measured memory_bytes: 384
// D - String Equivalence
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vector<string> s(1,"a");
	while(--N){
		vector<string>t; swap(s,t);
		rp(i, 0, t.size()){
			char mx = *max_element(t[i].begin(), t[i].end()) + 1;
			rp(c, 'a', mx+1) s.push_back(t[i] + char(c));

		}
	}
	rp(i, 0, s.size()) cout<< s[i] <<endl;
}

Measured memory_bytes: 10956
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

#define int long long

struct Med{
	multiset<int>f,b;
	ll s1=0,s2=0;
	void balance(){
		int n=f.size()+b.size();
		int sz1=(n%2==0?n/2:n/2+1);
		int sz2=n-sz1;
		while(f.size()>sz1){
			int t=*f.rbegin();
			f.erase(--f.end());
			s1-=t;
			s2+=t;
			b.insert(t);
		}
		while(b.size()>sz2){
			int t=*b.begin();
			b.erase(b.begin());
			s2-=t;
			s1+=t;
			f.insert(t);
		}
	}
	void insert(int x){
		if(!b.empty()&&*b.begin()<x){
			b.insert(x),s2+=x;
		}
		else f.insert(x),s1+=x;
		balance();
	}
};
Med med;
signed main(){
	int q;cin>>q;
	ll t=0;
	rep(i,q){
		int ty;scanf("%lld",&ty);
		if(ty==1){
			int a,b;scanf("%lld%lld",&a,&b);
			t+=b;
			med.insert(a);
		}
		else{
			ll x=*med.f.rbegin();
			printf("%lld %lld\n",x,t+x*(ll)med.f.size()-med.s1+med.s2-x*(ll)med.b.size());
		}
	}
}

Measured memory_bytes: 9600
#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;
	cin >> n;
	cin >> s;
	
	vector<int> ints(n);
	rep(i,n) ints[i] = s[i] - '0';
	
	vector<vector<int>> idx(10);
	rep(i,n) idx[ints[i]].push_back(i);

	int res = 0;
	rep(i,10){
		rep(j,10){
			rep(k,10){
				// "ijk"が作りたいとする
				if(idx[i].size() == 0) continue;
				if(idx[j].size() == 0) continue;
				if(idx[k].size() == 0) continue;
				int now = idx[i][0];
				
				auto jitr = upper_bound(idx[j].begin(), idx[j].end(), now);
				if(jitr == idx[j].end()) continue;
				now = *(jitr);
				
				auto kitr = upper_bound(idx[k].begin(), idx[k].end(), now);
				if(kitr == idx[k].end()) continue;
				res++;			
			}
		}
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
long long N,A,B;






int main()
{

	cin >> N >> A >> B;

	if(N==1){
		if(A==B){
			cout << 1 << endl;
			return 0;
		} else {
			cout << 0 << endl;
			return 0;
		}
	}
	if(A > B){
		cout << 0 << endl;
		return 0;
	}

	long long min,max;
	min = A*(N-1)+B;
	max = B*(N-1)+A;

	cout << max - min +1<< endl;



}




Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

const int MAX_H = 30, MAX_W = 30;
const int INF = 1000000;

typedef pair<int, int> pii;
typedef pair<pii, int> ppii;
typedef pair<int, ppii> node;

int w, h, s[MAX_H][MAX_W], c[4];
int d[MAX_H][MAX_W][4]; // 0: right, 1: down, 2: left, 3: up
int t[4][3] = {{1, 0, 0}, {0, 1, 1}, {-1, 0, 2}, {0, -1, 3}};

int md(int x, int y)
{
    int m = d[x][y][0];
    for (int k = 1; k < 4; ++k)
        m = min(m, d[x][y][k]);
    return m;
}

void pd()
{
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            printf("%7d ", md(j, i));
        }
        puts("");
    }
}

int main()
{
    for (;;) {
        scanf("%d %d", &w, &h);
        if (w == 0 && h == 0)
            break;

        for (int i = 0; i < h; ++i)
            for (int j = 0; j < w; ++j)
                scanf("%d", &s[j][i]);
        for (int i = 0; i < 4; ++i)
            scanf("%d", &c[i]);

        for (int i = 0; i < h; ++i)
            for (int j = 0; j < w; ++j)
                for (int k = 0; k < 4; ++k)
                    d[j][i][k] = INF;

        //printf("  start dijkstra\n");
        priority_queue<node, vector<node>, greater<node> > q;
        d[0][0][0] = 0;
        q.push(node(0, ppii(pii(0, 0), 0)));
        int e = 0;
        while (!q.empty()) {
            node p = q.top();
            q.pop();
            int x = p.second.first.first, y = p.second.first.second, z = p.second.second;

            if (d[x][y][z] < p.first) {
                //printf("    skip (%d, %d, %d)\n", x, y, z);
                continue;
            }
            //printf("    [%3d / %3d] pop (%d, %d, %d)\n", e++, w * h * 4, x, y, z);
            //pd();

            for (int i = 0; i < 4; ++i) {
                int nx = x + t[(i + z) % 4][0], ny = y + t[(i + z) % 4][1], nz = t[(i + z) % 4][2];

                if (nx < 0 || nx >= w || ny < 0 || ny >= h)
                    continue;
                //printf("      check (%d, %d, %d)\n", nx, ny, nz);

                int nd;
                if (s[x][y] == i)
                    nd = min(d[nx][ny][nz], d[x][y][z]);
                else
                    nd = min(d[nx][ny][nz], d[x][y][z] + c[i]);
                if (nd < d[nx][ny][nz]) {
                    d[nx][ny][nz] = nd;
                    q.push(node(nd, ppii(pii(nx, ny), nz)));
                }
            }
        }
        //printf("  finish dijkstra\n");

        printf("%d\n", md(w - 1, h - 1));
    }

    return 0;
}

Measured memory_bytes: 1164
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int x; cin >> x;
  for (int k = 1; ; ++k) {
    if (k * x % 360 == 0) {
      cout << k << '\n';
      return 0;
    }
  }
}


Measured memory_bytes: 3648
#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() {
    long n;
    cin >> n;
    vector<long> a(n);
    long p = 0;
    for (long i = 0; i < n; i++) {
        cin >> a[i];
        p = p xor a[i];
    }

    for (long i = 0; i < n; i++) cout << (p xor a[i]) << " ";
    cout << endl;
}


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

int main(int argc, char const *argv[]) {
  int n,count=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=1;i<n-1;i++){
    if(a[i-1]<a[i]&&a[i]<a[i+1]){
      count++;
    }else if(a[i-1]>a[i]&&a[i]>a[i+1]){
      count++;
    }
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
counter = 0

for i in 0..n-3 do
  target = []
  target << arr[i]
  target << arr[i + 1]
  target << arr[i + 2]

  counter += 1 if target.sort[1] == target[1]
end

puts counter

Measured memory_bytes: 1788
#include<stdio.h>
int max_pro(int [],int);
int main(){
  int number;
  int list[200000];
  int i;
  scanf("%d",&number);
  for(i=0;i<number;i++){
    scanf("%d",&list[i]);
  }
  printf("%d\n",max_pro(list,number));
  return 0;
}
int max_pro(int l[],int n){
int i;
int min=l[0];
int dif=l[1]-min;
for(i=1;i<n;i++){
  if(min>l[i])min=l[i];
  else if(dif<l[i]-min)dif=l[i]-min;
}
  return dif;
}



Measured memory_bytes: 2564
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    priority_queue<pair<int,int> >pq;
    set<int>s;
    map<int,int>mp;
    vector<int>v;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        mp[a]++;
        s.insert(a);
        v.push_back(a);
    }

    for(auto it:s){
        pq.push({mp[it],it});
    }
    while(!pq.empty()){
        int cur=pq.top().first;
        int val=pq.top().second;
        if(cur==1)
            break;
       // cout<<cur<<" "<<val<<endl;
        pq.pop();
        if(cur>=3){
            mp[val]-=3;
            mp[val]++;
            pq.push({mp[val],val});
        }
        else if(cur==2){
            mp[val]--;
            pq.push({mp[val],val});
            cur=pq.top().first;
            val=pq.top().second;
            mp[val]--;
            pq.pop();
            if(mp[val])
            pq.push({mp[val],val});
        }
    }
    cout<<pq.size()<<endl;
    return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

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

  if (N == 1)
    cout << abs(W - a[0]) << endl;
  else
    cout << max(abs(a[N - 2] - a[N - 1]), abs(a[N - 1] - W)) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define INF 1100000000
#define LLINF 1100000000000000000
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair

using namespace std;
typedef long long ll;

void fact(int n, map<int, int>& mp)
{
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      mp[i]++;
      n /= i;
    }
  }
  if (n != 1) mp[n]++;
}

int main()
{
  int N;
  cin >> N;
  map<int, int> mp;
  for (int i = 2; i <= N; i++) {
    fact(i, mp);
  }

  ll ans = 1;
  for (auto e : mp) {
    (ans *= e.SE + 1) %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int l;
#define fastIO              ios::sync_with_stdio(false), cin.tie(0)
#define pf                  push_front
#define pb                  push_back
#define popb                pop_back()
#define popf                pop_front()
#define loop(i,n)           for(int i=0;i<n;i++)
#define loop1(i,n)           for(int i=1;i<n;i++)
#define loopx(i,x,n)        for(int i=x;i<n;i++)
#define loopr(i,n)          for(int i=n-1;i>=0;i--)
#define loop1e(i,n)          for(int i=1;i<=n;i++)
#define loopxe(i,x,n)          for(int i=x;i<=n;i++)
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long>
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define INT_BITS 32
#define  st                  l t; cin>>t;
#define  sn                  l n; cin>>n;
//#define  unordered_map<l,l>  u;
#define MOD1 1000000007
l partition(l a[],l low,l high)
{
	l pivot = a[high];
	l i = low - 1;
	for(l j = low;j<=high-1;j++)
	{
		if (a[j] <= pivot) {

            i++;
            swap(a[i], a[j]);
        }
	}
		 swap(a[i + 1], a[high]);
    return (i + 1);
}
l partition_r(l a[],l low,l high)
{
	srand(time(NULL));
    l random = low + rand() % (high - low);
    swap(a[random], a[high]);

    return partition(a, low, high);
}
void quicksort(l a[],l low,l high)
{
	 if (low < high) {
        l pi = partition_r(a, low, high);
        quicksort(a, low, pi - 1);
        quicksort(a, pi + 1, high);
    }
}
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int decToHexa(int n)
{
    int hexaDeciNum[100];
    int i = 0;
    while(n!=0)
    {
        int temp  = 0;
        temp = n % 16;
        if(temp < 10)
        {
            hexaDeciNum[i] = temp;
            i++;
        }
        else
        {
            hexaDeciNum[i] = temp;
            i++;
        }

        n = n/16;
    }
    l sm = 0;
    for(int j=i-1; j>=0; j--)
        sm+=hexaDeciNum[j];
    return sm;
}
int main()
{
    fastIO;
    st;
    l r=1;
    while((t*r)%360)r++;
    cout<<r;

	return 0;
}


Measured memory_bytes: 3572
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){

    /*
    vector<ll> sum_a;
    for (int l = 0; l < N; l++) {
        ll sm = 0;
        for (int r = l+1; r <= N; r++) {
            sm += a[r-1];
            sum_a.push_back(sm);
        }
    }
    */
 
    int N,K;
    cin >> N >> K;
    int a[N];
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }

    //int sum_a[N * (N+1) / 2] = {0};
    //vector<int> sum_a(N * (N+1) /2);
    /*
    vector<ll> sum_a;
    for (int i = 0; i < N; i++){
        for (int k = i; k < N; k++){
            int t_sum = 0;
            for (int p = i; p <= k; p++){
                t_sum += a[p];
            }
            sum_a.push_back(t_sum);
            cout << t_sum <<endl;
        }
    }
    */
    vector<ll> sum_a;
    for (int i = 0; i < N; i++){
        ll sum = 0;
        for (int k = i; k < N; k++){
            sum += a[k];
            sum_a.push_back(sum);
        }
    }

    /*
    int x = 0;
    int t = 40;
    while(t != 0){
        int cnt = 0;
        ll prov = x + pow(2,t-1);
        for (int i = 0; i < sum_a.size(); i++){
            if ((prov & sum_a[i]) == prov){
                cnt++;
            }
        }
        if (cnt >= K){
            x += prov -x;
        }
        t--;
    }

    cout << x << endl;
    */
    ll ans = 0;
    for (int lg = 50; lg >= 0; lg--) {
        ll nans = ans | (1LL << lg);
        int cnt = 0;
        for (ll d: sum_a) {
            if ((nans & d) == nans) cnt++;
        }
        if (cnt >= K) ans = nans;
    }
    cout << ans << endl;



}



Measured memory_bytes: 6384
/**
*    created: 27.06.2020 19:04:28
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;
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;}

signed main() {

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

    int a, b;
    cin >> a >> b;
    if (a % b == 0) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define int ll
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
#define INF 1e10
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
vector<int>v;
int a,b;
bool ssimulate(int val){
    vi temp=v;
    int now=val;
    rep(i,temp.size()){
        temp[i]-=val*b;
        if(temp[i]>0){
            int res=temp[i]/(a-b);
            now-=(res);
            if(temp[i]%(a-b))now--;
            if(now<0)return false;
        }
    }
    return true;
}
signed main(){
    int left=0;
    int right=INF;
    int n; cin>>n;
    cin>>a>>b;
    rep(i,n){
        int hoge; cin>>hoge;
        v.push_back(hoge);
    }
    int mid = 0;
    while(right-left>1){
        mid=(right+left)/2;
        if(ssimulate(mid))right=mid;
        else left=mid;
    }
    cout<<right<<endl;
}


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

pair<int, int> solve(int N, int M) {
    vector<int> T(N);
    vector<int> H(M);
    int sumt           = 0;
    int sumh           = 0;
    int sumret         = INT_MAX;
    pair<int, int> ret = make_pair(-1, -1);
    for (int i = 0; i < N; i++) {
        cin >> T[i];
        sumt += T[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> H[i];
        sumh += H[i];
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (sumt - T[i] + H[j] == sumh - H[j] + T[i] && sumret > T[i] + H[j]) {
                sumret = T[i] + H[j];
                ret    = make_pair(T[i], H[j]);
            }
        }
    }
    return ret;
}

int main() {
    int N, M;
    vector<pair<int, int>> ans;
    while (cin >> N >> M) {
        if (!N && !M) break;
        ans.push_back(solve(N, M));
    }

    for (int i = 0; i < ans.size(); i++) {
        if (ans[i].first == -1)
            cout << -1 << endl;
        else
            cout << ans[i].first << " " << ans[i].second << endl;
    }
}


Measured memory_bytes: 3116
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;

int main(){

  int H[256],W[256];
  int i,j,r,m;

  for(i=0;i<300;i++){
    cin >>H[i] >>W[i];
    if(H[i]==0 && W[i]==0) break;
  }
  for(m=0;m<i;m++){
    for(j=0;j<H[m];j++){
      for(r=0;r<W[m];r++){
	cout <<"#";
      }
      cout <<endl;
    }
    cout <<endl;
  }

  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll s; cin >> s;
    ll sita = s % 1000000000;
    ll ue = s / 1000000000 + 1;
    sita = 1000000000 - sita;
    if(s == 1000000000000000000) printf("0 0 1000000000 0 0 1000000000");
    else printf("0 0 %lld 1 %lld 1000000000", ue, sita);
}

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

s = sum(list(map(lambda x: int(x < 0),A)))
absA = sorted(list(map(lambda a: abs(a), A)))

if s % 2 == 1:
    print(-2*absA[0]+sum(absA))
else:
    print(sum(absA))

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
const int tam = 100005;
long long dp[100][tam];
int n, w;
long long v[100][2];

long long solve(int idx, int peso) {
    if(idx == n) {
        return 0;
    }
    long long &ans = dp[idx][peso];
    if(ans != -1) {
        return ans;
    }
    if(peso >= v[idx][0]) {
        ans = max(solve(idx+1, peso), solve(idx+1, peso-v[idx][0]) + v[idx][1]);
    } else {
        ans = solve(idx+1, peso);
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> w;
    for(int i=0; i<n; i++) {
        cin >> v[i][0] >> v[i][1];
    }
    memset(dp, -1, sizeof dp);
    cout << solve(0, w) << '\n';
    return 0;
}

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


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

int main(){

	int h,w;
	cin >> h >> w;
	char m[402][402] = {};
	bool c[402][402] = {};
	fill(c[0],c[402],0);

	char a;
	rep(i, h) {
		rep(j, w) {
			cin >> a;
			m[i][j] = a;
		}
	}
	ll all = 0;
	rep(i, h) {
		rep(j, w) {
			if (!c[i][j]) {
				ll white=0, b=0;
				if (m[i][j] == '.') {
					white++;
				} else {
					b++;
				}
				c[i][j]=1;
				queue<P> Q;
				Q.push(P(i,j));

				while(!Q.empty()) {
					P p = Q.front(); Q.pop();
					rep(k,4) {
						int x = p.first + dx[k];
						int y = p.second + dy[k];
						// cout << "x " << x << " y " << y << " c " << c[x][y] << endl;
						if ( x>=0 && x<h && y>=0 && y<w && c[x][y] == 0) {
							// ?\cout << "a" << endl;
							if ((m[p.first][p.second]=='.' && m[x][y] == '#') || (m[p.first][p.second]=='#' && m[x][y] == '.')) {
								// cout << "hoge" << endl;
								Q.push(P(x,y));
								c[x][y] = 1;
								if (m[p.first][p.second]=='.' && m[x][y] == '#') {
									b++;
								} else {
									white++;
								}
							}
						} 
					}
				}
				// cout << "b " <<b << " w " << white << endl;
				all += b*white;
			}

		}
	}
	cout << all << endl;
}



Measured memory_bytes: 640
import sys
import itertools
row = sys.stdin.readline
def read_int(row):
    return int(row().rstrip())
def read_ints(row):
    return list(map(int, row().split()))
  
N = read_int(row)
d_ls = read_ints(row)
print(sum([i[0] * i[1] for i in list(itertools.combinations(d_ls,2))]))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


int main() {

	long n; cin >> n;

	vector<long> ans(n,0);
	vector<long> h(n,0);
	vector<long> l(n,0);

	long old_h = 0;
	vector<long> T(n);
	vector<long> A(n);
	for (int i = 0; i < n; i++) {
		cin >> T[i];	
	}
	for (int i = 0; i < n; i++) {
		cin >> A[i];	
	}

	for (int i = 0; i < n; i++) {
		h[i] = T[i];
		if (T[i] > old_h) {
			ans[i] = 1;
			l[i] = T[i];
		}
		old_h = T[i];
	}

	old_h = 0;
	for (int i = n-1; i >= 0; i--) {
		h[i] = min(A[i],h[i]);
		if (A[i] > old_h) {
			if (h[i] < A[i] || l[i] > A[i]) {
				cout << 0 << endl;
				return 0;
			}
			ans[i] = 1;
		}
		old_h = A[i];
	}

	

	long ANS = 1;
	for (int i = 0; i < n; i++) {
		if (ans[i] == 0) {
			ANS *= h[i] % MOD;	
			ANS %= MOD;
		}
	}

	if (T[n-1] != A[0]) {
		cout << 0 << endl;
	}else {
		cout << ANS << endl;
	}




	return 0;
}


Measured memory_bytes: 4224
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> al = new ArrayList<>();
		
		int in, tmp = sc.nextInt();
		String asc = "", desc = "";
		String[] sort;
		
		for(int i = 0; i < tmp; i++) {
			in = sc.nextInt();
			sort = String.valueOf(in).split("");
			
			Arrays.sort(sort);
			
			for(int j = 0; j < sort.length; j++) {
				asc += sort[j];
			}
			
			for(int j = sort.length - 1; j >= 0; j--) {
				desc += sort[j];
			}
			
			al.add(Integer.parseInt(desc) - Integer.parseInt(asc));
			
			asc = "";
			desc = "";
		}
		
		
		for(int i : al) {
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 26016
#include <bits/stdc++.h>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <vector>
#include <array>
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
	int k,s;
	std::cin >> k >> s;
	int cnt=0;
	for ( int x = 0 ; x <= k ; x++ ) {
		for ( int y = 0 ; y <= k ; y++ ) {
			int z = s-x-y;
			if (z>=0 && z<=k) cnt++;
		}
	}
	std::cout << cnt << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1e9+5
#define int long long
#define LINF 1000000000000000005

int n,m,v[805][805],ans=INF,x,y,k;

char a[805][805];

queue <pi> q;

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n >> m >> k;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> a[i][j];
            if(a[i][j]=='S') x=i,y=j,a[i][j]='.';
        }
    }
    q.push({x,y}); v[x][y]=1;
    while(q.size()){
        x=q.front().x, y=q.front().y;
        q.pop();
        if(x<n && !v[x+1][y] && a[x+1][y]=='.') q.push({x+1,y}),v[x+1][y]=v[x][y]+1;
        if(y<m && !v[x][y+1] && a[x][y+1]=='.') q.push({x,y+1}),v[x][y+1]=v[x][y]+1;
        if(x>1 && !v[x-1][y] && a[x-1][y]=='.') q.push({x-1,y}),v[x-1][y]=v[x][y]+1;
        if(y>1 && !v[x][y-1] && a[x][y-1]=='.') q.push({x,y-1}),v[x][y-1]=v[x][y]+1;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(v[i][j] && v[i][j]<=k+1){
                ans=min(ans,(i+k-2)/k);
                ans=min(ans,(n-i+k-1)/k);
                ans=min(ans,(j+k-2)/k);
                ans=min(ans,(m-j+k-1)/k);
            }
        }
    }
    cout << ans+1;
}


Measured memory_bytes: 6016
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
using namespace std;
using namespace __gnu_pbds; 
typedef long long int ll;
typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
inline ll mod(ll x) { return x%MOD; }
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x);   } return res; } 
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	vector<ll> ans(k+1);
	ll sum = 0;
	for(ll i=k;i>=1;--i)
	{
		ll co = 0;
		for(ll j=i;j<=k;j+=i) co++;
		ans[i] = power(co,n,MOD);
		for(ll j=2*i;j<=k;j+=i) ans[i] = mod(ans[i] - ans[j] + MOD);
		sum = mod(mod(sum) + mod(mod(ans[i]) * mod(i)));
	}
	cout<<sum<<endl;
	
}

Measured memory_bytes: 3944
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

class TrieNode:
    def __init__(self, n_alphabets):
        self.children = [None]*n_alphabets
        self.end = False

class Trie:
    def __init__(self, n_alphabets):
        self.n_alphabets = n_alphabets
        self.root = TrieNode(n_alphabets)

    def add(self, s):
        n = self.root
        for c in s:
            if n.children[c] is None:
                n.children[c] = TrieNode(self.n_alphabets)
            n = n.children[c]
        n.end = True


def solve(L):
    L = [tuple(ord(c)-ord('a') for c in reversed(s)) for s in L]
    trie = Trie(26)

    for s in L:
        trie.add(s)
    
    cnt = 0
    for s in L:

        app = [0]*26
        for c in s:
            app[c] += 1

        node = trie.root
        for c in s:
            if node is None:
                break
            for d,n in enumerate(node.children):
                if n is not None and app[d] > 0 and n.end:
                    cnt += 1
            app[c] -= 1
            node = node.children[c]
    return cnt - len(L)




if __name__ == '__main__':
    N = int(readline())
    L = [s.decode().rstrip() for s in read().split()]
    print(solve(L))

Measured memory_bytes: 517488
import sys

if __name__=="__main__":
    ab=[]
    cd=[]
    [n,m]=map(int,raw_input().split(" "))
    for i in range(n):
        ab.append( map(int,raw_input().split(" ")) )
    for j in range(m):
        cd.append( map(int,raw_input().split(" ")) )
    for i in range(n):
        min=sys.maxint
        index=0
        for j in range(m):
            distance = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            if min > distance :
                min=distance 
                index=j
        print(index+1)


Measured memory_bytes: 2692
import math


def check(a):
    for i, v in enumerate(a):
        if v != i + 1:
            return False
        else:
            if i == len(a) - 1:
                return True


while True:
    n = int(raw_input())
    if n == 0:
        break

    a = map(int, raw_input().split())
    if sum(a) != (lambda s: s * (s + 1) // 2)(int(math.sqrt(sum(a) * 2))):
        print -1
    else:
        c = 0
        while not check(a):
            c += 1
            a = [x - 1 for x in a if x - 1 != 0] + [len(a)]
            if c == 10000:
                c = -1
                break

        print c

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll h, w, d;
	vector<pair<ll, ll>> val;

	cin >> h >> w >> d;

	vector<ll> val2;

	REP(i, h) {
		REP(j, w) {
			val.push_back(make_pair(0, 0));
			val2.push_back(0);
		}
	}

	REP(i, h) {
		REP(j, w) {
			ll a;
			cin >> a;
			val[a - 1] = make_pair(i + 1, j + 1);
		}
	}

	REP(i, d) {
		ll x = i;
		ll prev = i;
		ll now = i + d;
		while (now < w*h) {
			val2[now] = val2[prev] + abs(val[x].first - val[x + d].first) + abs(val[x].second - val[x + d].second);
			x += d;
			prev = now;
			now += d;
		}
	}

	ll q;

	cin >> q;

	REP(i, q) {
		ll l, r;
		cin >> l >> r;

		ll ans = val2[r - 1] - val2[l - 1];

		cout << ans << endl;
	}
}

Measured memory_bytes: 4208
#include <cstdio>
#include <cstring>
static const int MAXN = 1e5 + 4;
static const int LOGN = 20;

int slen, tlen;
char s[MAXN], t[MAXN];
int q, a, b, c, d;

enum substr { EMPTY = 0, A, B } stab[MAXN][LOGN], ttab[MAXN][LOGN];
enum substr trans[3][3] = {
    { EMPTY, A    , B     },
    { A    , B    , EMPTY },
    { B    , EMPTY, A     }
};

void build_sparse(int len, char *s, enum substr tab[][LOGN])
{
    for (int i = 0; i < len; ++i) tab[i][0] = (s[i] == 'A' ? A : B);
    for (int j = 1; j < LOGN; ++j) {
        for (int i = 0; i <= len - (1 << j); ++i)
            tab[i][j] = trans[tab[i][j - 1]][tab[i + (1 << (j - 1))][j - 1]];
    }
}
enum substr get_from_sparse(enum substr tab[][LOGN], int start, int len)
{
    enum substr ret = EMPTY;
    //printf("Get from sparse (%d,%d):\n", start, len);
    for (int i = LOGN - 1; i >= 0; --i) if (len >= (1 << i)) {
        ret = trans[ret][tab[start][i]];
        //printf("    Combined with (%d,%d) value %d -> %d\n", start, 1 << i, tab[start][i], ret);
        start += (1 << i);
        len -= (1 << i);
    }
    //printf("%d\n", (int)ret);
    return ret;
}

int main()
{
    scanf("%s%s%d", s, t, &q);
    slen = strlen(s);
    tlen = strlen(t);
    build_sparse(slen, s, stab);
    build_sparse(tlen, t, ttab);

    for (int i = 0; i < q; ++i) {
        scanf("%d%d%d%d", &a, &b, &c, &d); --a, --b, --c, --d;
        puts(get_from_sparse(stab, a, b - a + 1) == get_from_sparse(ttab, c, d - c + 1) ? "YES" : "NO");
    }

    return 0;
}


Measured memory_bytes: 16256
#include<stdio.h>

int abs(int input){
  if(input < 0){
    input = -input;
  }
  return input;
}

int main()
{
  int n, a[100002];

  a[0] = 0;

  scanf("%d", &n);
  for(int i = 1; i <= n; i++){
    scanf("%d", &a[i]);
  }

  a[n+1] = 0;

  int all = 0;
  for(int i = 1; i <= n + 1; i++){
    all += abs(a[i] - a[i - 1]);
  }

  for(int i = 1; i <= n; i++){
    int normal = abs(a[i + 1] - a[i]) + abs(a[i] - a[i - 1]);
    int skip = abs(a[i + 1] - a[i - 1]);

    printf("%d\n", all + (skip - normal));
  }

  return 0;
}


Measured memory_bytes: 1536
h,w=map(int,input().split())
ans=10**9
if h%3==0 or w%3==0:
  ans=0
ans=min(ans,w)
ans=min(ans,h)
for i in range(w//3,min((w//3+4),w)):
  m=[]
  m.append(i*h)
  m.append((w-i)*(h//2))
  m.append((w-i)*(h-(h//2)))
  m.sort()
  ans=min(ans,m[2]-m[0])
for i in range(h//3,min((h//3+4),h)):
  m=[]
  m.append(i*w)
  m.append((h-i)*(w//2))
  m.append((h-i)*(w-(w//2)))
  m.sort()
  ans=min(ans,m[2]-m[0])
print(ans)

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


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

struct edge {int to; ll cost; };

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

 
int main(){
  int h, n;
  cin >> h >> n;
  int inf = 1000000009;
  vector<vector<int>> dp(n+1, vector<int>(h+1, inf));
  for(int i=0; i<=n; i++){
    dp[i][0] = 0;
  }
  for(int i=0; i<n; i++){
    int s, t;
    cin >> s >> t;
    for(int j=0; j<=h; j++){
      if(j-s>=0){
        dp[i+1][j] = min(dp[i][j], dp[i+1][j-s]+t);
      }else{
        dp[i+1][j] = min(dp[i][j], dp[i+1][0]+t);
      }
    }
  }
  cout << dp[n][h] << endl;
  return 0;
}


Measured memory_bytes: 42232
N = int(input())
total_number = 0
n = 0
while 2*n+1 <=N:
    yakusuu = 1
    yakusuu_number = 0
    while yakusuu <=2*n+1:
        if (2*n+1) % yakusuu ==0:
            yakusuu_number += 1
        yakusuu += 1
    n += 1
    if yakusuu_number == 8:
        total_number += 1
print(total_number)


Measured memory_bytes: 2940
q=int(input())
lr=[list(map(int,input().split())) for _ in range(q)]

sosuu=[2]
s=sosuu.append
for i in range(1,50001):
	k=2*i+1
	for j in sosuu:
		if k%j==0:
			break
		elif j>320:
			s(k)
			break
	else:
		s(k)

sosuu2=set(sosuu)
num=[]
n=num.append
for i in sosuu:
	k=(i+1)//2
	if k in sosuu2:
		n(i)

lis=[0]*100000

for i in num:
	lis[i-1]=1
	
from itertools import accumulate
lis=[0]+list(accumulate(lis))

for i in range(q):
	l,r=lr[i]
	print(lis[r]-lis[l-1])

Measured memory_bytes: 32988
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

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

  bool ans = true;

  int year = ((S[0] - 48) * 1000) + ((S[1] - 48) * 100) + ((S[2] - 48) * 10) + (S[3] - 48);
  int month = ((S[5] - 48) * 10) + (S[6] - 48);


  if (year < 2019) {
    ans = false;
  }
  else if (year == 2019 && month <= 04) {
    ans = false;
  }

  if (ans)
    cout << "TBD" << endl;

  else
    cout << "Heisei" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

string s,t;
int main() {
	cin >> s >> t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	reverse(t.begin(),t.end());
	
	if (s < t) cout << "Yes";
	else cout << "No";
	
}


Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
dict = {}
for ss in s :
    if ss in dict :
        dict[ss] += 1
    else :
        dict[ss] = 1
for tt in t:
    if tt in dict:
        dict[tt] -= 1
print(max(list(dict.values())+[0]))

Measured memory_bytes: 3064
#include <stdio.h>
int main(void) {
int a, b, c, d;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
scanf("%d", &d);
if (a >= b) {
a = b;
} if (c >= d) {
c = d;
} printf("%d\n", a + c);
return 0;
}

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

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;}
template<class T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T lcm(T a,T b){return a*b/gcd(a,b);}

const int INF=1e9;
const double eps=0.0000000001;

int main(){
  int n,m;
  cin >> n >> m;
  int a[1000000],b[1000000];
  vector<int> v;
  FOR(i,m){
    cin >> a[i] >> b[i];
    if(a[i]==1 || a[i]==n)v.push_back(b[i]);
    if(b[i]==1 || b[i]==n)v.push_back(a[i]);
  }
  sort(v.begin(),v.end());
  FOR(i,v.size()-1){
    if(v[i]==v[i+1]){cout << "POSSIBLE" << endl;return 0;}
  }

  cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
typedef pair<int,int> P;
vector< P > nex[114514];
int dist[114514];
signed main(){
	int k;
	cin>>k;
	for(int i=0;i<=k-1;i++){
		nex[i].pb( mp((i+1)%k,1) );
		nex[i].pb( mp( (i*10)%k, 0 ) );
	}
	for(int i=0;i<=k-1;i++){
		dist[i] = inf;
	}
	dist[1] = 1;
	priority_queue< P, vector<P>, greater<P> > que;
	que.push( mp(1,1) );
	while(!que.empty()){
		int cur = que.top().second; que.pop();
		for(int i=0;i<nex[cur].size();i++){
			P nx = nex[cur][i];
			if( dist[nx.first] > dist[cur] + nx.second ){
				dist[nx.first] = dist[cur] + nx.second;
				que.push( mp( dist[nx.first], nx.first ) );
			}
		}
	}
	cout<< dist[0] <<endl;
	return 0;
}

Measured memory_bytes: 9592
package main

import (
	"fmt"
	//"math"
)

func main() {
	var a,b int 
	fmt.Scanf("%d %d", &a,&b)
	if a >= 13{
		fmt.Print(b)
	}else if a >= 6{
		fmt.Print(b/2)
	}else{
		fmt.Print(0)
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define int long long
#define eb emplace_back
#define ef emplace_front
#define rep(i, x, n) for (int i = x; i < n; ++i)
#define mp make_pair
#define fi first
#define se second
#define ii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vii vector<pair<int, int>>
#define reverse(s) reverse(s.begin(), s.end())
#define ld long double
#define vs vector<string>
#define inf INT_MAX
#define vc vector<char>
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vb vector<bool>
#define lb(a, x) lower_bound(a.begin(), a.end(), x)
#define ub(a, x) upper_bound(a.begin(), a.end(), x) 
#define vvi vector<vi>
#define mine(a) min_element(a.begin(),a.end())
#define maxe(a) max_element(a.begin(), a.end())
#define iota(a,i) iota(a.begin(),a.end(),i)
#define fileopen(filename) if (fopen(filename".INP", "r")) {freopen(filename".INP", "r", stdin);freopen(filename".OUT", "w", stdout);}
int n, m;
map<ii, int> a;
vi par, val;
vvi adj;
vb d;
int findset(int x) {
	int u = x;
	while (par[x] != -1) {
		x = par[x];
		par[u] = x;
	}
	return x;
}
bool sameset(int x, int y) {
	return findset(x) == findset(y);
}
void unionset(int x, int y) {
	x = findset(x);
	y = findset(y);
	if (x == y) return;
	par[x] = y;
}
void dfs(int x) {
	for (int i : adj[x]) {
		if (d[i] == 0) {
			d[i] = 1;
			val[i] = val[x] + a[mp(x, i)];
			dfs(i);
		}
		else if (val[i] != val[x] + a[mp(x, i)]) {
			cout << "No";
			exit(0);
		}
	}
}
signed main() {
	fastio;
	cin >> n >> m;
	par.resize(n + 1, -1);
	adj.resize(n + 1);
	d.resize(n + 1, 0);
	val.resize(n + 1, 0);
	while (m--) {
		int x, y, z;
		cin >> x >> y >> z;
		a[mp(x, y)] = z;
		a[mp(y, x)] = -z;
		unionset(x, y);
		adj[x].emplace_back(y);
		adj[y].emplace_back(x);
	}
	rep(i, 1, n + 1) {
		if (d[i] == 0) {
			int x = findset(i);
			d[x] = 1;
			val[x] = 0;
			dfs(x);
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 46620
#include<stdio.h>

int main(void){

  int num[3]={0};
  int K=0;
  int i=0, j=0;
  int buffer=0;

  for(i=0; i<3; i++){
    scanf("%d", num+i);
  }
  scanf("%d", &K);


  for(i=0; i<2; i++){
    for(j=i+1; j<3; j++){
      if(num[i]<num[j]){
        buffer=num[i];
        num[i]=num[j];
        num[j]=buffer;
      }
    }
  }

  for(i=0; i<K; i++){
    num[0]=2*num[0];
  }
  printf("%d\n", num[0]+num[1]+num[2]);


  return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    string s;cin>>s;
    bool t1=false,t2=false,t3=false;
    if(s[0]=='A'){
        t1=true;
    }
    for (int i = 2; i < s.size()-1; i++)
    {
        /* code */
        if (s[i]=='C')
        {
            /* code */
            t2=true;
        }
        
    }
    int cnt=0;
    for (int i = 0; i < s.size(); i++)
    {
        /* code */
        if (isupper(s[i]))
        {
            /* code */
            cnt++;
        }
        
    }
    if (t1&&t2&&cnt==2)
    {
        /* code */
        cout<<"AC"<<endl;
    }
    else
    {
        cout<<"WA"<<endl;
    }   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n, s) for (int i = s; i < n; i++)
using namespace std;
const double PI = acos(-1);
int main()
{
    int n;
    cin >> n;
    reps(i, n + 1,1)
    {   
        int x=i;
        if (x % 3 == 0)
        {
            cout << " " << i;
            continue;
        }
        while(x){
            if(x%10==3){
                cout << " " << i;
                break;
            }
            x/=10;

        }
    }
    cout << endl;
 //   system("pause");
    return 0;
}


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


char s[110][110];
char ans[110][110];

int main(){
  int h, w;
  cin >> h >> w;

  for(int i = 0;i < h;i++){
    cin >> s[i];
  }

  int ah = 0;
  int aw = 0;
  for(int i = 0;i < h;i++){
    int j;
    for(j = 0;j < w;j++){
      if(s[i][j] == '#'){
        break;
      }
    }
    if(j != w){
      for(j = 0;j < w;j++){
        ans[ah][j] = s[i][j];
      }
      ah++;
    }
  }

  h = ah;

  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      s[i][j] = ans[i][j];
    }
  }

  for(int j = 0;j < w;j++){
    int i;
    for(i = 0;i < h;i++){
      if(s[i][j] == '#'){
        break;
      }
    }
    if(i != h){
      for(i = 0;i < h;i++){
        ans[i][aw] = s[i][j];
      }
      aw++;
    }
  }

  w = aw;

  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cout << ans[i][j];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
b = [0,2,5,5,4,5,6,3,7,6]
a = [0]+list(map(int, input().split()))
f = [-1]*10010
f[0]=0
for i in range(1,n+1):
    for j in range(1,m+1):
        x = a[j]
        if(i-b[x]<0):
            continue
        f[i] = max(f[i],f[i-b[x]]*10 + x)
print(f[n])

Measured memory_bytes: 14388