akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
using namespace std;

const int N = 200500;

vector<int> E[N];
vector<int> F[N];

const int LGN = 18;
int up[LGN][N];
int D[N];

void DFS(int x, int p = -1) {
    D[x] = (p == -1) ? 0 : D[p] + 1;
    up[0][x] = (p == -1) ? x : p;
    for (int d = 1; d < LGN; d++)
        up[d][x] = up[d - 1][up[d - 1][x]];
    for (int y : E[x]) {
        if (y != p)
            DFS(y, x);
    }
}

inline int lca(int a, int b) {
    if (D[a] > D[b]) {
        swap(a, b);
    }
    for (int d = LGN - 1; d >= 0; d--)
        if (D[up[d][b]] >= D[a])
            b = up[d][b];
    if (a == b)
        return a;
    for (int d = LGN - 1; d >= 0; d--)
        if (up[d][a] != up[d][b])
            a = up[d][a], b = up[d][b];
    return up[0][a];
}

inline int dist(int a, int b) {
    int l = lca(a, b);
    return D[a] + D[b] - 2 * D[l];
}

bool infinite(int x) {
    for (int y : F[x]) {
        if (dist(x, y) >= 3)
            return true;
    }
    return false;
}

bool isinfinite = false;
int best = 0;

int s, t;


void DFS2(int x, int p = -1, int d = 0) {
    best = max(best, dist(t, x));
    if (infinite(x)) {
        isinfinite = true;
        return;
    }
    for (int y : F[x]) {
        if (y == p)
            continue;
        if (d + 1 < dist(t, y)) {
            DFS2(y, x, d + 1);
            if (isinfinite)
                return;
        }
    }
}

int main() {
    int n;
    scanf("%d %d %d", &n, &s, &t);
    --s, --t;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        --a, --b;
        F[a].push_back(b);
        F[b].push_back(a);
    }
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        --a, --b;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    DFS(0);
    DFS2(s);
    if (isinfinite) {
        printf("%d\n", -1);
    } else {
        printf("%d\n", 2 * best);
    }
}


Measured memory_bytes: 45952
#include <bits/stdc++.h>
#define fuck 2000000000
#define hell 2000000000000000000
#define ff first
#define ss second 
#define forn(i,n) for (int i=0;i<int(n);i++)
#define nfor(i,n) for (int i=int(n)-1;i>=0;i--)
#define N 100010
#define M 1000010
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
int gcd(int a,int b){return (b==0) ? a : gcd(b,a%b);}
int n;
int ar;
int ans=0;
int sum[100010];
int main(){
	
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		scanf("%d",&ar);
		sum[ar]++;
	}
	ans=sum[0]+sum[1];
	for (int i=1;i<N-1;i++){
		ans=max(ans,sum[i]+sum[i+1]+sum[i-1]);
	}
	printf("%d",ans);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

vvll g;

int dfs(int v,int n,vector<bool> visited){
	bool all_visited=true;
	rep(i,n){
		if(visited[i]==false) all_visited=false;
	}
	if(all_visited) return 1;
	int ret=0;
	rep(i,n){
		if(g[v][i]==0) continue;
		if(visited[i]) continue;
		visited[i]=true;
		ret+=dfs(i,n,visited);
		visited[i]=false;
	}
	return ret;
}

int main()
{
	ll n,m;
	vector<bool> visited;
	cin >> n >> m;
	g.resize(n,vll(n,0));
	visited.resize(n,false);
	rep(i,m){
		ll a,b;
		cin >> a >> b;
		a--;
		b--;
		g[a][b]=1;
		g[b][a]=1;
	}
	visited[0]=true;
	cout << dfs(0,n,visited) << endl;
	return 0;
}

Measured memory_bytes: 256
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 1e5 + 5, mod = (int) 1e9 + 7;
int nn[2], sum[2], a[N];
int main() {
	cin >> nn[0] >> nn[1];
	for (int repeat = 0; repeat <= 1; ++repeat) {
		int n = nn[repeat];
		int cur = 0, res = 0;
		for (int j = 0; j < n; ++j) {
			cin >> a[j];
			res = (res + ((LL) a[j] * j % mod - cur + mod) % mod) % mod;
			cur = (cur + a[j]) % mod;
		}
		sum[repeat] = res;
	}
	cout << sum[0] * (LL) sum[1] % mod << endl;
}



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

int main() {
  long long A,ans,x,y,z;
  cin >>A;
  ans=0;
  for(int i=1;i<=A;i++){
    for(int j=1;j<=A;j++){
      for(int u=1;u<=A;u++){
        x=i;
        y=j;
        if(x<y){
          swap(x,y);
        }
        z=x%y;
        while(z!=0){

          x=y;
          y=z;
          z=x%y;
        }
                x=y;
        y=u;
        if(x<y){
          swap(x,y);
        }
         z=x%y;
        while(z!=0){

          x=y;
          y=z;
          z=x%y;
        }
        ans+=y;
      }
      }
  }
  cout <<ans<< endl;
}


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
using namespace std;

