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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using ld = long double;

template <typename T>
int sz(T &x) {
  return (int)(x.size());
}

int power(int x, int y, int mod) {
  if (y == 0) {
    return 1;
  }
  int z = power(x, y >> 1, mod);
  z = z * 1ll * z % mod;
  if (y & 1) {
    z = z * 1ll * x % mod;
  }
  return z;
}

const int mod = 998244353;
const int inf = 1'000'000'007;

void solve() {
  int n, k;
  cin >> n >> k;

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

  r[n - 1] = n - 1;

  for (int i = n - 2; i >= 0; --i) {
    if (a[i] < a[i + 1]) {
      r[i] = r[i + 1];
    } else {
      r[i] = i;
    }
  }

  set<int> s;
  int sorted = 1;

  for (int i = 0; i < k; ++i) {
    s.insert(a[i]);
    if (i + 1 < k && a[i] > a[i + 1]) {
      sorted = 0;
    }
  }

  int sortedCnt = sorted;
  int cnt = !sorted;

  for (int i = 1; i + k - 1 < n; ++i) {
    int goodLeft = 1;
    int goodRight = 1;
    if (a[i - 1] == *s.begin()) {
      goodLeft = 0;
    }
    s.erase(a[i - 1]);
    s.insert(a[i + k - 1]);
    if (a[i + k - 1] == *s.rbegin()) {
      goodRight = 0;
    }
    if (r[i] >= i + k - 1) {
      sortedCnt++;
      continue;
    }
    if (goodLeft || goodRight) {
      cnt++;
    }
  }
  cout << cnt + min(1, sortedCnt) << "\n";
}

int main() {
  #ifndef LOCAL58
    // don't forget to remove if interactive
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
  #endif

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

  return 0;
}


Measured memory_bytes: 14232
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",c);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int primes[200];
int prime[1000000];
int pr[100000];
int el[314514],wl[314514];
int er[314514],wr[314514];
int a[114514];
string s[114514];
int ans[114514];
signed main(){
	ic(n)
	rep(0,i,n){
		cin>>a[i];
		if(a[i]%2==0){
			if(a[i]%3!=0&&a[i]%5!=0){
				c("DENIED")
				return 0;
			}
		}
	}
	c("APPROVED")
}				

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define read(arr,n)	for(int i=0;i<n;i++) cin>>arr[i];
#define print(arr,n) for(int i=0;i<n;i++) cout << arr[i]<<' ';cout << endl;
typedef int int32;
#define int ll

using namespace std;

typedef long long ll;

void solve() {
	string s;	cin >> s;
	if (s == "AAA" || s == "BBB") {
		cout << "No\n";
	} else {
		cout << "Yes\n";
	}
}

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


Measured memory_bytes: 256
N=gets.chomp.to_i
task_matrix = []
N.times do
  task_matrix << gets.chomp.split.map(&:to_i)
end

flg = true
total_time = 0

task_matrix.sort_by(&:last).each do |task|
  total_time += task.first
  if total_time > task.last
    flg = false
    break
  end
end

if flg
  puts "Yes"
else
  puts "No"
end

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

