akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		private const int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			//System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start();
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			long ans = 0;
			for (int i = 1; i <= n; i++) {
				if (i % 3 != 0 && i % 5 != 0) {
					ans += i;

				}
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
			//System.Diagnostics.Debug.WriteLine(stopwatch.Elapsed);
		}
	}
}


Measured memory_bytes: 27536
N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')
ans = r * g * b
for j in range(1, N - 1):
    for v in range(1, min(j+1, N - j)):
        if S[j - v] != S[j] and S[j + v] != S[j] and S[j - v] != S[j + v]:
            ans -= 1

print(ans)

Measured memory_bytes: 67656
n,m = map(int, input().split())
s = input()
dp = [0]*n
fp = [0]*n
for i in range(1,n):
    if s[i] == "C" and s[i-1] == "A":
        dp[i]+=dp[i-1]+1
        fp[i-1]+=1
    else:dp[i] =dp[i-1]
#print(dp)
for i in range(m):
    tn,tm = map(int, input().split())
    print(dp[tm-1]-dp[tn-1])


Measured memory_bytes: 6900
import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

ans1 = ans2 = ans3 = 0
ans4 = -1

for i in range(n):
	a = math.fabs(x[i] - y[i])
	ans1 += a
	ans2 += a**2
	ans3 += a**3
	ans4 = max(ans4, a) 

print(ans1)
print(ans2**(1./2.))
print(ans3**(1./3.))
print(ans4)


Measured memory_bytes: 5716
// i<j -> j-i = A[i]+A[j] -> j-A[j] = A[i] + i
// なんか解説もtwtterでも解説記事でもぜんぜんわからんかったんだけど
// https://www.cnblogs.com/prjruckyone/p/12825560.html
// を読んだら分かった ありがとう 謝謝 暴力即可

package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		var V int
		fmt.Scan(&V)
		A[i] = V
	}
	X, Y := make(map[int]int), make(map[int]int)
	for i := 1; i <= N; i++ {
		x := A[i-1] + i
		y := i - A[i-1]
		X[x] += 1
		Y[y] += 1
	}
	ans := 0
	for k, v := range X {
		ans += Y[k] * v
	}
	fmt.Println(ans)
}


Measured memory_bytes: 25472
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;


class Main{
	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		//Scanner sc = new Scanner(new FileReader("sample.txt"));
						
		String x=sc.next();
		
		String str;
		int count=0;
		for(;!((str=sc.next()).equals("END_OF_TEXT"));){
			
			if((str.equalsIgnoreCase(x)))count++;
			}sc.close();
			
			System.out.println(count);
		}
		
		}

Measured memory_bytes: 18060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()

const ll mod=1000000007;

int countBits(int in){
  int res=0;
  for(int i=0;i<10;i++){
    int msk=1<<i;
    if((in&msk)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

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);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"consonant":"vowel");
}
int main() {
  char c;cin>>c;
  string v="aiueo";
  bool ans=v.find(c)==string::npos;
  cout<<outputYesNo(ans)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int N, remain;
  scanf("%d", &N);
  if(N%1000==0){
    printf("0\n");
  }else{
    remain = (((N/1000)+1)*1000) - N;
    printf("%d\n", remain);
  }
  return 0;
}


