akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll INF = 1LL << 60; //MAX 9223372036854775807

template <typename T>
struct edge
{
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x)
  {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T>
using Matrix = vector<vector<T>>;

template <typename T>
vector<T> bellman_ford(Edges<T> &edges, int V, int s)
{
  const auto INF = numeric_limits<T>::max();
  vector<T> dist(V, INF);
  dist[s] = 0;
  for (int i = 0; i < V - 1; i++)
  {
    for (auto &e : edges)
    {
      if (dist[e.src] == INF)
        continue;
      dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
    }
  }
  for (auto &e : edges)
  {
    if (dist[e.src] == INF)
      continue;
    if (dist[e.src] + e.cost < dist[e.to])
      return vector<T>();
  }
  return dist;
};

int main()
{
  int V, E, p;
  scanf("%d %d %d", &V, &E, &p);
  Edges<int> es;
  Edges<int> ess;
  for (int i = 0; i < E; i++)
  {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    //if(a==b)continue;
    es.emplace_back(a-1, b-1, c);
    ess.emplace_back(b-1, a-1, c);
  }
  auto flont = bellman_ford(es, V, 0);
  auto back = bellman_ford(ess, V, V-1);
  set<ll> ng;
  rep(i,flont.size()){
    if(flont[i]==2147483647)ng.insert(i);
    if(back[i]==2147483647)ng.insert(i);
  }
  Edges<int> si;
  rep(i,es.size()){
    auto ee=es[i];
    if(ng.find(ee.src)==ng.end()&&ng.find(ee.to)==ng.end()){
      si.emplace_back(ee.src, ee.to, -ee.cost+p);
    }
  }
  auto k = bellman_ford(si, V, 0);
  if(k.empty()) {cout << -1 << endl;return 0;}
  if(k[V-1]>0)cout << 0 << endl;
  else cout << k[V-1]*-1 << endl;
  return 0;
}


Measured memory_bytes: 640
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
//AtCoderC++.cpp

using namespace std;

vector<int> _prime;
vector<int> build_prime_table(int max) {
	vector<int> table = vector<int>(max + 1, -1);
	table[0] = 0;
	table[1] = 0;
	table[2] = 1;
	for (int i = 3; i <= max; i++) {
		if (i % 2 == 0) { table[i] = 0; continue; }
		if (table[i] != -1)continue;
		table[i] = 1;
		for (int j = i + i; j <= max; j += i) {
			table[j] = 0;
		}
	}
	return table;
}

inline int ceileing(int a, int b) {
	return a % b == 0 ? a / b : a / b + 1;
}


vector<long long> comb = vector<long long>(100 * 100, -1);

long long combination(long long n, long long r) {
	if (n == 1 || n == 0)return 1;
	if (n == r)	return 1;
	else if (r == 0)return 1;
	else if (r == 1)return n;
	else if (comb[100 * (n - 1) + (r - 1)] != -1) return comb[100 * (n - 1) + (r - 1)];
	else {
		auto res = combination(n - 1, r - 1) + combination(n - 1, r);
		comb[100 * (n - 1) + (r - 1)] = res;
		return res;
	}
}


int main() {
	int A, B; cin >> A >> B;
	auto is_white = vector<bool>(100 * 100);
	for (size_t i = 0; i < 100; i++) {
		for (size_t j = 0; j < 100; j++) {
			is_white[i * 100 + j] = j >= 50;
		}
	}
	--A; --B;
	//左半分を黒の領地にして、欲しい数だけ白を打つ。
	//黒を分割せずに白だけを増やす。
	/*
	.#.#.#.#.#.#.#.#
	################
	.#.#.#.#.#.#.#.#
	################
	*/
	//(HW)÷4は稼げる。W=50 H=100 -> 5000/4>500
	int i = 0; int j = 0;
	while (A > 0) {
		is_white[i * 100 + j] = true;
		--A;
		j += 2;
		if (j >= 50) {
			j = 0;
			i += 2;
		}
	}
	//黒について同様
	i = 0; j = 51;
	while (B > 0) {
		is_white[i * 100 + j] = false;
		--B;
		j += 2;
		if (j >= 100) {
			j = 51;
			i += 2;
		}
	}

	cout << 100 << " " << 100 << endl;
	for (size_t i = 0; i < 100; i++) {
		for (size_t j = 0; j < 100; j++) {
			cout << (is_white[i * 100 + j] ? '.' : '#');
		}
		cout << endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a < 0){
        if(b < 0){
            if(c < 0){
                if(d < 0){
                    // ----
                    cout << a*c << endl;
                }
                else{
                    // ---+
                    cout << a*c << endl;
                }
            }
            else{
                // --++
                cout << b*c << endl;
            }
        }
        else{
            if(c < 0){
                if(d < 0){
                    // -+--
                    cout << a*c << endl;
                }
                else{
                    // -+-+
                    cout << max(a*c, b*d) << endl;
                }
            }
            else{
                // -+++
                cout << b*d << endl;

            }
        }
    }
    else{
        if(c < 0){
            if(d < 0){
                // ++--
                cout << a*d << endl;
            }
            else{
                // ++-+
                cout << b*d << endl;
            }
        }
        else{
            // ++++
            cout << b*d << endl;
        }
    }
    return 0;
}

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

using namespace std;

signed main(){

    
    std::vector<int> nums(5);
    int k;
    
    for (int i = 0; i<5; i++) {
        int n;
        cin >> n;
        nums[i] = n;
    }
    
    cin >> k;
    
    for (int i = 0; i<4; i++) {
        for(int n = i; n<4; n++){
            if(  nums[n+1] - nums[i] >k){
                cout << ":(";
                return 0;
            }
        }
    }
    
    cout << "Yay!";

    return 0;

 }


Measured memory_bytes: 256
n, v = int(input()), list(map(int, input().split()))
from collections import Counter
import math
a = Counter(v[::2])
b = Counter(v[1::2])
a[-1] = 0
b[-1] = 0
a = list(a.items())
b = list(b.items())
a.sort(reverse=True, key=lambda x:x[1])
b.sort(reverse=True, key=lambda x:x[1])
if a[0][0] == b[0][0]:
    result = n - max(a[0][1] + b[1][1],
                     a[1][1] + b[0][1])
else:
    result = n - a[0][1] - b[0][1]
print(result)


Measured memory_bytes: 18548
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)
#define G 1
int l[2000];

