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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

constexpr char sp = ' ';
constexpr char cmm = ',';
constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    int n, k, q;
    cin >> n >> k >> q;
    vector<int> cnt(n);
    rep(i, q){
        int a;
        scanf("%d", &a);
        ++cnt[a-1];    
    }

    rep(i, n) Judge(cnt[i] > q-k);

    return 0;
}


Measured memory_bytes: 1024
/*
ID: seekho
PROG: friday
LANG: C++14                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
const int N = 3005;

string s,t;
int memo[N][N];

int mx = 0, ind1, ind2;
string ans = "";
void go() {
	rep(i,sz(s)) {
		rep(j,sz(t)) {
			if(s[i]==t[j]) {
				memo[i][j] = 1 + (i-1 >= 0 and j-1 >= 0 ? memo[i-1][j-1] : 0);
				if(mx < memo[i][j]) {
					mx = memo[i][j];
					ind1 = i;ind2 = j;
				}
			}
			else {
				memo[i][j] = i-1 >= 0 ? memo[i-1][j] : 0;
				if(j-1 >= 0)
					memo[i][j] = max(memo[i][j], memo[i][j-1]);
			}
		}
	}

	while(ind1 >= 0 and ind2 >= 0) {
		if(s[ind1] == t[ind2]) {
			ans += s[ind1];
			ind1--;ind2--;
			continue;
		}
		if(ind1-1 >= 0 and memo[ind1][ind2] == memo[ind1-1][ind2])
			ind1--;
		else
			ind2--;
	}
	assert(mx == sz(ans));
	reverse(all(ans));
}

int32_t main() {

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

    cin >> s >> t;
    go();
    cout << ans << '\n';
}

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

static const double pi = 3.141592653589793;

double Cos(double D)
{
    return cos(pi/180 * D);
}

void pattern(ll& ans,ll i,ll N,ll K)
{
    if(i%K==0) ans += (N/K)*(N/K);
    else ans += ((N+(K/2))/K)*((N+(K/2))/K);
}

int main()
{
    ll N,K;
    cin >> N >> K;

    ll ans=0;

    if(K%2!=0)
    {
        ans = (N/K)*(N/K)*(N/K);
    }
    else
    {
        for(ll i=K/2;i<=N;i+=K/2)
        {
            pattern(ans,i,N,K);
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
	int i,j;
	int count = 9;

	for(i = 0; i < count; i++)
	{
		for (j = 0; j < count; j++)
		{
			cout << i+1 << "x" << j+1 << "=" << (i+1)*(j+1) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3052
import itertools

N, K = map(int, input().split())
P = [tuple(map(int, input().split())) for _ in range(N)]

X = sorted([x for x, _ in P])
Y = sorted([y for _, y in P])
dict_x = {v: k + 1 for k, v in enumerate(X)}
dict_y = {v: k + 1 for k, v in enumerate(Y)}

table = [[0] * (N + 1) for _ in range(N + 1)]
for x, y in P:
    table[dict_y[y]][dict_x[x]] = 1

for x in range(N + 1):
    for y in range(N):
        table[y + 1][x] += table[y][x]
for y in range(N + 1):
    for x in range(N):
        table[y][x + 1] += table[y][x]

ans = float('inf')
for x1, x2 in itertools.combinations(range(N), 2):
    for y1, y2 in itertools.combinations(range(N), 2):
        if table[y2 + 1][x2 + 1] - table[y2 + 1][x1] - table[y1][x2 + 1] + table[y1][x1] >= K:
            ans = min(ans, (X[x2] - X[x1]) * (Y[y2] - Y[y1]))
print(ans)

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

typedef long long ll;
#define rep(i,n) for( ll (i)=0; (i)<(n); ++(i) )
#define rpi(i,n) for( int (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#if __cplusplus < 201703L
  std::ostream& co_(){ return std::cout << std::endl; }
  std::istream& cn_(){ return std::cin; }
  template<class Head, class... Args>
  std::ostream& co_( Head&& head, Args&&... args ){ std::cout << head; return co_(std::forward<Args>(args)...); }
  template<class Head, class... Args>
  std::istream& cn_( Head&& head, Args&&... args ){ std::cin >> head; return cn_(std::forward<Args>(args)...); }
#else
  template<class... Args>
  std::ostream& co_( Args... args ){ return std::cout << ... << args << std::endl; }
  template<class... Args>
  std::istream& cn_( Args... args ){ return std::cin >> ... >> args; }
#endif
#define co(...) co_(__VA_ARGS__);
#define cn(...) cn_(__VA_ARGS__);
#define all(x) (x).begin(), (x).end()
#define rgt(x,i) (x).begin(), (x).begin()+(i)

int main(){
  string s;cn(s)
  if (s=="AAA"||s=="BBB"){
    co("No")
  }else{
    co("Yes")
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()

string S;
int N;

bool subs(char a, char b, char c) {
	int x = 0;
	for (int i = 0;i < N;i++) {
		if (x == 0) {
			if (S[i] == a)x++;
		}
		else if (x == 1) {
			if (S[i] == b)x++;
		}
		else {
			if (S[i] == c)return 1;
		}
	}
	return 0;
}

int main() {
	cin >> N;
	cin >> S;
	int x, cnt = 0;
	char a, b, c;
	for (int i = 0;i < 1000;i++) {
		x = i;a = x % 10 + 48;
		x /= 10;b = x % 10 + 48;
		x /= 10;c = x % 10 + 48;
		if (subs(a, b, c))cnt++;
	}
	cout << cnt << endl;
}

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

int main() {
    std::queue<ll> que;
    ll count = 0;
    ll K;
    ll x;

    cin >> K;

    rep(i, 9){
        que.push(i+1);//1から9まで追加
    }

    while (count < K) {
        x = que.front(); // 先頭要素を参照する
        que.pop(); // 先頭要素を削除

        if(x%10 != 0) que.push(x*10 + x%10 - 1);
        que.push(x*10 + x%10);
        if(x%10 != 9) que.push(x*10 + x%10 + 1);
        
        count ++;        
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 1792
k,n = map(int,input().split())
a = list(map(int,input().split()))
tm = a[0]
a.append(tm)
m = -9878789894545656
 
for i in range(n-1):
  m = max(m,a[i+1]-a[i])
  
m = max(m,a[0]+k-a[n-1])
  
print(k-m)

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

int main() {
  int N, a, b, c,d;
  cin >> N;
  a = N%10;
  b = (N/10)%10;
  c = (N/100)%10;
  d = N/1000;

  if ( (a==b && b==c) || (b==c && c==d) ) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(void)
{
	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	for (int i = 0; i < n; i++)
		cin >> s[i];

	sort(s.begin(), s.end());
	string result = "";
	for (auto str: s) {
		result += str;
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  var w = lines[0].split(' ');
  var n = parseInt(w[0]);
  var x = parseInt(w[1]);
  var t = parseInt(w[2]);
  var c = Math.ceil(n / x) * t;
  console.log(c);
});

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

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

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const int MOD = 1000000007;
int rui(int a, int b) {
    if(b == 0) {
        return 1;
    }
    return rui(a, b - 1) * a;
}
int main() {
    int N;
    cin >> N;
    vector<int> p(N);

    rep(i, 0, N) { cin >> p[i]; }
    int count = 0;
    rep(i, 1, N - 1) {
        if(p[i - 1] < p[i] && p[i] < p[i + 1]) {
            count++;
        } else if(p[i + 1] < p[i] && p[i] < p[i - 1]) {
            count++;
        } else if(p[i + 1] == p[i] && p[i] > p[i - 1]) {
            count++;
        } else if(p[i - 1] == p[i] && p[i] > p[i + 1]) {
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define N 250000
using namespace std;

int main()
{
  int n,Prime[N];
  Prime[0]=2;
  Prime[1]=3;
  Prime[2]=5;
  Prime[3]=7;
  Prime[4]=11;
  Prime[5]=13;
  Prime[6]=17;
  Prime[7]=19;
  Prime[8]=23;
  int key=9;
  int fl=0;
  
  for(int i=29;i<=N;i++)
    {
      for(int j=2;j<=sqrt(i);j++)
	{
	  if(i%j == 0)
	    {
	      fl=1; 
	      break;
	    }
	}
      if(fl == 0)
	{
	  Prime[key]=i;
	  key++;
	}
      else fl = 0;
    }
  

  int cou=0;
  
  while(1)
    {
      cin >> n;
      if(n == 0)break;
      for(int i=0;i<key-1;i++)
	{
	  if(Prime[i] <= n)continue;
	  else if(n < Prime[i] && Prime[i] <= 2*n)cou++;
	  else if(2*n < Prime[i])break;
	}
      cout << cou << endl;
      cou = 0;

    }
  



}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;


int main() {
	int n, k;
	cin >> n >> k;
	vector<long long> a(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}

	long long ans = LLONG_MAX;
	for (int bit = 0;bit < (1 << n);bit++) {

		long long max = a[0];
		long long tmp = 0;
		int count = 1;
		for (int i = 1;i < n;i++) {
			if (bit & (1 << i)) {
				if (max >= a[i]) {
					tmp += max + 1 - a[i];
					max++;
				}
				count++;
			}
			if (max < a[i]) {
				max = a[i];
			}
		}

		if (count >= k) {
			if (ans > tmp) ans = tmp;
		}
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		int h = cin.nextInt();
		int w = cin.nextInt();
		String sharps = String.valueOf(new char[w + 2]).replace(String.valueOf(new char[1]), "#");
		cout.println(sharps);
		for (int i = 0; i < h; i++) {
			cout.print("#");
			cout.print(cin.nextLine());
			cout.println("#");
		}
		cout.println(sharps);
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

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

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

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

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

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

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

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, a, num = 1, count = 0;
    cin >> n;
    vector<int> v(1);
    for(int i = 0; i < n; ++i){
        cin >> a; 
        if(a != num) count++; 
        else num++;
    }
    if(count == n) cout << -1 << endl;
    else cout << count << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>

using namespace std;

int main(){

  vector<int> V;
  int in;
  while(cin >> in){
    if(in != 0) V.push_back(in);
    else{
      cout <<  V.back() << endl;
      V.pop_back();
    }
  }
  return 0;
}

Measured memory_bytes: 0
import itertools
def main():
    n = int(input())
    
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    for _ in range(n):
        s = input()
        if(s[0] == "M"):
            m += 1
        elif(s[0] == "A"):
            a += 1
        elif(s[0] == "R"):
            r += 1
        elif(s[0] == "C"):
            c += 1
        elif(s[0] == "H"):
            h += 1

    T = [m, a, r, c, h]

    ans = 0
    for i in range(3):
        for j in range(i + 1, 4):
            for k in range(j + 1, 5):
                ans += T[i] * T[j] * T[k]
    print(ans)

if __name__ == "__main__":
    main()

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 101;
const int maxk = 1e5+1;




int n, k;
ll dp[maxn][maxk];
int a[maxn];


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

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

    dp[0][0] = 1;
    for (int i=1; i<=n; i++) {
	for (int j=1; j<=k; j++) {
	    dp[i-1][j] += dp[i-1][j-1];
	    dp[i-1][j] %= mod;
	}
	for (int j=0; j<=k; j++) {
	    ll R = dp[i-1][j];
	    ll L = j-a[i]-1>=0? dp[i-1][j-a[i]-1]: 0;
	    dp[i][j] = (R-L+mod)%mod;
	}
    }

    ll res = dp[n][k];
    res%=mod;
    res+=mod;
    res%=mod;
    cout<<res<<endl;
  

    return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

const string YES = "Yes";
const string NO = "No";

void func(long long N, long long A, long long B, std::string S){

    lli a=0,b=0;

    REP(i,0,S.size()){
        if(S.at(i)=='a'){
            if((a+b)< (A+B)){
                cout<<"Yes"<<endl;
                a++;
            }
            else cout<<"No"<<endl;
        }
        else if(S.at(i)=='b'){
            if( (a+b)<(A+B) && (b<B)){
                cout<<"Yes"<<endl;
                b++;
            }
            else cout<<"No"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);

    lli a=0,b=0;
    REP(i,0,N){
        char s;
        cin>>s;
        if(s=='a'){
            if((a+b)< (A+B)){
                cout<<"Yes"<<endl;
                a++;
            }
            else cout<<"No"<<endl;
        }
        else if(s=='b'){
            if( (a+b)<(A+B) && (b<B)){
                cout<<"Yes"<<endl;
                b++;
            }
            else cout<<"No"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 640
h, w = map(int, input().split())
pic = []
pic.append(["."] * (w + 2))
for i in range(h):
  pic.append(["."] + list(input()) + ["."])
pic.append(["."] * (w + 2))


can_paint = True
for i in range(1, h+1):
  for j in range(1, w+1):
    if pic[i][j] == "#":
      up = pic[i-1][j]
      down = pic[i+1][j]
      left = pic[i][j-1]
      right = pic[i][j+1]
      if up == "." and down == "." and left == "." and right == ".":
        can_paint = False
      
if can_paint == True:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>
#include <bitset>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 998244353;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}

int main() {
  int n,k; cin>>n>>k;
  int l[k],r[k];
  for(int i=0;i<k;i++) {
    cin>>l[i]>>r[i];
  }
  ll dp[n]={1}, su[n]={}, ss = 0;
  for(int i=0;i<n;i++) {
    //cout<<dp[i]<<" "<<su[i]<<" "<<ss<<endl;
    add(ss, su[i]);
    add(dp[i],ss);
    for(int j=0;j<k;j++) {
      int p0 = i+l[j];
      int p1 = i+r[j]+1;
      if (p0 < n) add(su[p0],dp[i]);
      if (p1 < n) add(su[p1],M-dp[i]);
    }
  }
  cout<<dp[n-1]<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 6800
<?php
#include <stdio.h>
# 整数の入力
fscanf(STDIN, "%d %d", $a, $b);
$mod2 = ($a * $b) % 2;
if($mod2 == 1){
  $result = "Odd";
} else {
  $result = "Even";
}
echo $result."\n";

Measured memory_bytes: 3828
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	char a[N + 1];
	f(i, N + 1)a[i] = 0;
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = false;
	scanf("%s", a);
	if (a[0] == a[1]) {
		if (a[0] != a[2] && a[2] == a[3])v = true;
}
	if (a[0] == a[2]) {
		if (a[0] != a[1] && a[1] == a[3])v = true;
	}
	if (a[0] == a[3]) {
		if (a[0] != a[1] && a[1] == a[2])v = true;
	}
	if (v)printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pii a, pii b)//true for a before b
{
	if(a.S < b.S)
		return 1;
	if(a.S > b.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (1e2) + 9;
const int M = (672*672) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 900;

vector < pii > ans;

void solve()
{
	int n, k, i, val = 0, j;
	cin >> n >> k;

	if(n == 2)
	{
		if(k > 0)
			cout << -1 << '\n';
		else
		{
			cout << 1 << '\n';
			cout << 1 << " " << 2 << '\n';
		}
		return;
	}

	fo(i,2,n+1)
		ans.pb({1,i});
	val = ((n-1)*(n-2))/2;

	fo(i,2,n+1)
	{
		if(val <= k)
			break;
		fo(j,i+1,n+1)
		{
			if(val <= k)
				break;
			ans.pb({i,j});
			val--;
		}
	}

	if(val != k)
	{
		cout << -1 << '\n';
		return;
	}

	cout << sz(ans) << '\n';
	for(auto x : ans)
		cout << x.F << " " << x.S << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand(clock());

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(15);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int X; cin >> X;
  int result = 0;
  rep(i,X) if (X>=100*i&&X<=105*i) result = 1;
  cout << result << endl;
  return 0;
}

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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

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

    string s;
    cin>>s;

    ll res=1000;
    FOR(i,0,s.size()-2){
      ll x=(s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
      res = min(res,abs(753-x));
    }
    cout<<res<<endl;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N;
    cin >> N;
    vector<P> A;
    rep(i, N) {
        string s;
        cin >> s;
        int p = -1;
        rep(j, s.size()) {
            if (s[j] == '.') {
                p = j;
            }
        }
        if (p == -1) {
            A.push_back({stoll(s), 0});
        } else {
            string x = "";
            rep(j, p) {
                x += s[j];
            }
            rep2(j, p + 1, s.size()) {
                x += s[j];
            }
            A.push_back({stoll(x), s.size() - (p + 1)});
        }
    }
    vector<vector<ll>> grid(80, vector<ll>(80, 0));
    ll base = 40;
    rep(i, N) {
        P p = A[i];
        ll f = p.first;
        ll two = 0;
        ll five = 0;
        while (f % 2 == 0) {
            two++;
            f /= 2;
        }
        while (f % 5 == 0) {
            five++;
            f /= 5;
        }
        five -= p.second;
        two -= p.second;
        grid[two + base][five + base]++;
    }
    ll ans = 0;
    rep2(i, base, 80) {
        rep2(j, base, 80) {
            ans += grid[i][j];
        }
    }
    ans = (ans - 1) * ans;
    ans /= 2;
    ll c = 0;
    rep(i, 80) {
        rep(j, 80) {
            if (i >= base && j >= base) continue;
            ll i_t = base;
            if (i < base) {
                i_t = base + abs(base - i);
            } else {
                i_t = base - abs(base - i);
            }
            ll j_t = base;
            if (j < base) {
                j_t = base + abs(base - j);
            }else {
                j_t = base - abs(base - j);
            }
            if (grid[i][j] == 0) continue;
            rep2(x, i_t, 80) {
                rep2(y, j_t, 80) {
                    if (x >= base && y >= base) {
                        ans +=grid[x][y] * grid[i][j];
                    }else {
                        c += grid[x][y] * grid[i][j];
                    }
                }
            }
        }
    }
    cout << ans + c / 2<< '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 7384
import scala.io.StdIn._

object Main extends App {
  val Array(n, x) = readLine().split(' ').map(_.toInt)
  val ms = (1 to n).map { _ =>
    readInt()
  }.toSeq
  
  val remain = x - ms.sum
  val availableCount = remain / ms.min
  println(n + availableCount)
}

Measured memory_bytes: 54920
#include <stdio.h>
#include <stdlib.h>

void Quicksort_rand(int A[], int L, int R);

int main(void)
{
	int N, L[105], i, sum = 0;

	scanf("%d", &N);
	for (i = 0; i < N; i++) { scanf("%d", &L[i]); }
	Quicksort_rand(L, 0, N - 1);
	for (i = 0; i < N-1; i++) {
		sum += L[i];
	}
	if (L[N - 1] < sum) {
		printf("Yes");
	}
	else printf("No");


	return 0;
}

void Quicksort_rand(int A[], int L, int R)/*A[L]~A[R]までソート*/
{
	if (L < R)
	{
		int r, tmp, p = L, k = L + 1;

		srand(0);
		r = rand() % (R - L + 1) + L;//pivotを選択

		//pivotを先頭に置く
		tmp = A[L];
		A[L] = A[r];
		A[r] = tmp;

		//左の翼と右の翼に分ける
		while (k <= R) {
			if (A[k] < A[L]) {
				tmp = A[k];
				A[k] = A[p + 1];
				A[p + 1] = tmp;
				p++;
			}
			k++;
		}

		//pivotを左右の翼の境目に置く
		tmp = A[L];
		A[L] = A[p];
		A[p] = tmp;

		//左右の翼で再帰
		Quicksort_rand(A, L, p - 1);
		Quicksort_rand(A, p + 1, R);
	}
	return;
}

