akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

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

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll mod_pow(ll x, ll n, ll m) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % m;
    x = x * x % m;
    n >>= 1;
  }
  return res;
}

void solve() {
  ll m, n; cin >> m >> n;
  outl(mod_pow(m, n, MOD));
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}



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

const int mx=100010;
const ll mod=1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
};

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  rep(i,n) cin >> s[i];
  rep(i,m) cin >> t[i];
  vector<vector<mint>> dp(n+5, vector<mint>(m+5,0));
  vector<vector<mint>> sum(n+5, vector<mint>(m+5,0));

  dp[0][0] = 1;
  sum[1][1] = 1;
  rep(i,n+1)rep(j,m+1){
    if(j==0 && i==0) continue;
    if(i>0 && j>0 && s[i-1]==t[j-1]) dp[i][j] = sum[i][j];
    sum[i+1][j+1] = sum[i+1][j].x + sum[i][j+1].x - sum[i][j].x + dp[i][j].x;
  }
  ll ans = sum[n+1][m+1].x;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 63232
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<string>v(n);
  for(int i=0;i<n;i++)
  {
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  for(int i=0;i<n;i++)
  {
    cout << v[i]; 
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(
				new InputStreamReader (System.in));
		String line=br.readLine();
		String[] str = line.split(" ");
		Arrays.sort(str);
		int a=Integer.parseInt(str[0]);
		int b=Integer.parseInt(str[1]);
		int c=Integer.parseInt(str[2]);
		System.out.println(a+" "+b+" "+c);
	}
}

Measured memory_bytes: 24332
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		double a = saori.Hayamin();
		double b = saori.Hayamin();
		double num = (a+b)/2;
		System.out.println((int)Math.ceil(num));
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 23124
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())

for l in range(len(N)):
    num = N[l]
    ans = 0
    d = 0
    d_past = 9999
    for i in range(len(num)):
        if num[i] == "I":
            d = 1
        elif num[i] == "V":
            d = 5
        elif num[i] == "X":
            d = 10
        elif num[i] == "L":
            d = 50
        elif num[i] == "C":
            d = 100
        elif num[i] == "D":
            d = 500
        elif num[i] == "M":
            d = 1000

        if d_past < d:
            ans -= d_past * 2

        ans += d
        d_past = d
    print(ans)


Measured memory_bytes: 5560
import fractions 
N = int(input())
a = list(map(int,input().split()))
ans = a[0]
cnt = 0
for i in range(1,N):
    ans = ans * a[i] // fractions.gcd(ans,a[i])
for i in range(N):
    cnt += ((ans-1) % a[i]) 
print(cnt)

Measured memory_bytes: 5344
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, char *argv[])
{
    int n, m;
    bool open = false;
    cin >> n;
    string line;
    vector<string> ids;
    for (int i = 0; i < n; ++i) {
        cin >> line;
        ids.push_back(line);
    }
    cin >> m;
    for (int i = 0; i < m; ++i) {
        cin >> line;
        vector<string>::iterator itr = find(ids.begin(), ids.end(), line);
        if (itr == ids.end()) {
            cout << "Unknown " << line << endl;
        } else if (open) {
            cout << "Closed by " << line << endl;
            open = false;
        } else {
            cout << "Opened by " << line << endl;
            open = true;
        }
    }
    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  int n, k;cin >> n >> k;
  vector<int> base(k);
  rep_i(i, k){
    cin >> base[i];
  }
  vector<int> posi;
  for (int i = 0; i < (1 << n); i++){
    // cout << i << endl;
    // cout << bitset<8>(i) << endl;
    for (int v = 0; v < n; v++){
      if(i & (1 << v)){
        posi.push_back(v);
      }
    }
    
    // check
    bool flag = true;
    rep_i(v, k){
      if(find(posi.begin(), posi.end(), base[v]) == posi.end()){
        flag = false;
        break;
      }
    }
    if(flag){
      cout << i << ":";
      if (!posi.empty()){
        for (auto itr = posi.begin(); itr != posi.end(); itr++){
          cout << " " << *itr;
        }
      }
      cout << endl;
    }
    posi.clear();
  }
}


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

