akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

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

  int n, m;
  cin >> n >> m;
  vi h(n), good(n, 1);
  rep(i, 0, n)
  {
    cin >> h[i];
  }
  rep(i, 0, m)
  {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if (h[x] <= h[y])
      good[x] = 0;
    if (h[y] <= h[x])
      good[y] = 0;
  }
  int ans = 0;
  rep(i, 0, n)
  {
    ans += good[i];
  }
  cout << ans << endl;

  // rep(i, 0, n)
  // {
  //   cout << "good[i]:" << good[i] << endl;
  // }
  // rep(i, 0, n)
  // {
  //   cout << "h[i]:" << h[i] << endl;
  // }
  return 0;
}

Measured memory_bytes: 3988
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

char s[100002];
int main() {
	scanf("%s",s+1);
	int n=strlen(s+1);
	if(s[n]=='1' || s[1]=='0')return !printf("-1");
	bool ok=1;
	fup(i,1,n/2,1)
	{
		if(s[i]!=s[n-i])return !printf("-1");
	}
	Vi v;
	fup(i,1,n,1)if(s[i]=='1')v.pb(i);
	int k=v.size();
	fup(i,2,k+1,1)printf("%d %d\n",i-1,i);
	int now=k+2;
	fup(i,1,k-1,1)
	{
		int t=v[i]-v[i-1]-1;
		while(t--)
		{
			printf("%d %d\n",i+1,now++);
		}
	}
}

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

 
int main() {
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(a-x)>abs(b-x))cout<<'B'<<endl;
    else cout<<'A'<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
const int maxn=105;
struct p {int x,y;} a[105],b[105];
namespace Dinic {
	struct edge {
		int u,v,c,f;
	};
	std::vector<edge> edges;
	std::vector<int> g[2*maxn];
	inline void add_edge(int u,int v,int c) {
		int size=edges.size();
		edges.push_back((edge){u,v,c,0});
		edges.push_back((edge){v,u,0,0});
		g[u].push_back(size);
		g[v].push_back(size+1);
	}
	int s,t,d[2*maxn];
	inline bool bfs() {
		memset(d,-1,sizeof(d));
		std::queue<int> q;
		d[s]=0;
		q.push(s);
		while(q.size()) {
			int x=q.front();q.pop();
			for(int i=0;i<g[x].size();++i) {
				edge &e=edges[g[x][i]];
				if(d[e.v]==-1&&e.f<e.c) {
					d[e.v]=d[x]+1;
					q.push(e.v);
				}
			}
		}
		return d[t]!=-1;
	}
	int cur[2*maxn];
	int dfs(int x,int a) {
		if(x==t||a==0) return a;
		int flow=0,f;
		for(int &i=cur[x];i<g[x].size();++i) {
			edge &e=edges[g[x][i]];
			if(d[e.v]==d[x]+1&&(f=dfs(e.v,std::min(e.c-e.f,a)))>0) {
				flow+=f;
				a-=f;
				e.f+=f;
				edges[g[x][i]^1].f-=f;
				if(a==0) break;
			}
		}
		return flow;
	}
	inline int solve(int ss,int tt) {
		s=ss;t=tt;
		int ans=0;
		while(bfs()) {
			memset(cur,0,sizeof(cur));
			ans+=dfs(s,INT_MAX);
		}
		return ans;
	}
}
int main() {
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i) {
		scanf("%d%d",&a[i].x,&a[i].y);
		Dinic::add_edge(0,i,1);
	}
	for(int i=1;i<=n;++i) {
		scanf("%d%d",&b[i].x,&b[i].y);
		Dinic::add_edge(i+n,n*2+1,1);
	}
	for(int i=1;i<=n;++i) {
		for(int j=1;j<=n;++j) {
			if(a[i].x<b[j].x&&a[i].y<b[j].y) {
				Dinic::add_edge(i,j+n,1);
			}
		}
	}
	printf("%d\n",Dinic::solve(0,2*n+1));
	return 0;
}


Measured memory_bytes: 512
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) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        int n = Integer.parseInt(tokenizer.nextToken());
        int x = Integer.parseInt(tokenizer.nextToken());
        int t = Integer.parseInt(tokenizer.nextToken());
        int time = (n / x) * t;
        if (n % x != 0) time += t;

        out.println(time);

        out.close();
    }
}

Measured memory_bytes: 32680
#import <stdio.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    int v = 1;
    for (int i=0;i<n;i++) {
        v = MIN(2*v,v+k);
    }
    printf("%d",v);
}


Measured memory_bytes: 2164
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    int V;
    cin >> V;
    ll edges = 0;
    for(int i = 0; i < V - 1; ++i){
        int a, b;
        cin >> a >> b;
        edges += 1LL * min(a, b) * (V - max(a, b) + 1);
    }
    cout << 1LL * V * (V + 1) * (V + 2) / 6 - edges << endl;
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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