int main(){
	string s;
	while(getline(cin, s)) {
		while (s.find("the") == string::npos && s.find("this") == string::npos && s.find("that") == string::npos) {
			for (int i = 0; i < s.length(); ++i) {
				if ('a' <= s[i] && s[i] <= 'z') {
					int c;
					c = (s[i] - 'a' + 1) % ('z' - 'a' + 1);
					s[i] = c + 'a';
				}
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    int A,P;
    cin>>A>>P;
    int B=3*A+P;
    B/=2;
    cout<<B<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;



int main()
{
    FAST
    ll x;cin>>x;
    if(x>=400 && x<600) cout<<8;
    if(x>=600 && x<800) cout<<7;
    if(x>=800 && x<1000) cout<<6;
    if(x>=1000 && x<1200) cout<<5;

    if(x>=1200 && x<1400) cout<<4;
    if(x>=1400 && x<1600) cout<<3;
    if(x>=1600 && x<1800) cout<<2;
    if(x>=1800 && x<2000) cout<<1;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	int r, d, x;
	cin>>r>>d>>x;
	for(int i = 0; i<10; i++){
		x = r*x -d;
		cout<<x<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<set>
#define int long long
using namespace std;
int n, a[345678], sum1, sum2, ans;
priority_queue<int, vector<int>, greater<int>>q;
multiset<int>m, m1;
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum1 += a[i];
		q.push(a[i]);
	}
	for (int i = n; i < 3 * n; i++) {
		cin >> a[i];
		m.insert(a[i]);
	}
	auto ir = m.begin();
	for (int i = 0; i < n; i++) {
		sum2 += *ir;
		ir++;
	}
	ans = sum1 - sum2;
	for (int i = 0; i < n; i++) {
		q.push(a[i + n]);
		sum1 += a[i + n] - q.top();
		q.pop();
		if (*ir >= a[i + n]) {
			sum2 -= a[i + n];
			while (*ir == *(m1.begin())) {
				ir++; m1.erase(m1.begin());
			}
			sum2 += *ir;
			ir++;
		}
		else m1.insert(a[i + n]);
		ans = max(ans, sum1 - sum2);
	}cout << ans << endl;
}

Measured memory_bytes: 13556
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    string str;
    cin >> str;
    // cout << str.substr(0,5) << " " << str.substr(6,7) << " " << str.substr(14,5) << endl;
    for (int i=0; i<str.size(); ++i)
    {
        if(str[i]==',') str[i] = ' ';
    }
    cout << str << endl;
    return 0;
}

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

int main() {
	int n;
	while(scanf("%d",&n),n!=0){
		int x=0;
		for(int i=0;i<n*(n-1)/2;i=i+1){
			int c;
			cin >> c;
			x = x + c;
		}
		cout << x/(n-1) << endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC146 D - Coloring Edges on Tree
// 2020.07.01

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<vector<int> > G(N, vector<int>());
  map<pair<int, int>, int> mp;
  REP(i, N-1){
    int a, b; cin >> a >> b; a--; b--;
    G[a].push_back(b);
    mp[{a, b}] = i;
    G[b].push_back(a);
  }
  int E = 0;
  REP(i, N-1){
    int siz = G[i].size();
    E = max(E, siz);
  }
  cout << E << endl;
  vector<int> ans(N-1);
  vector<int> d(N, -1);
  queue<int> q;
  q.push(0);
  d[0] = 0;
  while(!q.empty()){
    int cur = q.front(); q.pop();
    int col = 0;
    for(int i : G[cur]){
      if(d[i] != -1) continue;
      col++;
      if(col == d[cur]) col++;
      d[i] = col;
      ans[mp[{cur, i}]] = col;
      q.push(i);
    }
  }
  REP(i, N-1){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 15908
#include<iostream>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
#define me(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=1111122;
const int M=200005;
int aa,bb,n,sum=0,w,q;
int a[11],b[11],c[11],v[11];
void dfs(int ct)
{
	int i;
	if(ct==n)
	{
		//for(i=0;i<n;i++)
		//cout<<c[i]<<" ";
		sum++;
		w=0;
		q=0;
		for(i=0;i<n;i++)
		{
			if(a[i]!=c[i])
			{
				w=1;
			}
			if(b[i]!=c[i])
			{
				q=1;
			}
		}
		if(w==0)aa=sum;
		if(q==0)bb=sum;
		return ;
	}
	else 
	{
		for(i=1;i<=n;i++)
		{
			if(!v[i])
			{
				v[i]=1;
				c[ct]=i;
				dfs(ct+1);
				v[i]=0;
			}
		}
	}
}
int main()
{
	me(v,0);
	int i,j,m;
	cin>>n;
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	cin>>b[i];
	dfs(0);
	cout<<abs(aa-bb)<<endl;
	return 0;
}


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

using namespace std;

const int   N   = 1e5 + 1;

vector<int> g[N];
vector<int> v(N);

int f[N];
int tot = 0;

int dfs(int u,int p)    {
    v[u] = ++tot;
    for(int x : g[u])   if (x != p) {
        if(!v[x])   dfs(x,u);
        if (v[x] < v[u])    {
            cout << u << " " << x << "\n";
            f[u] ^= 1;
        }
    }
    if (f[u])   cout << u << " " << p << "\n", f[u] ^= 1;
    else if (p) cout << p << " " << u << "\n", f[p] ^= 1;
}

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

    int n, m;   cin >> n >> m;

    if (m & 1)  return  0 * puts("-1");

    while (m--) {
        int x;  cin >> x;
        int y;  cin >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1,0);
}


Measured memory_bytes: 15488
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;

// #define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (st                                  derr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<pii, int> mpii;
typedef set<int> sti;
const int INF = 1e9, MOD = /* INF + 7 */ 998244353;
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
int power(int a, int b) { return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1)); }
int mod(int a) { return (a % MOD + MOD) % MOD; }

/////////////////////////////////////////////////////////////////////

const int N = 1e5 + 20, M = 5 + 2;

int32_t main(){
    
    sync;

    int a, b, c; cin >> a >> b >> c;

    int ans = 0;

    int x = min(a, c);
    ans += x;
    c -= x;
    a -= x;

    x = min(b, c);
    ans += 2 * x;
    c -= x;
    b -= x;

    ans += b;
    ans += (c > 0 ? 1 : 0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = null;
		try {
			sc = new Scanner(System.in);
			while (sc.hasNextInt()) {
				int dataSetRows = sc.nextInt();
				for (int i = 0; i < dataSetRows; i++) {
					String originalNum = sc.next();
					char[] charNum = originalNum.toCharArray();

					// asc
					int minNum = Integer.parseInt(String.valueOf(asc(charNum)));

					// desc
					int maxNum = Integer.parseInt(String.valueOf(desc(charNum)));

					// max-min
					int result = maxNum - minNum;
					System.out.println(result);
				}
			}
		} finally {
			sc.close();
		}
	}

	private static char[] asc(char[] cArrays) {
		Arrays.sort(cArrays);
		return cArrays;
	}

	private static char[] desc(char[] cArrays) {
		char[] after = new char[cArrays.length];

		for (int i = 0; i < cArrays.length; i++) {
			after[i] = cArrays[cArrays.length - (1 + i)];
		}
		return after;
	}
}

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

using namespace std;

void solve(long long N) {
  string ans = "";

  while (N != 0) {
    if (N % 2 == 0) {
      ans = "0" + ans;
      N /= (-2);
    } else {
      ans = "1" + ans;
      N -= 1;
      N /= (-2);
    }
  }
  if (ans.length() == 0) {
    cout << "0" << endl;
  } else {
    cout << ans << endl;
  }
}

int main() {
  long long N;
  cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n=sc.nextLong();
        if(n%2==1){
            System.out.println(0);
            return;
        }
        n/=2;
        long ans=0;
        long i=1;
        while(n>=Math.pow(5, i)){
            ans+=(long)(n/(long)Math.pow(5, i));
            i++;
        }
        System.out.println(ans);
        

    }



}

Measured memory_bytes: 23252
# -*- coding: utf-8 -*-
import numpy as np

if __name__ == '__main__':
    N = int(input())
    B = list(map(int, input().split()))

    A = [B[0]]
    for i in range(1,N-1):
        A.append(min([B[i-1],B[i]]))

    A.append(B[-1])


    print(np.sum(A))


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

public class AtCoder
{
  public static void Main()
  {
    var dg = Console.ReadLine().Trim().Split();
    var d = int.Parse(dg[0]);
    var g = int.Parse(dg[1]);


    var p = new List<int>(d);
    var c = new List<int>(d);

    for(var i=0; i < d; i++)
    {
      var pc = Console.ReadLine().Trim().Split();
      p.Add(int.Parse(pc[0]));
      c.Add(int.Parse(pc[1]));
    }

    var ans = int.MaxValue;

    for(var mask = 0; mask < (1 << d); mask++)
    {
      int s = 0;
      int num = 0;
      int rest_max = -1;
      for(int i = 0; i < d; i++)
      {
        if(((mask >> i) & 1) > 0)
        {
          s += 100 * (i + 1) * p[i] + c[i];
          num += p[i];
        }
        else
        {
          rest_max = i;
        }
      }
      if(s < g)
      {
        int s1 = 100 * (rest_max + 1);
        int need = (g - s + s1 - 1) / s1;
        if (need >= p[rest_max])
        {
          continue;
        }
        num += need;
      }
      ans = Math.Min(ans, num);
    }

    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 11092
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)

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

A,B,C,K=acinput()


nA=min(K,A)
nB=min(K-nA,B)
nC=min(K-nA-nB,C)

print(nA-nC)


Measured memory_bytes: 27164
N,M = map(int,input().split())
AB = [[] for _ in range(N)]
ans = [0]*N
for _ in range(M):
  a,b = map(int,input().split())
  AB[a-1].append(b-1)
  AB[b-1].append(a-1)

from collections import deque

node = 0
q = deque([0])

check = [0]*N
check[0] = 1
while len(q) > 0:
  node = q.popleft()
  for i in AB[node]:
    if check[i] == 0:
      q.append(i)
      check[i] = 1
      ans[i] = node
print("Yes")
for i in range(1,N):
  print(ans[i]+1)


Measured memory_bytes: 34876
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n, = map(int,read().split())

MOD = 10**9+7

ans = pow(10,n,MOD) - 2*pow(9,n,MOD) + pow(8,n,MOD)
print(ans%MOD)

Measured memory_bytes: 9112
use std::io::*;
use std::cmp::*;

fn main(){
    let mut input = String::new();
    stdin().read_line(&mut input);
    let mut list = input.split_whitespace().map(|e| e.parse::<i64>().unwrap());
    let n = list.next().unwrap();
    let a = list.next().unwrap();
    let b = list.next().unwrap();

    let c = n / (a+b) * a;
    let d = n % (a+b);
    println!("{}", c + min(a, d));
}


Measured memory_bytes: 4352
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void add(int &a,int b){ a+=b; if(a>=mod) a%=mod; }  
void subtract(int &a,int b){ a-=(b-mod); if(a>=mod) a-=mod;}
int multiply(int a,int b){ int res=a; res*=b; if(res>=mod) res%=mod; return res; }
const int N = 101; 
char a[N][N];
int dp[N][N];
void solve(){
	int n,m;
	cin>>n>>m; 
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
			dp[i][j] = INT_MAX;
		}
	}
	int ans = 0;
	if(a[1][1]=='#')
		dp[1][1] = 1;
	else 
		dp[1][1] = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(i+1<=n)
			{
				if(a[i+1][j]=='#')
					dp[i+1][j] = min(dp[i+1][j],dp[i][j]+(a[i][j]=='.')); 
				else 
					dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
			}
			if(j+1<=m)
			{
				if(a[i][j+1]=='#')
					dp[i][j+1] = min(dp[i][j+1],dp[i][j]+(a[i][j]=='.')); 
				else 
					dp[i][j+1] = min(dp[i][j+1],dp[i][j]);
			}
		}
	}
	cout<<dp[n][m]<<endl;
} 
int32_t main(){
	BOLT;
	int t; 
    t = 1;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int H,w,k,X,Y,xx,yy,maxx=23333333;
int q[4]={-1,0,1,0};
int p[4]={0,1,0,-1};
vector<int>l[3];
int main(void)
{
    cin>>H>>w>>k>>xx>>yy>>X>>Y;
    xx--;yy--;X--;Y--;
    char c[H][w];
    int f[H][w];
    for(int i=0;i<H;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>c[i][j];
            f[i][j]=maxx;
        }
    }
    int h=0,r=1;
    l[0].push_back(xx);l[1].push_back(yy);l[2].push_back(0);
    f[xx][yy]=0;
    while(h<r)
    {
        for(int i=0;i<4;i++)
        {
            int x1=l[0][h],y1=l[1][h];
            for(int j=0;j<k;j++)
            {
                x1+=q[i];y1+=p[i];
                if(x1<0||x1>=H||y1<0||y1>=w||c[x1][y1]=='@'||f[x1][y1]<l[2][h]+1)break;
                if(f[x1][y1]>l[2][h]+1)
                {
                f[x1][y1]=l[2][h]+1;
                l[0].push_back(x1);l[1].push_back(y1);l[2].push_back(l[2][h]+1);
                r++;
                }
            }
        }
        h++;
    }
    if(f[X][Y]==maxx)cout<<"-1"<<endl;
    else cout<<f[X][Y]<<endl;
    return 0;
}


