akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ar array
#define ll long long int

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
      ll n, k;
      cin >> n >> k;
      vector<ll> p(n + 1), c(n + 1);
      for (int i = 1; i <= n; ++i) {
          cin >> p[i];
      } 
      for (int i = 1; i <= n; ++i) {
          cin >> c[i];
      }
      ll ans = LLONG_MIN;
      for (int i = 1; i <= n; ++i) {
          vector<bool> vis(n + 1);
          int j = i;
          ll score = 0;
          ll q = 0;
          while (q < k and !vis[j]) {
              vis[j] = true;
              score += c[p[j]];
              ans = max(ans, score);
              j = p[j];
              ++q;
          }
          if (q == k)
            ans = max(ans, score);
          ll qq = k / q;
          ll s = score;
          if (qq > 1) {
              fill(vis.begin(), vis.end(), 0);
                q = 0;
                while (q < k and !vis[j]) {
                vis[j] = true;
                score += c[p[j]];
                ans = max(ans, score);
                j = p[j];
                ++q;
            }
          }
          score = s;

          score = qq * score;
          ans = max(ans, score);
          ll r = k % q;
          if (r == 0) {
              r = k;
              score -=s;
          }
          fill(vis.begin(), vis.end(), 0);
          q = 0 ;
          while (q < r and !vis[j]) {
              vis[j] = true;
              score += c[p[j]];
              ans = max(ans, score);
              j = p[j];
              ++q;
          }
          ans = max(ans, score);
      }
      cout << ans;
    }

    return 0;
}

Measured memory_bytes: 3740
from itertools import product

for _ in [0]*int(input()):
    a = [ord(c)-97 for c in input()]

    for p1, p2 in product(range(3, 10000, 2), range(26)):
        text = ""
        for code in a:
            if code == -65:
                text += " "
                continue
            for x in range(26):
                if (p1*x+p2)%26 == code:
                    text += chr(x+97)
                    break

        if "that" in text or "this" in text:
            print(text)
            break


Measured memory_bytes: 5820
#include <iostream>
#include <bitset>
#include <cstring>
using namespace std;

bitset<720> bm[10001];
int d[1001];