Measured memory_bytes: 3656
#include <bits/stdtr1c++.h>

using namespace std;

#define INP "solve"
#define OUT "solve"

const int QQ = 3e5 + 10;
const int maxN = 5e5;
const int maxM = 3e5 + 10;
const int oo = 2e9;
const int module = 1e9 + 7;
const long double du = 1e-9;

void doc() {
    freopen(INP ".inp","r",stdin);
    freopen(OUT ".out","w",stdout);
}

void solve() {
    int n;
    cin >> n;
    cout << n * n * n;
}
int main(int argc,char *argv[]) {
    //srand(time(nullptr));
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    //doc();
    solve();
}


Measured memory_bytes: 256
// include headers{{{
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*}}}*/
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;


string s;
int ans = 0;


int main() {
    cin >> s; size_t len = s.length();
    queue<char> _queue;

    rep (i, len) {
        if (_queue.size() == 0) {
            // cout << "push" << endl;
            _queue.push(s[i]);
            continue;
        }
        else if (_queue.front() != s[i]) {
            // cout << "pop" << endl;
            _queue.pop();
            ans += 2;
            continue;
        }
        else {
            // cout << "push" << endl;
            _queue.push(s[i]);
            continue;
        }
    }

    // for (; !_queue.empty(); _queue.pop()) {
    //     cout << _queue.front() << endl;
    // }

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



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

int main()
{
	char c[1024];
	while(cin.getline(c, sizeof(c))){
		for(int i=0;i<1024;i++)
			if(c[i]>='a' && c[i]<='z')
				c[i] = static_cast<char>(c[i]-32);
		cout << c << endl;
	}
	return 0;
}

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

int main(){
    vector<int> a(3);
    for (int i=0;i<3;i++) scanf("%d",&a[i]);
    sort(a.begin(),a.end());
    printf("%d %d %d\n",a[0],a[1],a[2]);
    return 0;
}


Measured memory_bytes: 3248
//package AtCoder;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		int w=sc.nextInt();
		
		int weight[]=new int[n];
		int value[]=new int[n];
		
		for(int i=0;i<n;i++)
		{
			weight[i]=sc.nextInt();
			value[i]=sc.nextInt();
		}
		
		long[][] ans=new long[n][w+1];
		
		for(int i=0;i<n;i++)
		{
			ans[i][0]=weight[i];
		}
		
		for(int i=0;i<n;i++)
		{
			for(int j=1;j<=w;j++)
			{
				if(i==0)
				{
					if(j>=ans[i][0])
					ans[i][j]=value[i];
				}
				else
				{
					if(j<ans[i][0])
						ans[i][j]=ans[i-1][j];
					else
					{
						int left=(int)(j-ans[i][0]);
						if(left==0)
							ans[i][j]=Math.max(value[i], ans[i-1][j]);
						else
							ans[i][j]=Math.max(value[i]+ans[i-1][left], ans[i-1][j]);
					}
				}
			}
		}
		
		
		
		
		
		
		
		
//		for(int i=0;i<n;i++)
//		{
//			for(int j=0;j<=w;j++)
//			{
//				System.out.print(ans[i][j]+" ");
//			}
//			System.out.println();
//		}
		
		System.out.println(ans[n-1][w]);

	}

}


Measured memory_bytes: 127572
from collections import deque

H, W = map(int, input().split())
A = [input() for _ in range(H)]

minDist = [[10**10] * W for _ in range(H)]
que = deque([])
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            que.append((h, w, 0))
            minDist[h][w] = 0

while que:
    h, w, d = que.popleft()

    if minDist[h][w] < d:
        continue
    minDist[h][w] = d

    for dh, dw in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
        if 0 <= dh + h < H and 0 <= dw + w < W:
            if minDist[dh + h][dw + w] > d + 1:
                que.append((dh + h, dw + w, d + 1))
                minDist[dh + h][dw + w] = d + 1

ans = max(max(d) for d in minDist)
print(ans)


Measured memory_bytes: 135516
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
		//文字列から10進数に変換するときはparseIntを使います
	var n = parseInt(input[0], 10);
	s = input[1].trim().split("");///////  trim  文字
   	var cnt = 0;
	    for(i=0;i<n;i++){
     if (s[i] == s[i+1]){//console.log(i);
                        }else{cnt =cnt +1;}
                         }
	console.log(cnt);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8268
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int N;
	string S;
	cin >> N >>S;
	string ter = "ABC";
	int pos = 0;
	int ans = 0;
	while(pos != string::npos){
		pos = S.find(ter, pos);
		if (pos != string::npos) {
			++ans;
			pos += ter.size();
		}
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
int main() {
  int n, k;
  vector<char> v;
  cin >> n >> k;
  while(k--) {
    char a;
    cin >> a;
    v.push_back(a);
  }
  int c = n;
  while (1) {
    bool bad = false;
    for (char d : to_string(c)) {
      for (char dc : v) {
        if (d == dc) {
          bad = true;
          c++;
          break;
        }
      }
      if (bad) {
        break;
      }
    }
    if (!bad) {
      break;
    }
  }
  cout << c << endl;
  return 0;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0; i<n; i++){
    cin >> v[i];
  }
  int count = 0;
  sort(v.begin(), v.end());
  int sum = 0;
  for(int i=0; i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(v[i]+v[j]>v[k] && (v[k]+v[j]>v[i] && v[i]+v[k]>v[j])){
          sum += 1;
        }
        else{
          break;
        }
      }
    }
  }
  
  cout << sum << endl;
        
}
   