signed main(){
  int n,m;
  cin>>n>>m;
  lp(i,m){
    int a,b;
    cin>>a>>b;
    l[b]--;
    l[a]++;
  }
  int ans=0;
  lp(i,n+1){
    if(i!=0) l[i]+=l[i-1];
    ans++;
    if(l[i]!=0) ans+=2;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3112
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:

};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    for (int i = 1; i < 10; ++i) {
        if (n % i == 0 && n / i < 10) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<iterator>
#include<set>
#include<stack>
#include<queue>
#include<fstream>
#include<iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include<cmath>
#include<list>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;


#define FOR(i,a,b) for(LL i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

using namespace std;

const LL MOD = 1000000007;



int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	LL d,t,s;
	cin >> d >> t >> s;
	if (s*t >= d) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}









Measured memory_bytes: 3648
from sys import stdin
from queue import LifoQueue

exps = stdin.readline().rstrip().split()

stc = LifoQueue()
for i in exps:
    if i == "+":
        b = stc.get()
        a = stc.get()
        stc.put(a+b)
    elif i == "-":
        b = stc.get()
        a = stc.get()
        stc.put(a-b)
    elif i == "*":
        b = stc.get()
        a = stc.get()
        stc.put(a*b)
    else:
        stc.put(int(i))

print(stc.get())


Measured memory_bytes: 6836
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define pb push_back

#define NEWPATH 0
#define OLDPATH 1
#define SAME    2

typedef vector<string> vecs;
const int INF = (1 << 21);
int cost[10][10];
string dp[1 << 10][10];

string solve(vecs in){
  int n = in.size();
  string inf;
  rep(i,n)inf+=in[i];
  inf = inf+inf;
  rep(i,1 << n)
    rep(j,n)dp[i][j] =inf;
  rep(i,n)dp[1 << i][i] = in[i];

  rep(i,(1 << n)){
    rep(j,n){
      if ( (i & (1 << j)) == 0)continue;
      rep(k,n){
	if ( (i & (1 << k)) != 0)continue;
	int next = i | (1 << k);
	string nextstring = dp[i][j] + in[k].substr(in[k].size() - cost[j][k]);
	if ( nextstring.size() < dp[next][k].size() ){
	  dp[next][k] = nextstring;
	}else if ( nextstring.size() == dp[next][k].size() &&
		   nextstring < dp[next][k]){	   
	  dp[next][k] = nextstring;
	}
      }
    }
  }

  string ans=inf+inf;
  int res = (1 << n) -1;
  rep(i,n){
    if ( dp[res][i].size() < ans.size() ||
	 (dp[res][i].size() == ans.size() && dp[res][i] < ans))
      ans = dp[res][i];
  }
  
  
  return ans;
}

void calc_cost(vecs in){
  int n = in.size();
  rep(i,n){
    rep(j,n){
      if ( i == j ){cost[i][j] = INF;continue;}
      cost[i][j] = in[j].size();
      rep(k,in[i].size() && k < in[j].size()){
	bool flag = true;
	rep(l,k){ 
	  if (in[i][in[i].size() - k + l] != in[j][l]){
	    flag =false;
	    break;
	  }
	}
	if ( flag == true)cost[i][j] = in[j].size() - k;
      }
    }
  }
}

vecs del(vecs in){
  vecs ret;
  bool tmp[in.size()];
  fill(tmp,tmp+in.size(),true);
  rep(i,in.size()){
    bool flag = true;
    rep(j,in.size()){
      if ( i == j)continue;
      if (tmp[j] == true && search(in[j].begin(),in[j].end(),in[i].begin(),in[i].end()) != in[j].end()){
	flag = false;
	break;
      }
    }
    if ( flag == true)ret.pb(in[i]);
    tmp[i]=flag;
  }
  return ret;
}



main(){
  int n;
  int tc = 1;
  while(cin>>n && n ){

    vecs in;
    rep(i,n){
      string tmp;cin>>tmp;in.pb(tmp);
    }

    in = del(in);
    n = in.size();
    sort(in.begin(),in.end());
    reverse(in.begin(),in.end());
    calc_cost(in);


    cout << solve(in) << endl;
  }
  return false;
}  

Measured memory_bytes: 1352
/******************************************
*    AUTHOR:         CHIRAG AGARWAL       *
*    INSTITUITION:   BITS PILANI, PILANI  *
******************************************/
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL; 
typedef long double LD;


int cn[26];

int main() 
{
	string s;
	cin>>s;
	LL n=s.length();
	LL ans=1;
	for(int i=0;i<s.length();i++)
	{
		ans+=i-cn[s[i]-'a'];
		cn[s[i]-'a']++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>

using namespace std;

int main(void) {
  string number;
  int answer = 0;
  while(cin >> number && number[0] != '0') {
    for(int i = 0; i < number.length(); i++) {
      answer += number[i] - '0';
    }
    cout << answer << endl;
    answer = 0;
  }
  return 0;
}

Measured memory_bytes: 3200
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>
#include<float.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<numeric>
using  ll = long long;
using namespace std;
const ll M = 1000000007;

int main(){
  string t; cin >> t;
  int n=0, w=0, s=0, e=0;
  string ans;
  for(int i = 0; i < t.size(); i++){
    if(t[i]=='N')n++;
    if(t[i]=='W')w++;
    if(t[i]=='S')s++;
    if(t[i]=='E') e++;
  }

  if(n!=0 && w!=0 && s!=0 && e!=0) ans = "Yes";
  else if(n != 0 && s != 0 && w==0 && e==0) ans = "Yes";
  else if(n == 0 && s == 0 && w!=0 && e!=0) ans = "Yes";
  else ans = "No";

  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getInt()
	k := getInt()
	xs := make([]int, n)

	for i := range xs {
		xs[i] = getInt()
	}

	ans := 1 << 60
	for i := k - 1; i < n; i++ {
		distM := abs(min(xs[i-(k-1)], 0))
		distP := abs(max(xs[i], 0))

		ans = min(ans, max(distM, distP)+min(distM, distP)*2)
	}

	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,num)for(int i=0;i<(num);++i)
#define ll long long
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int N,M,Q,a,b;
    // unordered_map<int,multiset<int> > mp;
    int mp[501][501]={0,};
    cin>>N>>M>>Q;
    REP(i,M){
        cin>>a>>b;
        mp[a][b]++;
        // mp[a].insert(b);
    }
    REP(i,N+1){
        for(int j=1;j<=N;j++){
            mp[i][j]+=mp[i][j-1];
        }
    }
    REP(i,Q){
        int ans=0;
        cin>>a>>b;
        for(int j=a;j<=b;j++){
            ans+=mp[j][b];
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<cmath>

int main(){
    int n,x[1000],y[1000];
    double a,max;
    scanf("%d",&n);
    for(int i = 0;i < n;i++)  scanf("%d",&x[i]);
    for(int i = 0;i < n;i++)  scanf("%d",&y[i]);
    for(double p = 1;p <= 3;p++){
        for(int i = 0;i < n;i++){
            a += pow(fabs(x[i] - y[i]),p);
        }
        printf("%lf\n",pow(a,1/p));
        a = 0;
    }
    for(int i = 0;i < n;i++) {
        if(fabs(x[i] - y[i]) > max) max = fabs(x[i] - y[i]);
    }
    printf("%lf",max);
    return 0;
}



Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
int n,w;
vector<ll> cost(101);
vector<ll> weight(101);
const ll INF = 1E18+5;
int main(){
    cin>>n>>w;
    ll i, j;
    for(i=0;i<n;i++)
        cin>>weight[i]>>cost[i];
    ll tot_sum = 0;
    for(auto i:cost)
        tot_sum+=i;
    ll dp[n+1][tot_sum+1];
    for(i=0;i<=n;i++)
        for(j=0;j<=tot_sum;j++)
            dp[i][j] = w+10;
    for(i=0;i<n;i++)
        dp[i][0] = 0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=tot_sum;j++)
        {
            if(cost[i-1]<=j)
                dp[i][j] = min(dp[i-1][j],dp[i-1][j-cost[i-1]]+weight[i-1]);
            else dp[i][j] = dp[i-1][j];
//            cout<<dp[i][j]<<" ";
        }
//        cout<<"\n";
    }
    ll ans = 0;
    for(j=1;j<=tot_sum;j++)
    {
        if(dp[n][j]<=w)
            ans = max(ans,j);
    }
    cout<<ans;
}




Measured memory_bytes: 82216
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;




signed main(){
    int x,y;
    cin >> n >> x >> y;
    x--;
    y--;
    FOR(i,1,n){
        int ans = n-i;
        REP(j,n){
            if(j+i == n) break;
            if(j <= x && x <= j+i || j-i <= x && x <= j){
                int tmp = i;
                //既に移動した距離
                tmp -= abs(x-j);
                if(tmp == 0){
                }
                else if(tmp == 1 && abs(y-j) > i){
                    ans++;
                }
                else if(tmp == 1 && abs(y-j) <= i){
                }
                else{
                    tmp--;
                    if(y + tmp < n && j < y + tmp && y + tmp > i+j) ans++;
                    if(y-tmp-j > i && j < y - tmp && y - tmp > i+j) ans++;
                    if(y - tmp < j+i && j+i < y + tmp) ans--;
                }
            }
            //print(ans);
        }
        print(ans);
        //print("");
    }

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

//key以上の初めてのitr
int nibul(auto a,auto b){return lower_bound(All(a),b) - a.begin();}
//key以下の最後のitr
int nibuu(auto a,auto b){return upper_bound(All(a),b) - a.begin()-1;}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 256
import math

a, b, x = map(int, input().split())
y = 2*b - 2*x/a**2
if y <= b:
    ans = math.degrees(math.atan(y/a))
    print(ans)
else:
    yy = 2*x/(a*b)
    ans = math.degrees(math.atan(b/yy))
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (a > b) a = b; }

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

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int x, y; cin >> x >> y;

  cout << x + y/2 << endl;

  return (0);
}


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

const int maxn=5005;
int pd[maxn],z[maxn];
long long d[maxn];
int k,q,n,x,m;

int main()
{
	scanf("%d %d",&k,&q);
	for(int i=0;i<k;++i) scanf("%d",pd+i);
	while(q--) {
		scanf("%d %d %d",&n,&x,&m);
		for(int i=0;i<k;++i) d[i]=pd[i]%m;
		int ans=n-1;
		memset(z,0,sizeof z);
		for(int i=0;i<k;++i) {
			if(!d[i]) z[i]++;
			if(i) z[i]+=z[i-1];
		}
		ans-=(n-1)/k*z[k-1];
		if((n-1)%k) ans-=z[(n-1)%k-1];
		for(int i=1;i<k;++i) d[i]+=d[i-1];
		long long num=x+(n-1)/k*d[k-1];
		if((n-1)%k) num+=d[(n-1)%k-1];
		ans-=num/m-x/m;
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 384
S=input()
n=len(S)
while n>0:
    if S[n-5:n]=='dream':
        n-=5
    elif S[n-5:n]=='erase':
        n-=5
    elif S[n-7:n]=='dreamer':
        n-=7
    elif S[n-6:n]=='eraser':
        n-=6
    else:
        print('NO')
        exit()
print('YES')

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
//ll const mod=998244353;
ll const mod = 1e9 + 7;
const ll MAX = 300000;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }


//////////////////////////////////////

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    bool ok=true;
    if(v<=w)ok=false;
    if(a<b&&a+v*t<b+w*t)ok=false;
    if(a>b&&a-v*t>b-w*t)ok=false;
    if(ok)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 3544
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
}


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

int main() {
    // input
    int n, m;
    cin >> n >> m;
    int a[n], b, c;
    vector<pair<int, int> > cb(m);
    rep(i, n) cin >> a[i];
    rep(i, m) {
        cin >> b >> c;
        cb[i] = make_pair(c, b);
    }    
    sort(a, a + n);
    sort(cb.begin(), cb.end());
    reverse(cb.begin(), cb.end());

    // solve
    int idx = 0;
    bool fin = false;
    rep(i, m) {
        while (cb[i].second--) {
            if (a[idx] < cb[i].first) {
                a[idx++] = cb[i].first;
            } else {
                fin = true;
            }
            if (idx >= n) fin = true;
            if (fin) break;
        }
        if (fin) break;
    }
    ll ans = accumulate(a, a + n, 0L);
    cout << ans << endl;
}

Measured memory_bytes: 1408
S = input()
keyence = "keyence"
answer = 'NO'
if keyence in S:
    if S[:7] == keyence:
         answer = "YES"
    elif S[-7:] == keyence:
        answer = "YES"
else:
    for i in range(6):
        if (S[:i+1] == keyence[:i+1]) & (S[-6+i:] == keyence[-6+i:]):
            answer = "YES"
print(answer)


Measured memory_bytes: 3060
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int[] a = new int[n+1];
        int[] b = new int[n];
        int[] c = new int[n+1];
        long cnt = 0;
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }
        
        
        for(int i=0; i<n; i++){
            b[i] = sc.nextInt();
        }
        
        
        for(int i=0; i<n; i++){
            c[i] = sc.nextInt();
        }
        
        
        a[n] = 1_000_000_001;
        c[n] = 1_000_000_001;
        
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);
        
        long Acnt=0;
        long Ccnt=0;
        
        for(int i=0; i<n; i++){
            while(a[(int)Acnt]<b[i]) {
                Acnt++;
            }
            while(c[(int)Ccnt]<=b[i]) {
                Ccnt++;
            }
            cnt += Acnt * (n-Ccnt);
        }
        
        System.out.println(cnt);
	}
}