main(){
	int i,r,q,N,M,t,n,m,s,ts,te;
	while(cin>>N>>M,N){
		memset(d, 0, sizeof(d));
		for(i=1;i<=M;i++) bm[i].reset();
		cin>>r;
		while(r--){
			cin >> t >> n >> m >>s;
			t -= 540;
			if(s) d[n] = t;
			else  for(ts=d[n];ts<t;ts++) bm[m].set(ts);
		}
		cin>>q;
		while(q--){
			cin >> ts >> te >> m;
			ts -= 540;
			te -= 540;
			for(s=0;ts<te;ts++) s+=bm[m][ts];
			cout << s << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define MOD (long long)(1e9+7)
typedef long long int ll;
typedef unsigned long long int ull;

ll modularExponentiation(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;
}

bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll T=1;
  // cin>>T;
  for(int t=0;t<T;t++){
    ll k;
    cin>>k;
    queue<ll> q;
    for(int i=1;i<10;i++) q.push(i);
    ll f;
    while(k){
      f=q.front();
      q.pop();
      k--;
      if(f%10!=0) q.push(f*10+f%10-1);
      q.push(f*10+f%10);
      if(f%10!=9) q.push(f*10+f%10+1);
    }
    cout<<f<<endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];
    sort(v.begin(), v.end());

    deque<ll> q;
    for (ll l : v) q.push_back(l);

    list<ll> l;

    int i = 0;
    while (!q.empty()) {

        if (q.size() == 1) {
            if (abs(l.back() - q.front()) > abs(l.front() - q.front())) {
                l.push_back(q.front());
            } else {
                l.push_front(q.front());
            }
            break;
        }

        if (i % 2 == 0) {
            ll f = q.front();
            q.pop_front();
            l.push_front(f);

            ll b = q.back();
            q.pop_back();
            l.push_back(b);
        } else {
            ll f = q.front();
            q.pop_front();
            l.push_back(f);

            ll b = q.back();
            q.pop_back();
            l.push_front(b);
        }

//        for(ll k : l) cout << k << ' ';
//        cout << endl;

        i++;
    }

    vector<ll> a;
    for (ll j : l) a.push_back(j);
    ll ans = 0;
    rep(i, n - 1) ans += abs(a[i] - a[i + 1]);
    cout << ans << endl;
}


Measured memory_bytes: 8280
/*
        Author: Prokash
                CSE48, JU

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int ara[2005];
int main()
{
    FAST;
    ll decimal;
    cin>>decimal;
    if(decimal==0)
    {
        cout<<0<<endl;
        return 0;
    }
    string s;
    while(decimal)
    {
        if(!(decimal%2))
        {
            s="0"+s;
        }
        else

        {
            s="1"+s;
            decimal--;
        }
        decimal/=(-2);
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define FOR(xxx,begin,num) for(int xxx = (begin);xxx < ((begin) + (num)); xxx++)
#define MIN(a,b) (((a)<(b))?(a):(b))
typedef long long ll;
int main(){
  int k,q;
  ll d[5010],n[5010],x[5010],m[5010],Am[5010],Dd[5010];
  cin >> k >> q;
  FOR(i,0,k) cin >> d[i];
  FOR(i,0,q) cin >> n[i] >> x[i] >> m[i];
  FOR(i,0,q){
    ll smcase=0, eqcase=0, A = x[i];
    FOR(j,0,k) Dd[j] = d[j] % m[i];
    FOR(j,0,k){
      if(Dd[j] == 0) eqcase += (( (n[i]-1)%k<=j )?( (n[i]-1)/k ):( (n[i]-1)/k + 1 ));
      A += Dd[j] * (( (n[i]-1)%k<=j )?( (n[i]-1)/k ):( (n[i]-1)/k + 1 ));
    }
    smcase = (A) / m[i] - x[i] / m[i];
    cout << (n[i] - 1 - smcase - eqcase ) << endl;
  }
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;

int N, M;
int a[60], b[60];

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
    }

    int ans = 0;
    for (int i = 0; i < M; i++) {
        UnionFind tree(N+1);
        for (int j = 0; j < M; j++) {
            if (i != j) {
                tree.unite(a[j], b[j]);
            }
        }

        int r = tree.root(1);
        bool f = true;
        for (int j = 2; j <= N; j++) {
            if (r != tree.root(j)) {
                f = false;
                break;
            }
        }
        if (!f) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int S = sc.nextInt();
            int S1 = S % 3600;
            int se = S1 % 60;
            int m = (S1 - se)/60;
            int h = (S - S1)/3600;
             
            System.out.println( h + ":" + m +":" + se);
        }
    }
}

Measured memory_bytes: 26140
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

int main()
{
    int N,h,mae,ans=0,c=0;
    cin>>N;
    for(int i=0;i<N;i++){
    	cin>>h;
    	if(i!=0&&h<=mae)c++;
    	else c=0;
    	ans=max(ans,c);
    	mae=h;
    }
    cout<<ans;
}


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

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

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

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

ll N;
string S;
ll T[100005];
bool check(ll k)
{
    REP(n, 2)
    {
        memset(T, 0, sizeof(T));
        ll m = 0;
        string s = "";
        REP(i, N)
        {
            m += T[i];
            ll t = (S[i] - '0' + m) % 2;

            if (i + k <= N && t != n)
            {
                m++;
                T[i + k] = -1;
                t = (t + 1) % 2;
            }
            s.push_back(t + '0');
        }

        ll max = 0;
        ll sum = 0;
        REP(i, N)
        {
            sum++;
            if (i == N - 1 || s[i] != s[i + 1])
            {
                max = std::max(max, sum);
                sum = 0;
            }
        }

        if (max >= k)
            return true;
    }
    return false;
}

int main()
{
    cin >> S;
    N = S.length();
    ll ok = 1, ng = N + 1;
    while (abs(ok - ng) > 1)
    {
        ll mid = (ok + ng) / 2;
        if (check(mid))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

int main(void) {
    int r, g, b;
    cin >> r >> g >> b;

    int rgb = 100 * r + 10 * g + b;
    cout << (rgb % 4 == 0 ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int INF=(1e9);
const int maxn=200010;
int n,m[maxn],s,t,cur[maxn];
int level[maxn],tot;
int ans,flow[maxn*4];
int head[maxn],nxt[maxn*4];
int to[maxn*4];
queue<int> q;
vector<int> g[maxn];
void Add_edge(int a,int b,int c) {
	tot++; nxt[tot]=head[a];
	head[a]=tot; to[tot]=b; flow[tot]=c;
}
void add_edge(int a,int b,int c) {
	Add_edge(a,b,c);
	Add_edge(b,a,0);
}
bool bfs() {
	q=queue<int>();
	memset(level,-1,sizeof(level));
	for (int i=1;i<=t;i++) cur[i]=head[i];
	q.push(s);
	level[s]=0;
	while (!q.empty()) {
		int a=q.front(),b; q.pop();
		for (register int i=head[a];i;i=nxt[i]) {
			b=to[i];
			if (flow[i]>0&&level[b]==-1) {
				level[b]=level[a]+1;
				q.push(b);
			}
		}
	}
	return level[t]!=-1;
}
int dfs(int x,int rest) {
	if (x==t) return rest;
	int used=0;
	for (register int i=cur[x];i;i=nxt[i]) {
		cur[x]=i;
		int y=to[i];
		if (flow[i]>0&&level[y]==level[x]+1) {
			int tflow=dfs(y,min(flow[i],rest-used));
			used+=tflow;
			flow[i]-=tflow;
			flow[i^1]+=tflow;
			if (rest-used==0) break;
		}
	}
	if (!used) level[x]=-1;
	return used;
}
bool vis[maxn];
pair<int,int> Ans[maxn];
void dfs(int u) {
	vis[u]=1;
	for (int i=0,v;i<g[u].size();i++) {
		v=g[u][i];
		if (!vis[m[v]]) Ans[v]=make_pair(u,m[v]),dfs(m[v]);
	}
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); tot=1;
	s=n*2+1,t=n*2+2;
	int x,y;
	for (int i=1;i<n;i++) {
		add_edge(s,i,1);
		read(x);
		while (x--) {
			read(y);
			g[y].push_back(i);
			if (y>1) add_edge(i,y+n,1);
		}
	}
	for (int i=1;i<=n;i++) add_edge(i+n,t,1);
	while (bfs()) ans+=dfs(s,INF);
	if (ans!=n-1) { printf("-1\n"); return 0; }
	for (int i=1;i<n;i++)
	for (int j=head[i];j;j=nxt[j])
		if (!flow[j]&&to[j]!=s) {
			m[i]=to[j]-n; break;
		}
	dfs(1);
	for (int i=1;i<n;i++) if (!Ans[i].first) { printf("-1\n"); return 0; }
	for (int i=1;i<n;i++) printf("%d %d\n",Ans[i].first,Ans[i].second);
	return 0;
}

Measured memory_bytes: 25044
import sys
from collections import deque
import copy
import bisect
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, C] = [int(input_raw[0]), int(input_raw[1])]
    dic_s = {}
    dic_t = {}
    max_t = 0
    for i in range(N):
        input_raw = read_func().strip().split()
        [s, t, c] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
        max_t = max(t, max_t)
        if c not in dic_s:
            dic_s[c] = [s]
            dic_t[c] = [t]
        else:
            dic_s[c].append(s)
            dic_t[c].append(t)

    for c in dic_s:
        dic_s[c].sort()
        dic_t[c].sort()

    max_count = 0

    for s in range(1, max_t):
        t = s + 1
        count = 0
        for c in dic_s:
            idx_s = bisect.bisect_left(dic_s[c], t) - 1
            idx_t = bisect.bisect_left(dic_t[c], s)

            if idx_t >= len(dic_t[c]) or idx_s < 0:
                continue
            if dic_s[c][idx_t] <= s or t <= dic_t[c][idx_s]:
                count += 1
        max_count = max(count, max_count)
    print max_count




if __name__ == '__main__':
    main()


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

int main() {
    vector<int> v;
    for (int i = 0; i < 10000; ++i) {
        int a;
        cin >> a;
        if (a == 0) break;
        v.push_back(a);
    }
    
    for (int i = 0; i < (int)v.size(); ++i) {
        cout << "Case " << i + 1 << ": " << v[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl

template<typename T>
T gcd(T x, T y){
    if ((x==1)||(y==1)) return 1;
    if (x>y) {
        if (x%y==0) {
            return y;
        }else{
            return gcd(y, x%y);
        }
    }else{
        if (y%x==0) {
            return x;
        }else{
            return gcd(x, y%x);
        }
    }
}

int main() {
    IN(int, s);
    IN(int, w);
    if (w>=s) {
        COUT("unsafe");
    }else{
        COUT("safe");
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
#define next nxt

int n,t,x[N],y[N],next[N],p[N],d[N],f[N];
long long a[N];

void travel(int x){
	if (d[x]==1) return;
	long long cnt=0,mx=0;
	for (int t=p[x];t;t=next[t])
		if (y[t]!=f[x]){
			f[y[t]]=x;travel(y[t]);
			cnt+=a[y[t]];
			mx=max(mx,a[y[t]]);
		}
	if (mx>a[x]||cnt<a[x]||cnt>2*a[x])
	{printf("NO\n");exit(0);}
	a[x]=2*a[x]-cnt;
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n-1;i++){
		x[2*i-1]=y[2*i]=read();
		y[2*i-1]=x[2*i]=read();
		d[x[2*i-1]]++;d[y[2*i-1]]++;
		next[2*i-1]=p[x[2*i-1]];p[x[2*i-1]]=2*i-1;
		next[2*i]=p[x[2*i]];p[x[2*i]]=2*i;
	}
	if (n==2){
		printf(a[1]!=a[2]?"NO\n":"YES\n");
		return 0;
	}
	for (t=1;d[t]==1;t++);
	travel(t);
	printf(a[t]?"NO\n":"YES\n");
	return 0;
}

Measured memory_bytes: 21376
#include <bits/stdc++.h>
#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 PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int n ;
	vector< pair<ll,ll> > a;
	cin >> n;
	if(n==0)break;
	REP(i,n){
	    ll a1,a2,a3;
	    cin >> a1 >> a2 >> a3;
	    a.PB( pair<ll,ll>(a2,a1) );
	    a.PB( pair<ll,ll>(a3,-1*a1) );
	}
	bool flg = false;
	sort(ALL(a));
	ll sum = 0;
	REP(i,2*n){
	    sum += a[i].second;
	    if(sum > 150){
	       	flg = true;
	    }
	}
	if(flg) cout << "NG" << endl;
	else cout << "OK" << endl;
    }
    return 0;
}

Measured memory_bytes: 1208
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let s: Vec<u8> = read::<String>().into_bytes();
    let mut ans = 0;
    for i in 0..s.len()-1 {
        if s[i] != s[i+1] {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
let solve d n m =
  let dp = Array.make (n + 1) max_int in
  dp.(0) <- 0;
  for j = 1 to n do dp.(j) <- dp.(j-1) + 1 done;
  for i = 1 to m - 1 do
    for j = 1 to n do
      if j - d.(i) >= 0 && dp.(j - d.(i)) + 1 < dp.(j)
      then dp.(j) <- dp.(j - d.(i)) + 1;
    done
  done;
  dp.(n)

let () =
  let n, m = Scanf.scanf "%d %d " (fun n m -> n, m) in
  let d = Array.init m (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  solve d n m |> Printf.printf "%d\n"

Measured memory_bytes: 2760
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)

fun main(args: Array<String>) {
    val d = readInt()
    var s = "Christmas"
    for(i in 0 until 25 - d) {
        s += " Eve"
    }
    println(s)
    pw.flush()
}

fun inputList() = 
    readLine()!!.split(" ").map(String::toInt)

fun sum_digits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

/****** Decrared Functions ******/

// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)

fun println(value : Any) {
    pw.println(value)
}

fun gcd(a: Long, b: Long): Long = 
    if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
    if(b==0L) a else gcd(b, a % b)


Measured memory_bytes: 33988
N = int(input())
W = list(map(int,input().split()))
weight= sum(W)
cnt = 0
for i in range(N):
  if weight <= cnt:
    print(min(cnt-weight,abs((cnt-W[i-1])-(weight+W[i-1]))))
    exit()
  weight -= W[i]
  cnt += W[i]
 

Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
using namespace std;

int N, A[200200], B[200200], C[400200];

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &A[i]);
	for (int i = 0; i < N; i++) scanf("%d", &B[i]);
	int ans = 0;
	for (int k = 0; k <= 28; k++) {
		int step = (1 << k);
		for (int i = 0; i < N; i++) C[i] = A[i] % (step * 2);
		sort(C, C + N);
		for (int i = 0; i < N; i++) C[i + N] = C[i] + step * 2;
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			int st = step * 3 - B[i] % (step * 2);
			int ed = step * 4 - B[i] % (step * 2) - 1;
			cnt += upper_bound(C, C + N * 2, ed) - lower_bound(C, C + N * 2, st);
		}
		if (cnt & 1) ans |= step;
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 3328
/*input
60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34
*/
#include <iostream>
using namespace std;
#define MAX 5

int a[MAX][MAX];

int main() {
	for (int i = 1; i <= 3; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> a[i][j];
		}
	}
	int n; cin >> n;
	while (n--) {
		int now; cin >> now;

		for (int i = 1; i <= 3; i++) {
			for (int j = 1; j <= 3; j++) {
				if (a[i][j] == now) a[i][j] = -1;
			}
		}
	}
	int s3 = 0, s4 = 0;
	for (int i = 1; i <= 3; i++) {
		int s1 = 0, s2 = 0;
		for (int j = 1; j <= 3; j++) {
			s1 += a[i][j];
			s2 += a[j][i];
		}

		if (s1 == -3 || s2 == -3) {
			cout << "Yes\n";
			return 0;
		}
		s3 += a[i][i];
		s4 += a[i][4 - i];
	}
	if (s3 == -3 || s4 == -3) {
			cout << "Yes\n";
			return 0;
	}

	cout << "No\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[110];
int main() {
    int n;
    cin >> n;
    for(int i = 1 ; i <= n ; i++) {
        cin >> a[i];
    }
    int MAX = a[1] , MIN = a[1];
    for(int i = 1 ; i <= n ; i++) {
        MAX = max(MAX , a[i]);
        MIN = min(MIN , a[i]);
    }
    cout << MAX - MIN << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    bool ans = true;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(a % 2 == 0){
            if(a % 3 != 0 && a % 5 != 0){
                ans = false;
            }
        }
    }
    if(ans){
        cout << "APPROVED" << endl;
    }
    else{
        cout << "DENIED" << endl;
    }
}

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