Measured memory_bytes: 256
///supercalifragilisticexpialidocious.
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
const int MAXN = 5e3 + 10 , INF = 1e18;
pair<int , pii> a[MAXN];
int n , dp[MAXN][MAXN];
int32_t main()
{
	cin >> n;
	for(int i = 1 ; i <= n ; i ++)
        cin >> a[i].s.f >> a[i].s.s , a[i].f = a[i].s.f + a[i].s.s;
	sort(a + 1 , a + n + 1);
	for(int i = 0 ; i <= n + 1 ; i ++)
    	for(int j = 1 ; j <= n + 1 ; j ++)
    	    dp[i][j] = INF;
	for(int i = 1 ; i <= n ; i ++)
        for(int j = 1 ; j <= i ; j ++)
        {
			dp[i][j] = dp[i - 1][j];
			if(dp[i - 1][j - 1] <= a[i].s.f)
			    dp[i][j] = min(dp[i][j]	, dp[i - 1][j - 1] + a[i].s.s);
		}
	for(int i = n ; i >= 0 ; i --)
        if(dp[n][i] != INF)
            return cout << i << endl , 0;
	return 0;
}







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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> right(n, -1);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        right.at(b) = max(right.at(b), a);
    }

    int cnt = 0;
    int removed_max_num = -1;
    for (int i = 0; i < n; i++) {
        if (right.at(i) == -1) continue;

        if (right.at(i) <= removed_max_num) continue;
        else {
            removed_max_num = i - 1;
            cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

int main () {
    int k, n;
    std::cin >> k >> n;

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

    std::vector<int> diff;
    for (int i = 0; i < n - 1;i ++) {
        diff.push_back(a[i + 1] - a[i]);
    }

    diff.push_back(k - a[n - 1] + a[0]);

    std::cout << k - *std::max_element(diff.begin(), diff.end()) << "\n";
}

Measured memory_bytes: 2168
a, b = map(int, input().split())
if a == b == 1:
  a = b = 14
elif a == 1:
  a = 14
elif b == 1:
  b = 14

if a > b:
  print("Alice")
elif a < b:
  print("Bob")
elif a == b:
  print("Draw")

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

using namespace std;

int main(){


    string a, b;
    cin >> a >> b;
    a = a+b;
    int sum = atoi(a.c_str());
    int tmp = sqrt(sum);
    if(tmp * tmp == sum) cout << "Yes" << endl;
    else cout <<"No" << endl;
}


Measured memory_bytes: 256
import itertools
import decimal
import math
import collections
import sys
input = sys.stdin.readline

H1,M1,H2,M2,K=map(int,input().split())

ans= H2*60+M2 - (H1 * 60 + M1)
if(ans < 0):
    ans=ans+24*60

print(ans-K)


Measured memory_bytes: 9724
#include "bits/stdc++.h"
using namespace std;

int n;
string a;
long long ans;

int main()
{
	cin>>n>>a;

	for(int i=1;i+1<a.size();i++)
	{
		vector <int> al,bl,ar,br;
		if(a[i]=='R')
		{
			for(int j=i-1;j>=0;j--)
				if(a[j]=='G') al.push_back(j);
				else if(a[j]=='B') bl.push_back(j);
			for(int j=i+1;j<n;j++)
				if(a[j]=='G') ar.push_back(j);
				else if(a[j]=='B') br.push_back(j);
		}
		else if(a[i]=='G')
		{
			for(int j=i-1;j>=0;j--)
				if(a[j]=='R') al.push_back(j);
				else if(a[j]=='B') bl.push_back(j);
			for(int j=i+1;j<n;j++)
				if(a[j]=='R') ar.push_back(j);
				else if(a[j]=='B') br.push_back(j);
		}
		else
		{
			for(int j=i-1;j>=0;j--)
				if(a[j]=='R') al.push_back(j);
				else if(a[j]=='G') bl.push_back(j);
			for(int j=i+1;j<n;j++)
				if(a[j]=='R') ar.push_back(j);
				else if(a[j]=='G') br.push_back(j);
		}

		for(auto j:al)
		{
			ans+=br.size();
			if(binary_search(br.begin(),br.end(),i+(i-j))) ans--;
		}
		for(auto j:bl)
		{
			ans+=ar.size();
			if(binary_search(ar.begin(),ar.end(),i+(i-j))) ans--;
		}
	}

	cout<<ans;
}

Measured memory_bytes: 3644
N, M = map(int, input().split())
price = [list(map(int, input().split())) for i in range(N)]
price.sort()
#print(price)
num = 0
tot = 0
for i in range(N):
    c = min(price[i][1], M - num)
    num += c
    tot += c*price[i][0]
    if(num == M): break
print(tot)

Measured memory_bytes: 27752
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> cnt(n, 0);
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;
    cnt[a-1]++;
    cnt[b-1]++;
  }
  for(int i=0; i<n; i++) cout << cnt[i] << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            return Math.Pow(N, 3);
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 11092
N, K = map(int, input().split())
MOD = 10**9 + 7
 
if K < N:
    print(0)
else:
    p = q = 1
    for i in range(N):
        p = p * (K-i) % MOD
        q = q * (i+1) % MOD
 
    print(p * pow(q, MOD-2, MOD) % MOD)


Measured memory_bytes: 5596
N = int(input())
dp = [[0]*(19) for _ in range(19)]
ans = 0
for _ in range(N):
    a = round(float(input())*10**9)
    two = 0
    five = 0
    while a%2 == 0:
        a //= 2
        two += 1
    while a%5 == 0:
        a //= 5
        five += 1
    two = min(two,18)
    five = min(five,18)
    ans += dp[18-two][18-five]
    for i in range(two+1):
        for j in range(five+1):
            dp[i][j] += 1
print(ans)

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

template <typename T>
T modinv(T a, T m) {
    T b = m, u = 1, v = 0;
    while (b) {
        T t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// nCk % m
ll mcomb(ll n, ll k, ll m=1e9+7)
{
    if(n == 0 && k == 0) return 1;
    if(n < k || n < 0) return 0;

    ll ans = 1;
    rep(i,k) {
        ans = (ans*(n-i)) % m;
        ans = (ans*modinv<ll>(i+1, m)) % m;
    }

    return ans;
}

int main()
{
    const ll MOD = 1e9+7;
    ll n,a,b;
    cin >> n >> a >> b;

    auto mpow = [](ll x, ll y, ll m)
    {
        ll ret = 1;
        while(y!=0)
        {
            if(y&1) ret = (ret*x) % m;
            x = (x*x) % m;
            y = y >> 1;
        }
        return ret;
    };

    ll ans = ((mpow(2, n, MOD)-1) + MOD) % MOD;
    ll comb_a = mcomb(n, a, MOD);
    ll comb_b = mcomb(n, b, MOD);

    ans = ans - comb_a - comb_b + MOD*3;
    ans %= MOD;

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

Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto nodes = new Node[](n);

  foreach (_; n.iota) {
    auto rd = readln.chomp.splitter;
    auto id = rd.front.to!int; rd.popFront;
    auto k = rd.front.to!size_t; rd.popFront;
    auto children = new int[](k);
    foreach (j; k.iota) {
      children[j] = rd.front.to!int;
      rd.popFront;
    }
    nodes[id] = new Node(id, children);
  }

  foreach (node; nodes)
    foreach (child; node.children)
      nodes[child].parent = node.id;

  foreach (node; nodes)
    writefln("node %d: parent = %d, depth = %d, %s, %s",
             node.id, node.parent, node.depth(nodes),
             node.type, node.children);
}

class Node
{
  int id;
  int parent;
  int[] children;

  this(int id, int[] children)
  {
    this.id = id;
    this.parent = -1;
    this.children = children;
  }

  size_t depth(Node[] nodes)
  {
    if (parent == -1) return 0;
    else return nodes[parent].depth(nodes) + 1;
  }

  string type()
  {
    if (parent == -1) return "root";
    else if (!children.empty) return "internal node";
    else return "leaf";
  }
}

Measured memory_bytes: 11708
N, K = [int(x) for x in input().split()]
money_list = [int(x) for x in input().split()]

def calc_minmum_money(money_list, K):
    money_list.sort()
    minmum_money_list = money_list[:K]
    return sum(minmum_money_list)

print(calc_minmum_money(money_list, K))

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<bool> isPrime(55556, true);
    isPrime[0] = isPrime[1] = false;
    set<int32> primes;
    FOR(i,2,55556){
        if(!isPrime[i])continue;
        if(i % 5 == 1)primes.insert(i);
        int32 p = i;
        int32 j = 2;
        while(p * j < 55556){
            isPrime[p * j] = false;
            j++;
        }
    }
    int32 cnt = 0;
    for(auto p : primes){
        cout << p << " ";
        cnt++;
        if(cnt >= n)break;
    }
    cout << endl;
    return 0;
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    auto count_two = [&](ll x){
        int cnt = 0;
        while(x % 2 == 0){
            x /= 2;
            cnt++;
        }
        return cnt;
    };
    auto lcm = [&](ll a, ll b){
        return a*b / __gcd(a, b);
    };
    ll n,m; cin >> n >> m;
    vl a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) a[i] = a[i] / 2;
    rep(i,n) b[i] = count_two(a[i]);

    if(all_of(all(b), [b](ll x){ return x == b[0]; })){
        ll x = accumulate(all(a), 1ll, lcm);
        ll ans = (m + x) / (2 * x);
        cout << ans << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 8008
import sys

class Card:
    def __init__(self, kind, num):
        self.kind = kind
        self.num = num
    def __eq__(self, other):
        return (self.kind == other.kind) and (self.num == other.num)
    def __ne__(self, other):
        return not ((self.kind == other.kind) and (self.num == other.num))
    def __str__(self):
        return self.kind + self.num

def list_to_string(array):
    s = ""
    for n in array:
        s += str(n) + " "
    return s.strip()
    
def swap(array, i, j):
    tmp = array[i]
    array[i] = array[j]
    array[j] = tmp

def is_stable(array1, array2):
    if reduce(lambda x, y: x and y, map(lambda x: x[0] == x[1], zip(array1, array2))):
        return "Stable"
    else:
        return "Not stable"

def bubble_sort(array):
    for i in range(0, len(array)):
        for j in reversed(range(i+1, len(array))):
            if array[j].num < array[j-1].num:
                swap(array, j, j-1)
    return array
        
def selection_sort(array):
    for i in range(0, len(array)):
        min_index = i
        for j in range(i, len(array)):
            if array[min_index].num > array[j].num:
                min_index = j
        swap(array, i, min_index)
    return array

def main():
    num = int(sys.stdin.readline().strip())
    array = map(lambda x: Card(x[0], x[1]), sys.stdin.readline().strip().split(" "))

    a = list(array)
    b = list(array)

    print list_to_string(bubble_sort(a))
    print "Stable"
    print list_to_string(selection_sort(b))
    print is_stable(a, b)

if __name__ == "__main__":
    main()

Measured memory_bytes: 6472
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	char S[20];
	cin >> S;
	int i = 0;
	int count = 0;
	while (S[i] != '\0') {
		if (S[i] == 'x') count++;
		i++;
	}
	if (count >= 8) {
		cout << "NO";
	}
	else {
		cout << "YES";
	}
}

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

void solved()
{
    int n;
    cin >> n;
    set<string> st;
    for(int i = 0;i < n;i++)
    {
        string s;
        cin >> s;
        if(st.count(s) == 0)st.insert(s);
    }
    cout << st.size();
}

int main()
{
#ifdef ONLINE_JUEDGE
    ios::sycn_with_stdio(false);cin.tie(0);cout.tie(0);
#endif
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solved();
    }



#ifndef ONLINE_JUEDGE
    system("pause");
#endif 
    return 0;
}

Measured memory_bytes: 19320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007ll
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
// #define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> f(n, true);
  REP(i, m) {
    int tmp;
    cin >> tmp;
    f.at(tmp) = false;
  }
  ll dp[n + 1];
  REP(i, n + 1) { dp[i] = 0; }
  dp[0] = 1;
  REP(i, n) {
    if (f.at(i)) {
      dp[i] %= MOD;
      if (i + 1 <= n) dp[i + 1] += dp[i];
      if (i + 2 <= n) dp[i + 2] += dp[i];
    }
  }
  cout << dp[n]%MOD << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  int a[N + 1]{};
  for (int i = 0; i < N; i++) {
    cin >> a[i + 1];
  }
  int b[N + 1]{};
  int cnt = 0;
  for (int i = N; i >= 1; i--) {
    int k = 0;
    for (int j = i; j <= N; j += i) {
      if (b[j] == 1) k++;
    }
    if (a[i] != (k % 2)) {
      b[i] = 1;
      cnt++;
    }
  }
  if (cnt == 0) {
    cout << 0 <<"\n";
    return 0;
  }
  cout << cnt << "\n";
  bool flag = true;
  for (int i = 1; i <= N; i++) {
    if (b[i] == 1) {
      if (flag) {
        cout << i;
        flag = false;
      }  else {
        cout << " " << i;
      }
    }
  }
  cout << "\n";
  return 0;
}

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