Measured memory_bytes: 98876
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        System.out.println(solve(S));

        sc.close();
    }

    static String solve(String S) {
        boolean yymm = isMonth(S.substring(2));
        boolean mmyy = isMonth(S.substring(0, 2));

        if (yymm) {
            if (mmyy) {
                return "AMBIGUOUS";
            } else {
                return "YYMM";
            }
        } else {
            if (mmyy) {
                return "MMYY";
            } else {
                return "NA";
            }
        }
    }

    static boolean isMonth(String s) {
        int value = Integer.parseInt(s);

        return value >= 1 && value <= 12;
    }
}

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

namespace ConsoleApplication2
{
	class Program
	{
		static void Main(string[] args)
		{
			double x = 0;
			var inputNum = Console.ReadLine();
			x = Math.Pow(double.Parse(inputNum), 3);
			Console.WriteLine(x.ToString());
			Console.ReadKey();
		}
	}
}



Measured memory_bytes: 15924
// https://atcoder.jp/contests/dwacon5th-prelims/tasks/dwacon5th_prelims_b
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize, k: usize,
        a: [i64; n]
    };


    let mut subarrays = vec![];
    for i in 0..n {
        let mut sum = 0;
        for j in i..n {
            sum += a[j];
            subarrays.push(sum);
        }
    }


    let mut ans = 0;
    for i in (0..41).rev() {
        // debug!(subarrays, i);
        let mask = 1<<i;
        let mut next = vec![];
        for &s in &subarrays {
            if (s & mask) == mask {
                next.push(s);
            }
        }
        if next.len() >= k {
            ans |= mask;
            subarrays = next;
        }

    }
    println!("{}", ans);
}


