akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}

int main() {
  int n, m;
  cin >> n >> m;
  VEC<int> a(n), b(n), c(m), d(m);
  REP(i, 0, n) cin >> a[i] >> b[i];
  REP(i, 0, m) cin >> c[i] >> d[i];
  DUMP(a, b, c, d);
  REP(i, 0, n) {
    LL mi = LLONG_MAX;
    int indx = -1;
    for (int j = m - 1; j >= 0; j--) {
      LL e = abs(a[i] - c[j]);
      LL f = abs(b[i] - d[j]);
      DUMP(i,j,mi, e, f);
      if (e + f <= mi) {
        mi = e + f;
        indx = j + 1;
      }
    }
    cout << indx << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int p, q, r;
  scanf("%d %d %d", &p, &q, &r);
  int min = p+q;
  if(min >= q+r) min = q+r;
  if(min >= r+p) min = r+p;
  printf("%d", min);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

long long n,m,k,a[100005],v[100005],y,x[100005],vz[100005],s,t[100005],ans[100005];

vector <long long> p;

void DFS(long long nod){
    vz[nod]=1; p.push_back(nod);
    if(!vz[v[nod]]) DFS(v[nod]);
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++) cin >> x[i],v[i]=i;
    cin >> m >> k;
    for(int i=1;i<=m;i++) cin >> a[i],swap(v[a[i]],v[a[i]+1]);
    //for(int i=2;i<=n;i++) cout << v[i] << ' ';
    //cout << '\n';
    for(int i=2;i<=n;i++){
        if(!vz[i]){
            DFS(i);
            for(int i=0;i<p.size();i++){
                t[p[i]]=p[(i+k)%(p.size())];
            }
            p.clear();
        }
    }
    ans[1]=x[1]; cout << ans[1] << '\n';
    for(int i=2;i<=n;i++){
        //cout << t[i] << ' ';
        ans[i]=ans[i-1]+x[t[i]]-x[t[i]-1];
        cout << ans[i] << '\n';
    }
}


Measured memory_bytes: 9972
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vec vector<int>
#define vecll vector<ll>
#define pb(x) push_back(x)

using namespace std;
///////////////////////////////////////////////////////////



int main() {
    ll m = 1e9 + 7;

    ll n; cin >> n;

    ll a[n];
    ll sa[n];
    ll in;
    rep(i, n) {
        cin >> in;
        a[i] = in % m;
    }
    sa[0] = a[0];
    for (ll i = 1; i < n; i++) {
//        cout << sa[i-1] << " " << a[i] << endl;
        sa[i] = sa[i-1] + a[i];
    }

    ll ans = 0;
    for (ll j = 1; j < n; j++) {
        ans += (sa[j-1] % m) * (a[j] % m) % m;
        ans %= m;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6708
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/



ll dp[110][100005];
ll sdp[100005];
ll sum[100005];


int main() {

	ll n, k;
	cin >> n >> k;

	int layer = 0;//最大値がi/jになるグループにまとめる（高々2√N）
	
	for (int i = 1; i <= n;)
	{
		int j = n / i;

		if (i <= j) {
			//前半
			sum[layer] = 1;
			i++;
			layer++;
		}
		else
		{
			//後半
			sum[layer] = n / j - i + 1;
			i = n / j + 1;
			layer++;
		}
	}
	

	dp[0][0] = 1;


	for (int i = 0; i < k; i++)
	{

		//累積和
		memset(sdp, 0, sizeof(sdp));

		for (int j = 0; j < layer; j++)
		{
			sdp[j + 1] = sdp[j] + dp[i][j];
			sdp[j + 1] %= MOD;
		}

		for (int j = 0; j < layer; j++)
		{
			dp[i + 1][j] = sdp[layer - j] * sum[j];
			dp[i + 1][j] %= MOD;
		}

	}

	
	ll ans = 0;
	for (int i = 0; i <= layer; i++)
	{
		ans += dp[k][i];
		ans %= MOD;
	}

	cout << ans << endl;
	

	return 0;
}


Measured memory_bytes: 81408
#include<bits/stdc++.h>
using namespace std;
const int N=450;
struct node{
    int x,y;
}e[N*N];
int n,m,d;
bool bj[N*N];
int pre[N*N];
int zzh[N*N];
void cl()
{
    for(int i=1;i<=90000;i++){
        if(!bj[i]){
            int x=e[i].x,y=e[i].y,sum=0;
            for(int j=i;j<=90000;j+=d){
                pre[j]=i;bj[j]=1;
                zzh[j]=sum+abs(e[j].x-x)+abs(e[j].y-y);
                sum=zzh[j];x=e[j].x;y=e[j].y;
            }
        }
    }
}
int main()
{
    scanf("%d%d%d",&n,&m,&d);
    for(int i=1;i<=n;i++)
    for(int j=1,a;j<=m;j++)scanf("%d",&a),e[a].x=i,e[a].y=j;
    cl();
    int q;
    scanf("%d",&q);int l,r;
   // for(int i=1;i<=n*m;i++)cout<<zzh[i]<<endl;
    while(q--){
        scanf("%d%d",&l,&r);
        printf("%d\n",zzh[r]-zzh[l]);
    }
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}


using namespace std;

const int max_n = 3e5 + 5;

int mod = 998244353;
int powmod(int a, int n) {
	if (n == 0) return 1;
	int sq = powmod(a, n/2);
	sq = (sq * 1LL * sq) % mod;
	if (n%2 == 0) return sq;
	return (sq * 1LL * a) % mod;
}

int fac[max_n], ifac[max_n];

int newton(int n, int k) {
	if (n < k) return 0;
	int ans = (fac[n] * 1LL * ifac[k])%mod;
	return (ans * 1LL * ifac[n-k]) % mod;
}

int main() {
	fac[0] = 1;
	FOR(i,1,3e5+1) fac[i] = (i*1LL*fac[i-1]) % mod;
	FOR(i,0,3e5+1) ifac[i] = powmod(fac[i], mod - 2);
	make3(n, a, b);
	lint k; scanf("%lld", &k);
	int ans = 0;
	FOR(i,0,n+1) {
		lint u = k - a*1LL*i;
		if (u%b == 0) {
			lint j = u/b;
			if (j > n) continue;
			if (j < 0) continue;
			int loc = (newton(n, i) * 1LL * newton(n, j)) % mod;
			ans = (ans + loc) % mod;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 2688
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int n=s.size();
	for(int i=0;i<n;i++)
	{
		if(s[i]=='C')
		{
			for(int j=i+1;j<n;j++)
			{
				if(s[j]=='F')
				{
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>

using namespace std;


int main() {

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

	int n;
	cin >> n;
	double ans = 0;

	for (int i = 0; i < n; i++) {
		string u;
		double x;
		cin >> x >> u;
		if (u == "JPY") {
			ans += x;
		}
		else {
			ans += x * 380000;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a[5],k;
    for(int i=0;i<5;i++){
        cin>>a[i];
    }
    cin>>k;
    vector<int>v;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            v.push_back(a[j]-a[i]);
        }
    }
    for(int i=0;i<v.size();i++){
        if(v[i]>k){
            cout<<":("<<endl;
            return 0;
        }
    }
    cout<<"Yay!"<<endl;
    
    return 0;
    
}



Measured memory_bytes: 256
# coding: utf-8

import sys
import copy

M, K = (int(x) for x in input().split())

if K >= 2 ** M:
	print("-1")
	sys.exit()

if M == 0:
	print("0 0")
	sys.exit()

if M == 1:
	if K == 0:
		print("0 0 1 1")
		sys.exit()
	else:
		print("-1")
		sys.exit()

b = [x for x in range(2 ** M) if x != K]
c = list(reversed(copy.copy(b)))

for x in b:
	print(x, end = " ")

print(str(K), end = " ")

for x in c:
	print(x, end = " ")

print(str(K))

Measured memory_bytes: 11668
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()

typedef long long LL;
typedef long double LD;

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    } else {
        return a.second < a.second;
    }
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

int main()
{
    int D;
    cin >> D;

    cout << "Christmas";
    for (int i = 0; i < 25-D; i++)
        cout << " Eve";

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
P = map(int, input().split())

pos = {}
for i, p in enumerate(P):
    pos[p] = i+1

foll = [i+1 for i in range(N+1)]+[N+1]
prev = [0]+[i for i in range(N+1)]

ans = 0
for i in range(1, N+1):
    curr = pos[i]
    r = foll[curr]
    rr = foll[r]
    l = prev[curr]
    ll = prev[l]
    ans += (l-ll)*(r-curr)*i
    ans += (rr-r)*(curr-l)*i

    foll[l] = foll[curr]
    prev[r] = prev[curr]
    # print(*foll)
    # print(*prev)
print(ans)


Measured memory_bytes: 69100
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

int a, b;
int main(){
    cin >> a >> b;
    ll ans = -1;
    rep(i, 1, 1001){
        int t = i * 0.08;
        int s = i * 0.1;
        if(t != 0 && t == a && s == b) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3180
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repe(i, n) for(int i = 0; i <= (n); i++)
#define fo(i, a, b) for(int i = (a); i < (b); i++)
#define foe(i, a, b) for(int i = (a); i <= (b); i++)
#define NL << endl

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const ll LLMAX = numeric_limits<long long>::max();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;


int main() {

	int h, w;
	cin >> h >> w;
	vector<vector<int>> m(h, vector<int>(w));

	rep(i, w * h) cin >> m[i / w][i % w];
	vector<vector<int>> op;
	int d = 1;
	bool ho = false;
	int nx = 0, ny = 0;
	int x = 0, y = 0;
	rep(c, h * w) {
		if ((c + 1) % w == 0) {
			d *= -1;
			ny++;
		} else {
			nx += d;
		}
		if (c != w * h - 1) {
			if (m[y][x] % 2) {
				m[y][x]--;
				m[ny][nx]++;
				op.push_back(vector<int>{y, x, ny, nx });
			}
		}

		x = nx, y = ny;
	}

	cout << op.size() NL;
	rep(i, op.size()) {
		rep(j, 4) {
			cout << op[i][j] + 1;
			if (j == 3) {
				if (i == op.size() - 1) break;
				cout NL;
			} else {
				cout << ' ';
			}
		}
	}

	return 0;

}


Measured memory_bytes: 10800
using System;
class _0009
{
    public static void Main()
    {
        string str;
        bool[] prime = new bool[1000000];
        for (int i = 0; i < 1000000; i++) prime[i] = true;
        while ((str = Console.ReadLine()) != null)
        {
            int n = int.Parse(str);
            int c = 0;
            for (int i = 2; i <= n; i++)
                for (int j = 2; i * j <= n; j++) prime[i * j] = false;
            for (int i = 2; i <= n; i++) if (prime[i] == true) c++;
            Console.WriteLine(c);
        }
    }
}

Measured memory_bytes: 6584
#include<iostream>
using namespace std;
int main() {
  long a, b;
  int tmp;
  int r;
  cin >> a >> b;

  long x = a * b;

  if(a<b) {
    tmp = a;
    a = b;
    b = tmp;
  }

  r = a % b;
  //cout << a << " " << b << " " << r << endl;                  
  while(r != 0) {
    a = b;
    b = r;
    r = a % b;
    //cout << a << " " << b << " " << r << endl;                
  }
  cout << x/b << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    int A[n][m], B[m], ans[n];
    for (int i=0; i<n; i++){
        for (int j=0; j<m; j++){
            cin >> A[i][j];
        }
    }
    for (int k=0; k<m; k++){
        cin >> B[k];
    }
    for (int i=0; i<n; i++){
        ans[i] = 0;
    }
    for (int i=0; i<n; i++){
        for (int j=0; j<m; j++){
            ans[i] += A[i][j] * B[j];
        }
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){
  string s;
  cin >> s;
  if(s == "AAA" || s == "BBB") cout << "No" << endl;
  else cout << "Yes" <<endl;
 }

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def main():
    N = int(input())
    A = inpl()
    print(len([i for i, a in enumerate(A) if i % 2 == 0 and a % 2 == 1]))

    return


if __name__ == '__main__':
    main()


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

int main(){
    int a, b;
    cin >> a >> b;

    int s[a], t[b];
    for(int i = 0; i < a; i++)  cin >> s[i];
    for(int i = 0; i < b; i++)  cin >> t[i];

    int ans = 0;
    for(int i = 0; i < b; i++){
        int posa = 0, posb = i;
        while(posa < a && posb < b){
            if(s[posa] == t[posb])   posb++;
            posa++;
        }
        ans = max(ans, posb-i);
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3132
#include<cstdio>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll w, h, d[100][100];
char s[100][100];
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, -1, 0, 1};
ll INF = 1000000000LL;
bool used[100][100];

bool bfs(ll x, ll y) {
  queue<P> que, que2;
  que.push(P(x, y));
  ll ysum = 0, num = 0, l = INF, r = -1, color = d[x][y];
  while (!que.empty()) {
    P p = que.front(); que.pop();
    ll nx = p.first, ny = p.second;
    if (d[nx][ny] == -color) continue;
    d[nx][ny] = -d[nx][ny];
    used[nx][ny] = true;
    ysum += ny;
    num++;
    for (ll i = 0; i < 4; i++) {
      ll x2 = nx + dx[i], y2 = ny + dy[i];
      if (x2 < 0 || y2 < 0 || x2 == h+1 || y2 == w) continue;
      if (d[x2][y2] == 0) continue;
      if (d[x2][y2] + color == 0) continue;
      if (d[x2][y2] == color) {
        que.push(P(x2, y2));
      } else if (i == 0) {
        l = min(l, y2);
        r = max(r, y2);
      } else if (i == 2) {
        que2.push(P(x2, y2));
      }
    }
  }
  while (!que2.empty()) {
    P p = que2.front(); que2.pop();
    ll nx = p.first, ny = p.second;
    if (used[nx][ny]) continue;
    used[nx][ny] = true;
    ysum += ny;
    num++;
    for (ll i = 0; i < 4; i++) {
      ll x2 = nx + dx[i], y2 = ny + dy[i];
      if (x2 < 0 || y2 < 0 || x2 == h+1 || y2 == w) continue;
      if (d[x2][y2] == 0) continue;
      if (used[x2][y2]) continue;
      if (d[x2][y2] == d[nx][ny]) {
        que2.push(P(x2, y2));
      } else if (i == 2) {
        que2.push(P(x2, y2));
      }
    }
  }
  //printf("color: %lld, x: %lld, y: %lld, ysum: %lld, num: %lld, l: %lld, r: %lld\n", color, x, y, ysum, num, l, r);
  if ((2*l - 1) * num < 2*ysum && 2*ysum < (2*r + 1) * num) return false;
  return true;
}

int main() {
  while (scanf("%lld%lld", &w, &h), w) {
    for (ll i = 0; i < h; i++) scanf("%s", s[i]);
    for (ll i = 0; i < h; i++) for (ll j = 0; j < w; j++) {
      if (s[i][j] == '.') d[i][j] = 0;
      else d[i][j] = s[i][j] - '0';
    }
    for (ll i = 0; i < w; i++) d[h][i] = 10;
    bool flag = false;
    for (ll i = 0; i < h; i++) {
      for (ll j = 0; j < w; j++) {
        if (d[i][j] > 0) {
          for (ll k = 0; k < h; k++) for (ll r = 0; r < w; r++) used[k][r] = false;
          if (bfs(i, j)) {
            flag = true;
            i = h, j = w;
          }
        }
      }
    }
    if (flag) printf("UNSTABLE\n");
    else printf("STABLE\n");
  }
}



Measured memory_bytes: 2680
#include <iostream>
#include <vector>
#include <cstdlib>
#include <bits/stdc++.h>
#include <string>
#include <sstream>
using namespace std;
int main(){
  string a;
  cin >> a;
  int i = a[0]-'0';
  int j = a[1]-'0';
  int k = a[2]-'0';
  int l = a[3]-'0';
  if((i+j+k+l) == 7){
    cout <<i<<"+"<<j<<"+"<<k<<"+"<<l<<"=7\n";
  }
  else if((i+j+k-l) == 7){
    cout <<i<<"+"<<j<<"+"<<k<<"-"<<l<<"=7\n";
  }
  else if((i+j-k+l) == 7){
    cout <<i<<"+"<<j<<"-"<<k<<"+"<<l<<"=7\n";
  }
  else if((i-j+k+l) == 7){
    cout <<i<<"-"<<j<<"+"<<k<<"+"<<l<<"=7\n";
  }
  else if((i+j-k-l) == 7){
    cout <<i<<"+"<<j<<"-"<<k<<"-"<<l<<"=7\n";
  }
  else if((i-j+k-l) == 7){
    cout <<i<<"-"<<j<<"+"<<k<<"-"<<l<<"=7\n";
  }
  else if((i-j-k+l) == 7){
    cout <<i<<"-"<<j<<"-"<<k<<"+"<<l<<"=7\n";
  }
  else if((i-j-k-l) == 7){
    cout <<i<<"-"<<j<<"-"<<k<<"-"<<l<<"=7\n";
  }
  return 0;
}

Measured memory_bytes: 3648
n=int(input())
a=list(map(int, input().split()))
mod=10**9+7

bins_zero=[0]*61
bins_one=[0]*61
for a_i in a:
    a_i_bin=list(str(bin(a_i))[2:].zfill(61))
    for i in range(len(a_i_bin)):
        if a_i_bin[i]=='0':
            bins_zero[i]+=1
        else:
            bins_one[i]+=1

ans=0
for i in range(61):
    ans+=(bins_one[i]*bins_zero[i]*(2**(60-i)))
print(ans%mod)



Measured memory_bytes: 125624
n,m=gets.split.map &:to_i
a=gets.split.map{|i|i.to_i-m}
h=Hash.new(0)
h[0]=1
hh=h.dup
n.times do |i|
  h.each do |e,v|
    hh[a[i]+e]+=v
  end
  h=hh.dup
end
p h[0]-1

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << fixed << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

// end of template
struct node {
    int parent; // parent
    int left; // left child
    int right; // right sibling
    int depth; // root: 0
    void init(){
        parent = nil;
        left = nil;
        right = nil;
        depth = nil;
    }
};

vector<node> nd;

void calcDepth(int parent, int cd){ // parent index, node, current depth
    nd[parent].depth = cd;
    if (nd[parent].right != nil) {
        calcDepth(nd[parent].right, cd);
    }
    if (nd[parent].left != nil) {
        calcDepth(nd[parent].left, cd + 1);
    }
}

void print(int ind){
    cout << "node " << ind << ": ";
    cout << "parent = " << nd[ind].parent << ", ";
    cout << "depth = " << nd[ind].depth << ", ";
    if (nd[ind].parent == nil) {
        cout << "root";
    }
    else if(nd[ind].left == nil){
        cout << "leaf";
    }
    else{
        cout << "internal node";
    }
    cout << ", [";
    vector<int> child;
    if (nd[ind].left != nil) {
        child.push_back(nd[ind].left);
        int l = nd[ind].left;
        while (nd[l].right != nil) {
            child.push_back(nd[l].right);
            l = nd[l].right;
        }
    }
    rep(i, child.size()){
        if (i) cout << ", ";
        cout << child[i];
    }
    cout << "]" << endl;
}



int main() {
    // source code
    int N = inputValue();
    nd.resize(N);
    rep(i, N){
        nd[i].init();
    }
    rep(i, N){
        int ind = inputValue();
        int childnum = inputValue();
        vector<int> child(childnum);
        rep(j, childnum){
            child[j] = inputValue();
        }
        rep(j, childnum){
            if (j == 0) {
                nd[ind].left = child[j];
            }
            else{
                nd[child[j - 1]].right = child[j];
            }
            nd[child[j]].parent = ind;
        }
    }
    // set root
    int root = -1;
    rep(i, N){
        if (nd[i].parent == nil) {
            root = i;
        }
    }
    
    calcDepth(root, 0);
    
    rep(i, N){
        print(i);
    }
    
    return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  
  if((1<=a && a<=9) && (1<=b && b<=9)){
    cout << a*b << endl;
  }
  else{
    cout << -1 << endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

const int MOD = 1000000007;
const int MAX = 1000014;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

int main(){
  ll n,m;
  cin>>n>>m;
  if(abs(n-m)>1){
    cout<<0<<endl;
    return 0;
  }
  COMinit();
  if(n==m){
    cout<<(fac[n]*fac[n]*2)%MOD<<endl;
  }else cout<<(fac[n]*fac[m]%MOD)<<endl;
  
  return 0;
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define w(x) int x; cin>>x; while(x--)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int dp[100001],a[100001];
int fun(int n)
{
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    for(int i=2;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    return dp[n];
}
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<fun(n-1)<<endl;
    return 0;
}


Measured memory_bytes: 5176
#include<stdio.h>
#include<string.h>
#define MAX 1000

typedef struct dice{
 int num[7];
}dice;




int main(){
dice D;
int i,j;
int temp;
int q;
int mae,ue;

for(i=1;i<=6;i++)scanf("%d",&D.num[i]);

scanf("%d",&q);

for(i=0;i<q;i++){
 scanf("%d %d",&ue,&mae);

 if(D.num[1]==ue && D.num[2]!=mae){

  for(j=0;j<3;j++){
   temp=D.num[2];
   D.num[2]=D.num[4];
   D.num[4]=D.num[5];
   D.num[5]=D.num[3];
   D.num[3]=temp;
   if(D.num[2]==mae)break;
  }

 }

else if(D.num[1]!=ue && D.num[2]==mae){

 for(j=0;j<3;j++){
  temp=D.num[1];
  D.num[1]=D.num[4];
  D.num[4]=D.num[6];
  D.num[6]=D.num[3];
  D.num[3]=temp;
  if(D.num[1]==ue)break;
 }

}

else if(D.num[1]!=ue && D.num[2]!=mae){

 for(j=0;j<=3;j++){
  temp=D.num[1];
  D.num[1]=D.num[4];
  D.num[4]=D.num[6];
  D.num[6]=D.num[3];
  D.num[3]=temp;
  if(D.num[1]==ue)break;
 }

if(D.num[1]!=ue){

for(j=0;j<3;j++){
 temp=D.num[1];
 D.num[1]=D.num[2];
 D.num[2]=D.num[6];
 D.num[6]=D.num[5];
 D.num[5]=temp;
 if(D.num[1]==ue)break;
}
}





 for(j=0;j<3;j++){
   temp=D.num[2];
   D.num[2]=D.num[4];
   D.num[4]=D.num[5];
   D.num[5]=D.num[3];
   D.num[3]=temp;
   if(D.num[2]==mae)break;
  }


}

printf("%d\n",D.num[3]);

}

return 0;
}


Measured memory_bytes: 2048
#include <iostream>
using namespace std;
int main(void){
    
    int A, B, C;
    cin >> A >> B >> C;
    
    if(A == B && B != C){
        cout << "Yes" << endl;
        return 0;
    }
    if(B == C && C != A){
        cout << "Yes" << endl;
        return 0;
    }
    if(C == A && A != B){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8

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

int main(){
	while(1){
		int h,w,ret=0;
		cin>>w>>h;
		if(w==0)return 0;
		VS board(h);
		REP(i,h)cin>>board[i];
		priority_queue<PII> q;
		REP(i,h){
			REP(j,w){
				if(board[i][j]=='@'){
					board[i][j]='.';
					q.push(MP(i,j));
					break;
				}
			}
		}
		while(!q.empty()){
			PII tmp = q.top();
			q.pop();
			if(board[tmp.first][tmp.second] != '.')continue;
			board[tmp.first][tmp.second] = '#';
			ret++;
			REP(i,4){
				if(tmp.first+dy[i] < h&& 0<= tmp.first+dy[i] && tmp.second+dx[i]<w && 0<=tmp.second+dx[i])
					q.push(MP(tmp.first+dy[i], tmp.second+dx[i]));
			}
		}
		cout << ret << endl;

	}
}

Measured memory_bytes: 1220
H, W = map(int, input().split())
mass = [input() for i in range(H)]

# print(mass)
flag = 0
for i in range(H):
    for j in range(W):
        if mass[i][j] == ".":
            continue
        if 0 <= i-1 < H and mass[i-1][j] == '#':
            continue
        elif 0 <= i+1 < H and mass[i+1][j] == '#':
            continue
        elif 0 <= j-1 < H and mass[i][j-1] == '#':
            continue
        elif 0 <= j+1 < H and mass[i][j+1] == '#':
            continue
        else:
            # print(i, j)
            flag = 1
            break
if flag:
    print("No")
else:
    print("Yes")

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A < C && B < D && C <= B){
    cout << (B - C) << endl;
    return 0;
  }else if(C <= A  && B <= D){
  	cout << (B - A) << endl;
    return 0;
  }else if(C <A  && D < B && A <= D){
  	cout << (D - A) << endl;
    return 0;
  }else if(A <= C && D <= B){
    cout << (D - C) << endl;
    return 0;
  }else{
    cout << 0 << endl;
    return 0;
  }
}

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

long power(long x, long y, long mod){
  long ans = 1, tmp = x;
  while(y>0){
    if(y & 1){
      ans *= tmp%mod;
      ans %= mod;
    }
    tmp *= tmp;
    tmp %= mod;
    y >>= 1;
  }
  return ans;
}

int main(){
  long n,m,k;
  cin >> n >> m >> k;
  long mod = 998244353;
  long ans = 0;
  long comb = 1;
  rep(ki,k+1){
    ans += (((m*power(m-1,n-ki-1,mod))%mod)*comb)%mod;
    ans %= mod;
    comb *= n-1-ki;
    comb %= mod;
    comb *= power(ki+1,mod-2,mod);
    comb %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  bool p[8];
  int q=0;
  rep(i,0,8) p[i]=false;
  rep(i,0,n){
    int a;
    cin>>a;
    if(a<3200) p[a/400]=true;
    else q++;
  }
  int mi=0;
  rep(i,0,8){
    if(p[i]) mi++;
  }
  cout<<max(mi,1)<<' '<<mi+q<<endl;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    string sa = "", sb = "";
    rep(i, b)
    {
        sa += to_string(a);
    }
    rep(i, a)
    {
        sb += to_string(b);
    }
    vector<string> S{sa, sb};
    sort(S.begin(), S.end());
    cout << S[0] << endl;
    //system("pause");
    return 0;
}

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

namespace ConsoleApp1
{
    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            B();
        }

        static void B()
        {
            var ABC = ReadSplitInt();
            var A = ABC[0];
            var B = ABC[1];
            var C = ABC[2];

            for (int i = A; i <= A * B; i += A)
            {
                if (i % B == C)
                {
                    Console.WriteLine("YES");
                    return;
                }
            }
            Console.WriteLine("NO");
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static IList<string> ReadSplit() => Read().Split().ToList();
        static IList<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=1e9;
int m,n;
int in[100001];
int edge[100001][2];
vector<int> g[100001];
vector<int> mpp[100001];
vector<int> mp;
int rts,a,b,c,d;
int root[100001];
bool used[100001];
bool vis[100001];
int need,ans;
ll res;
int bug;
void dfs(int x,int r){
	used[x]=true;
	mpp[r].push_back(x);
	for(int t=0;t<g[x].size();t++){
		if(!used[g[x][t]]) dfs(g[x][t],r);
	}
	return;
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++){
    	cin>>in[i];
	}
	for(int i=0;i<m;i++){
		cin>>edge[i][0]>>edge[i][1];
		g[edge[i][0]].push_back(edge[i][1]);
		g[edge[i][1]].push_back(edge[i][0]);
	}
	if(n==1){
		cout<<0<<endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		if(!used[i]){
			dfs(i,i);
			root[rts]=i;
			rts++;
		}
	}
	if(rts==1){
		cout<<0<<endl;
		return 0;
	}
	for(int i=0;i<rts;i++){
		if(mpp[root[i]].size()==1) b++;
	}
	need=n-1-m;
	need*=2;
//	cout<<b<<" "<<need<<" "<<rts<<endl;
	if(n-rts<rts-2){
		cout<<"Impossible"<<endl;
		return 0;
	}
	for(int i=0;i<rts;i++){
		ans=inf;
		for(int j=0;j<mpp[root[i]].size();j++){
			if(ans>in[mpp[root[i]][j]]){
				ans=in[mpp[root[i]][j]];
				a=mpp[root[i]][j];
			}
		}
		res+=ans;
		vis[a]=1;
	}
	need-=rts;
	for(int i=0;i<n;i++){
		if(!vis[i]) mp.push_back(in[i]);
	}
	sort(mp.begin(),mp.end());
	for(int i=0;i<need;i++){
		res+=mp[i];
	}
	cout<<res<<endl;
    return 0;
}
/*
5 2
5 4 3 2 1
0 1
1 2
*/ 

Measured memory_bytes: 10872
N, M = map(int, input().split())
lLst = [0] * M
rLst = [0] * M
for i in range(M):
    lLst[i], rLst[i] = map(int, input().split())

lLst.sort(reverse=True)
rLst.sort()
if lLst[0] > rLst[0]:
    ans = 0
else:
    ans = rLst[0] - lLst[0] + 1

print(ans)

Measured memory_bytes: 13092
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def choose3(bamboos: list, a: int, b: int, c: int):
    bamboos.sort(reverse=True)
    l = len(bamboos)
    minmp = float('inf')
    
    for idx in range(l):
        for jdx in range(idx+1,l):
            for kdx in range(jdx+1,l):
                minmp = min(minmp,
                            abs(bamboos[idx]-a)\
                             + abs(bamboos[jdx]-b)\
                             + abs(bamboos[kdx]-c))
    return minmp


def dfs(bamboos: list, a: int, b: int, c: int, mp: int):

    l = len(bamboos)
    
    if l == 3:
        return mp + choose3(bamboos, a, b, c)
    
    else:
        minmp = mp + choose3(bamboos, a, b, c)
        
        for p1 in range(l):
            for p2 in range(p1+1,l):
                newbamboos = [bamboos[p1] + bamboos[p2]]
                
                for p in range(l):
                    if p == p1 or p == p2:
                        continue
                    else:
                        newbamboos.append(bamboos[p])
                
                minmp = min(minmp, dfs(newbamboos, a, b, c, mp+10))
                del newbamboos
                
        return minmp
    
n,a,b,c = li()
laaa = [ni() for _ in range(n)]

print(dfs(laaa, a, b, c, 0))

Measured memory_bytes: 63228
#include<bits/stdc++.h>
//#include <boost/lexical_cast.hpp>
using namespace std;

#define pb push_back
#define mp make_pair
#define inf 1000000000
#define mod 1000000007

#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define sc(n) scanf("%c",&n)
#define ssc(n) scanf(" %c",&n)

#define pin(n) printf("%d\n",n)
#define pis(n) printf("%d ",n)
#define pln(n) printf("%lld\n",n)
#define pls(n) printf("%lld ",n)
#define pn printf("\n")
#define ps(n) printf("%s",n)
#define psn(n) printf("%s\n",n)

vector<int> primes;  //primes.size() = 78498 //last prime number = 999983
void sieve()
{
    vector<bool> a(1000000,false);
    for(int u=2;u<=1000000;u++)
    {
        if(a[u])continue;
        for(int i=2*u;i<=1000000;i+=u)a[i]=true;
    }
    for(int i=2;i<=1000000;i++)
    {
        if(!a[i])primes.pb(i);
    }
}

 long gcd(long a, long b)
{
    //cout<<"entering numbers gcd "<< a << " "<<b<<endl;
    while(1)
    {
        if(a==0)return b;
        b%=a;
        if(b==0) return a;
        a%=b;
    }
}
long lcm(long  a, long b)
{
    //cout<<"entering numbers "<< a << " "<<b<<endl;
    long g=gcd(a,b);
    return a*(b/g);
}

int digitCount(int n)
{
    int c=0;
    while(n!=0)
    {
        c+=n%10;
        n/=10;
    }
    return c;
}

int parseInt(string str)
{
    int a=0;
    int l=str.length();
    for(int i=0;i<l;i++)
    {
        a*=10;
        a+=str[i]-48;
    }
    return a;
}

long parseLong(string str)
{
    long a=0;
    int l=str.length();
    for(int i=0;i<l;i++)
    {
        a*=10;
        a+=str[i]-48;
    }
    return a;
}

int main()
{
    int n;
    si(n);
    vector<long> v;
    //for(int i=0;i<n;i++)sl(ary[i]);
    while(n--)
    {
        long a;
        cin>>a;
        v.pb(a);
    }
    long ans;
    ans=accumulate(v.begin(),v.end(),(long)1,lcm);
    cout<<ans<<endl;
    //cout<<lcm(10,1000000000000000000);

}


Measured memory_bytes: 256
from heapq import *
N,M = map(int,input().split())
L = [[] for m in range(M)]
H = []
ans = 0

for n in range(N):
  a,b = map(int,input().split())
  if a<=M:
    L[M-a]+=[b]
    
for m in range(M-1,-1,-1):
  for l in L[m][::-1]:
    heappush(H,-l)
  if 0<len(H):
    ans-=heappop(H)

print(ans)

Measured memory_bytes: 24312
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
int N,x,y,sw,pw3=1,A[531441],B[531441],S[200001];
char T[200001];
char* replace(char* s,const char* before,const char* after)
{
  assert(s!=(char*)NULL);assert(before!=(char*)NULL);assert(after!=(char*)NULL);
  const size_t szb=strlen(before),sza=strlen(after);
  char* pt=s;
  if(szb==0)return s;
  for(;;)
  {
    pt=strstr(pt,before);if(pt==(char*)NULL)break;const char* remain=pt+szb;
    memmove(pt+sza,remain,strlen(remain)+1);
    memcpy(pt,after,sza);
    pt+=sza;
  }
  return s;
}
signed main(void)
{
  x=scanf("%d %s",&N,T);
  replace(T,"SS","");if(T[0]=='\n')return 0;
  rep(i,N)
  {
    rep(j,pw3)rep(k,3)B[j+k*pw3]=k;sw=0;
    rep(j,strlen(T))
    {
      if(T[j]=='R')
      {
        y=S[j];
        rep(k,3){x=y+k*pw3;if(B[x]+sw==2)S[j]=x;B[x]+=sw+1;B[x]%=3;}
      }
      if(T[j]=='S')sw^=1;
    }
    rep(j,pw3){y=A[j];rep(k,3){x=j+k*pw3;A[x]=y+(sw?3-B[x]:B[x])%3*pw3;}}
    pw3*=3;
  }
  rep(i,pw3)printf("%d%c",A[i],i+1==pw3?'\n':' ');
}

Measured memory_bytes: 8988
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
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; }
const ll LINF=0x1fffffffffffffff;
int main(){
    ll n;
    cin>>n;
    vector<ll> h(n),dp(n,LINF);
    rep(i,0,n) cin>>h[i];
    dp[0]=0;
    rep(i,1,n){
        chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i-1>0) chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1792
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a<b){
            if(b<=c){
                System.out.printf("%d %d %d\n",a,b,c);
            }else if(a>=c){
                System.out.printf("%d %d %d\n",c,a,b);
            }else if(a<c && c<b){
                System.out.printf("%d %d %d\n",a,c,b);
            }
        }else{
            if (a <=c) {
                System.out.printf("%d %d %d\n", b, a, c);
            } else if (b >=c) {
                System.out.printf("%d %d %d\n", c, b, a);
            }else if(b<c && c<a){
                System.out.printf("%d %d %d\n",b,c,a);
            }
        }
    }
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const LL INF = 1e15;

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

  LL N, K, Q;
  cin >> N >> K >> Q;
  VL xs(N);
  cin >> xs;

  LL ans = INF;
  REP(ii,N){
	LL mn = xs[ii];
	LL lb = mn-1, ub = 1e10;
	while(ub-lb>1){
	  LL m = (lb + ub) / 2;

	  LL sum = 0;
	  LL l = 0, o = 0;
	  REP(j,N){
		if(xs[j] < mn){
		  sum += max(0ll, min(l+o+1-K, l));
		  l = o = 0;
		  continue;
		}
		else if(xs[j] <= m){
		  ++l;
		}
		else
		  ++o;
	  }
	  sum += max(0ll, min(l+o+1-K, l));

	  if(sum >= Q) ub = m;
	  else lb = m;
	}

	if(ub >= mn && ub <= 1e9){
	  mini(ans, ub-mn);
	}
  }
  cout << ans << endl;
  

  return 0;
}


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

int main(){
  int n,c=0; cin>>n;
  string s; cin>>s;
  list<char> ls;
  for(int i=0;i<n;i++){
    if(s[i]=='('){
      c++;
      ls.push_back('(');
    }else{
      if(c!=0){
        c--;
        ls.push_back(')');
      }else{
        ls.push_front('(');
        ls.push_back(')');
      }
    }
  }for(int i=0;i<c;i++){
    ls.push_back(')');
  }
  int x=ls.size();
  for(int i=0;i<x;i++){
    cout<<ls.front();
    ls.pop_front();
  }cout<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();

		int ramen = 700;
		char[] ch = S.toCharArray();
		for(int i = 0;i < ch.length;i++) {
			if(ch[i] == 'o') {
				ramen += 100;
			}
		}
		System.out.println(ramen);
	}
}

Measured memory_bytes: 21972
N,K,Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
B=[]
for x in range(0,N):
    B.append(0)
for x in range(0,Q):
    B[A[x]-1]=B[A[x]-1]+1
for x in range(0,N):
    if B[x]>=Q-K+1:
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 8632
#include <bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main() {
int h,w;
cin>>h>>w;
 char m[66][66];
 for(int i=1;i<=h;i++){
      for(int j=1;j<=w;j++){
     cin>>m[i][j];
 }
 }
string ans ="Yes";
 for(int i=1;i<=h;i++){
      for(int j=1;j<=w;j++){
if(m[i][j]=='#' && m[i+1][j]!='#' && m[i-1][j]!='#' && m[i][j+1]!='#' && m[i][j-1]!='#')ans="No";
 }
 }
cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

			if(S.charAt(1) == 'B') {
				System.out.println("ARC");
			} else {
				System.out.println("ABC");
			}
		}
	}
}

Measured memory_bytes: 27004
def solve():
    N = int(input())
    V = "Vacant"    
    M = "Male"
    F = "Female"

    l = 0
    r = N-1

    print(l)
    s = input()
    if s == V:
        return

    x = [F, F]
    x[s==F] = M
    
    while True:
        mid = (l+r+1)//2
        print(mid)
        s = input()
        if s == V:
            return
            
        if s == x[mid&1]:
            l = mid+1
        else:
            r = mid-1

solve()

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

int main(){
  long long N,A,B;
  cin >> N >> A >> B;
  long long tmp1;
  long long tmp2;
  long long tmp3;
  tmp1 = N / (A+B);
  tmp2 = N % (A+B);
  if (tmp2 >= A){
    cout << tmp1 * A + A << endl;
  }else if (tmp2 < A){
    cout << tmp1 * A + tmp2 << endl;
  }
}

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

using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  int x = 0;
  int mx = 0;
  for(int i = 0; i < N; i++) { 
    char s;
    cin >> s; 
    if( s == 'I' ) {
      x++;
    } else if (s == 'D') {
      x--;
    }
    mx = max(mx, x);
  }

  cout << mx << "\n";

  return 0;
}


Measured memory_bytes: 256
m=0
a=0
r=0
c=0
h=0
n=int(input())
for i in range(n):
  s=input()
  if s[0]=="M":m+=1
  elif s[0]=="A":a+=1
  elif s[0]=="R":r+=1
  elif s[0]=="C":c+=1
  elif s[0]=="H":h+=1
  else:pass

li=[m,a,r,c,h]
ans=0
for ai in range(5):
  for bi in range(5):
    for ci in range(5):
      if ci>bi>ai:
        ans+=li[ai]*li[bi]*li[ci]
print(ans)

Measured memory_bytes: 49768