using namespace std;
bool check(vector<vector<bool>>B)
{
	for(int i=0;i<3;i++)
	{
		if(B[i][0]&&B[i][1]&&B[i][2])
			return true;
	}
	for(int i=0;i<3;i++)
	{
		if(B[0][i]&&B[1][i]&&B[2][i])
			return true;
	}
	if(B[0][0]&&B[1][1]&&B[2][2])
		return true;
	if(B[0][2]&&B[1][1]&&B[2][0])
		return true;

	return false;
}

int main()
{
	int n,m;
	cin>>n>>m;
	vector<int>A(n,-1);
	vector<vector<int>> B(m,vector<int>(2,-1));
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		B[i][0]=a;
		B[i][1]=b;
	}

	for(int i=0;i<m;i++)
	{
		if(B[i][0]>n)
		{
			cout<<"-1"<<endl;
			return 0;
		}
		if(B[i][0]==1 && B[i][1]==0 && n!=1)
		{
			cout<<"-1"<<endl;
			return 0;
		}
		if(A[B[i][0]-1]==-1)
			A[B[i][0]-1]=B[i][1];

		else
		{
			if(A[B[i][0]-1]!=B[i][1])
			{
				cout<<"-1"<<endl;
				return 0;
			}

		}

	}
	for(int i=0;i<n;i++)
	{
		if(A[0]==-1 && n!=1)
			A[0]=1;
		else if(A[i]==-1)
			A[i]=0;
		
	}
	string s="";
	for(int i=0;i<n;i++)
	{
		s+=to_string(A[i]);
	}
	cout<<s<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cstdio>