Measured memory_bytes: 10360
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=2e3+7;
bool ok[3][3][maxn];
int main()
{
    string s[3];
    for(int i=0;i<3;i++) cin>>s[i];
    vi id={0,1,2};
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(i==j) continue;
            for(int ii=0;ii<s[i].length();ii++)
            {
                bool yes=1;
                for(int jj=0;ii+jj<s[i].length()&&jj<s[j].length();jj++)
                {
                    if(s[i][ii+jj]==s[j][jj]||s[i][ii+jj]=='?'||s[j][jj]=='?');
                    else{
                        yes=0;
                        break;
                    }
                }
                if(yes) ok[i][j][ii]=1;
                //dbg(i,j,ii,ok[i][j][ii]);
            }
            ok[i][j][s[i].length()]=1;
        }
    }
    int ans=0x3f3f3f3f;
    do{
        //dbg(id);
        for(int i=0;i<=s[id[0]].length();i++)
        {
            if(ok[id[0]][id[1]][i])
            {
                int same=min(s[id[0]].length()-i,s[id[1]].length());
                int len=s[id[0]].length()+s[id[1]].length()-same;
                for(int j=0;j<=len;j++)
                {
                    //dbg(i,j,ok[id[0]][id[2]][i]);
                    if(j<s[id[0]].length()&&!ok[id[0]][id[2]][j]) continue;
                    if(j>=i)
                    {
                        int pos=j-i;
                        if(!ok[id[1]][id[2]][pos]) continue;
                    }
                    else{
                        if(j+s[id[2]].length()>i)
                        {
                            int pos=i-j;
                            if(!ok[id[2]][id[1]][pos]) continue;
                        }
                    }
                    int s2=min<int>(len-j,s[id[2]].length());
                    //dbg(i,j,same,s2);
                    ans=min<int>(ans,s[0].length()+s[1].length()+s[2].length()-same-s2);
                }
            }
        }
    }while(next_permutation(id.begin(),id.end()));
    
    print(ans);
}

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