Measured memory_bytes: 1696
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int ans = 0;
		for(int i=0;i<M;i++){
			var UF = new UnionFind(N);
			for(int j=0;j<M;j++){
				if(j == i) continue;
				UF.Unite(A[j],B[j]);
			}
			if(!UF.IsUnited(A[i],B[i])) ans++;
		}
		
		Console.WriteLine(ans);
		
	}
	int N,M;
	int[] A,B;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		A = new int[M];
		B = new int[M];
		for(int i=0;i<M;i++){
			d = ria();
			A[i] = d[0] - 1;
			B[i] = d[1] - 1;
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
class UnionFind{
	
	int[] parent;
	int[] mem;
	int compo;
	int N;
	public UnionFind(int n_){
		Initialize(n_);
	}
	
	public void Initialize(int n_){
		N=n_;
		parent=new int[N];
		mem=new int[N];
		for(int i=0;i<N;i++){
			parent[i]=i;
			mem[i]=1;
		}
		compo=N;
	}
	
	public int Parent(int a){
		if(parent[a]==a)return a;
		return parent[a]=Parent(parent[a]);
	}
	
	public bool IsUnited(int a,int b){
		return Parent(a)==Parent(b);
	}
	
	public void Unite(int a,int b){
		a=Parent(a);b=Parent(b);//Parent()を呼ぶことでa以上のノードは全てparentがrootになる
		if(a==b)return;
		parent[a]=b;
		mem[b]+=mem[a];
		compo-=1;
	}
	
	public bool IsRoot(int x){
		return x==parent[x];
	}
	public int MemCnt(int x){
		return mem[Parent(x)];
	}
	
	public void Dump(){
		for(int i=0;i<parent.Length;i++){
			Console.Write(i==0?"{0}":" {0}",parent[i]);
		}
		Console.WriteLine("");
	}
	
	public int Compo{
		get{
			return compo;
		}
	}
	
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  string t;
  while (t.size() < s.size()) {
    t += "hi";
  }
  if (s == t) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#define maxn 1005
using namespace std;
typedef long long  LL;
map<string,int>mp;
int main()
{
    int n;
    scanf("%d",&n);
    set<int>s;
    while(n--)
    {
        int t;
        scanf("%d",&t);
        if(s.count(t))
        {
            s.erase(t);
        }
        else
            s.insert(t);
    }
    cout<<s.size()<<endl;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a<c&& (c-a)<=b ||a==c)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


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

int n,k;
int input[100000];
int renzoku_num;
int renzoku[200000];

/* syo-zyun */
int qsort_comp(const void* x,const void* y) {
	int* a=(int*)x;
	int* b=(int*)y;
	if(*a>*b)return 1;
	if(*a<*b)return -1;
	return 0;
}

int main(void) {
	int i;
	int now_renzoku;
	int result;
	int now_ans;
	while(1) {
		scanf("%d%d",&n,&k);
		if(n==0 && k==0) break;
		for(i=0;i<k;i++)scanf("%d",&input[i]);
		qsort(input,k,sizeof(int),qsort_comp);
		renzoku_num=1;
		now_renzoku=0;
		for(i=(input[0]==0?2:1);i<k;i++) {
			if(input[i-1]+1!=input[i]) {
				renzoku[renzoku_num++]=now_renzoku;
				if(input[i-1]+2!=input[i] || input[0]!=0) {
					renzoku[renzoku_num++]=0;
				}
				now_renzoku=1;
			} else now_renzoku++;
		}
		renzoku[renzoku_num++]=now_renzoku;
		result=renzoku[0];
		for(i=1;i<renzoku_num;i++) {
			now_ans=renzoku[i-1]+renzoku[i];
			if(renzoku[i-1] && renzoku[i])now_ans++;
			if(now_ans>result)result=now_ans;
		}
		printf("%d\n",result);
	}
	return 0;
}

Measured memory_bytes: 904
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    vector<vector<char>> field(100, vector<char>(100));
    for(int i = 0; i < 100; i++)
    {
        for(int j = 0; j < 100; j++)
        {
            if(i < 50)
            {
                field[i][j] = '.';
            }
            else
            {
                field[i][j] = '#';
            }
        }
    }
    a--;
    b--;

    bool flag = false;
    if(a != 0)
    {
        for(int i = 51; i < 100; i += 2)
        {
            for(int j = 0; j < 100; j += 2)
            {
                field[i][j] = '.';
                a--;
                if(a == 0)
                {
                    flag = true;
                    break;
                }
            }
            if(flag) break;
        }
    }
    flag = false;
    if(b != 0)
    {
        for(int i = 0; i < 49; i += 2)
        {
            for(int j = 0; j < 100; j += 2)
            {
                field[i][j] = '#';
                b--;
                if(b == 0)
                {
                    flag = true;
                    break;
                }
            }
            if(flag) break;
        }
    }
    cout << 100 << " " << 100 << endl;
    for(int i = 0; i < 100; i++)
    {
        for(int j = 0; j < 100; j++)
        {
            cout << field[i][j];
        }
        cout << endl;
    }
}



Measured memory_bytes: 256
import collections

def main():
    N = int(input())
    S = []
    [S.append(input()) for i in range(N)]
    c = collections.Counter(S)
    l = ["AC", "WA", "TLE", "RE"]
    
    for i in l:
        print(i, "x", c[i])

if __name__ == "__main__":
    main()

Measured memory_bytes: 17364
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <functional>
using namespace std;

int main() {
	long double A, B; cin >> A >> B;
	printf("%.12Lf\n", 1.0L*A / B);
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class CLowElements {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      int mi = INT_MAX;
      int ret = 0;
      rep(i, n) {
        int a; cin >> a;
        if (chmin(mi, a)) ret++;
      }
      cout << ret << endl;
    }
};

signed main() {
  CLowElements solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

using namespace std;

int main() {
    long long A, B, C;
    cin >> A >> B >> C;

    long long u = min(B, C);
    long long ans = 2 * u;
    B -= u;
    C -= u;

    long long w = min(A, C);

    ans += w;

    A -= w;
    C -= w;

    ans += B;
    ans += C > 0 ? 1 : 0;

    cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};



int main(){
    Stream io;

    string N;
    io.read(N);
    int sum = 0;
    for(int i = 0; i < N.size(); i++){
        sum += N[i] - '0';
    }

    if(sum % 9 == 0) cout << "Yes";
    else cout << "No";

    return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  std::string S, T;
  std::cin >> S;
  std::cin >> T;
  std::cout << T << S << std::endl;
  return 0;
}


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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int N = 2e5 + 10;
const int INF = 1e9;

int n, a[N];

int cost(int a, int s) {
    if (s == 0 || s == 4) return a;
    if (s == 1 || s == 3) return max(2-a, int(a%2 == s%2));
    if (s == 2) return int(a%2 == s%2);
}

int memo[N][5];
int go(int from, int stage) {
    if (stage >= 5) return INF;
    if (from >= n) return 0;

    int &res = memo[from][stage];
    if (res != -1) return res;

    res = go(from,stage+1);
    res = min(res, go(from+1, stage) + cost(a[from], stage));
    return res;
}

int main() {
    scanf("%d", &n);
    forn(i,n) scanf("%d", &a[i]);

    memset(memo, -1, sizeof memo);
    cout << go(0,0) << endl;
    return 0;
}


Measured memory_bytes: 14336
n = gets.to_i
ans = "false"
for i in 0..100
  for j in 0..100
    if i*7+j*4 == n 
      puts "Yes"
      ans = "true"
      break
    end
  end
  if ans == "true"
      break
  end
end
if ans == "false"
  puts "No"
end

Measured memory_bytes: 1788
n = int(input())
dic = [[] for i in range(n)] 
for i in range(n-1):
    inf = input().split()
    u = int(inf[0])
    v = int(inf[1])
    w = int(inf[2])
    dic[u-1] += [(v-1, w)]
    dic[v-1] += [(u-1, w)] 
    
dist = [-1]*n
stack = []
stack.append(0)
dist[0] = 0 

while stack:
    label = stack.pop(-1) 
    #print(label, dic[label])
    for i, c in dic[label]: 
        if dist[i] == -1: 
            dist[i] = dist[label]+c
            stack += [i]
            
print(0)
for i in range(1,n):
    if dist[i]%2==0:
        print(0)
    else:
        print(1)

Measured memory_bytes: 42796
#pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")
         
        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
         
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;
         
        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
        const int N=300006;
        int unread[N],d[N];
        signed main()
        {
        	int n,m;
        	cin>>n>>m;
        	cout<<n*(n-1)/2+m*(m-1)/2;
		}

Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b,a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

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

	int cnt = 0;
	ll a;
	while (1) {
		a = pow(2, cnt);
		if (a <= N) {
			cnt++;
			continue;
		}
		else break;
	}

	cout << a/2 << endl;
}

Measured memory_bytes: 256
#powは繰り返し2乗法により指数計算を行う関数
mod=10**9+7
n,a,b=map(int,input().split())
ans=pow(2,n,mod)-1 #n種類の花を使って花束を作る総数は2^n-1通り

comb1=1 #nCaの計算
for i in range(n-a+1,n+1): #n*(n-1)*…*(n-a+1)を計算
 comb1*=i
 comb1%=mod
for i in range(1,a+1): #1/a!=1/(1*2*…*a)=1^(p-2)*2^(p-2)*…*a^(p-2) (p=10**9+7)を計算
 comb1*=pow(i,mod-2,mod)
 comb1%=mod

comb2=1  # nCbの計算
for i in range(n-b+1,n+1): #n*(n-1)*…*(n-b+1)を計算
 comb2*=i
 comb2%=mod
for i in range(1,b+1): #1/b!=1/(1*2*…*b)=1^(p-2)*2^(p-2)*…*b^(p-2) (p=10**9+7)を計算
 comb2*=pow(i,mod-2,mod)
 comb2%=mod
ans-=(comb1+comb2) #nCa、nCbを総数から引く
ans%=mod
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

int main() {
	int n;
	int k;
	cin >> n >> k;
	vector<int> d(k+2);
	d[0] = -1;
	for (int i = 1; i <=k; i++) {
		cin >> d[i];
	}
	d[k + 1] = 10;

	vector<int> l;
	


	for (int i = 0; i <= k; i++) {
		for (int j = d[i] + 1; j < d[i + 1];j++) {
			l.emplace_back(j);
			
		}
	}
	
	int ans;
	for (int i = n; i < n * 10;i++) {
		bool canPay = true;
		int num = i;
		while (num > 0) {
			int tmp = num % 10;
			bool cp = false;
			for (int j = 0; j < 10 - k; j++) {
				if (tmp == l[j]) {
					cp = true;
					break;
				}
			}

			if (!cp) {
				canPay = false;
				break;
			}
			num /= 10;
		}
		if (canPay) {
			ans = i;
			break;
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


int main(){
    int N,D,X; cin >> N >> D >> X;
    vector<int> A(N);
    int ans = X;
    int a;
    for(int i=0; i<N ;i++){
        cin >> a;
        ans += (D-1)/a+1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
ll n,k,ans=0;
string s;
void Main(){    
    cin>>n>>k>>s;
    vector<ll> bound;
    bound.push_back(0);
    For(i,1,n){
        if(s.at(i-1)!=s.at(i)){
            bound.push_back(i);
        }
    }
    ll l=bound.size();
    For(i,0,200000){
        bound.push_back(n);
    }
    for(ll i=0;i<l;i++){
        //cout<<ans<<endl;
        if(s.at(bound.at(i))=='0'){
            ans=max(ans,bound.at(i+2*k)-bound.at(i));
        }
        else {
            ans=max(ans,bound.at(i+2*k+1)-bound.at(i));
        }        
    }
    cout<<ans<<endl;         
}
int main(){
    Main();
    return 0;
}


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

t = [-1] * (N + 1)
t[0] = 1000
for i in range(N):
    t[i + 1] = max(t[i + 1], t[i])
    k = t[i] // A[i]
    y = t[i] % A[i]
    for j in range(i + 1, N):
        t[j + 1] = max(t[j + 1], k * A[j] + y)
print(t[N])


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

int main() {
    int n, x, y; scanf("%d%d%d", &n, &x, &y);
    vector<int> c(n), w(n);
    vector<vector<int>> ball(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d", &c[i], &w[i]);
        c[i]--;
        ball[c[i]].push_back(i);
    }
    vector<int> uf(n);
    for (int i = 0; i < n; ++i) uf[i] = i;

    function<int(int)> Find = [&](int x) {
        if (x == uf[x]) return x;
        return uf[x] = Find(uf[x]);
    };

    auto Merge = [&](int x, int y) {
        uf[Find(x)] = Find(y);
    };

    vector<int> pv;
    for (int i = 0; i < n; ++i) {
        if (ball[i].empty()) continue;
        sort(ball[i].begin(), ball[i].end(), [&](int x, int y) { return w[x] < w[y]; });
        for (int j = 1; j < ball[i].size(); ++j) {
            if (w[ball[i][j]] + w[ball[i][0]] > x) break;
            Merge(ball[i][j], ball[i][0]);
        }
        pv.push_back(ball[i][0]);
    }

    sort(pv.begin(), pv.end(), [&](int i, int j) { return w[i] < w[j]; });
    for (int i = 1; i < pv.size(); ++i) {
        if (w[pv[i]] + w[pv[0]] > y) break;
        Merge(pv[i], pv[0]);
    }

    int gd = -1;
    for (int i = 0; i < n; ++i) {
        int j = -1;
        for (int d = 20; d >= 0; --d) {
            if (j + (1 << d) >= pv.size()) continue;
            if (w[pv[j + (1 << d)]] + w[i] <= y) j += (1 << d);
        }
        while (j >= 0 && c[pv[j]] == c[i]) j--;
        if (j != -1) {
            Merge(i, pv[j]);
            gd = max(gd, j);
        }
    }
    for (int i = 1; i < gd; ++i) Merge(pv[i], pv[0]);

    // for (int i = 0; i < n; ++i) {
        // for (int j = 0; j < n; ++j) {
            // if (j == c[i] || ball[j].empty()) continue;
            // if (w[ball[j][0]] + w[i] <= y) Merge(ball[j][0], i);
        // }
    // }

    vector<map<int, int>> cnt(n);
    for (int i = 0; i < n; ++i) cnt[Find(i)][c[i]]++;

    constexpr int kMod = 1'000'000'000 + 7;
    
    auto fpow = [&](int a, int n) {
        int res = 1;
        while (n > 0) {
            if (n & 1) res = 1LL * res * a % kMod;
            a = 1LL * a * a % kMod;
            n >>= 1;
        }
        return res;
    };

    vector<int> fc(n + 1, 1), iv(n + 1, 1);
    for (int i = 1; i <= n; ++i) fc[i] = 1LL * fc[i - 1] * i % kMod;
    iv[n] = fpow(fc[n], kMod - 2);
    for (int i = n - 1; i > 0; --i) iv[i] = 1LL * iv[i + 1] * (i + 1) % kMod;

    int ans = 1;
    for (int i = 0; i < n; ++i) {
        if (Find(i) != i) continue;
        int s = 0, p = 1;
        for (auto it : cnt[i]) {
            s += it.second;
            p = 1LL * p * iv[it.second] % kMod;
        }
        p = 1LL * p * fc[s] % kMod;
        ans = 1LL * ans * p % kMod;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 32372
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] " << endl;
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    if (n == 3)
    {
        cout << 2 << endl;
        cout << 1 << " " << 3 << endl;
        cout << 2 << " " << 3 << endl;
        return 0;
    }
    int m;

    if (n % 2 == 0)
    {
        m = (n - 2) * n / 2;
        cout << m << endl;
        rep(i, n) rep(j, i + 1, n)
        {
            if (i == j || (i + 1) + (j + 1) == n + 1)
                continue;
            cout << i + 1 << " " << j + 1 << endl;
        }
        return 0;
    }
    else
    {
        m = (n - 3) * (n - 1) / 2 + (n - 1);
        cout << m << endl;
        rep(i, n - 1) rep(j, i + 1, n - 1)
        {
            if (i == j || (i + 1) + (j + 1) == n)
                continue;
            cout << i + 1 << " " << j + 1 << endl;
        }
        rep(i, n - 1)
        {
            cout << n << " " << i + 1 << endl;
        }
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
h=list(map(int, input().split()))
dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1])
print(dp[n-1])
                 

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

int main() {
    long long N, x;
    cin >> N >> x;

    if(x == 1 || x == 2 * N - 1) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        if(N == 2) {
            for(int i=1; i<=3; ++i) cout << i << endl;
        } else if(x == 2) {
            long long cur = 5;
            for(int i=0; i<N-2; ++i) {
                cout << cur << endl;
                ++cur;
            }
            cout << 3 << endl;
            cout << 2 << endl;
            cout << 1 << endl;
            cout << 4 << endl;
            for(int i=0; i<N-3; ++i) {
                cout << cur << endl;
                ++cur;
            }
        } else {
            long long cur = (x > 3 ? 1 : 5);
            for(int i=0; i<N-2; ++i) {
                cout << cur << endl;
                ++cur;
                if(cur == x - 2) cur = x + 2;
            }
            cout << x - 1 << endl;
            cout << x << endl;
            cout << x + 1 << endl;
            cout << x - 2 << endl;
            for(int i=0; i<N-3; ++i) {
                cout << cur << endl;
                ++cur;
                if(cur == x - 2) cur = x + 2;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1536
import math
n = int(input())
a = list(map(int,input().split()))
alice = 0
Bob = 0

list.sort(a, reverse=True)
for i in range(math.ceil(n/2)):
	alice += a[i*2]
for i in range(math.floor(n/2)):
	Bob += a[i*2 + 1]
print(alice - Bob)

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

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

 int checkG = 0;
 int checkK = 0;
 string Ans;

 int leng = S.length();


 for(int i = 0; i < leng; i++) {
	if(i%2 == 0) {
		if(S[i] == 'L') {
			checkG = 1;
		}
	} else {
		if(S[i] =='R') {
			checkK = 1;
		}
	}
 }

 if (checkG == 0 && checkK == 0) {
	Ans = "Yes";
 } else {
	Ans = "No";
 }
  

 cout << Ans << endl;
}

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

using namespace std;
using ll = long long;
int main() {
    char str[500005];
    int zero = 200001;
    string s;
    cin >> s;
    int i;
    for(i=0;i<s.size();i++)
        str[zero+i] = s[i];
    int end = zero + s.size() - 1;
    int q;
    cin >> q;
    int f = 0;
    // f = 1 means zero is on higher index
    while(q--)
    {
        int num;
        cin >> num;
        if(num == 1)
        {
            int temp = zero;
            zero = end;
            end = temp;
            f = 1-f;
        }
        else
        {
            int val;
            char c;
            cin >> val;
            cin >> c;
            if(val == 1)
            {
                if(f == 0)
                {
                    str[--zero] = c;
                }
                else
                {
                    str[++zero] = c;
                }
            }
            else if(val == 2)
            {
                if(f == 0)
                {
                    str[++end] = c;
                }
                else
                {
                    str[--end] = c;
                }
            }
        }
    }
    if(f == 0)
    {
        for(i=zero;i<=end;i++)
            cout << str[i];
        cout << '\n';    
    }
    else
    {
        for(i=zero;i>=end;i--)
            cout << str[i];
        cout << '\n';    
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
using namespace std;

int main() {
	int a; cin >> a;
	vector<int> vc(100010,0);
	REP(i, a) { int tmp; cin >> tmp;	vc[tmp]++; if(tmp) vc[tmp - 1]++; if(tmp<=100000)vc[tmp + 1]++; }
	cout << *max_element(vc.begin(), vc.end()) << endl;
}

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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >>d;
    
    while(1){
        c -= b;
        if(c <= 0){cout << "Yes" << endl; break;}
        a -= d;
        if(a <= 0){cout << "No" << endl; break;}
    }
    
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repr(i, n) for (ll i = (n); i >= 0; --i)
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define FORR(i, m, n) for (ll i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;
const int MAX = 1e5;


ll modpow(ll a,ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ll h, w, a, b;
  cin >> h >> w >> a >> b;

  vector<ll> r(MAX + 1);
  rep(i, MAX + 1) r[i] = modpow(i, mod - 2);

  ll res = 1;
  vector<ll> c1(h - a);
  rep(i, h - a) {
    c1[i] = res;
    res = (res * (b + i)) % mod;
    res = (res * r[i + 1]) % mod;
  }

  res = 1;
  FOR(i, a + 1, w - b + a) res = (res * i) % mod;
  FOR(i, 1, w - b) res = (res * r[i]) % mod;
  vector<ll> c2(h - a);
  rep(i, h - a) {
    c2[h - a - 1 - i] = res;
    res = (res * (w - b + a + i)) % mod;
    res = (res * r[a + 1 + i]) % mod;
  }

  ll ans = 0;
  rep(i, h - a) {
    ll comb = c1[i] * c2[i] % mod;
    ans = (ans + comb) % mod;
  }
  cout << ans << endl;

  
  



  
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    long long ans = 0;
    int count = 0, iter = 0;
    for (int i = 0; i < n; i++){
        if (i == 0) {
            count++;
            continue;
        }

        if (count == 0) {
            ans += v[iter];
            count++;
        } else {
            ans += v[iter];
            iter++;
            count = 0;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 4312
### constant

MAX_H = MAX_W = 150

### main

rects = []

for h in (1..MAX_H)
  for w in ((h + 1)..MAX_W)
    rects << [h * h + w * w, h, w]
  end
end
rects.sort!

loop do
  h, w = gets.split.map(&:to_i)
  break if (h | w) == 0

  d = h * h + w * w
  i = rects.index([d, h, w])

  dj, hj, wj = rects[i + 1]
  puts [hj, wj].join(' ')
end

Measured memory_bytes: 6308
s = input()
check = ["A", "C", "G", "T"]

output = 0
count = 0
for i in range(len(s)):
	if s[i] in check:
		count += 1
		if i == len(s)-1:
			output = max(output, count)
	else:
		output = max(output, count)
		count = 0

print(output)

Measured memory_bytes: 3060
package main

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

func main() {
	var cat   = 0
	var max   = 0
	var min   = 0
	var total = 0
	var sc    = bufio.NewScanner(os.Stdin)
	if sc.Scan() {
		var input = strings.Split(sc.Text(), " ")
		cat, _    = strconv.Atoi(input[0])
		max, _    = strconv.Atoi(input[1])
	}

	for i := 0; i < cat; i++ {
		if sc.Scan() {
			var gram, _  = strconv.Atoi(sc.Text())
			total += gram

			if min == 0 {
				min = gram
			} else {
				if gram < min {
					min = gram
				}
			}
		}
	}

	fmt.Println((max - total) / min + cat)

}

Measured memory_bytes: 640
object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)
    val w = scanner.next.toLowerCase()
    var c = 0
    while(true) {
      val t = scanner.next
      if(t.equals("END_OF_TEXT")) {
        println(c)
        System.exit(0)
      }
      if(w.equals(t.toLowerCase())) c = c + 1
    }
  }
}



Measured memory_bytes: 44924
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }

  int prev = h.at(0);
  int count = 0;
  int max = 0;
  for (int i = 1; i < n; i++) {
    int current = h.at(i);
    if (current <= prev) {
      count++;
    } else {
      if (count > max) {
        max = count;
      }
      count = 0;
    }
    prev = current;
  }
  if (count > max) {
    max = count;
  }

  cout << max << endl;
  return 0;
}


Measured memory_bytes: 640
n = int(input())
s = [0]*n
for i in range(n):
    s[i] = list(input())
t = [0]*n
for i in range(n):
    s[i][:] = sorted(s[i][:])
    t[i] = "".join(s[i][:])
import collections
c = collections.Counter(t)
ans = 0
for T in t:
    if c[T] >= 2:
        ans += c[T]-1
print(ans//2)

Measured memory_bytes: 40968
N = int(input())
li = list(map(int,input().split()))
bo = 0
shi = 1
for i in range (N):
    shi *= li[i]
for i in range(N):
    k = 1
    m = 1
    for j in range(i):
        k *= li[j]
    for n in range(i+1,N):
        m *= li[n]
    bo += k*m
print('{:.10g}'.format(shi/bo))


Measured memory_bytes: 39408
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define INF			100000000000000000
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  404

ll n;
ll a[N];
ll dp[N][N];
ll pre[N];

ll getval(ll st, ll en){
	if(st>en)return 0;
	if(st==en)return a[st];
	return pre[en]-pre[st-1];
}

ll solve(ll st, ll en){
	if(dp[st][en]!=-1)return dp[st][en];
	if(st==en)return dp[st][en]=0;
	ll ret=INF;
	rep(i,st,en){
		ll left=0;
		if(i>st)left=solve(st,i);
		ll right=solve(i+1,en);
		ll ans = left+right;
		ans+=getval(st,i);
		ans+=getval(i+1,en);
		ret=min(ret,ans);
	}
	// cerr<<st<<" "<<en<<" "<<ret<<endl;
	return dp[st][en]=ret;
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	rep(i,0,N)rep(j,0,N)dp[i][j]=-1;	
	while(TESTS--)
	{
		cin>>n;
		rep(i,0,n)cin>>a[i+1];
		pre[1]=a[1];
		rep(i,2,n+1)pre[i]=pre[i-1]+a[i];
		cout<<solve(1,n)<<endl;
		// cout<<getval(3,4)<<endl;

	}
	return 0;
}

Measured memory_bytes: 4932
#include <iostream>
#include <set>
#include <cstdio>

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

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

using namespace std;

int t[20][20];
int h, w;

bool ok(int x, int y){
  if(x < 0 || y < 0) return true;
  if(x >= w - 1 || y >= h - 1) return true;
  set<int> s;
  REP(i,2) REP(j,2){
    s.insert(t[y + i][x + j]);
  }
  if(s.count(0)) return true;
  return s.size() != 4;
}

int solve(int pos, int id){
  if(pos == h * w){
    // REP(i,h){ REP(j,w) printf("%2d ", t[i][j]); puts(""); } puts("");
    return 1;
  }
  int x = pos % w;
  int y = pos / w;
  if(t[y][x]) return solve(pos + 1, id);

  int ret = 0;
  if(x != w - 1 && !t[y][x + 1]){
    t[y][x] = t[y][x + 1] = id;
    if(ok(x - 1, y - 1))
      ret += solve(pos + 1, id + 1);
    t[y][x] = t[y][x + 1] = 0;
  }
  if(y != h - 1 && !t[y + 1][x]){
    t[y][x] = t[y + 1][x] = id;
    if(ok(x - 1, y - 1))
      ret += solve(pos + 1, id + 1);
    t[y][x] = t[y + 1][x] = 0;
  }
  return ret;
}

int main(){
  while(true){
    h = getInt();
    w = getInt();

    if(h + w == 0) break;

    printf("%d\n", solve(0, 1));
  }
  return 0;
}

Measured memory_bytes: 884
#include<iostream>

long long mod=1000000007;
int prime[1005];
int vi[1005];
int main(){
    int n;
    std::cin>>n;
    int cnt=0;
    long long ans=1;
    for(int i=2;i<=n;i++){
        if(!vi[i])
            prime[cnt++]=i;
        for(int j=0;j<cnt;j++){
            if(i*prime[j]>n)
                break;
            vi[i*prime[j]]=1;
            if(i%prime[j]==0)
                break;
        }
    }
    long long num[1005]={0};
    for(int i=2;i<=n;i++){
        int nu=i;
        for(int j=0;j<cnt;j++){
            if(nu==1)
                break;
            else{
                while(nu%prime[j]==0){
                    nu/=prime[j];
                    num[prime[j]]++;
                }
            }
        }
    }
    for(int i=0;i<cnt;i++){
        ans*=num[prime[i]]+1;
        ans%=mod;
    }
    std::cout<<ans<<std::endl;
}

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

struct UnionFind
{
    vector<int> par;
    UnionFind(int n) : par(n, -1){ }
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool issame(int x, int y){
        return root(x) == root(y);
    }
    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    UnionFind uf(n);
    for (int i = 0; i < q; i++)
    {
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0) uf.merge(x, y);
        else if(uf.issame(x, y)) cout << "1" << endl;
        else cout << 0 << endl;
    }

}


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

int main() {
	int n, m;
	cin >> n >> m;
	multiset<int, greater<int> > s;
	vector<pair<int, int>> v;
	for (int i = 0; i < n; ++i) {
		int A, B;
		cin >> A >> B;
		v.push_back( { A, B });

	}
	int j = 0;
	sort(v.begin(), v.end());
	long long res = 0;
	for (int i = 1; i <= m; i++) {
		while (j < n && v[j].first == i) {
			s.insert(v[j].second);
			j++;
		}
		if (s.size()) {
			res += *s.begin();
			s.erase(s.begin());
		}
	}
	cout << res;
	return 0;
}
/*
 *
 * 1 4
 * 1 4
 * 1 2
 * 2 3
 * 2 2
 * 2 1
 * 3 3 j
 * 3 4
 * 3 1
 1=>  4 2
 2=>
 3=> 3 4 1 2 3 1 2
 4+4+4
 */


Measured memory_bytes: 5620
/**
 *    Author:  "Robin Singh" !!!!    
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define szz(v) ((int)(v).size())  
#define vi vector<int>
#define vll vector<ll>
#define fr(i, j, k) for(i = j; i < k; i++)
#define bk(i, j, k) for(i = j; i >= k; i--)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0 //
#define rtn return 
#define time fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC)
#define nl "\n"
#define INF 1LL<<61
#define inf 1<<31
#define dbg(x) (cerr << #x << ": " << x << "\n")
const long long mod = 998244353;

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }
ll expo(ll x, ll y){ ll res = 1; x = x % mod;  while (y > 0) { if (y & 1)res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }

const int nn = 3e5+10;
ll fact[nn], ifact[nn];

ll ncr(ll N, ll r)
{
    ll res;
    res = ( ( (fact[N] * ifact[r]) %mod )* ifact[N-r] )%mod;
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll N, A, B, K, ans = 0;
    cin >> N >> A >> B >> K;
    
    fact[0] = 1;
    ifact[0] = 1;
    for(int i=1; i<=N; i++)
    {
        fact[i] = (fact[i-1]*i)%mod;
        ifact[i] = expo(fact[i], mod-2);
    }
    
    for(int a=0; a<=N; a++)               // A*a + B*b == K
    {
        if(K - a*A < 0) break;
        if( (K-A*a) % B == 0)
        {
            int b = (K - A*a)/B;
            if(b <= N)
                ans = (ans + ncr(N,a)*ncr(N,b))%mod;
        }
    }
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 4992
N = int(input())
 
testimony = [[] for _ in range(N)]
 
for i in range(N):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1, state])
        
honest = 0
for i in range(1, 2**N):
    flag = 0
    for j in range(N):
        if (i>>j)&1 == 1: # j番目は正直と仮定
            for x,y in testimony[j]:
                if (i>>x)&1 != y: # j番目は正直だが矛盾を発見
                    flag = 1
                    break
    if flag == 0:  # 矛盾がある場合はflag == 1になる
        honest = max(honest, bin(i)[2:].count('1'))  # 1の数をカウントし最大となるものを選択
print(honest)

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int A,P; cin>>A>>P;
  P+=A*3;
  cout<<P/2<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

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

inline bool simu(const ll k, ll n) {
    while (n>1) {
        if (n%k==0) n = n/k;
        else {
            n = n%k;
            break;
        }
    }
    if (n==1) return true;
    else return false;
}

int main(int argc, char const *argv[]) {
    ll n; cin>>n;
    set<ll> st;
    ll m = n-1;
    for (ll i = 1; i * i <= n; ++i) {
        if (n%i == 0) {
            st.insert(i);
            st.insert(n/i);
        }
    }

    for (ll i = 1; i*i <= m; ++i) {
        if (m%i == 0) {
            st.insert(i);
            st.insert(m/i);
        }
    }
    st.erase(1); 
    ll ans = 0;

    for (auto &&e: st) {
        if (simu(e,n)) {
            ans++;
        }
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(17);
  int n; cin >> n;
  map<string, int> mpp;
  string s, pre;
  cin >> s;
  mpp[s]++;
  for(int i = 1; i < n; i++){
    pre = s;
    cin >> s;
    if(mpp[s]){
      cout << "No\n";
      return 0;
    }
    if(s[0] != pre[pre.size()-1]){
      cout << "No\n";
      return 0;
    }
    mpp[s]++;
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 256