#define LL long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
typedef pair<pii,int>piii;
const int maxn=2010;
int n,n3;
int a[3*maxn],b[maxn];
int dp[maxn][maxn];
int ans,ans2;
vector<piii>vis;
void update(int i,int j,int k){
	vis.pb(mp(mp(i,j),k));
	vis.pb(mp(mp(j,i),k));
}
void init(){
	memset(b,-0x3f,sizeof b);
	memset(dp,-0x3f,sizeof dp);
	dp[a[1]][a[2]]=b[a[1]]=b[a[2]]=ans2;
}
void solve(){
	for(int i=3;i<=n3;i+=3,vis.clear()){
		if(a[i]==a[i+1]&&a[i]==a[i+2]){
			ans2--;
			continue;
		}
		for(int _=0;_<3;_++){
			swap(a[i],a[i+1]),swap(a[i+1],a[i+2]);
			update(a[i],a[i+1],max(ans,dp[a[i+2]][a[i+2]]+1));
			for(int j=1;j<=n;j++){
				if(a[i+1]==a[i+2])update(j,a[i],dp[j][a[i+1]]+1);
				update(j,a[i],b[j]);
			}
		}
		for(auto j:vis){
			int e=j.F.F;
			int f=j.F.S;
			int g=j.S;
			dp[e][f]=max(dp[e][f],g);
			b[e]=max(b[e],g);
			ans=max(ans,g);
		}
	}
}
int main(){
	cin>>n;
	n3=3*n;
	for(int i=1;i<=n3;i++)cin>>a[i];
	init();
	solve();
	cout<<ans-ans2<<endl;
	return 0;
}


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