int a,b;
int num = 0;

int main()
{
    scanf("%d%d",&a,&b);
    if(b == 100)num = a * 1000 + b;
    else if(10 <= b && b < 100)num = a * 100 + b;
    else if(0 <= b && b < 10)num = a * 10 + b;
    double res1 = sqrt((double)num);
    double res2 = (double)((int)res1);
    if(res1 - res2)printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
n = input()
ans = 0
num753 = [[]for _ in range(len(n)+1)]

def create753(n): #357いずれかの数字からなるn桁の数をnum753に格納
  num753[0].append('0')
  num753[1].append('3')
  num753[1].append('5')
  num753[1].append('7')
  
  for i in range(1,n):
    for j in num753[i]:
      for k in '357':
        num_next = j + k
        num753[i+1].append(num_next)
  
create753(len(n))

for i in num753:
  for j in i:
    if all(j.count(c) > 0 for c in '753') and (1 <= int(j) <=int(n)):
      ans += 1

print(ans)

Measured memory_bytes: 5228
tmp = input().split()
K = int(tmp[0])
A = int(tmp[1])
B = int(tmp[2])
diff = B-A

if B-A <=2:
	print(K+1)
else:
	tmp = (A-1)
	tmp2 = A + diff*int((K-tmp)/2) + (K-tmp)%2
	print(int(tmp2))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
#define N 100
int F[N][10];
int P[N][11];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 10; j++) {
            cin >> F[i][j];
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= 10; j++) {
            cin >> P[i][j];
        }
    }
    int ans = 0;
    for(int s = 1; s < (1 << 10); s++) {
        set<int> open;
        for(int j = 0; j < 10; j++) {
            if(s & (1 << j)) {
                open.insert(j);
            }
        }
        int cur = 0;
        for(int i = 0; i < n; i++) {
            int ci = 0;
            for(int j = 0; j < 10; j++) {
                if(F[i][j] and open.count(j)) {
                    ci++;
                }
            }
            cur += P[i][ci];
        }
        ans = s == 1 ? cur : max(ans, cur);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n, m, a[100000], r[100000]={}, ans=0;
	scanf("%d %d", &n, &m);
	fill(a, a+n, 1);
	r[0]=1;
	int x, y;
	for(int i=0; i<m; i++){
		scanf("%d %d", &x, &y);
		x--;
		y--;
		if(a[x]>1 && r[x]==1){
			r[y]=1;
		}else if(a[x]==1 && r[x]==1){
			r[x]=0;
			r[y]=1;
		}
		a[x]--;
		a[y]++;
	}
	for(int i=0; i<n; i++){
		ans=ans+r[i];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1000000007;

int a[10],b[10];
int c[10][10];

int main(){

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


    for ( int i = 0; i < 3; i++ ){
      for (int j =0; j < 3; j++){
        cin >> c[i][j];
      }
    }

    a[0] = 0;
    for (int j = 0; j < 3;j++){

      b[j] = c[0][j] - a[0];
    }

    for (int i = 0; i < 3; i++){

      a[i] = c[i][0] - b[0];

    }
    bool ans = true;

    for ( int i = 0; i < 3; i++ ){
      for (int j =0; j < 3; j++){
        if (c[i][j] != a[i] + b[j] ) ans = false;
      }
    }

    if (ans == true ) {
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S=input()

if S.count('AC'):
    Yes()
else:
    No()


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

using namespace std;

int main(){
    int n,q; cin>>n>>q;
    int s,t,x;
    int count=0;
    vector<int> d(q);
    vector<tuple<int,int,int>> event(2*n);
    for(int i=0;i<n;i++){
        cin>>s>>t>>x;
        get<0>(event[count])=s-x;//ひっかかり開始時刻
        get<1>(event[count])=1;//
        get<2>(event[count++])=x;//座標
        get<0>(event[count])=t-x;//ここと
        get<1>(event[count])=-1;
        get<2>(event[count++])=x;
    }
    for(int i=0;i<q;i++) cin>>d[i];
 	sort(event.begin(),event.end());

    set<int> se;
  	se.insert(INT_MAX);

  	int i=0,h=0;
    while(1){
        while(get<0>(event[i])<=d[h] && i<2*n){
            if(get<1>(event[i])==1) se.insert(get<2>(event[i]));
       		else if(get<1>(event[i])==-1) se.erase(get<2>(event[i]));
          	i++;
        }
      	decltype(se)::iterator it=se.upper_bound(0);
        if(*it!=INT_MAX) printf("%d\n",*it);
        else printf("-1\n");
        h++;
        if(h==q) break;
    }
}

Measured memory_bytes: 16128
package main

import (
	"fmt"
)

func main() {
	var a, b, c int64

	fmt.Scanf("%d %d %d\n", &a, &b, &c)

	d := c - a - b
	if d < 0 {
		fmt.Println("No")
		return
	}

	if 4*a*b < d*d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
typedef long long ll;
int main(){
	int n,l;
	cin>>n>>l;
	int head,tail,eat;
	head=l;
	tail=l+n-1;
	if(head<0){
		if(tail<0){
			eat=tail;
		}else{
			eat=0;
		}
	}else{
		eat=head;
	}
	int sum=0;
	sum=(head+tail)*n/2;
	cout<<sum-eat<<endl;
	return 0;
}

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
const ll mod = 1000000007;

int main() {
    int n; cin >> n;
    int a[n]; rep(i,n) cin >> a[i];
    rep(i,n) {
        rep(j,i) {
            swap(a[i],a[j]);
            int b = 1;
            rep(k,n-1) {
                if (a[k] >= a[k+1]) {
                    b = 0;
                    break;
                }
            }
            if (b) {
                cout << "YES" << endl;
                return 0;
            }
            swap(a[i],a[j]);
        }
    }
    rep(i,n-1) {
        if (a[i] >= a[i+1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 3516
def func(num,total=0)
    if num < 1
        0
    elsif num == 1
        total + 9
    else
        func(num-2,total+10**(num-1)*9)
    end
end

num = gets.to_i
digits = num.to_s.length
ans = 0
if digits %2 == 0
    digits -= 1
    ans += func digits
else
    ans += num - 10**(digits-1) + 1
    ans += func digits-2
end
puts ans



Measured memory_bytes: 1788
/*
 タクシー
 <問題文>
 駅には、横N列にPCK社のタクシー乗り場が設置されている。
 各乗り場には1からNまでの番号が順番に付いており、タクシーが１台ずつ停まっている。
また、各乗り場にはタクシーを待つ客が並んでおり、それぞれの客が払う料金はあらかじめわかっている。
 PCKタクシーの運転手は提示額の低い客の乗車を断り、提示額の高い客を乗車させることでPCK社の売り上げを上げている。
1.i番目の乗り場の列の先頭の客をタクシーにのせる。
2.i番目の乗り場の列の先頭の客の乗車を断る。断られた客は列から消える。
3.i+1番目のタクシー乗り場に他のタクシーが存在しなければ、そこに移動する。ただし、N番目の乗り場にいる場合は、公道に出てタクシー乗り場を去る。
あなたの仕事は、事前調査で得られた客の希望料金の表を基に、PCK社の売り上げを最大化することである。なお、１台のタクシーには最大一人の客を乗せることができる。
タクシー乗り場の数と、各タクシー乗り場に並んでいる客の情報が与えられたとき、売り上げの総和の最大値を求めよ。
<入力>
入力は以下の形式で与えられる
N
s1
s2
・・・
sN
１行目にタクシー乗り場の数N(1≤N≤300,000)が与えられる。続くN行に、
i番目のタクシー乗り場に並んでいる客の情報siが与えられる。各情報siは以下の形式で与えられる。
M c1 c2... cM
最初の整数M(1≤M≤300,000)が、このタクシー乗り場に並んでいる人の数を表す。
それに続いて、この乗り場のj番目に並んでいる客が払う料金cj(1≤cj≤10,000)が与えられる。
ただし、タクシー乗り場に並んでいる客の総数は300,000人以下である
*/
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
typedef long long int ll;
//unsigned・・・符号なし（正の値のみ取り扱う）
typedef unsigned long long int ull;
using namespace std;
#define NUM 300005
int N;
vector<ll> V[NUM];
int main(void){
	cin>>N;
	int tmp_num;
	ll tmp;
	for(int loop=0;loop<N;loop++){
		cin>>tmp_num;
		for(int i=0;i<tmp_num;i++){
			cin>>tmp;
			V[loop].push_back(tmp);
		}
	}
	ll ans=0;
	priority_queue<ll> Q;
	for(int i=N-1;i>=0;i--){
		for(int k=0;k<V[i].size();k++){
			Q.push(V[i][k]);
		}
		ans+=Q.top();
		Q.pop();
	}
	cout<<ans<<endl;
	return 0;
}
/*
#intclue<vector>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int N=0;
int M[300030]=0;
long long sum=0;
int c;
std::vector<int> C;
int main(void){
	int count=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>M[i];
		for(int j=0;j<M;j++)
		{
			cin>>c;
			C.insert(C.begin(),1,c);
		}	
	}
	for(int i=0;i<N;i++){
		sort(C,C+M[])
	}
	sort(C,C+count,std::greater<int>());
	sum+=C[0];
	C[0]=0;
	cout<<sum<<endl;
}
*/



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

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int>l(n);
    for(int i=0; i<n; ++i) {
        cin >> l.at(i);
    }
    sort(l.begin(), l.end(), greater<int>());
    int ans = 0;
    for (int i=0; i<k; ++i) {
        ans += l.at(i);
    }
    cout << ans << endl;
    return 0;
}


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

/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//main function
fn main() {
    let n: usize = read();
    let mut t: Vec<i64> = Vec::with_capacity(n);
    let mut sum: i64 = 0;
    for i in 0..n{
	t.push(read());
	sum += t[i as usize];
    }
    let m: usize = read();
    for _i in 0..m{
	let p: usize = read();
	let x: i64 = read();
	println!("{}",sum-t[p-1]+x);
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

const int INF = 2002002002;

void solve(long long N, long long K){
    ll ans = K;
    REP(i, N - 1)
        ans *= (K - 1);
    print(ans);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readInt()
    val found = mutableMapOf<String, Long>()
    var cnt = 0L
    repeat(n) {
        val s = readLine()!!.toCharArray().sorted().toString()
        if (found.contains(s)) {
           cnt += found[s]!!
            found[s] = found[s]!! + 1L
        } else {
            found[s] = 1L
        }
    }
    println(cnt)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

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

int main(){
    int H,W;
    while (1){
        int i,t;
        cin >> H >> W;
        if (H==0 && W==0) break;

        for (i=1; i<=H; i+=1){
            for (t=1; t<=W; t+=1){
                if (i==1 || i==H){
                    cout << '#';
                } else {
                    if (t==1 || t==W){
                        cout << '#';
                    } else{
                        cout << '.';
                    }
                }
                }
            cout << "\n";
        }
        cout << "\n"; 
    }

    return 0;
}


Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
int main(){
  ll k,x; cin >> k >> x;
  if(500*k>=x) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a;
    int b;
    int c;

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

    if (a <= b && b <= c)
        printf("%d %d %d\n", a, b, c);
    else if (a <= c && c <= b)
        printf("%d %d %d\n", a, c, b);
    else if (b <= a && a <= c)
        printf("%d %d %d\n", b, a, c);
    else if (b <= c && c <= a)
        printf("%d %d %d\n", b, c, a);
    else if (c <= a && a <= b)
        printf("%d %d %d\n", c, a, b);
    else if (c <= b && b <= a)
        printf("%d %d %d\n", c, b, a);
    else
        printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2608
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n, m, q; cin >> n >> m >> q;

	vector<vector<int>> tb(n+2, vector<int>(n+2,0));


	for (int i = 0; i < m; i++) {
		int l, r; cin >> l >> r;

		tb[l][r]++;
	}

	for (int i = 0; i < n+1; i++) {
		for (int j = 0; j < n+1; j++) {
			tb[i][j + 1] += tb[i][j];
		}
	}

	for (int i = 0; i < q; i++) {
		int p, q; cin >> p >> q;

		int ans = 0;
		for (int j = p; j <q+1; j++) {
			ans += tb[j][q] - tb[j][p - 1];
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9

ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll n;cin>>n;
    ll a[n];f(i,0,n)cin>>a[i];
    if(n==1)cout<<"Yes";
    else {bool ok=0;
    f(i,1,n){
        if(a[i]>a[i-1])a[i]--;
        if(a[i]<a[i-1]){ok=1;break;}
    }
    if(ok)cout<<"No";
    else cout<<"Yes";
    }
    return 0;  
} 


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

int main(){
  int n, m, max = 0;
  cin >> n;
  string s[n];
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  cin >> m;
  string t[m];
  for(int i=0;i<m;i++)cin >> t[i];
  for(int i=0;i<n;i++){
    int tmax = 0;
    for(int j=0;j<n;j++){
      if(s[i]==s[j])tmax++;
    } 
    for(int j=0;j<m;j++){
      if(s[i]==t[j])tmax--;
    }
    if(max<tmax)max = tmax;
  }
  cout << max<< endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;

int main() {
	ll N;
	cin >> N;
	ll cnt, ans = 0;
	for (ll i = 2;i * i <= N;i++) {
		cnt = 0;
		while (N % i == 0) {
			N /= i;
			cnt++;
		}
		ll ok = 0, ng = 200, mid = 100;
		while (ok + 1 < ng) {
			mid = (ok + ng) / 2;
			if (mid * (mid + 1) / 2 > cnt) {
				ng = mid;
			}
			else {
				ok = mid;
			}
		}
		ans += ok;
	}
	if (N != 1)ans++;
	cout << ans << endl;
}

Measured memory_bytes: 3620
package main

import (
    "fmt"
    "os"
)

func main() {

    var N int 
    var x int 
    fmt.Fscanf(os.Stdin, "%d %d", &N, &x) 

    xmin := 1
    xmax := N*2 - 1 
    if x <= xmin || x >= xmax {
        fmt.Printf("No\n")
        return
    }   
    fmt.Printf("Yes\n")
  
    if N == 2 {
        fmt.Printf("1\n2\n3\n")
        return
    }

    ans := make([]int, 0)
    if x <= 2 { 
        // x+1 x x-1 x+2
        //     x x
        ans = append(ans, []int{x + 1, x, x - 1, x + 2}...)
        for i := 1; i < x-1; i++ {
            ans = append(ans, i)
        }   
        for i := x + 3; i <= xmax; i++ {
            ans = append(ans, i)
        }   
    } else {
        // x-1 x x+1 x-2
        //     x x
        ans = append(ans, []int{x - 1, x, x + 1, x - 2}...)
         for i := 1; i < x-2; i++ {
            ans = append(ans, i)
        }
        for i := x + 2; i <= xmax; i++ {
            ans = append(ans, i)
        }
    }

    //fmt.Printf("%v\n", ans)
    ans2 := make([]int, 0)
    div := (xmax - 4) / 2
    ans2 = append(ans2, ans[4+div:]...)
    ans2 = append(ans2, ans[0:4+div]...)

    for _, v := range ans2 {
        fmt.Println(v)
    }
}


Measured memory_bytes: 11008
N, M = list(map(int, input().split()))
X = sorted(list(map(int, input().split())))

dis = []
for i in range(M-1):
    dis.append(abs(X[i]-X[i+1]))
dis1 = sorted(dis)

ans = 0
if N >= M:
    print(0)
else:
    for j in range(M-N):
        ans += dis1[j]
    print(ans)

Measured memory_bytes: 13968
#include <cstdio>
#include <algorithm>
#include <queue>
#include <utility>
#include <functional>

struct edge
{
  int to;
  int cost;
};

edge edges[100000][2];
int dist[100000];

int main()
{
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; ++i)
  {
    edges[i][0] = edge{(i * 10) % k, 0};
    edges[i][1] = edge{(i + 1) % k, 1};
  }
  std::fill(dist, dist + k, (int)1e9);
  dist[1] = 0;
  using pair = std::pair<int, int>;
  std::priority_queue<pair, std::vector<pair>, std::greater<pair>> q;
  q.emplace(pair{0, 1});
  while (q.size() > 0)
  {
    auto p = q.top(); q.pop();
    if (p.first > dist[p.second]) continue;
    for (auto &e : edges[p.second])
    {
      int nc = e.cost + dist[p.second];
      if (nc < dist[e.to])
      {
        dist[e.to] = nc;
        q.emplace(pair{nc, e.to});
      }
    }
  }
  printf("%d\n", dist[0] + 1);
  return 0;
}


Measured memory_bytes: 2812
//In the name of Allah
//In the name of the compassionate of the merciful
//Ya Ali!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll ;
typedef long double ld ;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll maxn = 1000 * 1000 ;
const ll INF = 1e18 ;

#define f first
#define s second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front

// cout << *ss.find_by_order(index) ; -> return the value that indexed in index position
// cout << ss.order_of_key(value) ; -> lower_bound in ordered_set

ll mod = 1e9 + 7 , p1 = 999999929 , p2 = 999999937 ;

ll n , a[maxn] ;

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

string s1 ;
cin >> s1 ;
for(int i = 0 ; i < s1.size() ; i++){
    if(s1[i] == '<'){
        a[i+1] = max(a[i+1] , a[i]+1) ;
    }
}
for(int i = s1.size()-1 ; i >= 0 ; i --){
    if(s1[i] == '>'){
        a[i] = max(a[i] , a[i+1]+1) ;
    }
}
ll ans = 0 ;
for(int i = 0 ; i <= s1.size() ; i ++)ans += a[i] ;
cout << ans ;
 return 0;
}
/*
                  _     _   __
            /_\  (_    (_)  __)
           /   \  _) . (_) (__
*/


Measured memory_bytes: 5020
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll Q = 1000000007;

int main(){
  int H,W;cin >> H >> W;
  vector<string> S(H);
  for(int i=0;i<H;i++){
    cin >> S[i];
  }
  vector<vector<int>> U(H,vector<int>(W,0));
  vector<vector<int>> D(H,vector<int>(W,0));
  vector<vector<int>> L(H,vector<int>(W,0));
  vector<vector<int>> R(H,vector<int>(W,0));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j]=='#'){
        L[i][j]=0;
      }else{
        if(j==0){
          L[i][j]=1;
        }else{
          L[i][j]=L[i][j-1]+1;
        }
      }
    }
    for(int j=W-1;j>=0;j--){
      if(S[i][j]=='#'){
        R[i][j]=0;
      }else{
        if(j==W-1){
          R[i][j]=1;
        }else{
          R[i][j]=R[i][j+1]+1;
        }
      }
    }
  }
  for(int j=0;j<W;j++){
    for(int i=0;i<H;i++){
      if(S[i][j]=='#'){
        U[i][j]=0;
      }else{
        if(i==0){
          U[i][j]=1;
        }else{
          U[i][j]=U[i-1][j]+1;
        }
      }
    }
    for(int i=H-1;i>=0;i--){
      if(S[i][j]=='#'){
        D[i][j]=0;
      }else{
        if(i==H-1){
          D[i][j]=1;
        }else{
          D[i][j]=D[i+1][j]+1;
        }
      }
    }
  }
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      ans = max(ans,U[i][j]+D[i][j]+L[i][j]+R[i][j]-3);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 67200
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 31 02:12:27 2020

@author: liang
"""

n = int(input())
ans = 0
for num in range(1, n+1,2):
    cnt = 0
    for i in range(1,num+1):
        if num % i == 0:
            cnt += 1
    if cnt == 8:
        ans += 1
print(ans)

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

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

typedef long long ll;
const ll MOD = 998244353;

static std::map<int, std::map<int, ll>> memo;

ll pow(int a, int b) {
  if(a == 1 || b == 0) {
    return 1;
  }
  if(memo[a][b] > 0) {
    return memo[a][b];
  }

  ll ret;
  if(b % 2 == 0) {
    ll p = pow(a, b / 2);
    ret = p * p % MOD;
  } else {
    ret = a * pow(a, b - 1) % MOD;
  }

  memo[a][b] = ret;
  return ret;
}

int main() {
  int N;
  std::cin >> N;

  std::vector<int> D(N);
  rep(i, N) {
    std::cin >> D[i];
  }

  if(D[0] != 0) {
    std::cout << 0 << '\n';
    return 0;
  }

  std::map<int, int> cnt;
  int max = 0;
  rep(i, N) {
    ++cnt[D[i]];
    max = std::max(max, D[i]);
  }
  if(cnt[0] > 1) {
    std::cout << 0 << '\n';
    return 0;
  }
  for(int i = 0; i < max; ++i) {
    if(cnt[i] == 0) {
      std::cout << 0 << '\n';
      return 0;
    }
  }

  ll ans = 1;
  for(int i = 1; i <= max; ++i) {
    ans *= pow(cnt[i - 1], cnt[i]);
    ans %= MOD;
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 5376