int main(){
  int a,b;cin>>a>>b;
  int ans=a*b;
  if(ans%2==0){
    cout<<"Even"<<endl;
  }else{
    cout<<"Odd"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool pass(string s, int b, int d) {
	bool x = true;
	for (int i = b - 1; i < d - 2; i++) {
		if (s.at(i) == '#' && s.at(i + 1) == '#') {
			x = false;
			break;
		}
	}
	return x;
}
bool over(string s, int b, int d) {
	bool x = false;
	for (int i = b - 2; i < d - 1; i++) {
		if (s.at(i) == '.' && s.at(i + 1) == '.' && s.at(i + 2) == '.') x = true;
	}
	return x;
}
int main() {
	int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
	string s; cin >> s;
	if (c < d) {
		bool x = pass(s, b, d);
		bool y = pass(s, a, c);
		if (x && y)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else {
		bool x = over(s, b, d);
		if (!x)cout << "No" << endl;
		else {
			bool y = pass(s, a, d);
			bool z = pass(s, b, c);
			if (y && z)cout << "Yes" << endl;
			else cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
#define ll unsighned long int(

int main(){
    string s[3] = {"Sunny","Cloudy","Rainy"};
    string t;

    cin >> t;
    

    int k;
    for(int i = 0; i < 3; ++i){
        if(s[i] == t)k = i;
    }

    cout << s[(k + 1) % 3] << endl;
}

Measured memory_bytes: 256
N, D = map(int, input().split())
ansB = True
iMinT = D + 1
iMaxT = iMinT + D
ansCnt = 1
while ansB:
    if N <= iMaxT:
        break

    iMinT = iMaxT + D + 1
    iMaxT = iMinT + D
    ansCnt += 1

print(ansCnt)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

ll dp[3005][3005];
int main() {
  int n;cin >> n;
  vi a(n,0);
  rep(i,n) cin >> a.at(i);

  orep(length,n) rep(i,n) {
    int j = i + length;
    // 先手
    if((n + length) % 2 == 0) {
      if(j <= n ) dp[i][j] = max(dp[i][j-1] + a.at(j-1),dp[i+1][j] + a.at(i));
    }
    // 後手
    else {
      if(j <= n ) dp[i][j] = min(dp[i][j-1] - a.at(j-1),dp[i+1][j] - a.at(i));
    }
  }

  cout << dp[0][n] << endl;

  return 0;
}


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

const int INF = 1001001001;
const int mod = 1000000007;

ll pow(ll base, ll order) {
	ll ans = 1;
	rep(i,order - 1) ans *= base;
	return ans;
}

int gcd(int a, int b) {
	if (a < b) {
		int c = a;
		a = b;
		b = c;
	}
	if (b == 0) return a;
	return gcd (b, a % b);
}

int main() {
	int n, m, x;
	cin >> n >> m >> x;

	vector<vector<int>> ca(n, vector<int>(m));
	rep(i, n) rep(j, m + 1) cin >> ca[i][j];
	ll ans = INF;
	for (int bit = 0; bit < (1<<n); bit++) {
		bitset<12> bs(bit);
		ll tmp = 0;
		vector<int> und(m, 0);
		rep(i, n) {
			if (!bs[i]) continue;
			tmp += ca[i][0];
			rep(j, m) {
				und[j] += ca[i][j + 1];
			}
		}
		int learned = 0;
		rep(i, m) {
			if (und[i] >= x) learned++;
		}
		if (learned != m) continue;
		ans = min(ans, tmp);
	}
	if (ans == INF) ans = -1;
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   string s,t;
   cin >>s;
    if(s=="A")t="T";
    if(s=="C")t="G";
    if(s=="T")t="A";
    if(s=="G")t="C";
  cout<<t<<endl;
}

Measured memory_bytes: 256
#include <iostream>                                             
#include <cmath>                                                
using namespace std;                                            
                                                                
int main(void) {                                                
  int n;                                                        
  cin >> n;                                                     
  int R[n];                                                     
  for (int k=0; k<n; k++) {                                     
    cin >> R[k];                                                
  }                                                             
  int maxv = -pow(10,9);                                        
  int minv = R[0];                                              
  for (int j=1; j<n; j++) {                                     
    maxv = max(maxv,R[j]-minv);                                 
    minv = min(minv,R[j]);                                      
  }                                                             
  cout << maxv << endl;                                         
  return 0;                                                     
}                                                               
                                                                
                                                                
                                                                
                                                                
                      

Measured memory_bytes: 3856
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
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); }
template <typename T> int len(const T &x) { return x.size(); }
 
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }
 
template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}
 
struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};
 
void solve(ll N, ll K, vector<ll> l) {
  sort(l.rbegin(), l.rend());
  cout << accumulate(begin(l), begin(l) + K, 0LL) << endl;
}
 
int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	ll K;
	scanf("%lld", &N);
	vector<ll> l(N-1+1);
	scanf("%lld", &K);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &l[i]);
	}
	solve(N, K, l);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int a[3];
	for (int i = 0; i < 3; ++i)
	{
		cin >> a[i];
	}
	sort(a, a + 3);
	cout << a[0] + a[1];
	return 0;
}

Measured memory_bytes: 3592
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def s(): return input()

def cuts(H):
    for i in range(1<<H):
        yield bin(i)[2:].zfill(H)

def main():
    H, W, K = LI()
    S = []
    for _ in range(H):
        S.append(s())
    ans = inf
    for cut in cuts(H-1):
        p = sum([1 for x in cut if x == '1'])
        cnt = p
        lines = [[0 for _ in range(W)] for __ in range(p+1)]
        cumr = 0
        for c in range(W):
            n_line = 0
            for r in range(H):
                if S[r][c] == '1':
                    cumr += 1
                if r >= H-1:
                    continue
                if cut[r] == '1':
                    lines[n_line][c] += cumr
                    n_line += 1
                    cumr = 0
            lines[-1][c] = cumr
            cumr = 0

        ng = False
        cumsum = [[0 for _ in range(W+1)] for __ in range(p+1)]

        for i in range(p+1):
            line = lines[i]
            for j in range(W):
                cumsum[i][j+1] = line[j] + cumsum[i][j]

        before = 0
        for j in range(1, W+1):
            # import pdb
            # pdb.set_trace()
            for i in range(p+1):
                if ng:
                    break
                if cumsum[i][j] - cumsum[i][before] > K:
                    if j - before == 1:
                        ng = True
                    cnt += 1
                    before = j - 1
                    break
        if ng:
            continue
        ans = min(ans, cnt)
    print(ans)
main()