int main()
{
 int N; cin >> N;
 long int A[N];
 long int accum[N+1];
 accum[0] = 0;
 long int mod = 1e9+7;
 for(int i=0;i<N;i++){
     long int A_i; cin >> A_i;
     A[i] = A_i;
     accum[i+1] = accum[i] + A_i;
 }
 long int ans = 0;
 for(int i=0;i<N;i++){
     ans+=A[i]*((accum[N]-accum[i+1])%mod);
     ans%=mod;
 }
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 6660
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
#define ll long long
#define mod 1000000007;

int main() {
	int n, a[1010][1010], now[1010];
	cin >> n;
	ll hoge = 0, en = (n * (n - 1)) / 2;
	for (int i = 0; i < n; i++)now[i] = n - 2;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - 1; j++) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	bool flag[1010], cc[1010];
	int last[1010];
	for (int k = 0; k < n; k++)cc[k] = 0;
	for (int k = 0; k < n; k++)last[k] = -1;
	bool ff = 1;
	while(1) {
		ff = 1;
		for (int i = 0; i < n; i++) {
			if (last[i]==ans||cc[i])continue;
		int j = a[i][now[i]] - 1;
			if (a[i][now[i]] == (j+1) && a[j][now[j]] == (i+1) && last[i] != ans && last[j] != ans) {
				last[i] = ans;
				last[j] = ans;
				now[i]--;
				now[j]--;
				hoge++;
				ff = 0;
				if (now[i] == -1)cc[i] = 1;
				if (now[j] == -1)cc[j] = 1;
			}
		}
		ans++;
		if (hoge == en) {
			cout << ans << endl;
			return 0;
		}
		if (ff)break;
	}
	cout << -1 << endl;
	return 0;
}

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