Measured memory_bytes: 16704
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N; cin >> N;
	string S; cin >> S;
	int cntL[26] = {};
	int cntR[26] = {};
	int ans = 0;
	rep(j, S.length()) {
		int cntL[26] = {};
		int cntR[26] = {};
		int L = j;
		REP(i, 0, L) cntL[S[i] - 'a']++;
		REP(i, L + 1, (int)S.length() - 1)  cntR[S[i] - 'a']++;
		int tmp = 0;
		rep(i, 26) if (cntL[i] >= 1 && cntR[i] >= 1) tmp++;
		// dump(tmp);
		ans = max(ans, tmp);
	}
	cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
def main():
    h,w,_ = map(int,input().split())
    ls = [list(input()) for _ in range(h)]
    check = [False for _ in range(h)]


    for i in range(h):
        flg = False
        for j in range(w):
            if ls[i][j] == "#":
                flg = True
        if flg:
            check[i] = True


    ans = [[0 for _ in range(w)] for _ in range(h)]
    now = 1
    for i,flg in enumerate(check):
        if flg:
            ball = False
            for j in range(w):
                if ball == True and ls[i][j]=="#":
                    now +=1
                    ans[i][j]=now
                elif ball == False and ls[i][j]=="#":
                    ans[i][j]=now
                    ball = True
                else:
                    ans[i][j]=now
            now += 1


        else:
            pass
    

    for i,flg in enumerate(check):

        if flg:
            pass

        else:
            k = i
            while 1:
                if k == h-1 and check[h-1]==False:
                    break

                if check[k]:
                    break
                else:
                    k += 1

            for j in range(w):
                ans[i][j] = ans[k][j]
        
    if check[-1]==False:
        index = 0
        for i in range(h):
            if check[i]==True:
                index = i
            else:
                pass

        for i in range(index+1,h):
            for j in range(w):
                ans[i][j]=ans[index][j]


    for i in range(h):
        for j in range(w):
            print(ans[i][j],end=" ")
        print("\n")