Measured memory_bytes: 86104
#include<stdio.h>
int main(void)
{ 
	int p1,p2,p3,p4,p5,s,U,N,M,C,P,L,K,J,i;
	scanf("%d",&N);
	scanf("%d",&C);
	P=0;
	for(i=0;i<C;i++)	{ 
		scanf("%d",&p1);
		P=P+p1;
	}
	K=N+1;
	L=P/K;
	M=P%K;
	if (M>0) { 
	         L=L+1;
	}
//	printf("L=%d M=%d\n",L,M);
    printf("%d\n",L);
	return 0;
}	



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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

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

long long extGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long g = extGCD(b, a%b, y, x);
  y -= (a/b) * x;
  return g;
}

const int maxn=200010;
ll fact[maxn];
ll invfact[maxn];

ll nCr(ll n, ll r){
  ll res=fact[n];
  (res*=invfact[r])%=MOD;
  (res*=invfact[n-r])%=MOD;
  return res;
}

signed main()
{
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  cin.tie( 0 ); ios::sync_with_stdio( false );
  fact[0]=1;
  for(int i=1; i<=maxn; i++){
    fact[i]=(fact[i-1]*i)%MOD;
  }
  rep(i,maxn){
    ll x,y;
    extGCD(fact[i], MOD, x, y);
    while(x<0) x+=MOD;
    x%=MOD;
    invfact[i]=x;
  }
  ll ans=0;
  for(int i=1; i<=w-b; i++){
    ll tmp = (nCr(h-a-1 + b-1+i, h-a-1) * nCr(a-1 + w-b-i, a-1)) % MOD;
    (ans+=tmp) %= MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){


int s;
cin >>s;
int a[1000010];
int n[1000010]={};
a[1]=s;
n[s]=1;
int Answer;
for(int i=2;i<=1000000;i++){
        if(a[i-1]%2==0){
        a[i]=a[i-1]/2;
        }
        else{
        a[i]=3*a[i-1]+1;
        }
        if(n[a[i]]!=0){
            Answer=i;
            break;
        }
        else{
        n[a[i]]=i;
        }
    }
    

    
cout <<Answer<<endl;
 return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;

int main() {
	int N,A,B;
	string S;
	cin >> N >> A >> B;
	cin >> S;
	int X = 0,Y = 0;
	for(int i = 0; i < N; i++){
		if(S[i] == 'a' && X < A + B){
			cout << "Yes" << endl;
			X++;
		}
		else if(S[i] == 'b' && X < A + B && Y < B){
			cout << "Yes" << endl;
			X++;
			Y++;
		}
		else{
			cout <<"No" << endl;
		}
	}
	return 0;
}

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

int main() {
  string S;
  int Q;
  cin >> S >> Q;
  
  int cnt = 0;
  string R = "";
  while (Q--) {
    int T;
    cin >> T;
    if (T == 1)
    {
      cnt++;
    } else
    {
      int F;
      char C;
      cin >> F >> C;
      if ((F == 1 && cnt % 2 == 0) || (F == 2 && cnt % 2 == 1)) {
        R += C;
      } else
      {
        S += C;
      }      
    }  
  }

  reverse(R.begin(), R.end());
  S = R + S;
  if (cnt % 2 == 1)
  {
    reverse(S.begin(), S.end());
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 4024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    vector<int>v(3);
    cin>>v[0]>>v[1]>>v[2];
    sort(v.begin(),v.end());
    if(v[0]+v[1]==v[2]){
        cout<<"Yes"<<endl;
    }
    else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int MX=4e5+7;
const int mod=9901;
using namespace std;
int p[MX],k[MX];
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}
ll __gcm(ll a,ll b){return a*b/__gcd(a,b);}
map<string,int>mp;
int a[MX];
int main()
{
  ios::sync_with_stdio(0),cin.tie(0);
  int n;
  cin>>n;
  rep(i,1,n)cin>>a[i];
  sort(a+1,a+n+1);
  for(int i=2;i<=n;i++)
  {
      if(a[i]==a[i-1]){
        cout<<"NO"<<endl;
        return 0;
      }
  }
  cout<<"YES"<<endl;
}


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

const int INF = 1000000007;

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        int v;
        cin >> v;
        a[i] = v - 1;
    }
    vector<int> used(n, -1);
    int cur = 0, cnt = 0;
    used[0] = 0;
    for (int i = 1; i < n; i++) {
        cur = a[cur];
        if (i == k) {
            cout << cur + 1 << endl;
            return 0;
        }
        if (used[cur] == -1) {
            used[cur] = i;
        } else {
            cnt = i - used[cur];
            break;
        }
    }
    k -= used[cur];
    k %= cnt;
    for (int i = 0; i < k; i++) cur = a[cur];
    cout << cur + 1 << endl;
    return 0;
}

Measured memory_bytes: 4844
# dp_b.py
def chmin(h, k, i):
    if i == 0:
        return 0
    ans = 10**9
    for j in range(min(i, k)):
        _min = dp[i-j-1] + abs(h[i]-h[i-j-1])
        if ans > _min:
            ans = _min
    return ans


N, K = map(int, input().split())
H = list(map(int, input().split()))
dp = [0]*N
for i in range(N):
    dp[i] = chmin(H, K, i)
    # print(dp)
print(dp[N-1])


Measured memory_bytes: 84044
import math

c1x,c1y,c1r = [int(i) for i in input().split()]
c2x,c2y,c2r = [int(i) for i in input().split()]

dis = math.sqrt(pow(c1x-c2x, 2) +  pow(c1y-c2y, 2))

bcr = 0
scr = 0

if c1r > c2r:
    bcr = c1r
    scr = c2r
else:
    bcr = c2r
    scr = c1r

if dis > bcr + scr:
    print(4)
elif dis == bcr + scr:
    print(3)
elif dis + scr > bcr:
    print(2)
elif dis + scr == bcr:
    print(1)
else:
    print(0)


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

bool five(int a){
    for(int i = 2; i < a; i++) if(a % i == 0) return false;
    return true;
}

int main(){
int N;
cin >> N;
for(int i = 11; i <= 55555; i += 5){ 
     if(five(i)){
         if(i != 11) cout << " ";
         cout << i;
         N--;
     }
     if(N == 0) break;
}

cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#include "string"
#define int long long 
int n;
int dp[501][501];
int a[501][501];

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

void dfs(int i,int j) {
    int cost = dp[i][j] + a[i][j];
    for(int l=0;l<4;l++){
        int x = i + dx[l];
        int y = j + dy[l];
        if(x<0 or y<0 or x>=n or y>=n)
            continue;
        if(dp[x][y] > cost){
            dp[x][y] = cost;
            dfs(x,y);
        }
    }
}

int32_t main() { 
    boost;
    cin >> n;
    vector<int>v(n*n);
    for(int &i : v)
        cin >> i;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dp[i][j] = min(min(i,n-i-1),min(j,n-j-1)) ;
            a[i][j] = 1;
        }
    }
    int ans = 0;
    for(int &i : v){
        i--;
        int x = i/n;
        int y = i%n;
        a[x][y] = 0;
        ans += dp[x][y];
        dfs(x,y);
    }
    cout<<ans<<endl;
}  


