akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint dp[55][55][2605];

int main() {
  int n, score;
  cin >> n >> score;
  dp[0][0][0] = 1;
  rep(i,n) {
    rep(j,i+1)rep(k,score+1) {
      {
        int nj = j;
        dp[i+1][nj][k+nj*2] += dp[i][j][k];
      }
      {
        int nj = j+1;
        dp[i+1][nj][k+nj*2] += dp[i][j][k];
      }
      {
        int nj = j;
        mint x = j*2;
        dp[i+1][nj][k+nj*2] += dp[i][j][k]*x;
      }
      if (j >= 1) {
        int nj = j-1;
        mint x = j*j;
        dp[i+1][nj][k+nj*2] += dp[i][j][k]*x;
      }
    }
  }
  mint ans = dp[n][0][score];
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 61952
import sys
input = sys.stdin.readline
S = list(input())[: -1]
g = 0
p = 0
res = 0
for i in range(len(S)):
  if g > p:
    p += 1
    res += S[i] == "g"
  else:
    g += 1
    res -= S[i] == "p"
print(res)

Measured memory_bytes: 49776
// AOJ 0539: Pizza
// 2017.9.1 bal4u@uu
// 2017.11.14

#include <stdio.h>
#include <stdlib.h>

#define MIN(a,b) ((a)<=(b)?(a):(b))

int p[100003]; int n;

int cmp(int *a, int *b) { return *a - *b; }

int bsrch(int x)
{
	int m, l = 0, r = n;
    while (l < r) {
        m = (l + r) >> 1;
		if (p[m] == x) return 0;
		if (p[m] < x) l = m + 1; else r = m;
    }
	return MIN(x-p[l-1], p[l]-x); 
}

char buf[15], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int d, m, i, k;
	int final, ans;

	while (fgets(bp=buf, 15, stdin) && *buf != '0') {
		d = getint();
		fgets(bp=buf, 15, stdin), n = getint();
		fgets(bp=buf, 15, stdin), m = getint();

		p[0] = 0;
		for (i = 1; i < n; i++) fgets(bp=buf, 15, stdin), p[i] = getint();
		qsort(p, n, sizeof(int), cmp);
		final = p[n-1];

		for (ans = 0, i = 0; i < m; i++) {
			fgets(bp=buf, 15, stdin);
			k = getint();
			if (k >= final) ans += MIN(d-k, k-final);
			else ans += bsrch(k);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2520
from collections import defaultdict
from itertools import permutations
import sys
sys.setrecursionlimit(10000)
N,M=list(map(int,input().split()))
links=defaultdict(set)
for i in range(M):
    a,b=list(map(int, input().split()))
    links[a].add(b)
    links[b].add(a)
ct=0
for pts in permutations(range(2,N+1),N-1):
    current=1
    for p in pts:
        if  p not in links[current]:
            break
        else:
            current=p
    else:
        ct+=1
print(ct)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch DiceAndCoin | diff DiceAndCoin.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address DiceAndCoin.cpp && ./a.out

/*
 
 5/19/2019
 
 5:10-
 
 */

LL N,K;

void solve() {
  double res=0;
  FORE(x,1,N) {
    if(x<=K-1) {
      LL xx=x; int cnt=0;
      while((xx<<cnt)<K) ++cnt;
      double a=1.0/N*pow(0.5,cnt);
      res+=a;
    } else {
      res+=1.0/N;
    }
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>K;
  solve();
  
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
obstacles = [[] for _ in range(H+1)]
for _ in range(N):
    X, Y = map(int, input().split())
    obstacles[X].append(Y)
max_y = 1
for x in range(2, H+1):
    if not obstacles[x]:
        max_y += 1
        continue
    my = min(obstacles[x])
    if max_y >= my:
        print(x - 1)
        exit()
    if max_y + 1 < my:
        max_y += 1
print(H)

Measured memory_bytes: 90728
n,m=map(int,input().split())
ans=0
l=[0] * n
d={}
for i in range(m):
  p,s=input().split()
  q=int(p)-1
  if q in d:
    continue
  if s=="AC":
    ans+=l[q]
    d[q]=s
  else:
    l[q]+=1
print(len(d),ans)

Measured memory_bytes: 20708
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
//typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int T,P,R;
    while(cin>>T>>P>>R && T){
        vector<vector<int>> AC(T,vector<int>(P,0)),WA(T,vector<int>(P,0));
        vector<int> tim(T,0);
        
        rep(i,0,R){
            int t,p,timee;
            string s;
            cin>>t>>p>>timee>>s;
            t--; p--;
            if(s=="CORRECT"){
                AC[t][p]++;
                tim[t]+=timee+WA[t][p]*1200;
            }else if(s=="WRONG"){
                WA[t][p]++;
            }
        }
        
        vector<int> AC_count(T,0),WA_count(T,0);
        rep(i,0,T){
            rep(j,0,P){
                if(AC[i][j])AC_count[i]++;
                if(WA[i][j])WA_count[i]++;
            }
        }
        
        vector<pair<int,pair<int,int>>> rank(T);
        rep(i,0,T)rank[i]=MP(-AC_count[i],MP(tim[i],i+1));
        Sort(rank);
        
        rep(i,0,T){
            cout<<rank[i].se.se<<" "<<-rank[i].fi<<" "<<rank[i].se.fi<<endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3156
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<ll,ll> P;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    int n,m;
    cin >> n >> m;
    priority_queue<P> que;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
        ll v = a[i];
        int cnt = 1;
        while(i+1<n && v==a[i+1]){
            cnt++;
            i++;
        }
        que.push(P(v,cnt));
    }
    rep(i,m){
        ll b,c;
        cin >> b >> c;
        que.push(P(c,b));
    }

    ll sum=0;
    ll ans=0;
    while(sum<=n){
        P v = que.top(); que.pop();
        if(sum+v.second<=n){
            sum += v.second;
            ans += v.first*v.second;
        }else{
            ans += v.first*(n-sum);
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,a,b,i,ans=0,num;
	cin>>n>>a>>b;
	for(i=1;i<=n;i++){
		int sum=0;
		num=i;
		while(num>0){
			sum+=num%10;
			num/=10;
		}
		if(a<=sum&&b>=sum)ans+=i;
	}
	cout<<ans<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define EPS (1e-7)
#define INF (1e9 + 10)
#define PI (acos(-1))
#define MOD (1000000007)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
template<class T>string watch(T &v){string res="";for(auto f:v)res+=(to_string(f)+" ");return res;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N, K;cin >> N >> K;
    VI a(N, 0);
    REP(i, N) {
        cin >> a[i];
    }
    sort(ALL(a), greater<int>());
    ll DP[N+1][K];
    REP(i, N+1) {
        REP(j, K+1) {
            DP[i][j] = 0;
        }
    }
    DP[0][0] = 1;
    int flag;
    int ans = 0;
    REP(i, N) {
        flag = 1;
        REP(j, K) {
            DP[i+1][j] |= DP[i][j];
            if (j + a[i] <= K-1){
                DP[i+1][j+a[i]] |= DP[i][j];
            } else {
                if (DP[i][j] > 0){
                    flag = 0;
                }
            }
        }
        if (flag){
            ans += flag;
        } else {
            ans = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 195584
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		
		
			

		
		
		System.out.println(K*(int)Math.pow(K-1, N-1));
		
		
	}

}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#pragma region include

#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>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
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;

void solve() {
	int A[3][3];
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> A[i][j];
		}
	}
	int N;
	cin >> N;
	int b;
	for (int cnt = 0; cnt < N; ++cnt) {
		cin >> b;
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < 3; ++j) {
				if (A[i][j] == b) {
					A[i][j] = 999;
				}
			}
		}
	}
	////////////////////////
	//
	bool ans = false;

	for (int i = 0; ans ==  false && i < 3; ++i) {
		ans = true;
		for (int j = 0; ans && j < 3; ++j) {
			if (A[i][j] != A[i][(j + 1) % 3] ) {
				ans = false;
				break;
			}
		}
		
	}
	if (ans) {
		cout << "Yes" << endl;
		return;
	}
	////////
	ans = false;
	for (int i = 0; ans == false && i < 3; ++i) {
		ans = true;
		for (int j = 0; ans && j < 3; ++j) {
			if (A[j][i] != A[(j+1)%3][i]) {
				ans = false;
				break;
			}
		}

	}
	if (ans) {
		cout << "Yes" << endl;
		return;
	}
	//
	{
		ans = true;
		if (A[0][0] != A[1][1] || A[1][1] != A[2][2] || A[2][2] != A[0][0]) {
			ans = false;
		}
		if (ans) {
			cout << "Yes" << endl;
			return;
		}

		ans = true;
		if (A[0][2] != A[1][1] || A[1][1] != A[2][0] || A[2][0] != A[0][2]) {
			ans = false;
		}
		if (ans) {
			cout << "Yes" << endl;
			return;
		}
	}
	{
		cout << "No" << endl;
	}
}

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

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
s = int(input())

def fac(n):
  if n == 0:
    return 1
  rst = n
  for i in range(1,n):
    rst *= i
  return rst

max_ind = s // 3
rst = 0
for i in range(1, max_ind+1):
  rst += fac(s-3*i+i-1)//fac(i-1)//fac(s-3*i)
print(rst % (10**9+7))


Measured memory_bytes: 9180
x1, y1, x2, y2 = map(int, input().split());

x3 = x2 - (y2-y1);
y3 = y2 + (x2-x1);
x4 = x1 - (y2-y1);
y4 = y1 + (x2-x1);

print(x3,y3,x4,y4);


Measured memory_bytes: 2940
/* in the name of allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 105, V = 1e5 + 5;
long long n, w, a[N], v[N], dp[N][V];

void readInput() {
	cin >> n >> w;
	for (int i = 1; i <= n; i++)
		cin >> a[i] >> v[i];
}

void solve() {
	memset(dp, 63, sizeof dp);
	for (int i = 0; i <= n; i++)
		dp[i][0] = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j < V; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j >= v[i] && dp[i - 1][j - v[i]] + a[i] < dp[i][j])
				dp[i][j] = dp[i - 1][j - v[i]] + a[i];
		}
	for (int j = V - 1; j >= 0; j--)
		for (int i = 1; i <= n; i++)
			if (dp[i][j] <= w) {
				cout << j << endl;
				return;
			}
	cout << 0 << endl;
}

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve();
	return 0;
}


Measured memory_bytes: 82304
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
using namespace std;
int main()
{
    int a, ans;
    cin >> a;
    if (a % 2 == 1)
    {
        ans = (a / 2) * (a / 2 + 1);
    }
    else
    {
        ans = (a / 2 ) * (a / 2);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
const double EPS = 1e-3;
const double PI = 3.1415926535897932384626433832795028841971;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const int MAX = 510000;
const int MOD = 1000000007;

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

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<ll> primes;
void primeinit()
{
    primes.push_back(2);
    ll cur = 3;
    while (cur * cur <= 1000'100'000ll)
    {
        bool is_prime = true;
        for (auto prime : primes)
        {
            if (cur % prime == 0)
            {
                is_prime = false;
                break;
            }
            if (prime * prime > cur)
                break;
        }
        if (is_prime)
            primes.push_back(cur);
        cur++;
    }
}
map<ll, int> factorization(int m)
{
    map<ll, int> ret;
    for (ll prime : primes)
    {
        if (m % prime == 0)
        {
            while (m % prime == 0)
            {
                ret[prime]++;
                m /= prime;
            }
            if (m == 1)
                break;
        }
    }
    if (m != 1)
        ret[m]++;
    return ret;
}
int main(int argc, char const *argv[])
{
    COMinit();
    cerr << "ok" << endl;
    primeinit();
    cerr << "ok" << endl;
    int n, m;
    cin >> n >> m;
    cerr << m << endl;
    auto fact = factorization(m);
    ll ans = 1;
    for (auto x : fact)
    {
        ll num = x.second;
        ans *= COM(num + n - 1, n - 1);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12288
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;


void solve(){
    int n, d, a, j = 0, ans = 0;
    cin>>n>>d>>a;
    vector<pair<int,int> > v;
    int c[n+10] = {0};
    f(i,n){
        int x, y;
        cin>>x>>y;
        v.pb(mp(x,y));
    }
    sort(all(v));
    f(i,n){
        while(j < n && v[j].F <= v[i].F + 2*d)j++;
        int cnt = max((v[i].S - c[i]*a + a - 1) / a, 0ll);
        c[i] += cnt;
        c[j] -= cnt;    
        ans += cnt;
        c[i+1] += c[i];
    }
    cout<<ans;
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 8048
#include<cstdio>
#include<cmath>
using namespace std;
#define LL long long
#define pa pair<int,int>
LL read()
{
	LL x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int main()
{
	int q=read();
	while(q--)
	{
		LL a=read(),b=read(),m=a*b;
		LL M=(LL)sqrt((long double)(m-1LL)),ans=M*2LL;
		LL t;
		if(a!=b)
		{
			if(a<=M)ans--;
			if(b<=M)ans--;
			if(m%M==0)t=m/M-1;
			else t=m/M;
			if(t==M)
			{
				ans--;
				if(a==M&&b==M)ans++;
			}
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = [int(x) - 1 for x in input().split()]

# 最初のループを回るまで
loop = 0
city = 0
b = set([0])
while True:
    loop += 1
    if A[city] in b:
        break
    else:
        city = A[city]
        b.add(city)

loop_start = A[city]

# ループの始点にたどり着くまで
pre = 0
city = 0
while True:
    pre += 1
    if A[city] == loop_start:
        break
    else:
        city = A[city]

if loop > pre:
    loop -= pre

if K < pre:  # ループに入る前に終了の場合
    city = 0
    for i in range(K):
        city = A[city]
    print(city + 1)
    
else:  # ループに入って終了
    K -= pre
    last = K % loop
    city = loop_start
    
    for i in range(last):
        city = A[city]
    print(city + 1)

Measured memory_bytes: 32576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll n,m,d[102][102],L[1001],R[1001],C[1001];

void warshall_floyd() {
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
	cin>>n>>m;
	for(int i=0;i<102;i++){
		for(int j=0;j<102;j++){
			d[i][j]=inf;
		}
	}
	for(int i=0;i<m;i++){
		int l,r,c;
		cin>>l>>r>>c;
		l--;r--;
		d[l][r]=d[r][l]=c;
		L[i]=l;R[i]=r;C[i]=c;
	}
	warshall_floyd();
	ll ans=m;
	for(int i=0;i<m;i++){
		ll nowl=L[i],nowr=R[i],nowc=C[i];
		if(d[nowl][nowr]==nowc){
			ans--;
		}
	}
	cout <<ans;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
const long long MOD = 1e9 + 7, INF = 1e16;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

int N, M, K, A, B, C, D, H, W, X, Y, Z;
string s, t;

signed main()
{
    cin >> N >> s;
    vector<int> sum(N + 1, 0);
    for (int i = 0; i < N; i++)
    {
        sum[i + 1] += sum[i] + (s[i] == '#');
    }

    int ans = INF;
    for (int i = 0; i < N; i++)
    {
        chmin(ans, sum[i] + (N - i - 1) - (sum[N] - sum[i + 1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	int cnt=0;
	int s = a;
	int i=2;
	int bl = 1;
	while(bl<b){
	    bl--;
	    bl+=a;
		cnt++;   		
	}
	cout<<cnt<<endl;
	
	
}

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


int main(){
    
    long long H,N,A,AA=0;
    cin>>H>>N;
    rep(i,0,N){
        cin>>A;
        AA+=A;
    }
    if(AA>=H)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}




Measured memory_bytes: 256
n=int(input())
l=list(map(int, input().split()))
dap=1
nodap=0
zeroexist=0
for i in range(n):
    zeroexist+=(l[i]==0)
if zeroexist>0:
    print("0")
else:
    for i in range(n):
        dap*=l[i]
        if dap>1000000000000000000:
            nodap+=1
            break
    if nodap==1:
        print("-1")
    else:
        print(dap)
    

Measured memory_bytes: 84716
#include<bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int  // ranges from (0 - twice of long long int)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define mod 1000000007LL
#define llpair pair<ll,ll>
#define INF 1000000000000000000ll
#define np next_permutation
#define PI acos(-1)
#define deb(x) cout<<#x<<" "<<x<<endl;
#define rotate_left(vec,amt) rotate(vec.begin(),vec.begin()+amt,vec.end());
#define rotate_right(vec,amt) rotate(vec.begin(),vec.begin()+vec.size()-amt,vec.end());

int main() {
  //  auto start = chrono::high_resolution_clock::now();
    fio;
    ll t=1; 
   // cin>>t;
    while(t--)
    {
		ll r; cin>>r;
		double ans= 2 * PI *r;
		cout<<ans<<"\n";
    }

   // auto finish = chrono::high_resolution_clock::now();
   // cerr << "Time elapsed: " << (chrono::duration<long double>(finish-start)).count() << "s\n";
    return 0;
        
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


int main() {
    ll N;
    cin >> N;
    
    ll m = 0;
    
    for (ll i=1; i*i <= N; i++) {
        if (N % i == 0) {
            if (N / i - 1 > i) m += N / i - 1;
        }
    }
    
    cout << m << endl;
    
}

Measured memory_bytes: 256
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()
ans = 10 ** 9
for i in range(-100, 101):
    summ = 0
    for aa in a:
        summ += (aa - i) ** 2
    ans = min(ans, summ)
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

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

    int ans = 0;
    int cnt = 1;
    for ( int i = 1; i < N; i++ ) {
        if ( A[i] == A[i-1] ) { cnt++; }
        else {
            if ( cnt != 1 ) { ans += (cnt)/2; }
            cnt = 1;
        }
    }
    if ( cnt != 1 ) { ans += (cnt)/2; }

    cout << ans << endl;


    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

map<string, VI> idx;
signed main(void)
{
  string s;
  int num;
  while(cin>>s>>num) {
    idx[s].PB(num);
  }

  for(auto i: idx) {
    cout << i.first << endl;
    sort(ALL(i.second));
    REP(j, i.second.size()) {
      cout << i.second[j];
      if(j != i.second.size()-1) cout << " ";
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3112
N = int(input())
a = list(map(int, input().split()))
A_total = 0
B_total = 0
a.sort(reverse = True)
for i in range(0, N):
  if i%2 == 0:
    A_total += a[i]
  else:
    B_total += a[i]
    
print(A_total - B_total)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
  ll n, a, count = 0;
  cin >> n;
  map<ll, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a;
    count += mp[i - a];
    mp[a + i]++;
  }
  cout << count << endl;
}


Measured memory_bytes: 26296
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;


const int d8[8][2] = {
	{0, 1},
	{1, 0},
	{0, -1},
	{-1, 0},
	{1, 1},
	{1, -1},
	{-1, 1},
	{-1, -1}
};

int h, w;

bool isB(int x, int y) {
	return (0 <= x && x < w && 0 <= y && y < h);
}

const int INF = 10000;
int n;
int l[5];
int px[5][100], py[5][100];
bool isBomb[22][22];

int dp[22][22][50][32];
bool used[22][22][50][32];

int solve(int x, int y, int t, int f) {
//	printf("%d %d %d %d\n", x, y, t, f);
	for (int i = 0; i < n; i++) {
		if (!(f & (1<<i))) continue;
		if (l[i] == t) return INF;
	}
	for (int i = 0; i < n; i++) {
		if (!(f & (1<<i))) continue;
		if (px[i][t] != x || py[i][t] != y) continue;
		f &= ~(1<<i);
	}
	if (!f) return t;
	if (used[x][y][t][f]) return dp[x][y][t][f];
	used[x][y][t][f] = true;

	int res = solve(x, y, t+1, f);
	for (int i = 0; i < 8; i++) {
		int yy = y + d8[i][1], xx = x + d8[i][0];
		if (!isB(xx, yy)) continue;
		if (isBomb[yy][xx]) continue;
		res = min(res, solve(xx, yy, t+1, f));
	}
	return dp[x][y][t][f] = res;
}

int main() {
	cin >> w >> h >> n;
	int sx, sy;
	cin >> sx >> sy; sx--; sy--;
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		l[i] = k;
		for (int j = 0; j < k; j++) {
			cin >> px[i][j] >> py[i][j];
			px[i][j]--; py[i][j]--;
		}
		isBomb[py[i][k-1]][px[i][k-1]] = true;
		l[i]--;
	}
	int res = solve(sx, sy, 0, (1<<n)-1);
	if (res == INF) res = -1;
	printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 4352
N = int(raw_input())

W = [raw_input().replace("\r", "") for _ in range(N)]

ans = "Yes"

for i in range(N):
    if W.count(W[i]) != 1:
        ans = "No"
        break

    else:
        if i == 0:
            continue

        if W[i][0] != W[i-1][-1:]:
            ans = "No"
            break

print ans

Measured memory_bytes: 2568
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>
#include<ctype.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000000;
int main() {   
    int n;
    bool f=false;
    cin>>n;
    for(int i=0;i<n;i++){
        char c;
        cin>>c;
        if(c=='Y'){
            f=true;
        }
    }
    if(f){
        cout<<"Four"<<endl;
    }else{
        cout<<"Three"<<endl;
    }
}

                           


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int n, m;
    cin >> n >> m;

    int l[m], r[m];
    for (int i = 0; i < m; i++) {
        cin >> l[i] >> r[i];
    }

    int l_max = *(max_element(l, l + m));
    int r_min = *(min_element(r, r + m));

    if (l_max <= r_min) {
        cout << (r_min - l_max + 1) << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


using namespace std;
using namespace __gnu_pbds;

typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<pair<int,int>, null_type,less<pair<int, int> >,rb_tree_tag,tree_order_statistics_node_update > pbds;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)

#define pb push_back
#define ft first
#define sd second
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll power(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b % 2) {
            res *= a;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll power(ll a, ll b, ll mod) {
    ll res = 1;
    a %= mod;
    while(b) {
        if(b % 2) {
            res *= a;
            res %= mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res % mod;
}
const int N = 5e6 + 5;
int n, k, p;

bool ispalin(string &s) {
    int b = true;
    int i=0, j=s.length()-1;
    for(; i<j; i++, j--) {
        if(s[i] != s[j]) return false;
    }
    return true;
}
signed main() {
    int t;
    // cin >> t;
    for(int _=1; _<=t; _++) {
        t = 1;
        string s;
        cin >> s;
        if(ispalin(s)) {
            int len = (s.length()-1)/2;
            string str = s.substr(0, len);
            if(ispalin(str)) {
                int l = (s.length()+3)/2;
                l--;
                string ss = s.substr(l);
                if(ispalin(ss)) {
                    cout << "Yes\n";
                }
                else cout << "No\n";
            }
            else {
                cout << "No\n";
            }
        }
        else {
            cout << "No\n";
        }
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 35000;
const int K = 19;
int mod =  998244353;

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt", "r", stdin);
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c && c == a) cout << "Yes"; else cout << "No";
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] a = new int[m+1];
    for(int i = 0; i < n; i++){
      int k = sc.nextInt();
      for(int j = 0; j < k; j++){
        int tmp = sc.nextInt();
        a[tmp]++;
      }
    }
    int count = 0;
    for(int i = 1; i < m+1; i++){
      if(a[i] == n) count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 23248
import itertools
n, m = map(int, input().split())
d = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a-=1
    b-=1
    d[a][b] = 1
    d[b][a] = 1
ans = 0

nums = [i for i in range(n)]
for num in itertools.permutations(nums):
    if(num[0] != 0):
        continue
    flag = True
    for i in range(n - 1):
        if(d[num[i]][num[i+1]] != 1):
            flag = False
            break
    if(flag):
        ans += 1

print(ans)


Measured memory_bytes: 3188
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int solve(){
  int n,m;cin>>n>>m;
  dump(n,m);

  int c[m]={};
  rep(i, n){
    int k;cin>>k;
    rep(j, k){
      int t;cin>>t;
      t--;
      dump(t, j, k);
      c[t] += 1;
    }
  }

  int res = 0;
  rep(i, m){
    if (c[i]==n) res++;
  }
  cout << res << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

int main()
{
	int r;
	cin >> r;
	if(r < 1200)
	{
		cout << "ABC";
	}
	else if(r < 2800)
	{
		cout << "ARC";
	}
	else
	{
		cout << "AGC";
	}
	cout << endl;
	return 0;
}

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


#define ll          long long
#define uint        unsigned int 
#define ld          long double
#define SAM         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define mod         1000000007
#define mxn         200005
#define pb          push_back
#define pii         pair<int,int>
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define all(x)      x.begin(),x.end()

using namespace std;

/*mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1) return a;
    if(n == 0) return 1;
    if(n%2) return (a*(power((a*a)%mod,n/2)%mod))%mod;           //n is odd
    return power((a*a)%mod,n/2)%mod;                             //n is even
}

const int inf = (int) 1e18;

int inverse(int x)
{
    return power(x,mod-2)%mod;     //Fermat's little theorem
}*/

int main()
{
    SAM;
    int d,t,s;
    cin>>d>>t>>s;
    
    ll temp=t*s;
    if(temp>=d)
        cout<<"Yes";
    else
        cout<<"No";
   
   
    
    return 0;
}




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

using namespace std;

const long long INF = (1ll << 60);

void dfs(int node, vector<bool>& from, vector<bool>& to, vector<vector<int>>& graph){
  if(from[node]) return;
  from[node] = true;
  for(int next : graph[node]){
    dfs(next, from, to, graph);
    if(to[next]){
      to[node] = true;
    }
  }
}

int main(){
  int N, M;
  long long P;
  scanf("%d%d%lld", &N, &M, &P);
  
  vector<long long> coin(N, -INF);
  coin[0] = 0;
  
  vector<vector<int>> graph(N);
  vector<int> A(M), B(M);
  vector<long long> C(M);
  for(int j = 0; j < M; j++){
    scanf("%d%d%lld", &A[j], &B[j], &C[j]);
    A[j]--;
    B[j]--;
    C[j] -= P;
    graph[A[j]].push_back(B[j]);
  }
  
  vector<bool> from(N, false), to(N, false);
  to[N - 1] = true;
  for(int t = 0; t < N; t++){
    for(int i = 0; i < N; i++) from[i] = false;
    dfs(0, from, to, graph);
  }
  
  int num = 0;
  for(int i = 0; i < N; i++){
    if(from[i] && to[i]) num++;
  }
  
  bool fever = false;
  for(int i = 0; i < num; i++){
    for(int j = 0; j < M; j++){
      if(!(from[A[j]] && to[B[j]])) continue;
      if(coin[B[j]] < coin[A[j]] + C[j]){
        coin[B[j]] = coin[A[j]] + C[j];
        if(i == num - 1){
          fever = true;
          break;
        }
      }
    }
  }
  
  if(fever){
    puts("-1");
  }else{
    printf("%lld\n", max(coin[N - 1], 0ll));
  }
  
  return 0;
}

Measured memory_bytes: 640
import sys

def parse(inp):
    n,m = map(int,next(inp).split())
    a = sorted(list(map(int,next(inp).split())))
    bc =[]
    for _ in range(m):
        bc.append(list(map(int,next(inp).split())))
    bc.sort(key = lambda x:x[1],reverse=True)
    return n,m,a,bc
  
def main(inp):
    n,m,a,bc = inp
    changable = sum(row[0] for row in bc)
#     print(changable)
    new =[]
    for i in range(m):
        if(len(new)==n): break
        for _ in range(bc[i][0]):
            if(len(new)==n): break
            new.append(bc[i][1])
    if(changable < n):
        for _ in range(n-changable):
            new.append(0)
#     print(new)
        
    for i in range(n):
        if(a[i] < new[i]): a[i] = new[i]
        else: break
    
    return sum(a)
  
print(main(parse(sys.stdin)))

Measured memory_bytes: 32880
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MOD 1000000007
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail

    int a, b, c;
    cin >> a >> b >> c;
    if ((b * 10 + c) % 4 == 0)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }

    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	var n, k int
	if scanner.Scan() {
		tmp := scanner.Text()
		n, _ = strconv.Atoi(tmp)
	}
	if scanner.Scan() {
		tmp := scanner.Text()
		k, _ = strconv.Atoi(tmp)
	}

	if k%2 == 0 {
		var rs1, rs2 []int
		for i := 1; i <= n; i++ {
			if i%k == 0 {
				rs1 = append(rs1, i)
			} else if i%k == k/2 {
				rs2 = append(rs2, i)
			}
		}
		fmt.Println(len(rs1)*len(rs1)*len(rs1) + len(rs2)*len(rs2)*len(rs2))
	} else {
		var rs []int
		for i := 1; i <= n; i++ {
			if i%k == 0 {
				rs = append(rs, i)
			}
		}
		fmt.Println(len(rs) * len(rs) * len(rs))
	}
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define INF 1e9
#define MOD 1000000007
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main(void){
    ll N,K,Q;cin>>N>>K>>Q;
    vector<int> A(N,0);
    REP(i,Q){
        int a;cin>>a;
        a--;
        A[a]++;
    }
    REP(i,N){
        if(K-(Q-A[i])<=0)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}

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

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define FOR(i,l,r) for(long long i=l; i<r; i++)
#define FOR_REV(i,r,l) for(long long i=r; i>=l; i--)
#define pb push_back
#define mp make_pair

const long long INF = 1e9;

vector <int> spell;
vector <int> cost;

int main()
{
    FAST_IO;
	int h,n;
    cin>>h>>n;

    int a,b;
    FOR(i,0,n)
    {
        cin>>a>>b;
        spell.pb(a);
        cost.pb(b);
    }

    int dp[10004];
    for(int i = 0; i <= 10001; i++){
        dp[i] = INF;
    }

    dp[0] = 0;

    for (int i=0; i<=h; i++)
    {
        for (int j=0; j<n; j++)
        {
            int x = min(h, i + spell[j]);
            // cout<<" x "<<x;
            dp[x] = min(dp[x], dp[i]+ cost[j]);
            // cout<<"val "<<dp[x];
        }
        // cout<<endl;
    }

    cout<<dp[h]<<endl;

}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int town[4];

int main(void) {
    // insert code here...
    for(int i = 0; i < 6; i++){
        int a;
        cin >> a;
        if(a==1){
            town[0]++;
        }
        if(a==2){
            town[1]++;
        }
        if(a==3){
            town[2]++;
        }
        if(a==4){
            town[3]++;
        }
        
    }
    
    bool ans = true;
    for(int i = 0; i < 4; i++){
        if(town[i] > 2 || town[i] == 0){
            ans = false;
        }
    }
    
    if(ans){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np

n = int(input())
b = np.array(list(map(int, input().split())))

ans = []
for i in range(n):
    c = np.arange(1, n - i + 1)
    diff = b - c
    if not 0 in diff:
        print(-1)
        sys.exit()
    rem = np.where(diff == 0)[0][-1]
    ans.append(rem + 1)
    b = np.delete(b, rem)

print(*ans[::-1], sep="\n")

Measured memory_bytes: 27388
#include <iostream> // includes cin to read from stdin and cout to write to stdout
using namespace std; // since cin and cout are both in namespace std, this saves some text
#include <math.h>

int main()
{
    int A, B;
    cin >> A >> B;
    
    int result = max(A+B, max(A-B, A*B));
                     
    cout << result << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val pl = List.fill(n)(sc.nextInt)

  val illegals = pl.zipWithIndex.map(t => (t._1, t._2 + 1)).filter{t => t._1 != t._2}

  val res = if( illegals.size == 0 || illegals.size == 2 ) "YES" else "NO"

  println(res)

}

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

using namespace std;

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

  int num_buf, length;
  cin >> num_buf >> length;

  int cmd, index, val;

  vector<list<int>> arr(num_buf);

  for (int i = 0; i < length; i++) {
    cin >> cmd;
    switch (cmd) {
      // push back
      case 0:
        cin >> index >> val;
        arr[index].push_back(val);

        break;

      // dump
      case 1:
        cin >> index;

        if (!arr[index].empty()) {
          for (auto itr = arr[index].begin(); itr != prev(arr[index].end(), 1); itr++) {
            // cout << " " << *itr;
            cout << *itr << " ";
          }
          cout << arr[index].back() << endl;
        } else {
          cout << endl;
        }

        break;

      // clear
      case 2:
        cin >> index;
        arr[index].clear();
        break;
    }
  }
}




Measured memory_bytes: 18812
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int main(){
	vector<int>prime;
	for(int i=2;i<=100000;i++){
		bool f=1;
		for(int j=2;j*j<=i;j++)if(i%j==0)f=0;
		if(f)prime.push_back(i);
	}
	int n;
	while(cin>>n){
	int a=0,b=0;
	for(int i=0;;i++){
		if(prime[i]>n){b=prime[i];break;}
		else if(prime[i]==n){b=prime[i+1];break;}
		a=max(prime[i],a);
	}
	cout<<a<<" "<<b<<endl;
	}
	return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
 
    int x,y;
    cin >> x >> y;
 
    int a=((4*x)-y)/2;
    int b=(y-(2*x))/2;
 
    if ((a<0)||(b<0))
    {
        cout << "No" << endl;
        return 0;
    }
 
    if (((a+b)==x)&&(((2*a)+(4*b))==y))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3600