if __name__ == "__main__":
    main()

Measured memory_bytes: 54232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<pr> vp;
typedef vector<vp> vpp;
typedef vector<vector<ll> > graph;
#define pb push_back
#define mp make_pair
#define endl '\n'
void set_val(vector<ll>& v, ll val){for(ll i=0;i<v.size();i++) v[i]=val;}

ll mod = pow(10,9) + 7;
ll modulo = 998244353;
double pi = 3.141592653589793238;
ll i_mov[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
ll j_mov[8] = {1, 1, 1, 0, -1, -1, -1, 0};


ll power(ll a, ll n)
{
    if(n==0)
    return 1;
    ll temp = power(a,n/2);
    if(n%2==0)
    return (temp*temp)%mod;
    return (((temp*temp)%mod)*a)%mod;
}

int fact(ll n)
{
    if(n==0) return 1;
    return n*fact(n-1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout<<setprecision(10);
    int n;
    cin>>n;
    vector<ll> a(n), b(n);
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<n;i++)
    cin>>b[i];
    ll p = 0, q=0;
    vector<ll> freq1(n+1,0), freq2(n+1,0);
    for(int i=0;i<n-1;i++)
    {
        int count1 = 0, count2 = 0;
        for(int j = 1; j<a[i];j++)
        {
            if(freq1[j]==0)
            count1++;
        }
        for(int j = 1; j<b[i];j++)
        {
            if(freq2[j]==0)
            count2++;
        }
        p += count1 * fact(n-i-1);
        q += count2* fact(n-i-1);
        freq1[a[i]]=1, freq2[b[i]]=1;
    }
    
    cout<<abs(p-q);
    
} 

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n;
	int i, j;
	scanf("%d", &n);
	for (i = 0; i <= 9; i++) {
		for (j = 0; j <= 9; j++) {
			if (n == (i*j)) {
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");

}




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

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

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int N,Q;
  ll K;
  cin >> N >> K >> Q;

  vector<ll> m(N,0);
  REP(i,Q){
    int A;
    cin >> A;
    A--;
    m[A]++;
  }

  REP(i,N){
    if(K - Q + m[i] > 0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }

}



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

char a[100][101], b[102][102];
int main() {
    int H, W;
    cin >> H >> W;

    for(int i = 0; i < H; i++) {
        cin >> a[i];
    }

    for(int i = 0; i < H+2; i++) {
        for(int j = 0; j < W+2; j++) {
            b[i][j] = '#';
        }
    }

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            b[i+1][j+1] = a[i][j];
        }
    }
    for(int i = 0; i < H+2; i++) {
        for(int j = 0; j < W+2; j++) {
            cout << b[i][j];
        }
        cout << endl;
    }

}

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

int main(){
	int n, m, s, c;
	int s1, s2, s3;
	s1 = s2 = s3 = -1;
	cin >> n >> m;
	rep(i, m){
		cin >> s >> c;
		if(s == 1 && (s1 == -1 || s1 == c)){
			s1 = c;
		}else if(s == 2 && (s2 == -1 || s2 == c)){
			s2 = c;
		}else if(s == 3 && (s3 == -1 || s3 == c)){
			s3 = c;
		}else{
			cout << -1 << endl;
			return 0;
		}
	}
	
	int ans = 0;
	if(n > 1 && s1 == 0){
		cout << -1 << endl;
		return 0;
	}
	if(s1 == -1){
		if(n != 1) s1 = 1;
		else s1 = 0;
	}
	if(s2 == -1) s2 = 0;
	if(s3 == -1) s3 = 0;
	if(n == 3){
		for(int i = 100; i < 1000; i++){
			int a1, a2, a3;
			string str = to_string(i);
			a1 = str[0] - '0';
			a2 = str[1] - '0';
			a3 = str[2] - '0';
			if(a3 == s3 && a2 == s2 && a1 == s1){
				ans = i;
				break;
			}
		}
	}else if(n == 2){
		for(int i = 10; i < 100; i++){
			int a1, a2;
			string str = to_string(i);
			a1 = str[0] - '0';
			a2 = str[1] - '0';
			if(a2 == s2 && a1 == s1){
				ans = i;
				break;
			}
		}
	}else if(n == 1){
		ans = s1;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define mod 998244353
#define int long long
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int mul(int x,int y){return 1LL*x*y%mod;}
#define N 200005
struct Node
{
	int x,y;
};
vector<Node> a;
vector<int> b;
int f[N];
bool cmp(Node x,Node y)
{
	return y.x*(x.y+1)<x.x*(y.y+1);
}
signed main()
{
	int n=read(),T=read();
	for(int i=1;i<=n;i++)
	{
		int x=read(),y=read();
		if(x) a.pb((Node){x,y});
		else b.pb(y+1);
	}
	sort(a.begin(),a.end(),cmp);
	sort(b.begin(),b.end());
	for(int i=1;i<b.size();i++)
	{
		b[i]+=b[i-1];
	}
	for(int i=1;i<=30;i++) f[i]=T+5;
	for(int i=0;i<a.size();i++)
	{
		for(int j=30;j>0;j--)
		{
			int R=(f[j-1]+1)*(a[i].x+1)+a[i].y;
			if(R<f[j]) f[j]=R;
		}
	}
	// for(int i=0;i<=30;i++) printf("%lld ",f[i]); cout<<"\n";
	int ans=0;
	for(int i=0;i<=30;i++)
	{
		if(f[i]<=T)
		{
			int R=i+(upper_bound(b.begin(),b.end(),T-f[i])-b.begin());
			if(R>ans) ans=R;
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 6128
#include <bits/stdc++.h>
typedef long long ll; 
 
using namespace std;
using P = pair<ll, ll>;

vector<P> prime_factorize(ll n) {
	vector<P> res;

	for (ll p = 2; p * p <= n; p++) {
		if (n % p != 0) continue;

		int num = 0;
		while (n % p ==0) {
			num++;
			n /= p;
		}
		res.push_back(P(p, num));
	}
	if (n != 1) res.push_back(P(n, 1));

	return res;
}

template <typename T>
T calc(T a, T b, T p) {
    if (b == 0) return 1;

    if (b % 2 == 0) {
		T d = calc(a, b / 2, p);
		return (d * d) % p;
    } else {
		return (a * calc(a, b - 1, p)) % p;
    }

    return 0;
}

template <typename T>
void ModConb(T& v, T& vi, ll mod) {
	v[0] = 1;
	vi[0] = 1;
	for (int i = 1; i < v.size(); i++) {
		v[i] = v[i - 1] * i;
		v[i] %= mod;

		vi[i] = calc(v[i], mod - 2, mod);
		vi[i] %= mod;
	}
}

int main() {
	const ll MOD = 1e9 + 7;
	ll N, M;
	cin >> N >> M;
	vector<P> fac = prime_factorize(M);

	vector<ll> v(N + 1000);
	vector<ll> vi(N + 1000);
	ModConb(v, vi, MOD);

	ll res = 1;
	for (int i = 0; i < fac.size(); i++) {
		ll n = fac[i].second;

		ll tmp = (((v[N + n - 1] * vi[n]) % MOD) * vi[N - 1]) % MOD;
		res = (res * tmp) % MOD;
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll n,m,k;cin>>n>>m>>k;
    vector<ll> a(n),b(m),asum(n+1,0),bsum(m+1,0);
    rep(i,n){
        cin>>a[i];
        asum[i+1]=asum[i]+a[i];
    }
    rep(i,m){
        cin>>b[i];
        bsum[i+1]=bsum[i]+b[i];
    }

    ll ans=0;
    for(ll i=0;i<=n;i++){
        ll rem=k-asum[i];
        if(rem<0) continue;

        auto j=lower_bound(ALL(bsum),rem+1);
        j=prev(j);
        ll idx=j-bsum.begin();
        chmax(ans,idx+i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9532
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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




int main(){
    int n, k; cin >> n >> k;
    VI a(n);
    REP(i, n) cin >> a[i];
    vector<VI> dp(n+1, VI(k+1, 0));
    REPS(i, n) dp[i][0] = 1;
    REP(i, n){
        VI sum(k+1, 0);//sum[j] = dp[i][t] t=0...jの累積和
        sum[0] = 1;
        FORS(j, 1, k){
            sum[j] = (dp[i][j] + sum[j-1]) % MOD;
            if(sum[j] < 0) sum[j] += MOD;
        }
        FORS(j, 1, k){
            if(j <= a[i]){
                dp[i+1][j] = sum[j] % MOD;
                if(dp[i+1][j] < 0) dp[i+1][j] += MOD;
            }else{
                dp[i+1][j] = (sum[j] - sum[j-a[i]-1]) % MOD;
                if(dp[i+1][j] < 0) dp[i+1][j] += MOD;
            }
            
        }
    }
    cout << dp[n][k] << "\n";
    return 0;
}


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
//const i64 inf = 10000000000000007ll;

const double eps = 1e-10;


const i64 MAXN = 53;
const i64 MAXM = 20;

i64 n, m;

vector<i64> e[MAXN];

pair<i64, i64> h[MAXN];
i64 z[MAXN][MAXN];

long long int dp[MAXN][1 << MAXM];

set<i64> w[MAXM];

bool dfs(i64 c, i64 p, i64 t, set<i64>& r) {
    if (c == t) {
        return true;
    }

    for (auto n : e[c]) {
        if (n == p) {
            continue;
        }

        r.insert(z[c][n]);
        if (dfs(n, c, t, r)) {
            return true;
        }
        r.erase(z[c][n]);

    }
    return false;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n;

    for (i64 i = 1; i < n; i++) {
        i64 u, v;
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
        z[u][v] = i;
        z[v][u] = i;
        h[i] = { u, v };
    }

    cin >> m;
    for (i64 i = 0; i < m; i++) {
        i64 u, v;
        cin >> u >> v;
        dfs(u, 0, v, w[i]);
    }

    dp[0][0] = 1;
    for (i64 i = 1; i < n; i++) {
        i64 t = 0;
        for (i64 j = 0; j < m; j++) {
            if (w[j].count(z[h[i].first][h[i].second])) {
                t |= (1 << j);
            }
        }

        for (i64 j = 0; j < (1 << MAXM); j++) {
            dp[i][j | t] += dp[i - 1][j];
            dp[i][j] += dp[i - 1][j];
        }
    }


    cout << dp[n - 1][(1 << m) - 1] << endl;

    return 0;
}

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

int c(int n, int k, vector<int> a) {
  if((n-1) % (k-1) == 0) {
    return (n-1) / (k-1);
  }
  return (n-1) / (k-1) + 1;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0;i<n;i++) {
    cin >> a[i];
  }

  cout << c(n, k, a);
}

Measured memory_bytes: 3976
#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, m;
	cin >> n >> m;
	map<int, int> mod;
	ll sum = 0;
	int it = 0;
	rep(j, n){
		int i;
		cin >> i;
		if(j == 0){
			mod[i%m]++;
		}else{
			it -= i%m;
			if(it < 0) it += m;
			mod[(it+i%m)%m]++;
		}
		sum += mod[it];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3200
import sys
import math

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	a,b = MI()
	n=int(str(a)+str(b))
	sqrtn = int(math.sqrt(n))
	if(sqrtn**2==n):
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
n = int(input())
list = [int(x) for x in input().split(" ")]
result = 'APPROVED'
for i in range(len(list)):
    if list[i]%2 == 0:
        if list[i]%3 != 0 and list[i]%5 != 0:
            result = 'DENIED'
            break
print(result)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
		}
		int ans = 0;
		for (int i = 1; i < N - 1; i++) {
			if (p[i - 1] < p[i] && p[i] < p[i + 1]) {
				ans++;
			} else if (p[i + 1] < p[i] && p[i] < p[i - 1]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23892
n = int(input())    # 2
t, a = map(int, input().split())    # 12, 5
h_list = list(map(int, input().split()))    # [1000, 2000]

ans_ind = None
ans_diff = float('inf')

for i, h in enumerate(h_list):
  avg_tmp = t - h * 0.006    # fist:6, second:0
  if abs(a - avg_tmp) < ans_diff:    # first:True, second:False
    ans_ind = i    # first:0
    ans_diff = abs(a - avg_tmp)    # first:1

print(ans_ind + 1)   # 0


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

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)
#define QSIZE 300010
int que[QSIZE + 5];
int qsize;

void max_heapify(int i)
{
	int l, r, max;
	int qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l] > que[i]) max = l; else max = i;
	if (r < qsize && que[r] > que[max]) max = r;
	if (max != i) {
		qt = que[i], que[i] = que[max], que[max] = qt;
		max_heapify(max);
	}
}

void deq()
{
	que[0] = que[--qsize];
	max_heapify(0);
}

void enq(int c)
{
	int i, max;
	int qt;

	i = qsize++;
	que[i] = c;
	while (i > 0 && que[max = PARENT(i)] < que[i]) {
		qt = que[i]; que[i] = que[max], que[max] = qt;
		i = max;
	}
}

int c[300010];
int top[300010], sz[300010]; int N;

int main()
{
	int i, k, M;
	unsigned ans;

    scanf("%d", &N);
	k = 0;
	for (i = 0; i < N; i++) {
	    scanf("%d", &M);
		sz[i] = M;
		top[i] = k;
		while (M--) scanf("%d", &c[k++]);
	}
	
	ans = 0, qsize = 0;
	for (i = N - 1; i >= 0; i--) {
		M = sz[i], k = top[i];
		while (M--) enq(c[k++]);
		ans += (unsigned)que[0];
		deq();
	}
	printf("%u\n", ans);
	return (0);
}


Measured memory_bytes: 5240
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;

int main(){
    ll n,k;cin>>n>>k;
    map<ll,ll> m;
    ll mm=0;
    for(ll i=0;i<n;i++){
        ll a;cin>>a;
        if(m[a]==0)mm++;
        m[a]++;
    }
    vector<ll> v;
    for(auto it=m.begin();it!=m.end();it++){
        v.push_back(it->second);
    }
    sort(v.begin(),v.end());
    if(k>=mm){cout<<0;return 0;}
    ll ans=0;
    for(ll i=0;i<mm-k;i++)ans+=v[i];
    cout<<ans;return 0;
    
}

Measured memory_bytes: 14964
n,k=[int(k) for k in input().split(" ")]

if k>(n-1)*(n-2)//2:
    print(-1)
else:
    res=[]
    for i in range(2,n+1):
        res+=[(1,i)]
    nbpass=k
    for i in range(2,n+1):
        for j in range(i+1,n+1):
            if nbpass:
                nbpass-=1
            else:
                res+=[(i,j)]
    print(len(res))
    for i in res:
        print(i[0],i[1])


Measured memory_bytes: 3992
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long int LL;
typedef long long int ll;
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include<stack>

const int maxn=1e6+100;
long long a[maxn];
long long b[maxn];

int main()
{
#ifdef LOCAL
    freopen("data.h", "r", stdin);
    //freopen("1.h","w",stdout);
#endif
    int n,l,r;
    long long k;
    scanf("%d",&n);
    cin>>k;
    memset(a,0,sizeof(a));
    while(n--){
        scanf("%d%d",&l,&r);
        a[l]+=r;
    }
    memset(b,0,sizeof(b));
    for(int i=1;i<=100002;i++){
        b[i]=b[i-1]+a[i];
    }
    int ans=lower_bound(b,b+100002,k)-b;
    printf("%d\n",ans);
}


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

int main() {
  std::string S, T;
  std::cin >> S >> T;

  std::cout << (S == T.substr(0, T.size() - 1) ? "Yes" : "No") << std::endl;

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
	int x,t;
	cin >> x >> t;
	(x - t > 0)? P(x-t): P(0);

	

	return  0;
}

Measured memory_bytes: 256
#include <cassert>
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>
#include <fstream>
#include <ostream>
#include <random>
#include <chrono>

using namespace std;

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

	vector<int> all;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;

		all.push_back(x);
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		ans += max(0, all[i] - x);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
using namespace std;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;

  int n = (int)s.size();
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'a') continue;
    int diff = 'z' - s[i] + 1;
    if (diff <= k) {
      k -= diff;
      s[i] = 'a';
    }
    if (k == 0) break;
  }

  if (k == 0) {
    cout << s << endl;
    return 0;
  }

  int last = s.back() - 'a';
  last += k;
  last %= 26;
  char last_char = last + 'a';
  s.back() = last_char;
  
  cout << s << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, h;
  cin >> n >> h;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  ll ans = 0;
  for (int i = 0; b[i] >= a[0]; i++) {
    ans++;
    h -= b[i];
    if (h <= 0) {
      cout << ans << endl;
      return 0;
    }
  }
  ans += (h + a[0] - 1) / a[0];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792