using namespace std;

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()
int GCD(int a,int b){ return b ? GCD(b,a%b) : a ;} 

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

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

   vector<int> left(n+1);
   vector<int> right(n+1);
   for(int i=0;i<n;i++)left[i+1] = GCD(left[i],a[i]);
   for(int i=n-1;i>=0;i--)right[i] = GCD(right[i+1],a[i]);

   int ans = 0;
   for(int i=0;i<n;i++){
      int l = left[i];
      int r = right[i+1];
      ans = max(GCD(l,r),ans);
   }
   cout << ans << endl;
   return 0;
}

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

int main() {
  int N;
  cin >> N ;
  
  int X = N;
  int f = 0;

  while(N !=0){
    f += N % 10;
	N /= 10;
  }
  if ( X % f == 0){
    cout << "Yes" << endl;
  }
  else 
    cout << "No" << endl;
}

Measured memory_bytes: 3512
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N, L; cin >> N >> L;
    int sum = 0;
    int selectedApple = 0;
    int mi = 1000000;
    for (int i = 1; i <= N; i++) {
        sum += L + i - 1;
        if (mi > abs(L + i - 1)) {
            mi = abs(L + i - 1);
            selectedApple = L + i - 1;
        }
    }
    cout << sum - selectedApple << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <climits>