Measured memory_bytes: 28532
sx,sy,tx,ty=map(int,input().split())

ans=""
for i in range(tx-sx):
    ans+="R"
for i in range(ty-sy):
    ans+="U"
for i in range(tx-sx):
    ans+="L"
for i in range(ty-sy):
    ans+="D"

ans+="D"
for i in range(tx-sx+1):
    ans+="R"
for i in range(ty-sy+1):
    ans+="U"
ans+="L"
ans+="U"
for i in range(tx-sx+1):
    ans+="L"
for i in range(ty-sy+1):
    ans+="D"
ans+="R"

print(ans)

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

int main() {
    int n, A[10000];
    int min, max;
    long long int sum = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
        if (!i) { 
            max = min = A[i];
            sum += A[i];
        }
        else {
            if (min > A[i]) min = A[i];
            else if (max < A[i]) max = A[i];
            sum += A[i];
        }
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3152
// #[warn(dead_code)]
// const TOP: u64 = 1000000007;

pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace<'a>) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());

	let r: u64 = iter.read();
	let d: u64 = iter.read();
	let mut x: u64 = iter.read();

	for _ in 0..10 {
		x = r * x - d;
		println!("{}", x);
	}
}


Measured memory_bytes: 4352
#include <stdio.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) ((a) > 0 ? (a) : -(a))