int main(){
	int n,w;
	cin>>n>>w;
	int weights[n];
	int values[n];
	for(int i=0;i<n;i++){
		cin>>weights[i]>>values[i];
	}
	long long  dp[n+1][w+1];
	for(int i=0;i<n+1;i++){
		dp[i][0] = 0;
	}
	for(int i=0;i<w+1;i++){
		dp[0][i] = 0;
	}
	for(int i = 1;i < n+1;i++){
		for(int j = 1;j<w+1;j++){
			if(j < weights[i-1]){
				dp[i][j] = dp[i-1][j];
			}
			else{
			dp[i][j] = max(dp[i-1][j],dp[i-1][max(0,j-weights[i-1])]+values[i-1]);
			
		}
		}
	}
	
	cout << dp[n][w] << endl;
	return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
#define SIZE_OF_ARRAY(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
typedef long long ll;
  
  int main(void){
    cin.tie(0); //cin高速化
    ios::sync_with_stdio(false); //cin高速化
	int a,b;
    cin >> a >> b;
    string s = to_string(a);
    string t = to_string(b);
    s += t;
    a = atoi(s.c_str());
    int i=1;
    while(i*i<=a){
      if(i*i==a){
        cout << "Yes" << endl;
        return 0;
      }
      i++;
    }
    cout << "No" << endl;
    return 0;
  } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int ans;
    if (a > b) ans = a + a - 1;
    else if (a == b) ans = a + a;
    else ans = b + b - 1;
    cout << ans << endl;

    return 0;
}



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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

#define random_shuffle(...) shuffle(__VA_ARGS__, rng)
#define rand() rng()

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

const int N = 5111111;
long long fact[N], inv[N], invfact[N];
const int mod = 998244353;

long long C(int n, int k) {
	if (n < k) {
		return 0;
	}
	return fact[n] * invfact[k] % mod * invfact[n - k] % mod;
}

int main() {
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

	fact[0] = invfact[0] = 1;
	for (int i = 1; i < N; ++i) {
		inv[i] = (i == 1) ? 1 : mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = fact[i - 1] * i % mod;
		invfact[i] = invfact[i - 1] * inv[i] % mod;
	}

	int n = nxt(), m = nxt();
	long long ans = C(3 * m + n - 1, n - 1) - n * C(m + n - 2, n - 1);

	for (int i = m + 1; i <= n; ++i) {
		if (i % 2 != m % 2) {
			continue;
		}
		long long tmp = C((3 * m - i) / 2 + n - 1, n - 1) * C(n, i) % mod;
		ans -= tmp;
	}

	ans %= mod;
	cout << (ans + mod) % mod << "\n";

	return 0;
}