Measured memory_bytes: 128
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())

    for i in range(1, n + 1):
        min_lim = (i - 1) * i // 2 + 1
        max_lim = i * (i + 1) // 2
        if min_lim <= n <= max_lim:
            print(i)
            sys.exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 63084
#include <stdio.h>

#define MAX 100

int adj[MAX][MAX];
int discover[MAX];
int finish[MAX];
int time;

void dfp(int id, int n) {
  // 0-origin
  int i;
  if (finish[id] != 0) {
    return;
  }
  else if (discover[id] == 0){
    discover[id] = (++time);
  }

  for (i = 0; i < n; i++) {
    if (adj[id][i] == 1 && discover[i] == 0) {
      discover[i] = (++time);
      dfp(i, n);
    }
  }
  finish[id] = (++time);
}

int main() {
  int i, j;
  int n, index, k, v;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      adj[i][j] = 0;
    }
    discover[i] = 0;
    finish[i] = 0;
  }

  
  for (i = 0; i < n; i++) {
    scanf("%d %d", &index, &k);
    for (j = 0; j < k; j++) {
      scanf("%d", &v);
      adj[index - 1][v - 1] = 1;
    }
  }

  time = 0;
  for (i = 0; i < n; i++) {
    dfp(i, n);
  }

  for (i = 0; i < n; i++) {
    printf("%d %d %d\n", i+1, discover[i], finish[i]);
  }
  
  return 0;
}



Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;