#include <functional>

#define REP(i,n) for(int i = 0;i < n;i++)
#define pyfor(j,s,n,i) for(int j = s;j < n;j += i)

using namespace std;
typedef long long ll;
const int INF = INT_MAX;

const int max_n = 1e5;

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

  char s[max_n];
  cin >> s;
  int K;
  cin >> K;
  int sl = strlen(s);

  REP(i, sl){
    if(s[i] == 'a') continue;
    int c = 'z' - s[i] + 1;
    if(K >= c) {
      K -= c;
      s[i] = 'a';
    }
  }

  s[sl-1] += (K % 26);

  cout << s << "\n";

  return 0;
}


Measured memory_bytes: 512
n=int(input())
xy=[[]for _ in range(n)]
for i in range(n):
  for j in range(int(input())):
    xy[i].append(list(map(int,input().split())))
ans=0
for i in range(1,1<<n):
  syojiki=[(i&(1<<j)!=0)+0 for j in range(n)]
  flag=True
  for j in range(n):
    for x,y in xy[j]:
      if syojiki[x-1]!=y and syojiki[j]==1:flag=False
  if flag:
    ans=max(ans,syojiki.count(1))
print(ans)

Measured memory_bytes: 43484
#include<stdio.h>
int main(){
  int i,num,counter[26];
  char ch;

  for(i = 0;i < 26;i++){
    counter[i] = 0;
  }

  while(scanf("%c",&ch) != EOF){
    if(islower(ch)){
      num = ch - 'a';
      counter[num]++;
    }
    else if(isupper(ch)){
      num = ch - 'A';
      counter[num]++;
    }
  }

  for(i =0;i < 26;i++){
    ch = i + 'a';
    printf("%c : %d\n",ch,counter[i]);
  }

  return 0;
}

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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define endl            "\n"