Measured memory_bytes: 120064
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007LL;
bool b[100001] = { false };
int num[100001];
LL fact[100001];
LL inv[100001];
LL inv_fact[100001];
LL mod_pow(LL x, LL a) {
	if (a == 0) return 1;
	if (a % 2 == 0) {
		LL ret = mod_pow(x, a / 2);
		return (ret*ret) % MOD;
	}
	else {
		return (x*mod_pow(x, a - 1)) % MOD;
	}
}
LL comb(LL n, LL k) {
	if (n < k) return 0;
	LL ans = (fact[n] * inv_fact[k]) % MOD;
	ans = (ans*inv_fact[n - k]) % MOD;
	return ans;
}
int main() {
	int n, dup[2];
	cin >> n;
	for (int i = 0; i <= n; i++) {
		int a;
		cin >> a;
		num[i] = a;
		if (!b[a - 1])b[a - 1] = true;
		else {
			dup[1] = i;
			break;
		}
	}
	for (int i = 0; i < dup[1]; i++) {
		if (num[i] == num[dup[1]])dup[0] = i;
	}
	fact[0] = 1;
	inv_fact[0] = 1;
	for (int i = 1; i < n + 1; i++) {
		inv[i] = mod_pow(i, MOD - 2);
		fact[i] = (fact[i - 1] * i) % MOD;
		inv_fact[i] = (inv_fact[i - 1] * inv[i]) % MOD;
	}
	int cen = dup[1] - dup[0] - 1;
	cout << n << endl;
	for (int i = 2; i <= n + 1; i++) {
		LL sum = 0;
		sum = (sum + comb(n - 1, i)) % MOD;
		sum = (sum + comb(n - 1, i - 2)) % MOD;
		sum = (sum + 2 * comb(n - 1, i - 1)) % MOD;
		sum = (sum - comb(n - cen - 1, i - 1) + MOD) % MOD;
		cout << sum << endl;
	}
}

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

  int gcd(int x, int y) {
    return (x % y == 0 ? y : gcd(y, x % y));
  }

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

  long long A, B;
  cin >> A >> B;
  for(int i = 1; i <= B; i++){
    if((A * i) % B == 0){
      cout << A * i << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  1999999999
#define pa pair<int,int>
using namespace std;
 
 
 
int main(){
//cout<<"1"<<endl;
string s,t;
cin>>s>>t;
int ls=s.length(),lt=t.length();
//cout<<ls<<endl;
//cout<<s<<endl;
 
 
int dp[1010][1010];
for(int i=0;i<=max(ls,lt);i++){
dp[i][0]=i;
dp[0][i]=i;
}
 
for(int i=1;i<=ls;i++){
for(int j=1;j<=lt;j++){
if(s[i-1]==t[j-1]) dp[i][j]=min(min(dp[i-1][j]+1,dp[i][j-1]+1),dp[i-1][j-1]);
else dp[i][j]=min(min(dp[i-1][j]+1,dp[i][j-1]+1),dp[i-1][j-1]+1);
//cout<<dp[i][j]<<endl;
}
}
cout<<dp[ls][lt]<<endl;
 
 
 
return 0;
}

Measured memory_bytes: 5140
N = input()
L = len(N)
NUM = int(N)

count = 0
for l in range(1, L):
        count += 3**l - 3*2**l + 3
q = '3'*L
while True:
        if int(q) > NUM:
                break
        if q.count('3') > 0 and q.count('5') > 0 and q.count('7') > 0:
                count += 1
        if q == '7'*(L-2) + '5' + '3':
                break
        for i in range(1, L+1):
                k = q[-i]
                if k == '3':
                        next = q[:-i] + '5' + '3'*(i-1)
                        break
                elif k == '5':
                        next = q[:-i] + '7' + '3'*(i-1)
                        break
        q = next

print(count) 

                      


        

    


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()


int main() {
	ll H, W;
	cin >> H >> W;
	vector<vector<ll>> a(H, vll(W));
	rep(i, H) rep(j, W) cin >> a[i][j];

	vll y, x, y_prime, x_prime;

	bool right = false;
	rep(i, H) {
		right = !right;
		if (right) {
			fori(j, 0, W) {
				if (a[i][j] % 2 == 1) {
					if (j == W - 1) {
						if (i != H - 1) {
							y.push_back(i + 1); x.push_back(j + 1);
							y_prime.push_back(i + 2), x_prime.push_back(j + 1);
							--a[i][j], ++a[i + 1][j];
						}
					}
					else {
						y.push_back(i + 1); x.push_back(j + 1);
						y_prime.push_back(i + 1), x_prime.push_back(j + 2);
						--a[i][j], ++a[i][j + 1];
					}
				}
			}
		}
		else {
			ford(j, 0, W) {
				if (a[i][j] % 2 == 1) {
					if (j == 0) {
						if (i != H - 1) {
							y.push_back(i + 1); x.push_back(j + 1);
							y_prime.push_back(i + 2), x_prime.push_back(j + 1);
							--a[i][j], ++a[i + 1][j];
						}
					}
					else {
						y.push_back(i + 1); x.push_back(j + 1);
						y_prime.push_back(i + 1), x_prime.push_back(j);
						--a[i][j], ++a[i][j - 1];
					}
				}
			}
		}
		
	}

	cout << x.size() << endl;
	rep(i, x.size()) cout << y[i] << " " << x[i] << " " << y_prime[i] << " " << x_prime[i] << endl;
}


Measured memory_bytes: 8152
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    string a,b,c;
    cin >> a >> b >>c;
    if(a[a.length()-1]==b[0] && b[b.length()-1]==c[0]){
        cout << "YES";
    }else{
        cout << "NO";
    }
}

Measured memory_bytes: 256
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# bit毎で１と０の多い方の値、K以下でdfs
N, K = lr()
A = lr()
limit = max(max(A), K).bit_length()
X = [0] * (limit)
for a in A:
    for i in range(limit):
        if (a >> i) & 1:
            X[i] += 1

Y = [max(x, N-x) for x in X]

def cal(index, total):
    total += sum([y * 2 ** i for i, y in enumerate(Y[:index+1])])
    return total

def dfs(index, sum, y):
    if index == limit:
        return sum
    i = limit - 1 - index
    if y + 2 ** (i + 1) <= K:
        return cal(i, sum)
    ret = dfs(index+1, sum + X[i] * 2 ** i, y)
    if y + 2 ** i <= K:
        ret = max(ret, dfs(index+1, sum+(N-X[i])*2**i, y+2**i))
    return ret

answer = dfs(0, 0, 0)
print(answer)


Measured memory_bytes: 23632
# input
inp_ls = input().split(" ")
n,m = [int(e) for e in inp_ls[:2]]
inp_a_ls = input().split(" ")
a_ls = [int(e) for e in inp_a_ls[:m]]

# calc
rest = n - sum(a_ls)
out = rest if rest >= 0 else -1

# result
print(out)

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

int main(){
	int n;
	cin >> n;
	vector<pair<int,int>> stu(n);
	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		stu.at(i) = make_pair(a,i);
	}
	sort(stu.begin(),stu.end());
	for(int i = 0;i < n;i++){
		cout << stu.at(i).second + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 1664
from heapq import heappop,heappush
N = int(input())
A = list(map(lambda x: -1*int(x),input().split()))

now = -1 * heappop(A)
while(A):
    next = -1 * heappop(A)
    if now % next != 0:
        heappush(A,-1*(now%next))
    now = next
print(now)

Measured memory_bytes: 20196