int
main(int argc, char *argv[])
{
  int n, w[100], s1 = 0, s2 = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &w[i]);
    s2 += w[i];
  }

  int ans = 100;
  for(int i = 0; i < n - 1; i++){
    s1 += w[i];
    s2-= w[i];
    ans = min(ans, abs(s1 - s2));
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>

using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int a[n]; rep(i,0,n)cin>>a[i];
    int res=0;
    while(1){
        bool flag=true;
        rep(i,0,n){
            if(a[i]%2!=0){
                flag=false;
                break;   
            }
            a[i]/=2;
        }
        if(flag)res++;
        else break;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
lis = []
for i in range(10**n):
    num = list(str(i))
    if len(num) == n:
        flag = True
        for j in s:
            if num[j[0] - 1] != str(j[-1]):
                flag = False
        if flag:
            lis.append(i)
            break
if lis:
    print(lis[0])
else:
    print(-1)

Measured memory_bytes: 3064
A,B = map(int,input().split())
def cumulativeXor(n):
    if n < 0 : return(0)
    rem = n%4
    q = n-rem
    res = q
    for i in range(1,rem+1):
        res = res ^ (q+i)

    return(res)
print(cumulativeXor(B) ^ cumulativeXor(A-1))

Measured memory_bytes: 3064
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <set>
using namespace std;
int a[200000] = {0};
int b[200000] = {0};
int main()
{
	 int n, k;
	 int i, count, j;
	 while(scanf("%d %d", &n, &k)!=EOF)
	 {
	 	 memset(a, 0 ,sizeof(a));
	 	 memset(b, 0 ,sizeof(b));
	 	 for(i = 0 ; i < n ; i++)
		 {
		 	 scanf("%d", &a[i]);
		 }
		 sort(a,a + n);
		 j = 0, count = 0;
		 for(i = 0 ; i < n ; i++)
		 {
		 	 if(a[i] == a[i + 1] )
			 {
			 	 count++;
			 }
			 if(a[i] != a[i + 1])
			 {
			 	 b[j] = count;
			 	 j++;
			 	 count = 0;
			 }
		 }
		 sort(b, b+j);
		 for(i = 0 ; i < j ; i++)
		 {
		 	 b[i]++;
		 }
		 int sum = 0;
		 for(i = 0 ; i < j - k ; i++)
		 {
		 	 sum = sum + b[i];
		 }
		 printf("%d\n",sum);
	 }
	 return 0;
}


Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {Main instance = new Main();sc = instance.new Scanner();instance.solve();}
    private class Scanner {String[] s = new String[0];String regex = " ";int i = 0;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));public String next() {try {if (i < s.length) { return s[i++];}String st = br.readLine();while ("".equals(st)) { st = br.readLine(); }s = st.split(regex, 0);i = 0;return s[i++];} catch (IOException e) { return null; }}public int nextInt(){return Integer.parseInt(next());}}        
    private static Scanner sc;

    private void solve() {
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        int ans = 0;
        for (int i = 0; i <= A; i++) {
            for (int j = 0; j <= B; j++) {
                for (int k = 0; k <= C; k++) {
                    if (500*i+100*j+50*k == X) {
                        ans++;
                    }
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second

using namespace std;

const int maxN = 2e5 + 10;

typedef pair<int, int> ii;

map<ii, int> mp;

int n,k,l;
int par1[maxN], par2[maxN];

int findSet(int u, int *par){
    if(u != par[u]) par[u] = findSet(par[u], par);
    return par[u];
}

void join(int x, int y, int *par){
    int px = findSet(x, par);
    int py = findSet(y, par);
    if(px != py){
        par[px] = py;
    }

}

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

    cin >> n >> k >> l;

    for(int i = 1; i <= n; ++i){
        par1[i] = i;
        par2[i] = i;
    }

    for(int i = 1; i <= k; ++i){
        int x,y;
        cin >> x >> y;
        join(x, y, par1);
    }

    for(int i = 1; i <= l; ++i){
        int x,y;
        cin >> x >> y;
        join(x, y, par2);
    }

    for(int i = 1; i <= n; ++i){
        findSet(i, par1);
        findSet(i, par2);
    }

    for(int i = 1; i <= n; ++i){
        ++mp[{par1[i], par2[i]}];
    }

    for(int i = 1; i <= n; ++i)
        cout << mp[{par1[i], par2[i]}] << " ";

}


Measured memory_bytes: 16548
(async () => {
    let input = '';
    for await (const chunk of process.stdin) input += chunk;
    const k = +input;

    let x = 0;
    for(let i = 1; i <= k; i++){
        x = x * 10 + 7;
        x %= k;
        if(x == 0){
            console.log(i);
            return;
        }
    }
    console.log(-1);
})()


Measured memory_bytes: 32860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; 

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  ll sum = a+b;
  if(sum == 0){
    cout << 0 << endl;
    return 0;
  }
  ll cnt = n/sum;
  cout << a*cnt + min(n%sum,a) << endl;
}

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

int main(){
    int h = 0;cin >> h;
    int a;cin >> a;
    if(h % a == 0)
    cout << h / a  << endl;
    else
    {
        cout << h / a + 1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
M=10**9+7
n,m=map(int,input().split())
F=[1]
for i in range(1,m+1): F+=[i*F[-1]%M]
c=lambda n,r: F[n]*pow(F[r]*F[n-r],M-2,M)%M
p=lambda n,r: F[n]*pow(F[n-r],M-2,M)%M
a=0
for k in range(n+1):
  a+=(-1)**k*c(n,k)*p(m,k)*p(m-k,n-k)**2%M
print(a%M)

Measured memory_bytes: 104944
#include <cmath>
#include <iostream>

using namespace std;

int IsPrime(int a) {
  if (a == 2) {
    return 1;
  } else if (a % 2 == 0) {
    return 0;
  }

  for (int i = 3; i <= sqrt(a); i += 2) {
    if (a % i == 0) {
      return 0;
    }
  }

  return 1;
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans += IsPrime(a);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3084
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
q,h,s,d = iim()
n = ii()

if q*8 <= min(4*h,2*s,d):
    print(n*4*q)
elif 4*h <= min(2*s,d):
    print(n*2*h)
elif s*2 <= d:
    print(n*s)
else:
    print(n//2*d + n%2*min(s,2*h,4*q))

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


int main(){
    int n,t,a;
    cin >> n >> t >> a;
    VI h(n);
    
    for(int i=0; i<n; ++i){
        cin >> h[i];
    }
    int min = abs(a*1000-(t*1000-6*h[0]));

    int ans = 1;
    for(int i=1; i<n; ++i){
        if(abs(a*1000-(t*1000-6*h[i])) < min){
            min = abs(a*1000-(t*1000-6*h[i]));
            ans = i+1;
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int A[100200] = {};

int main(void) {

	int X;
	cin >> X;

	A[0] = 1;

	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 100000; j++) {
			CHMAX(A[j + (100 + i)],A[j]);
		}
	}

	if (A[X] == 0) {
		COUT(0);
	}
	else {
		COUT(1);
	}

	return 0;
}


Measured memory_bytes: 640
N = int(input())

x = [0] * N
y = [0] * N
h = [0] * N

for k in range(N):
    x[k],y[k],h[k] = map(int,input().split())

for i in range(101):
    for j in range(101):
        det = 0
        H = 0
        for k in range(N):
            if H == 0 and h[k] > 0:
                H = h[k] + abs(x[k]-i) + abs(y[k]-j)
            elif h[k] != max(0,H - abs(x[k]-i) - abs(y[k]-j)):
                det = -1
                break
        if det == 0:
            ans = [i,j,H]

print(" ".join(map(str,ans)))

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

int main(){
	int n,k;
	cin >> k >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	vector<int> l(n);
	rep(i,n-1){
		l[i] = a[i+1] - a[i]; 
	}
	l[n-1] = k - a[n-1] + a[0];
	int max = 0;
	rep(i,n){
		if(max < l[i]) max = l[i];
	}
	int sum = 0;
	rep(i,n){
		sum += l[i];
	}
	// rep(i,n) cout << l[i] << endl;
	cout << k-max << endl;
}

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

int main() {
  int x, y;
  cin>>x>>y;
  vector<int> X={0,1,3,1,2,1,2,1,1,2,1,2,1,};
  if (X[x]==X[y]){
    cout<<"Yes"<<endl;
  }
  else{cout<<"No"<<endl;}
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int X[202020],Y[202020];
ll mo=998244353;
vector<int> Xs,Ys;

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT<int,20> Lbt,Rbt;
int ev[202020];
ll p2[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	p2[0]=1;
	FOR(i,202010) p2[i+1]=p2[i]*2%mo;
	
	
	cin>>N;
	Xs.push_back(-1<<30);
	Ys.push_back(-1<<30);
	Xs.push_back(1<<30);
	Ys.push_back(1<<30);
	FOR(i,N) {
		cin>>X[i]>>Y[i];
		Xs.push_back(X[i]);
		Ys.push_back(Y[i]);
	}
	sort(ALL(Xs));
	sort(ALL(Ys));
	Xs.erase(unique(ALL(Xs)),Xs.end());
	Ys.erase(unique(ALL(Ys)),Ys.end());
	FOR(i,N+5) ev[i]=1<<30;
	
	FOR(i,N) {
		X[i]=lower_bound(ALL(Xs),X[i])-Xs.begin();
		Y[i]=lower_bound(ALL(Ys),Y[i])-Ys.begin();
		ev[X[i]]=Y[i];
		Rbt.add(Y[i],1);
	}
	
	ll ret=0;
	FOR(i,N+2) if(ev[i]!=1<<30) {
		Rbt.add(ev[i],-1);
		ll LT=p2[Lbt(N+5)-Lbt(ev[i])];
		ll LD=p2[Lbt(ev[i])];
		ll RT=p2[Rbt(N+5)-Rbt(ev[i])];
		ll RD=p2[Rbt(ev[i])];
		//ret++;
		(ret+=(LT-1)*(LD-1)%mo*(RD-1)%mo*(RT-1)%mo*2)%=mo;
		(ret+=(1)*(LD-1)%mo*(RD-1)%mo*(RT-1)%mo*2)%=mo;
		(ret+=(LT-1)*(1)%mo*(RD-1)%mo*(RT-1)%mo*2)%=mo;
		(ret+=(LT-1)*(LD-1)%mo*(1)%mo*(RT-1)%mo*2)%=mo;
		(ret+=(LT-1)*(LD-1)%mo*(RD-1)%mo*(1)%mo*2)%=mo;
		(ret+=(1)*(1)%mo*(RD-1)%mo*(RT-1)%mo*1)%=mo;
		(ret+=(1)*(LD-1)%mo*(1)%mo*(RT-1)%mo*2)%=mo;
		(ret+=(1)*(LD-1)%mo*(RD-1)%mo*(1)%mo*1)%=mo;
		(ret+=(LT-1)*(1)%mo*(1)%mo*(RT-1)%mo*1)%=mo;
		(ret+=(LT-1)*(1)%mo*(RD-1)%mo*(1)%mo*2)%=mo;
		(ret+=(LT-1)*(LD-1)%mo*(1)%mo*(1)%mo*1)%=mo;
		(ret+=(1)*(1)%mo*(1)%mo*(RT-1)%mo*1)%=mo;
		(ret+=(1)*(1)%mo*(RD-1)%mo*(1)%mo*1)%=mo;
		(ret+=(1)*(LD-1)%mo*(1)%mo*(1)%mo*1)%=mo;
		(ret+=(LT-1)*(1)%mo*(1)%mo*(1)%mo*1)%=mo;
		(ret+=(1)*(1)%mo*(1)%mo*(1)%mo*1)%=mo;
		Lbt.add(ev[i],1);
	}
	cout<<(ret%mo+mo)%mo<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 13804
def main():
  a, b = input_list()
  ans = []
  for i in range(1, 1001):
    ai = i * 0.08
    bi = i * 0.1
    if int(ai) == a and int(bi) == b:
      ans.append(i)
  if len(ans) == 0:
    print(-1)
  else:
    print(min(ans))
    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
from functools import reduce
main()

Measured memory_bytes: 5292
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef pair <long long, long long> pll;
 
ll mod = 1000000000;
 
int main(){
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  if (n < 30)
   cout << "No";
  else
   cout << "Yes";
}

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

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

    std::vector<int> d(n);
    for(int i = 0; i < n; ++i){
        std::cin >> d.at(i);
    }
    std::sort(d.begin(), d.end());
    int sz = d.size(), ans = 0;
    if(0 == sz % 2){
        ans = d.at(sz/2) - d.at(sz/2 - 1);
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 640
use std::io;

fn main() {
    let numbers = input_number();
    let a = numbers[0];
    let b = numbers[1];
    let c: f64 = (a as f64) / (b as f64);
    
    println!("{} {} {}", a/b, a%b, c);
}

#[allow(dead_code)]
fn input_number() -> Vec<i32> {
    let mut input = String::new();

    io::stdin().read_line(&mut input)
        .expect("Failed to read line");

    let vec: Vec<i32> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap_or(0))
        .collect();
    vec
}



Measured memory_bytes: 5048
def f3(N,S,M):
    sm=S//M
    l=[]
    for i in range(M):
        l.append([])
    li=[i for i in range(1,N+1)]
    for x in range(M):
        tmp=0
        for i in reversed(range(N)):
            if li[i]==-1:
                continue
            tmp+=li[i]
            if tmp>sm:
                tmp-=li[i]
                if li[sm-tmp-1]==-1:
                    #print(N,sm,"!!!")
                    return
                l[x].append(sm-tmp)
                li[sm-tmp-1]=-1
                break
            l[x].append(li[i])
            li[i]=-1
            if tmp==sm:
                break
    y=0
    for x in range(M):
        y+=len(l[x])*(N-len(l[x]))
    y//=2
    print(y)
    for x in range(M):
        for xi in l[x]:
            for y in range(x+1,M):
                for yi in l[y]:
                    print(xi,yi)
    
    
def min_factor(S):
    for i in range(2,101):
        if S%i==0:
            return i

#24,39

N=int(input())
S=N*(N+1)//2
M=min_factor(S)
f3(N,S,M)

Measured memory_bytes: 3572
import math

def main():
    n = int(input())
    ans = 0
    a = {}
    for i in range(1,n+1):
        for j in range(1,n+1):
            tmp = math.gcd(i,j)
            a[tmp] = a.get(tmp, 0)
            a[tmp] += 1


    for key, val in a.items():
        for j in range(1, n+1):
            ans += math.gcd(key,j) * val

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9212
#include <stdio.h>

int main() {
  char c[5][5];

  for (int i = 0; i < 3; i++) {
    scanf("%s", c[i]);
  }
  for (int i = 0; i < 3; i++) {
    printf("%c", c[i][i]);
  }
  puts("");

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define P pair<ll,ll>
#define fs first
#define sc second
#define _GLIBCXX_DEBUG

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S>
void print(vector<S> &v){
	for(ll i=0; i<(ll)v.size(); i++){
		cerr << v[i] << ' ';
	}
	cerr << endl;
}
template <class S>
void print(vector<vector<S>> &v) {
  	for (ll i = 0; i < (ll)v.size(); i++) {
    	for (ll j = 0; j < (ll)v[i].size(); j++) {
      		cerr << v[i][j] << ' ';
    	}
    	cerr << endl;
  	}
}

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  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 { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main(){
	int h,w; cin >> h >> w;
	vector<vector<bool>> m(h, vector<bool>(w,false));
	rep(i,h){
		string s; cin >> s;
		rep(j, w){
			m[i][j] = (s[j] == '#');
		}
	}
	vector<vector<int>> left(h, vector<int>(w, 0));
	vector<vector<int>> right(h, vector<int>(w, 0));
	vector<vector<int>> up(h, vector<int>(w, 0));
	vector<vector<int>> down(h, vector<int>(w, 0));
	rep(i,h){
		int wall = -1;
		rep(j, w){
			if(m[i][j]){
				wall = j;
			}else{
				left[i][j] = j - wall;
			}
		}
	}
	rep(i,h){
		int wall = w;
		for(int j=w-1; j>=0; j--){
			if(m[i][j]){
				wall = j;
			}else{
				right[i][j] =  wall -  j;
			}
		}
	}
	rep(j, w){
		int wall = -1;
		rep(i, h){
			if(m[i][j]){
				wall = i;
			}else{
				up[i][j] = i - wall;
			}
		}
	}
	rep(j, w){
		int wall = h;
		for(int i=h-1; i>=0; i--){
			if(m[i][j]){
				wall = i;
			}else{
				down[i][j] = wall - i;
			}
		}
	}
	int ans = 0;
	rep(i,h){
		rep(j,w){
			if(!m[i][j]){
				ans = max(ans, left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 63616
import collections
s = input()
t = list(s)

ssgn=lambda x:(x*2+1)//2
gg = round(ssgn(len(t)/2))
pp = len(t) - gg

d = collections.Counter(t)
Top_g = d['g']
Top_p = d['p']
print(pp - Top_p)

Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if(b == 1){
        if(a != n){
            cout << -1 << endl;
            return 0;
        }else{
            rep(i, n)cout << i + 1 << ' ';
            cout << endl;
            return 0;
        }
    }else if(a == 1){
        if(b != n){
            cout << -1 << endl;
            return 0;
        }else{
            rep(i, n)cout << n - i << ' ';
            cout << endl;
            return 0;
        }
    }else{
        if(n < a + b - 1 || n > a * b){
            cout << -1 << endl;
            return 0;
        }
    }

    int c = (n - b) % (a - 1);
    int d = (n - b) / (a - 1);
    int cnt = 0;
    rep(i, a){
        if(i == 0){
            rep(j, b){
                cout << cnt + b - j << ' ';
            }
            cnt += b;
        }else if(i <= c){
            rep(j, d+1){
                cout << cnt + d + 1 - j << ' ';
            }
            cnt += d + 1;
        }else{
            rep(j, d){
                cout << cnt + d - j << ' ';
            }
            cnt += d;
        }
    }
    cout << endl;
}

Measured memory_bytes: 3616
#include<stdio.h>
int ads(int a){
  if(a<0)
    a=-a;
  return a;}

int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(ads(a-b)<d+1&&ads(b-c)<d+1)
    printf("Yes\n");
  else if(ads(a-c)<d+1)
    printf("Yes\n");
  else 
    printf("No\n");
  return 0;}


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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
        a.at(i) -= i + 1;
    }
    sort(a.begin(), a.end());
    ll b = a.at(n / 2);
    ll ans = 0;
    for(ll x : a){
        ans += abs(x - b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

// 154-c
int main() {
    int n, k;
    cin >> n >> k;

    int p;
    vector<double> v;
    rep(i, 0, n) {
        cin >> p;
        double sum = p * (p + 1);
        double div = 2 * p;
        v.push_back(sum / div);
    }

    double sum = 0;
    rep(i, 0, k) {
        sum += v[i];
    }

    double mx = sum;
    for (int i = 1; i + k - 1 < n; i++) {
        sum += v[i + k - 1];
        sum -= v[i - 1];
        mx = max(mx, sum);
    }

    printf("%lf\n", mx);
    return 0;
}


Measured memory_bytes: 2420
def INSTR():
	return input()

def INNUM():
	return int(INSTR())

def INSTR_S():
	return INSTR().split()

def INNUM_S():
	return map(int, INSTR_S())

def INSTR_SM(n):
	return [tuple(INSTR_S()) for _ in range(n)]

def INNUM_SM(n):
	return [tuple(INNUM_S()) for _ in range(n)]

S = INSTR()
print(S.rfind("Z") - S.find("A") + 1)

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

int main(){
    int k, x;
    cin >> k >> x;
    int l = x - k + 1;
    int r = x + k - 1;
    for(int i = l; i <= r; i++) cout << i << ' ';
}

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

int main(){
    std::string s;
    std::cin >> s;
    s = s + "e";

    int i = 0;
    int ans = 0;
    while (1)
    {
        std::string tmp = s.substr(i, 1);
        if (tmp == "e")
        {
            break;
        }
        int num = std::stoi(tmp);
        ans += num;
        i++;
    }
    
    if (ans % 9 == 0)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3924