#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))


#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << endl;// cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 3e5 + 7;
vector <vi > adj;
bool vis[N];




void solve()
{
	int n;
	cin >> n;
	map<string, int>mp;
	loop(i, 0, n)
	{
		string s;
		cin >> s;
		mp[s]++;
	}
	vector<pair<int, string> >v;
	for (auto x : mp)
	{
		v.pb({x.ss, x.ff});
	}
	sort(all(v));
	reverse(all(v));
	vector<string>ans;
	int i = 0;
	int mx = v[i].ff;
	while (v[i].ff == mx)
	{
		ans.pb(v[i].ss);
		i++;
	}
	sort(all(ans));
	print(ans);
	return;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


	cout << setprecision(9) << fixed;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}


	return 0;
}

Measured memory_bytes: 31212
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <cstdlib>
#include <iomanip>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0);
const int M = 1e9+7;
const int N = 2*1e5;
using namespace std;
int n;
vector<vector<ll>> adj;
ll k;
vector<vector<ll>> result;

void mulresult(){
    vector<vector<ll>> tmp = result;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            result[i][j]=0;
            for(int k=0; k<n; k++){
                result[i][j]=(result[i][j]+(tmp[i][k]*tmp[k][j]))%M;
            }
        }
    }
}

void mulodd(){
    vector<vector<ll>> tmp1 = result;
    vector<vector<ll>> tmp2 = adj;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            result[i][j]=0;
            for(int k=0; k<n; k++){
                result[i][j]=(result[i][j]+(tmp1[i][k]*tmp2[k][j]))%M;
            }
        }
    }
}

void solve(ll k){
    if(k==1)
        return;
    solve(k/2);
    mulresult();
    if(k%2!=0)
        mulodd();
    return;
}


int main(){
    AC
    cin>>n>>k;
    adj.resize(n);
    result.resize(n);
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            int x;
            cin>>x;
            adj[i].push_back(x);
            result[i].push_back(x);
        }
    }
    solve(k);
    ll ans = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++)
            ans+=(result[i][j]%M);
    }
    cout<<ans%M<<endl;
}

Measured memory_bytes: 3740
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
h1,m1,h2,m2,k=n1()
t=h2*60+m2-h1*60-m1
print(t-k)

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