int main()
{
  int64_t N, H, W, h, w, ans = 0;
  cin >> N >> H >> W;
  for (int i = 0; i < N; i++)
  {
    cin >> h >> w;
    if (h >= H && w >= W)
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, l;
    cin >> n >> l;
    int ans = (l + l + n - 1) * n / 2;
    if(l > 0) ans -= l;
    else if(l + n - 1 < 0) ans -= (l + n - 1);
    printf("%d\n", ans);
}

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

int countTwo(int in){
	int res = 0;
	while (in % 2 == 0){
		res++;
		in /= 2;
	}
	return res;
}
int main(){
	int a;
	cin >> a;
	vector<int> list;
	for (int i = 0; i < a; ++i){
		int b;
		cin >> b;
		list.push_back(b);
	}
	int total = 0;
	for (int i = 0; i < a; ++i){
		total += countTwo(list[i]);
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;
   
        signed main() {
           string s;
           cin>>s;
           int ans=0;
           for(int i=0;i<s.size();i++){
               if(s[i]=='+')ans++;
               else ans--;
           }
           cout<<ans;

           return 0;

        }


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;
ll K,A,B;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>K>>A>>B;
	ll ans;
	if(A>=K){
		ans=1;
	}else if(A-B<=0){
		ans=-1;
	}else{
		ans=(K-A+A-B-1)/(A-B)*2+1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
int main()

{
    int n;
    cin >> n;
    vi a(n);
    int max = 0;
    rep(i, n)
    {
        cin >> a[i];
        if (max < a[i])
        {
            max = a[i];
        }
    }
    vl x(max + 1, 0), y(max + 1, 0), z(max + 1, 0), ans(n, 0);
    rep(i, n)
    {
        x[a[i]]++;
    }
    rep(i, max + 1)
    {
        y[i] = x[i] * (x[i] - 1) / 2;
        z[i] = (x[i] - 1) * (x[i] - 2) / 2;
        ans[0] += y[i];
    }
    for (int i = 1; i < (max + 1); i++)
    {
        ans[i] = ans[0] + z[i] - y[i];
    }
    rep(i, n)
    {
        cout << ans[a[i]] << endl;
    }

    return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    if(n%2 == 1){
        cout << "No" << endl;
        return 0;
    }
    for(int i = 0; i < n/2;i++){
        if(s.at(i) != s.at(n/2 + i)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int n;

int main() {
	cin >> n;

	vector<int> arr(n);
	int sum = 0;
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
		sum += arr[i];
	}

	double ave = sum/(double)n;
	vector<double> arr2(n);
	double sa = 9999;
	for(int i = 0; i < n; i++) {
		arr2[i] = abs(ave-arr[i]);
		sa = min(sa,arr2[i]);
	}
	for(int i = 0; i < n; i++) {
		if(sa==arr2[i]) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = n//4 # max x
b = n//7 # max y
ok = False
for x in range(0,a+1):
    for y in range(0,b+1):
        if n == 4*x + 7*y:
            ok = True
            break
    if ok: break

if ok: print('Yes')
else: print('No')


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

int main(){
  int N, M, Q;cin>>N>>M>>Q;
  int dp[N+1][N+1];
  memset(dp,0, sizeof(dp));
  
  for (int i=0;i<M;++i){
    int l, r;cin>>l>>r;
    dp[l][r]++; 
  }

  int l_cumsum[N+1][N+1];
  memset(l_cumsum, 0, sizeof(l_cumsum));
  

  for (int l=1;l<N+1;++l){
    for (int i=0;i<N;++i){
      l_cumsum[l][i+1]=l_cumsum[l][i]+dp[l][i+1];
    }
  }

  int cumsum[N+1][N+1];
  memset(cumsum, 0, sizeof(cumsum));

  for (int r=1;r<N+1;++r){
    for (int i=0;i<N;++i){
      cumsum[i+1][r]=cumsum[i][r]+l_cumsum[i+1][r];
    }
  }

  for (int i=0;i<Q;++i){
    int p,q;cin>>p>>q;
    cout << cumsum[N][q]-cumsum[p-1][q] << endl;
  }

  return 0;
}

Measured memory_bytes: 3840
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

#define INF 1e30

struct ST {
  double x, y ,r;
};

int nNode;
double G[1005][1005];

double dist(const ST& a, const ST& b){
  double d = sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
  if(d <= a.r + b.r) return 0;
  return d - (a.r + b.r);
}

double dijkstra(int start, int goal){
  int nVisit = 0;
  bool visited[1005];
  double cost[1005];
 
  for(int i=0; i<nNode; i++){
    cost[i] = INF;
    visited[i] = false;
  }
  cost[start] = 0;
 
  while(nVisit != nNode){
    int minPos;
    double minVal = INF;
    
    for(int i=0; i<nNode; i++){
      if(minVal>cost[i] && !visited[i]){
        minVal = cost[i];
        minPos = i;
      }
    }
 
    if(minVal > INF-1) break;
    if(minPos == goal) return minVal;
    
    visited[minPos] = true;
    nVisit++;
 
    for(int i=0; i<nNode; i++){
      if(cost[i]>cost[minPos]+G[minPos][i]){
        cost[i] = cost[minPos]+G[minPos][i];
      }
    }
  }
}

int main(){
  double xs, ys, xt, yt;
  int N;
  cin >> xs >> ys >> xt >> yt;
  cin >> N;
  vector<ST> v;
  rep(i,N){
    double x, y, r;
    cin >> x >> y >> r;
    v.push_back((ST){x,y,r});
  }
  v.push_back((ST){xs,ys,0});
  v.push_back((ST){xt,yt,0});

  rep(i,1005) rep(j,1005) G[i][j] = INF;

  rep(i,N+2){
    REP(j,i,N+2){
      double d = dist(v[i], v[j]);
      G[i][j] = d;
      G[j][i] = d;
    }
  }
  nNode = N+2;

  printf("%.12lf\n", dijkstra(N, N+1));
  
  return 0;
}



Measured memory_bytes: 8192
import itertools


N, M, Q = map(int, input().split())

a = []
b = []
c = []
d = []

for i in range(Q):
    ai, bi, ci, di = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    d.append(di)

A = [i for i in range(1, M+1)] # [1, 2, 3, 4, ... M]

A_pattern = list(itertools.combinations_with_replacement(A, N))

ans = 0

for a_pattern in A_pattern: # 数列全部調べる
    ansi = 0
    for i in range(Q): # 得点になるかどうか調べる
        if a_pattern[b[i]-1] - a_pattern[a[i]-1] == c[i]: # A[bi] - A[ai] == ci -> ansi += di
            ansi += d[i]

    ans = max(ans, ansi)


print(ans)


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

cnt1 = 0
cnt2 = 0
for i in range(n):
    if a[i] > b[i]:
        cnt1 += a[i] - b[i]
    elif a[i] < b[i]:
        cnt2 += -(-(b[i] - a[i]) // 2)
        if (b[i] - a[i]) % 2 == 1:
            cnt1 += 1
if cnt1 <= cnt2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 73780
#include <stdio.h>
#include <algorithm>
using namespace std;
int dp[20001];
int v[1001];
int w[1001];
int main(){
  int N,H;scanf("%d %d",&H,&N);
  for(int i=0;i<N;i++){
  	scanf("%d %d",v+i,w+i);
  }
  for(int i=1;i<=H+10000;i++) dp[i]=987654321;
  for(int i=0;i<N;i++){
  	for(int j=v[i];j<=H+10000;j++){
    	dp[j] = min(dp[j],dp[j-v[i]]+w[i]);
    }
  }
  int Min=987654321;
  for(int i=H;i<=H+10000;i++) Min=min(Min,dp[i]);
  printf("%d",Min);
}

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

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 300001;
static const ll MOD = 1000000007;

//--global--//



//----------//

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    string str;
    int k;
    cin >> str >> k;

    if(str.size() >= k){
        set<string> s;
        for(int i=0; i<str.size(); i++){
            for(int j=1; j<k+1; j++){
                string tmp = str.substr(i, j);
                //cout << tmp << endl;
                //if(tmp.empty()) continue;
                s.insert(tmp);
            }
        }

        int k_c = 0;
        for(string a : s){
            k_c++;
            if(k_c == k)
                cout << a << endl;
        }
    }
    else{
        set<string> s;
        for(int i=0; i<str.size(); i++){
            for(int j=1; j<k; j++){
                string tmp = str.substr(i, j);
                //cout << tmp << endl;
                //if(tmp.empty()) continue;
                s.insert(tmp);
            }
        }

        int k_c = 0;
        for(string a : s){
            k_c++;
            if(k_c == k)
                cout << a << endl;
        }
        //cout << *(s.begin() + k-1) << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
//  Created by Vignesh Manoharan

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <numeric>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1000000000;
const ll LINF = 1e17;
const double PI =3.141592653589793238;
const ll lmod = 1000000007l;
const int mod=1000000007;
const double eps = 0.000001;
#pragma unused(INF, LINF, PI, lmod, mod, eps)

#define F(i,a,n) for(int i=(a);i<(n);i++)

template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){
    for(int i=0;i<(t).size();i++)s<<t[i]<<((i<(t).size()-1)?" ":"");return s; }
template<typename T> ostream& operator<<(ostream &s,set<T> t){for(T x:t) s<<x<<" ";return s; }
template<typename T> istream& operator>>(istream &s,vector<T> &t){
    for(int _i=0;_i<t.size();_i++) s>>t[_i];return s; }

#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()

void update(int idx, int value, vi &t){
    // increment t[idx] by value
    while(idx < t.size()){
        t[idx] += value;
        idx |= (idx+1);
    }
}

int query(int idx, vi &t){
    // get sum of t[0]..t[idx]
    int res=0;
    while(idx >= 0){
        res += t[idx];
        idx = (idx & (idx+1))-1;
    }
    return res;
}
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B

int main(int argc, const char * argv[]) {
    #ifdef LOCAL_TEST
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
    #endif
    int n,q;
    cin>>n>>q;
    vi a(n);
    F(i,0,q){
        int t,x,y;
        cin>>t>>x>>y;
        if(t==0){
            // a[x]+=y;
            x--;
            update(x,y,a);
        } else {
            // print sum(a[x..y]);
            x--;y--;
            int rsum = query(y,a);
            int lsum = (x>0?query(x-1,a):0);
            cout<<rsum-lsum<<"\n";
        }
    }

}

Measured memory_bytes: 3128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int judge(string s){
	for(int i=0;i<s.length();i++){
		if(s[i]!=s[s.length()-1-i]){
			return 0;
		}
	}
	return 1;
}
ll num[maxn];
ll a[maxn];
int main() {
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) num[a[i]]++;
	ll sum = 0;
	for(int i=1;i<=n;i++){
		if(num[i]>=2) sum+=((num[i]*(num[i]-1LL))/2LL);
	//	cout<<sum<<endl;
	}
	for(int i=1;i<=n;i++){
		ll t = sum;
		//cout<<num[a[i]]<<endl;
		t-=((num[a[i]]*(num[a[i]]-1LL))/2LL);
		//cout<<t<<endl;
		t+=((num[a[i]]-1)*(num[a[i]]-2LL))/2;
		cout<<t<<endl;
	}
    return 0;
}

Measured memory_bytes: 4736
N,M = map(int,input().split())
Load = [list(map(int,input().split())) for i in range(M)]
List = []
for i in range(N):
  List.append(0)
for i in range(len(Load)):
  List[Load[i][0]-1] += 1
  List[Load[i][1]-1] += 1
for i in List:
  print(i)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int s[2][4010][4010];
int k;

int rect(int c, int l, int r, int d, int u){
	int ret = s[c][r][u];
	if(l) ret -= s[c][l-1][u];
	if(d) ret -= s[c][r][d-1];
	if(l && d) ret += s[c][l-1][d-1];
	return ret;
}

int main()
{
	int n;
	read(n, k);
	int x, y; char buf[5];
	for(;n--;){
		scanf("%d%d%s", &x, &y, buf);
		x %= (2*k); y %= (2*k);
		s[buf[0]=='B'][x][y] += 1;
		s[buf[0]=='B'][x+2*k][y] += 1;
		s[buf[0]=='B'][x][y+2*k] += 1;
		s[buf[0]=='B'][x+2*k][y+2*k] += 1;
	}
	
	for(int c=0; c<2; ++c) for(int i=0; i<4*k; ++i) for(int j=0; j<4*k; ++j){
		if(i) s[c][i][j]+=s[c][i-1][j];
		if(j) s[c][i][j]+=s[c][i][j-1];
		if(i && j) s[c][i][j]-=s[c][i-1][j-1];
	}
	
	int ans = 0;
	for(x=0; x<2*k; ++x) for(y=0; y<2*k; ++y){
		ans = max(ans, 
		rect(0, x, x+k-1, y, y+k-1) + 
		rect(1, x+k, x+k+k-1, y, y+k-1) + 
		rect(1, x, x+k-1, y+k, y+k+k-1) + 
		rect(0, x+k, x+k+k-1, y+k, y+k+k-1));
		
		ans = ans;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 125696
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

let main() =
    let n = read int
    let s = readChars()
    seq {
        for i in 0 .. n - 3 do
            if s.[i] = 'A' && s.[i + 1] = 'B' && s.[i + 2] = 'C' then yield ()
    }
    |> Seq.length
    |> puts
    ()

main()
writer.Close()


Measured memory_bytes: 11348
import javax.swing.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        long n = s.nextLong();
        String s1="";
        while(n>0)
        {
            n--;
            s1 += Character.toString((char)((n % 26) + 'a'));
            n /= 26;
        }
        StringBuilder s2 = new StringBuilder();
        s2.append(s1);
        System.out.println(s2.reverse());

    }
    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 25324
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll x; cin >> x;
  ll now = 0;
  ll cnt = 1;
  while(1) {
    now += cnt;
    if(now >= x) {
      cout << cnt << endl;
      break;
    }
    cnt++;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] argc){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        
        HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();

        for(int i=0;i<N;i++){
            int A = sc.nextInt();
            if(map.get(A) != null){
                int old = map.get(A);
                map.put(A, old+1);
            }else{
                map.put(A,1);
            }
        }
        int s = map.size();
        if(s < K){
            System.out.println(0);
            return;
        }
        ArrayList<Integer> nums = new ArrayList<Integer>();
        for(Map.Entry<Integer,Integer> m : map.entrySet()){
            nums.add(m.getValue());
        }
        Collections.sort(nums);

        int ans = 0;
        for(int i=0;i<s-K;i++){
            ans += nums.get(i);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 99400
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b; cin>>a>>b;
  vector<vector<char>>A(a,vector<char>(a));
  vector<vector<char>>B(b,vector<char>(b));
  for(int i=0;i<a;i++){
    string S; cin>>S;
    for(int j=0;j<a;j++){
      A[i][j]=S.at(j);
    }
  }
  for(int i=0;i<b;i++){
    string S; cin>>S;
    for(int j=0;j<b;j++){
      B[i][j]=S.at(j);
    }
  }
  for(int i=0;i<a-b+1;i++){
    for(int j=0;j<a-b+1;j++){
      for(int k=0;k<b;k++){
        bool z=true;
        for(int l=0;l<b;l++){
          if(A[i+k][j+l]!=B[k][l])z=false;
        }
        if(z==false)break;
        if(k==b-1){cout<<"Yes"<<endl; return 0;}
      }
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,m,t[101],i,cnt,j,a,ans[101]={0};
	scanf("%d %d",&n,&m);
	for(i=1;i<=m;i++){
		scanf("%d",&t[i]);
	}
	for(i=1;i<=m;i++){
		cnt=0;
		for(j=1;j<=n;j++){
			scanf("%d",&a);
			if(t[i]==a){
				ans[j]++;
			}
			else{
				cnt++;
			}
		}
		ans[t[i]]+=cnt;
	}
	for(i=1;i<=n;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 2696
/**/
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;

int CalcTheDaySatisfaction(int d, const int N, vector<int>& c, vector<int>& s, int t, vector<int>& last)
{
    int ret = 0;

    // d日目にA[t]Cを開催すると上がる満足度を足す
    ret += s[t];

    // 低下する満足度を計算する
    for( int i = 0; i < N; ++i )
        ret -= c[i] * (d - last[i]);

    return ret;
}


int main()
{
    const int N = 26;

    // 入力
    int D;
    cin >> D;

    vector<int> c(N);
    for( int i = 0; i < N; ++i )
        cin >> c[i];

    vector<vector<int>> s(D);
    for( int i = 0; i < D; ++i ){
        vector<int> tmp(N);
        for( int j = 0; j < N; ++j )
            cin >> tmp[j];
        s[i] = tmp;
    }

    // 初期解生成
    srand(time(0));

    vector<int> t(D);
    for( int i = 0; i < D; ++i )
        t[i] = rand() % N + 1;

    // 出力
    for( auto& i : t )
        cout << i << endl;

    /*
    // B, C問題
    //// 入力
    vector<int> t(D);
    for( int i = 0; i < D; ++i )
        cin >> t[i];
    for( int i = 0; i < D; ++i )
        --t[i];

    int M;
    cin >> M;

    vector<int> d(M), q(M);
    for( int i = 0; i < M; ++i )
        cin >> d[i] >> q[i];

    //// 満足度計算
    int satisfication = 0;
    vector<int> last(N, 0);
    for( int i = 0; i < D; ++i ){
        // last(d, i)を更新する
        last[t[i]] = i + 1;

        // 満足度を更新する
        int initialSatisfication = satisfication + CalcTheDaySatisfaction(i + 1, N, c, s[i], t[i], last);
        int modificationSatisfication = satisfication + CalcTheDaySatisfaction(i + 1, N, c, s[i], t[i], last);

        satisfication += CalcTheDaySatisfaction(i + 1, N, c, s[i], t[i], last);

        // 出力
        cout << satisfication << endl;
    }
    /**/



    return 0;
}
/**/

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

int main()
{
  string str;
  unordered_set<char> s;
  cin>>str;
  int count[4] = {0};
  
  for(int i=0;i<4;i++)
  {
    if(s.find(str[i]) == s.end())
       {
         count[i]++;
         s.insert(str[i]);
       }
    else if(str[i] == str[0])
      count[0]++;
    else if(str[i] == str[1])
      count[1]++;
    else 
      count[2]++;
   }
  
  if(count[0] == 2 && count[1] == 2 || count[0]==2 && count[2]==2)
    cout<<"Yes\n";
  else
    cout<<"No\n";
  
  return 0;
  
}
    
    
    
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
int N;
  cin >> N;
    for (int a = 1; a < 10; a++) {
    for (int b = 1; b < 10; b++) {
      
      if(a*b==N){
      cout << "Yes" <<endl;
      return 0;
      }
      
    }
  }
cout << "No" <<endl;
}

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=2000;

int n;
char c[2*MAXN]; int a[2*MAXN];

int pos[2][MAXN];
int cnt[2*MAXN][2][MAXN]; // cnt[i][k][j] is number of values <= j at positions <= i of color k

int dp[MAXN+1][MAXN+1];

void run() {
	scanf("%d",&n); REP(i,2*n) scanf(" %c%d",&c[i],&a[i]),--a[i];

	memset(pos,-1,sizeof(pos));
	REP(i,2*n) if(c[i]=='B') pos[0][a[i]]=i; else if(c[i]=='W') pos[1][a[i]]=i;
	//REP(k,2) { printf("pos%c:",k==0?'B':'W'); REP(i,n) printf(" %d",pos[k][i]); puts(""); }

	memset(cnt,0,sizeof(cnt));
	REP(i,2*n) ++cnt[i][c[i]=='B'?0:1][a[i]];
	REP(i,2*n) REP(k,2) FOR(j,1,n) cnt[i][k][j]+=cnt[i][k][j-1];
	FOR(i,1,2*n) REP(k,2) REP(j,n) cnt[i][k][j]+=cnt[i-1][k][j];

	/*REP(i,2*n) REP(k,2) REP(j,n) {
		int chk=0; REPE(ii,i) if(c[ii]==(k==0?'B':'W')&&a[ii]<=j) ++chk;
		assert(chk==cnt[i][k][j]);
	}*/

	REPE(i,n) REPE(j,n) dp[i][j]=INT_MAX; dp[0][0]=0;
	REPE(i,n) REPE(j,n) if(dp[i][j]!=INT_MAX) {
		if(i<n) {
			int idx=pos[0][i];
			int have=cnt[idx][0][i]+(j==0?0:cnt[idx][1][j-1])-1;
			int oth=idx-have;
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]+oth);
		}
		if(j<n) {
			int idx=pos[1][j];
			int have=(i==0?0:cnt[idx][0][i-1])+cnt[idx][1][j]-1;
			int oth=idx-have;
			dp[i][j+1]=min(dp[i][j+1],dp[i][j]+oth);
		}
	}
	printf("%d\n",dp[n][n]);
}

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


Measured memory_bytes: 78464
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double db;
typedef vector<ll> VI;
typedef vector<pair<ll,ll> > VII;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
//
#define M 1000000007
#define INF (ll)0x3f3f3f3f3f3f3f3f
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define itr iterator
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}

void error_out() { cerr << endl; }
template <typename Head, typename... Tail>
void error_out(Head H, Tail... T) {
  cerr << " " << H;
  error_out(T...);
}
void time_elapsed(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}
#ifndef ONLINE_JUDGE
#define error(...) cerr << "[" << #__VA_ARGS__ << "]:", error_out(__VA_ARGS__)
#define fioe() fileioe()
#define time() time_elapsed()
#else
#define error(...) 1
#define fioe() 1
#define time() 1
#endif
const int maxr=1e5+4;
ll dp[maxr];
ll dfs(VI v[],ll start){
	if(dp[start]>-1){
		return dp[start];
	}
	if(v[start].size()==0){
		return 0;
	}
	ll ans=0;
	for(ll i=0;i<v[start].size();i++){
		ans=max(ans,dfs(v,v[start][i]));
	}
	dp[start]=ans+1;
	return ans+1;
}
//
int main()
{
	GO
	//fioe();
	ll n,m;
	cin>>n>>m;
	VI v[n+2];
	for(ll i=0;i<m;i++){
		ll a,b;
		cin>>a>>b;
		v[a].pb(b);
	}
	ll ans=0;
	memset(dp,-1,sizeof(dp));
	for(ll i=1;i<=n;i++){
		ans=max(ans,dfs(v,i));//error(i,ans);
	}
	cout<<ans<<endl;
	time();
	return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;

template<typename Key, typename Value>
class hashmap {
	std::vector<std::pair<Key, Value>> map;
	uint64 mask, temp, count;
public:
	hashmap() :map(8192, std::make_pair(~static_cast<Key>(0), Value())) {
		mask = 8191; count = 0;
	}
	hashmap(size_t s) {
		s |= s << 1;
		s |= s >> 2;
		s |= s >> 4;
		s |= s >> 8;
		s |= s >> 16;
		s |= s >> 32;
		mask = s;
		count = 0;
		map.resize(s + 1, std::make_pair(~static_cast<Key>(0), Value()));
	}
	Value &operator[](Key suf) {
		temp = mask&std::hash<Key>()(suf);
		while (map[temp].first != suf) {
			temp = mask&(temp + 1);
		}
		return map[temp].second;
	}
	void insert(Key key, const Value &value) {
		temp = mask&std::hash<Key>()(key);
		while (~map[temp].first) {
			if (map[temp].first == key) {
				map[temp].second = value;
				return;
			}
			temp = mask&(temp + 1);
		}
		map[temp] = std::make_pair(key, value);
		++count;
		if ((count << 1) > mask) {
			std::pair<Key, Value> mkey;
			uint64 t = mask;
			mask = mask << 1 | 1;
			map.resize(mask + 1, std::make_pair(~static_cast<Key>(0), Value()));
			while (~map[t].first) {
				--t;
			}
			while (++t <= (mask >> 1)) {
				mkey = map[t];
				map[t].first = ~static_cast<Key>(0);
				temp = mask&std::hash<Key>()(mkey.first);
				while (~map[temp].first) {
					temp = mask&(temp + 1);
				}
				map[temp] = mkey;
			}
			for (t = 0;t <= mask >> 1;++t) {
				if (~map[t].first) {
					mkey = map[t];
					map[t].first = ~static_cast<Key>(0);
					temp = mask&std::hash<Key>()(mkey.first);
					while (~map[temp].first) {
						temp = mask&(temp + 1);
					}
					map[temp] = mkey;
				}
			}
		}
		return;
	}
	bool find(Key key) {
		temp = mask&std::hash<Key>()(key);
		while (~map[temp].first) {
			if (map[temp].first == key) {
				return true;
			}
			temp = mask&(temp + 1);
		}
		return false;
	}
	bool empty(void) {
		return !count;
	}
	size_t size(void) {
		return count;
	}
};

int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	hashmap<uint64,uint32> map(1);
	uint32 n;
	std::cin >> n;
	int64 a, sum = 1LL<<50;
	uint32 ans = 0;
	map.insert(sum, 0);
	rep(i, 0, n) {
		std::cin >> a;
		sum += a;
		if (map.find(sum)) {
			ans = std::max(ans, i + 1 - map[sum]);
		}
		else {
			map.insert(sum, i + 1);
		}
	}
	std::cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 15316
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int v[22], c[22];
	for (i = 0; i < n; i++)
		scanf("%d", &v[i]);
	for (i = 0; i < n; i++)
		scanf("%d", &c[i]);
	int ans = 0;
	for (i = 0; i < n; i++)
		if (v[i] > c[i])
			ans += v[i] - c[i];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll int
#define ci cin>>
#define co cout<<
#define l <<endl
#define mp make_pair
#define v vector<int> v;
#define vv vector<vector<int>> vv
#define v_print for(auto x:v){cout<<x<<"\n";}
#define floop(i,a,b) for(int i=a;i<b;i++)
#define w(n) while(n--)
#define mod 1000000007
using namespace std;

int A[100003];


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n;	ci n;
	ll h[n];
	floop(i,0,n)
	{
		ci h[i];
	}
	A[0]=0;
	A[1]=abs(h[1]-h[0]);
	floop(i,2,n)
	{
		A[i]=min(abs(h[i]-h[i-1])+A[i-1],abs(h[i]-h[i-2])+A[i-2]);
	}
	co A[n-1];

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vi=vector<int>;  using vs=vector<string>;

int main() {
    int n,m;
    cin>>n;
    vs s(n); rep(i,n) cin>>s.at(i);
    cin>>m;
    vs t(m); rep(i,m) cin>>t.at(i);
    
    vi k(n);

    rep(i,n){
        rep(j,n){
            if(s.at(i)==s.at(j)) k.at(i)++;
        }
        rep(j,m){
            if(s.at(i)==t.at(j)) k.at(i)--;
        }
    }
    int M=0;
    rep(i,n) M=max(M,k.at(i));
    cout<<M<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

inline map<ll,int> sieve(ll n){
  map<ll,int> PrimeNumber;
  for(ll i = 2; i*i <= n; i++){
    while(n % i == 0){
      PrimeNumber[i]++;
      n /= i;
    }
  }
  if(n != 1) PrimeNumber[n] = 1;
  return PrimeNumber;
}

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  int gcd = 0;
  map<int,int> mp;
  bool ok = true;
  rep(i,n){
    int a; cin >> a;
    gcd = __gcd(gcd,a);
    auto res = sieve(a);
    for(auto x : res){
      if(mp[x.first]) ok = false;
      mp[x.first]++;
    }
  }
  if(gcd != 1){
    cout << "not coprime";
    return 0;
  }
  if(ok){
    cout << "pairwise coprime";
  }else{
    cout << "setwise coprime";
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 7280
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<bitset>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
 
using namespace std;
 
int main()
{
    int N;  cin >> N;
    string X;   cin >> X;
    vector<int> vu(N), vd(N), u(N), d(N);
    int mod, modu, modd, uu, dd;
    mod = bitset<200000>(X).count();
    modu = mod+1;
    modd = mod-1;

    if(modd == 0){
        for(int i=0; i<N-1; i++){
            if(X[N-1] == '1') cout << 2 << endl;
            else if(X[i] == '1') cout << 0 << endl;
            else    cout << 1 << endl;
        }
        if(X[N-1] == '1')   cout << 0 << endl;
        else    cout << 2 << endl;
    }else{
        int tmp, tmpu, tmpd;
        tmpu = 1;
        tmpd = 1;
        u[N-1] = 1;
        d[N-1] = 1;
        if(X[N-1] == '1'){
            vu[0] = 1;
            vd[0] = 1;
        }else{
            vu[0] = 0;
            vd[0] = 0;
        }
        for(int i=N-2; i>=0; i--){
            tmpu = tmpu * 2 % modu;
            tmpd = tmpd * 2 % modd;
            if(X[i] == '1'){
                vu[N-1-i] = (vu[N-2-i] + tmpu) % modu;
                vd[N-1-i] = (vd[N-2-i] + tmpd) % modd;
            }else{
                vu[N-1-i] = vu[N-2-i];
                vd[N-1-i] = vd[N-2-i];
            }
            u[i] = tmpu;
            d[i] = tmpd;
        }
        uu = vu[N-1];
        dd = vd[N-1];

        int ans;
        for(int i=0; i<N; i++){
            if(X[i] == '1'){
                tmp = (dd + modd - d[i]) % modd;
            }else{
                tmp = (uu + u[i]) % modu;
            }
            ans = 1;
            while(__builtin_popcount(tmp) > 0){
                tmp = tmp % __builtin_popcount(tmp);
                ans++;
            }
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 6768
#include <cassert>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<LL, LL> PII;

#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); puts("");}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return v;}
void err(vector<string>::iterator it) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) {cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}

#define all(x)  (x).begin(),(x).end()
#define tr(c, it)   for(auto it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))
#define forn(i, n)   for(int i=0; i<n; i++)

const double eps = 1e-5;
const int INF = 0x3f3f3f3f;

//最小素因子
const int MAX = 2E5;
bool isprm[MAX+10];
int prm[MAX+10],fac[MAX+10];

int minfac(int n)
{
    fac[1] = 1;
    clr(isprm, true);
    int cnt = 0;
    for(int i=2; i<=n; i++)
    {
        if(isprm[i])    prm[++cnt] = fac[i] = i;
        for(int j=1; j<=cnt && (LL)i*prm[j]<=n; j++)
        {
            isprm[ i*prm[j] ] = false;
            fac[ i*prm[j] ] = prm[j];
            if(i % prm[j] == 0)  break;
        }
    }
    return cnt;
}

int cnt[1111];

int n;
const LL mod = 1000000007;


int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif

    //scanf("%d",&T);

    minfac(10000);

    while(cin >> n)
    {
        clr(cnt, 0);

        LL ans = 1;
        for(int i=2; i<=n; i++)
        {
            int v = i;
            while(v != 1)
            {
                int p = fac[v];

                cnt[p]++;
                v /= p;
            }
        }
        for(int i=2; i<=1000; i++)
        {
            if(cnt[i] == 0) continue;
            ans = (ans * (cnt[i] + 1)) % mod;
        }
        cout << ans << endl;

    }
    return 0;
}

Measured memory_bytes: 640