int main(){
  ll p=998244353;
  ll n,s;
  cin >> n >> s;
  ll k[n];
  rep(i,n)cin >> k[i];
  ll dp[n+1][s+1];
  rep(i,n+1)rep(j,s+1)dp[i][j]=0;
  dp[0][0]=1;
  rep(i,n){
    rep(j,s+1)dp[i+1][j]=(2*dp[i][j])%p;
    rep(j,s+1){
      if(j+k[i]<=s){
        dp[i+1][j+k[i]]=(dp[i+1][j+k[i]]+dp[i][j])%p;
      }
    }
  }
  cout << dp[n][s] << endl;
}  


Measured memory_bytes: 73936
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
using namespace std;
int main(){
    int a=1;
    int b;
    for(int i=0;i<5;i++){
        cin>>b;
        if(b==0){
            break;
        }else{
            a++;
        }
    }
    cout<<a<<endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <string>

int main(){
    std::string s;
    std::cin >> s;

    if (s == "AAA" || s == "BBB")
    {
        std::cout << "No" << std::endl;
    }
    else
    {
        std::cout << "Yes" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
ll mod = 1e9+7;
ll dp[205][100005];
const int NUM_=2005;
ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
ll combi(ll N_, ll C_) {
    if(C_<0 || C_>N_) return 0;
    return factr[C_]*fact[N_]%mod*factr[N_-C_]%mod;
}
ll hcomb(ll P_, ll Q_) { return (P_==0&&Q_==0)?1:combi(P_+Q_-1,Q_);}
ll dfs(vector<int>&s, int n, int x){
    show(n,x);
    if(n == 0)return x;
    if(~dp[n][x])return dp[n][x];
    ll res = 0;
    if(s[n-1] <= x){
        for(int i = 0; i < n; i++){
            res = (res + dfs(s,n-1,x % s[i])) % mod;
        }
    }else{
        int pos = (int) (upper_bound(s.begin(),s.begin()+n,x)-s.begin());
        res = dfs(s,pos,x) * combi(n,pos)  % mod * fact[n-pos] % mod;
    }
    show(n,x,res);
    return dp[n][x] = res;
}
int main(){
    int n,x;
    cin >> n >> x;
    vector<int>s(n);
    rep(i,n){
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    show(s);
    memset(dp,-1,sizeof(dp));
    if (fact[0]==0) {
        inv[1]=fact[0]=factr[0]=1;
        for (int i=2;i<=NUM_;++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
        for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mod, factr[i]=factr[i-1]*inv[i]%mod;
    }
    
    cout << dfs(s, n, x) << endl;
}

Measured memory_bytes: 160512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,a,b,c,d;
    string s;
    cin>>n>>a>>b>>c>>d>>s;
    --a;--b;--c;--d;
    if(c<d){
        while(b!=d){
            if(s[b+1]=='.') ++b;
            else if(s[b+2]=='.') b+=2;
            else{
                cout<<"No"<<endl;
                return 0;
            }
        }
        while(a!=c){
            if(s[a+1]=='.') ++a;
            else if(s[a+2]=='.') a+=2;
            else{
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
        return 0;
    }
    int q=-1;
    ifr(i,n-2){
        if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'&&i+1<=d){
            q=i;
            break;
        }
    }
    if(q<b-1){
        cout<<"No"<<endl;
        return 0;
    }
    while(b!=q+1){
        if(s[b+1]=='.') ++b;
        else if(s[b+2]=='.') ++b;
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    s[b]='#';
    while(a!=c){
        if(s[a+1]=='.') ++a;
        else if(s[a+2]=='.') a+=2;
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    while(b!=d){
        if(s[b+1]=='.') ++b;
        else if(s[b+2]=='.') b+=2;
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
using namespace std;

int main(void)
{
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; ++i)
        cin >> vec[i];
    int P = accumulate(vec.begin(), vec.end(), 0) / N;
    int count = 0;
    for (int i = 0; i < N; ++i)
        count += (P - vec[i]) * (P - vec[i]);
    int MIN = count;
    count = 0;
    for (int i = 0; i < N; ++i)
        count += (P + 1 - vec[i]) * (P + 1 - vec[i]);
    MIN = min(MIN, count);
    cout << MIN << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int mod = 1000000007;


struct UnionFind {
  vector<int> d;
  // Default Constructor
  // if d[x] is minux, x is the root of union and d[x] is the minus of size of the union.
  // if d[x] is plus, d[x] show the root of the union of x. 
  // Intially, all number is root, so d[x] = -1, and the size of the union is 1.
  UnionFind(int n = 0): d(n,-1) {}

  // Find root number. Root is d[root] = -1
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if(x == y) return false;
    // Consider  the size of x is bigger than the size of y.
    if(d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }

  bool same(int x, int y) { return find(x) == find(y);}
    
  int size(int x) { return -d[find(x)];}
};

int deg[100005];
vector<int> to[100005];

int main() {

  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    deg[a]++;
    deg[b]++;
    uf.unite(a, b);
  }
  rep(i, k) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i, n){
    int ans = uf.size(i) - deg[i] - 1;
    for(int u: to[i]) {
      if(uf.same(i, u)) --ans;
    }
    printf("%d%c", ans, i==n-1? '\n': ' ');
  }
  return 0;
}

Measured memory_bytes: 6784
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define inf 1000000000000000000
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
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; }

// O(NlogN)
vector<long long> num_divisors_table(long long N) {
    vector<long long> table(N + 1);

    for (int i = 1; i < N + 1; i++) {
        for (int j = i; j < N + 1; j += i) {
            table[j]++;
        }
    }
    return table;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  
  ll N, ans = 0;
  cin >> N;
  vector<ll> table = num_divisors_table(N);
  for (int i = 1; i < N + 1; i += 2) {
    if (table[i] == 8) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
// D - Integer Cards

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

struct Exchange {
	int B;
	int C;
};

Exchange exc[100000];
int A[100000];

int main() {
	int N, M;
	cin >> N >> M;

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

	sort(A, A+N);

	for (int i=0; i<M; i++) {
		cin >> exc[i].B >> exc[i].C;
	}

	sort(exc, exc+M, [](const Exchange &a, const Exchange &b) {
		return a.C > b.C;
	});

	int i=0;
	int j=0;
	while (i < N && j < M) {
		for (int k=0; k<exc[j].B; k++) {
			if (i >= N || A[i] >= exc[j].C) {
				i = N;
				break;
			}

			A[i] = exc[j].C;
			i++;
		}
		j++;
	}

	ll ans = 0;
	for (int i=0; i<N; i++) {
		ans += A[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	cin>>n;
	int a[3*n];
	rep(i,3*n)cin>>a[i];
	sort(a,a+3*n,greater<int>());
	long long sum=0;
	rep(i,2*n){
		if(i%2)sum+=a[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end());
using namespace std;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;

int main(){
	int n,x;
	cin>> n >> x; 
	vector<int> M(n);
	rep(i,n) cin>> M[i];
	SORT(M);
	int ans = 0;// how many
	int sum = 0; // ingredience
	rep(i,n){
		sum+=M[i];
		ans ++ ;
	}
	while(sum+M[0]<=x){
		sum+=M[0];
		ans++;
	}
	cout << ans <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int a[5][7]={};
  int n;
  int ans;
  cin >> n;
  int r,t;
  rep(i,5){
    rep(j,7){
      a[i][j]=0;
    }
  }
  rep(i,n){
    ans=0;
    cin>>r>>t;
    if(r%100==0 && t%30==0){
      ans+=r/100;
      ans+=(t/30)*5;
      cout<<ans<<endl;
    }
    else if(r%100==0){
      ans+=r/100;
      ans+=(t/30)*5;
      cout<<ans<<" "<<ans+5<<endl;
    }
    else if(t%30==0){
      ans+=r/100;
      ans+=(t/30)*5;
      cout<<ans<<" "<<ans+1<<endl;
    }else{
      ans+=r/100;
      ans+=(t/30)*5;
      cout<<ans<<" "<<ans+1<<" "<<ans+5<<" "<<ans+6<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3104
n=int(input())
a=list(map(int, input().split()))
ans=0
cnt=[0]*((10**6)+1)
b=[]
for i in a:
    cnt[i]+=1
for i in range((10**6)+1):
    if cnt[i] ==1:
        b.append(i)

cnt=[0]*((10**6)+1)
for s in list(set(a)):
    for i in range(s*2,(10**6)+1,s):
        cnt[i]=1
for s in b:
    if cnt[s]==0:
        ans+=1
print(ans)

Measured memory_bytes: 48300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 60;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


// 入力
int N, K;
ll h[100010];

// DP テーブル
ll dp[101000];

int main() {
    cin >> N >> K;
    rep1(i, N) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    rep1(i, 100010) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (ll i=0; i<N; i++) {
        for (ll j=1; j<=K; j++)
            chmin(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
    }

    // 答え
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 5128
n = gets.chomp.to_i

def digit(i)
  (i % 2 == 0 ? +1 : -1) * (1 << i)
end

def stoi(s)
  n = 0
  
  s.split('').each_with_index do |c, i|
    j = s.size - i - 1
    n += c.to_i * digit(j)
  end
  
  return n
end

def solve(n)
  s = ''
  
  i = 0
  while i < 32 do
    k = n % (1 << (i + 1))
    
    if i % 2 == 0 then
      if k == digit(i) then
        n -= digit(i)
        s = '1' + s
      else
        s = '0' + s
      end
    else
      if k == -digit(i) then
        n -= digit(i)
        s = '1' + s
      else
        s = '0' + s
      end
    end
    
    i += 1
  end
  
  return s.gsub(/^0*/, '')
end

if n == 0 then
  puts '0'
else
  puts solve(n)
end

Measured memory_bytes: 1788
#include <iostream>
using namespace std;
 
int main() {
  int x, y, z;
  cin >> x >> y >> z;;
  int a[x][y], b[y][z];
  long long c[x][z];
  for (int i = 0; i < x; i++) {
    for (int o = 0; o < y; o++) {
      cin >> a[i][o];
    }
  }
  for (int i = 0; i < y; i++) {
    for (int o = 0; o < z; o++) {
      cin >> b[i][o];
    }
  }
  for (int i = 0; i < x; i++) {
    for (int d = 0; d < z; d++) {
      c[i][d] = 0;
    }
  }
  for (int i = 0; i < x; i++) {
    for (int o = 0; o < y; o++) {
      for (int p = 0; p < z; p++) {
        c[i][p] += a[i][o] * b[o][p];
      }
    }
  }
  for (int i = 0; i < x; i++) {
    for (int d = 0; d < z; d++) {
      cout << c[i][d];
      if (d < z - 1) cout << " ";
    }
    cout << endl;
  }
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()

int main(){
    int d, n;
    cin >> d >> n;
    if(n==100)n++;
    while(d--)n*=100;
    cout << n << endl;
    // cout << round( n * pow(100, d) ) << endl;
}

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

int K, S;

int main () {
  cin >> K >> S;
  int count = 0;
  
  for (int x = 0; x <= K; x++){
	for (int y = 0; y <= K; y++){
      if (((S-x-y) <= K) && ((S-x-y) >= 0)) {
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main(){
	int n;
	double p,q,r;
	double a1,a2,b1,b2,c1,c2;
	double x1,x2,x3,y1,y2,y3;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
		a1 = 2*(x2-x1);
		b1 = 2*(y2-y1);
		c1 = (x1*x1)+(y1*y1)-(x2*x2)-(y2*y2);
		a2 = 2*(x3-x1);
		b2 = 2*(y3-y1);
		c2 = (x1*x1)+(y1*y1)-(x3*x3)-(y3*y3);
		p = ((b1*c2)-(b2*c1))/((a1*b2)-(a2*b1));
		q = ((a2*c1)-(a1*c2))/((a1*b2)-(a2*b1));
		r = sqrt(((x1-p)*(x1-p))+((y1-q)*(y1-q)));
		printf("%.3f %.3f %.3f\n",p,q,r);
	}
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int dp[210][210][210];

int loop(int a, int b, int c) {
	if(a > 200 || b > 200 || c > 200) return inf;
	if(dp[a][b][c] != -1) return dp[a][b][c];
	if(a == b && b == c) return 0;
	// debug(a, b, c);
	int res = inf;
	MIN(res, loop(a + 2, b, c));
	MIN(res, loop(a, b + 2, c));
	MIN(res, loop(a, b, c + 2));
	MIN(res, loop(a + 1, b + 1, c));
	MIN(res, loop(a, b + 1, c + 1));
	MIN(res, loop(a + 1, b, c + 1));
	return dp[a][b][c] = res + 1;
}

void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	memset(dp, -1, sizeof(dp));
	cout << loop(a, b, c) << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 36480