int main(){
	long long n,t;	cin>>n>>t;
	vector<int> a(n);

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

	long long ans=t;

	for(int i=0;i<n-1;i++){
		if(abs(a[i+1]-a[i])<=t)ans+=abs(a[i+1]-a[i]);
		else ans+=t;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 1024
def order_sentence(args_num, arg_sentence_length, args_list):
    ordered_sentence = "".join(sorted(args_list))
    return ordered_sentence

if __name__=='__main__':
    args_num, arg_sentence_length = map(int, input().split())
    args_list = [input() for i in range(args_num)]
    print(order_sentence(args_num, arg_sentence_length, args_list))

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    count = 0
    for i in range(N):
        if (i+1)%2 == 1 and a[i]%2 == 1:
            count += 1
    print(count)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b):
    gcda = gcd(a,b)
    return a*b//gcda

#リストの最小公倍数
def lcmlist(lista):
    if len(lista) == 1:
        return lista[0]
    else:
        from functools import reduce
        return reduce(lcm,lista)
LCM = lcmlist(A)
ans = 0
for i in A:
    ans += LCM//i
print(ans%mod)

Measured memory_bytes: 4208
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<set>
#include<map>
#include<cmath>
using namespace std;
#define LL long long
#define MAXN 1000
#define INF 2000000000
int a[MAXN];
int main()
{
	int n,x,ans=0;
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		if(x>=a[i])
			x-=a[i],ans++;
		else
		{
			x=0;
			break;
		}
	if(x) ans--;
	printf("%d\n",ans);
}

Measured memory_bytes: 128
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B = MAP()
X = LIST()
ans = 0
for i in range(N-1):
    gap = X[i+1] - X[i]
    hA = gap * A
    if hA < B:
        ans += hA
    else:
        ans += B
print(ans)

Measured memory_bytes: 21616
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvl G;
vl ans;

void dfs(ll v, ll p = -1) {
    for(auto u : G[v]) {
        if(u == p) {
            continue;
        }
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main() {
    ll n, q;
    cin >> n >> q;    

    G.resize(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    ans.resize(n);
    rep(i, q) {
        ll p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    
    dfs(0);

    rep(i, n) {
        out(ans[i]);
    }
    
    re0;
}

Measured memory_bytes: 24320
#include <stdio.h>

int main()
{
  int l,r,d;
  scanf("%d%d%d",&l,&r,&d);
  int cnt;
  cnt = 0;
  while (l <= r)
  {
    if (l % d == 0)
    {
      cnt++;
    }
    l++;
  }
  printf("%d",cnt);
}

Measured memory_bytes: 1724
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] P = new int[N];
        int max = 0;
        for(int i=0; i<N; i++){
            P[i] = sc.nextInt();
            max = Math.max(max, P[i]);
        }
        int min = max;
        int count = 0;

        for(int i=0; i<N; i++){
            if(P[i] <= min) {
                count++;
                min = P[i];
            }
        }
        System.out.println(count);
    }
}

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

vector <int> all[20];
int p[20];

int main(){
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++){
		int k; scanf("%d", &k);
		while (k--){
			int x; scanf("%d", &x);
			x--;
			all[i].push_back(x);
		}
	}
	for (int i = 0; i < m; i++){
		scanf("%d", &p[i]);
	}
	int ans = 0;
	for (int mask = 0; mask < (1 << n); mask++){
		for (int i = 0; i < m; i++){
			int cnt = 0;
			for (int j = 0; j < all[i].size(); j++){
				int x = all[i][j];
				cnt += mask >> x & 1;
			}
			if (cnt % 2 != p[i]) goto END;
		}
		ans++;
		END:;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;
    int x = 1;
    if (S[A] != '-' ) x = 0;
    rep(i, A) {
        int num = S[i] - '0';
        if (num >= 0 && num <= 9 && x == 1) x = 1;
        else x = 0;
    }
    rep(i, B) {
        int num = S[A+i+1] - '0';
        if (num >= 0 && num <= 9 && x == 1) x = 1;
        else x = 0;
    }
    if (x == 1) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

bool check(int x,int W,int r){
    if(x-r < 0 || x+r > W){
        return false;
    }
    else return true;
}

int main(){
    int W,H,x,y,r;
    cin >>W >>H >>x >>y >>r;
    if(check(x,W,r)&&check(y,H,r))cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

const int N=105;
int n,f[3][N];

int main()
{
	cin>>n;
	int i,j;
	for(i=1;i<=2;i++)
	    for(j=1;j<=n;j++)
	    {
	        cin>>f[i][j];
	        f[i][j]+=max(f[i-1][j],f[i][j-1]);
	    }
	cout<<f[2][n];
	return 0;
}


Measured memory_bytes: 256