akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

typedef long long ll;

int n;
ll x;
ll a[202020];

__int128_t lol(int u) {
	__int128_t w = 0;
	for (int i = n; i >= n-u+1; i--) {
		w += x;
		w += a[i];
		int k = 1;
		int j = i;
		while (true) {
			w += x;
			if (j-u >= 1) {
				j -= u;
				w += (__int128_t)(a[j+u]-a[j])*(k+1)*(k+1);
			} else {
				w += (__int128_t)a[j]*(k+1)*(k+1);
				break;
			}
			k++;
		}
	}
	return w;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> x;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int k = 0;
	for (int b = n/2; b >= 1; b /= 2) {
		while (k+b+1 <= n && lol(k+b) > lol(k+b+1)) k += b;
	}
	cout << (ll)lol(k+1) << "\n";
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int> 
using namespace std ; 
signed main(){
    fast;
    int n;
    cin>>n;
    string s;
    cin>>s;
    s = '#'+s;
    int cnt = 0;
    int ans = 0;
    for(int i = 1;i<=n;i++){
    	if(s[i] == 'R')
    		cnt++;
    }
    for(int i = cnt+1;i<=n;i++){
    	if(s[i] == 'R') ans++;
    }
    cout<<ans;

}


Measured memory_bytes: 3876
#include <iostream>
#define ll long long
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n,idx = 1,cur = 1, sum = 0; cin>>n;
	while(sum + (cur * 26) < n){
		cur *= 26;
		sum += cur;
		idx++;
	}
	n -= sum + 1;
	while(idx--){
		int t = n / cur;
		if(t == 26) t--;
		cout<<(char)('a' + t);
		n -= t * cur;
		cur /= 26;
	}
}

Measured memory_bytes: 3588
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

typedef pair<ll, ll> P;

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

struct second_order {
    bool operator()(const pair<ll, ll>& x, const pair<ll, ll>& y) const {
        return x.second < y.second;
    }
};

int main() {
    INIT;
    ll N;
    cin >> N;
    vector<ll> v(N);
    rep(i, N) cin >> v[i];

    map<ll, ll> od, ev;
    for (ll i = 0; i < N; i += 2) ev[v[i]]++;
    for (ll i = 1; i < N; i += 2) od[v[i]]++;

    priority_queue<P, vector<P>, second_order> od_que;
    priority_queue<P, vector<P>, second_order> ev_que;

    for (auto e : od) od_que.push(e);
    for (auto e : ev) ev_que.push(e);

    // priority_queue<P, vector<P>, second_order> od_que_cp = od_que;
    // priority_queue<P, vector<P>, second_order> ev_que_cp = ev_que;

    // while (!od_que_cp.empty()) {
    //     P item = od_que_cp.top();
    //     cout << item.first << ", " << item.second << endl;
    //     od_que_cp.pop();
    // }

    // while (!ev_que_cp.empty()) {
    //     P item = ev_que_cp.top();
    //     cout << item.first << ", " << item.second << endl;
    //     ev_que_cp.pop();
    // }

    P od_cand = od_que.top();
    P ev_cand = ev_que.top();

    ll ans = INF;
    if (od_cand.first == ev_cand.first) {
        od_que.pop();
        ev_que.pop();

        P od_cand2, ev_cand2;
        if (od_que.empty()) {
            od_cand2 = {0, 0};
        } else {
            od_cand2 = od_que.top();
        }

        if (ev_que.empty()) {
            ev_cand2 = {0, 0};
        } else {
            ev_cand2 = ev_que.top();
        }
        // cout << od_cand.first << ", " << od_cand.second << " / "
        //      << ev_cand.first << ", " << ev_cand.second << endl;

        // cout << od_cand2.first << ", " << od_cand2.second << " / "
        //      << ev_cand2.first << ", " << ev_cand2.second << endl;

        chmin(ans, N - (od_cand2.second + ev_cand.second));
        chmin(ans, N - (od_cand.second + ev_cand2.second));
    } else {
        ans = N - (od_cand.second + ev_cand.second);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12544
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <cstring>

using namespace std;

int main(){
	stack<int> garage;
	vector<int> out;
	int enter;
	while(cin >> enter){
		if(enter == 0){
			out.push_back(garage.top());
			garage.pop();
		}
		else{
			garage.push(enter);
		}
	}

	for(vector<int>::iterator it = out.begin(); it != out.end(); it++){
		cout << *it << endl; 
	}

	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll H,W;
    cin>>H>>W;
    
    ll ans=1e12;
    
    for(int k=0;k<2;k++){
        if(k)swap(H,W);
        for(int i=1;i<H;i++){
            ll h=H-i;
            ll Sa=i*W,Sb,Sc;
            
            ll case1;
            Sb=(h/2)*W;
            Sc=(h-h/2)*W;
            case1=max({abs(Sa-Sb),abs(Sc-Sb),abs(Sc-Sa)});
            ans=min(ans,case1);
            
            ll case2;
            Sb=h*(W/2);
            Sc=h*(W-W/2);
            case2=max({abs(Sa-Sb),abs(Sc-Sb),abs(Sc-Sa)});
            ans=min(ans,case2);
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Printer pr = new Printer(System.out);

		final int MOD = 1_000_000_007;

		int n = sc.nextInt();
		int c = sc.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			b[i] = sc.nextInt();
		}

		long[][] tmp2 = new long[400 + 1][400 + 1];
		for (int i = 1; i <= 400; i++) {
			long tmp = 1;
			for (int j = 0; j <= 400; j++) {
				if (j > 0) {
					tmp *= i;
					tmp %= MOD;
				}
				tmp2[i][j] += tmp2[i - 1][j] + tmp;
				tmp2[i][j] %= MOD;
			}
		}

		long[][] dp = new long[n + 1][c + 1];
		dp[0][0] = 1;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= c; j++) {
				for (int k = 0; k <= j; k++) {
					dp[i][j] += dp[i - 1][j - k] * ((tmp2[b[i - 1]][k] - tmp2[a[i - 1] - 1][k] + MOD) % MOD) % MOD;
					dp[i][j] %= MOD;
				}
			}
		}

		pr.println(dp[n][c]);

		pr.close();
		sc.close();
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
//					it = Arrays.asList(br.readLine().split(" ")).iterator();
					it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 12112
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
    double r;
    cin>> r;
    double pi=3.141592653589;
    double arc=r*r*pi;
    double circ=2*r*pi;
    printf("%f %.5f\n",arc, circ);
    return 0;
}


Measured memory_bytes: 3200
#include<stdio.h>
int main(void)
{
	int p,q,r,max=0,result=0;
	scanf("%d %d %d",&p,&q,&r);
	max=p;
	if(max<q){
		max=q;
	}
	if(max<r){
		max=r;
	}
	result=p+q+r;
	printf("%d",result-max);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;

#define rep(i,x) for(Int i = 0; i < (Int)(x); i++)
#define rrep(i,x) for(Int i = ((Int)(x) - 1); i >= 0; i--)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back


template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

Int dx[4] = {1,0,-1,0};
Int dy[4] = {0,1,0,-1};
const Int INF = 1001002003004005006ll;
const Int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//









string s[60];

int main(){
        int n;
        cin >> n;
        int i;
        for(i = 0; i < n; i++) cin >> s[i];

        string ans;
        for(char c = 'a'; c <= 'z'; c++){
                Int small = INF;
                for(i = 0; i < n; i++){
                        Int cnt = 0;
                        for(int j = 0; j < s[i].length(); j++){
                                if(s[i][j] == c) cnt++;
                        }
                        small = min(small,cnt);
                }
                for(i = 0; i < small; i++) ans += c;
        }
        cout << ans << endl;
        return 0;
}















Measured memory_bytes: 256
#include <stdio.h>
char a[110];
int main(){
	scanf("%s",a);
	for(int i=0;a[i]!=0;i++){
		if(i%2){
			if(a[i]=='R'){
				printf("No\n");
				return 0;
			}
		} else{
			if(a[i]=='L'){
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
}

Measured memory_bytes: 128
def main():
    D, G = map(int, input().split())
    info = [tuple(map(int, input().split())) for _ in range(D)]

    ans = 100 * 10
    for bit in range(1<<D):
        score = 0
        num_problem = 0

        # complete bonus
        for i in range(D):
            if (bit>>i) & 1:
                base = 100 * (i+1)
                score += base * info[i][0] + info[i][1]
                num_problem += info[i][0]
        
        # other
        if score >= G:
            ans = min(ans, num_problem)
        else:
            for i in range(D-1, -1, -1):
                if not((bit>>i) & 1):
                    rest = G - score
                    base = 100 * (i+1)
                    need = (rest + base -1) // base
                    if need <= info[i][0] - 1:
                        num_problem += need
                        score += base * need
                        ans = min(ans, num_problem)
                    break

    print(ans)


if __name__ == "__main__":
    main()

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


int main () {
	long long int m,n,man,w;
	int *ans;
	long long int *a,*b,*c,*d;

	cin >> n >> m;

	a = new long long int[n];
	b = new long long int[n];
	c = new long long int[m];
	d = new long long int[m];
	ans = new int[n];

	for (int i=0;i<n;i++){
		cin >> a[i] >> b[i];
	}
	for (int i=0;i<m;i++){
		cin >> c[i] >> d[i];
	}


	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			w = max(a[i]-c[j],c[j]-a[i]) + max(b[i]-d[j],d[j]-b[i]);
			if(j==0){
				man = w;
				ans[i] = j+1;
			}

			if(man > w){
				man = w;
				ans[i] = j+1;
			}
		}
	}
	for(int i=0;i<n;i++){
		cout << ans[i] << endl;
	}


    return 0;
}

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

int main() {
  ll n, k , q;
  cin >> n >> k >> q;
  map<ll, ll> as;
  rep(i, n) {
    as[i] = 0;
  }
  rep(i, q) {
    int a;
    cin >> a;
    as[a]++;
  }
  for(auto it = as.begin(); it != as.end(); it++)  {
    if (it->second > q - k) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

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

int main(void){
	vector<int> a(3);
	rep(i, 3) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	if(a[0] % 2 != a[1] % 2){
		ans++;
		a[0]++;
		a[2]++;
	}
	ans += a[2]-a[1] + (a[1]-a[0])/2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
#include <complex>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef pair<int,int> p;
set <int> st;
int h,w,sx,sy,gx,gy;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
string c[55];
queue<pair<int,int> > que;
int cost[55][55];
bool ok=false;
int tmpscore=0;

int main(int argc,char const* argv[])
{
  cin >> h>> w;
  memset(cost,-1,sizeof(cost));
  tmpscore=h*w;
  for(int i=0;i<h;i++)
    {
      cin >> c[i];
      for(int j=0;j<w;j++)
	{
	  if(c[i][j]=='#') tmpscore--;
	}
    }
  cost[0][0]=0;
  que.push(p(0,0));
  while(!que.empty())
    {
      pair<int,int> q=que.front();que.pop();
      if(q.first==h-1 && q.second==w-1) break;
      for(int k=0;k<4;k++)
	{
	  int ny=q.first+dy[k],nx=q.second+dx[k];
	  if(ny<0 || ny>=h ||nx<0 || nx>=w || c[ny][nx]=='#'|| cost[ny][nx]!=-1) continue;
	  else
	    {
	      cost[ny][nx]=cost[q.first][q.second]+1;
	      que.push(p(ny,nx));
	    }
	}
    }
  if(cost[h-1][w-1]==-1) 
    {
      cout << -1 << endl;
      return 0;
    }
  else
    {
      cout << tmpscore-cost[h-1][w-1]-1 << endl;
      return 0;
    }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define sp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
 
}



void solve()
{
	int n;
	cin >> n;
	ll sum = 0;
	ll a[n];
	ll p = 0, res = 1e18;
	rep(i, n) cin >> a[i], sum += a[i];
	rep(i, n - 1){
		p += a[i];
		sum -= a[i];
		res = min(res, abs(p - sum));
	}
	cout << res;
}

 
int main()
{
	// freopen("crosses.in", "r", stdin);
	// freopen("crosses.out", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 5036
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int n;
    cin >> n;
    vector<int> t(n,0);
    rep(i,n)cin >> t.at(i);
    int m;
    cin >> m;
    vector<P> u(m);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        u.at(i) = make_pair(a,b);
    }
    ll sum = accumulate(t.begin(),t.end(),ll(0LL));
    rep(i,m){
        cout << sum - t[u[i].first-1] + u[i].second << endl;
    }
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    long long M, N, x;
    cin >> M >> N;
    x = (M - 2) * (N - 2);
    if (x < 0) x = -x;
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
l=[-1]*n
z=n*(n-1)//2
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m)[::-1]:
  x,y=map(f,b[i])
  if x!=y:
    s,t=l[x],l[y]
    z-=s*t
    if s>t:
      l[x]=y
      l[y]+=s
    else:
      l[y]=x
      l[x]+=t
  c[i]=z
for x in c[1:]:
  print(x)

Measured memory_bytes: 40268
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10;
char s[M];
int main(){
    int n;
    scanf("%d%s", &n, s + 1);
    int len = strlen(s + 1);
    if(n >= len) printf("%s\n", s + 1);
    else {
        s[n + 1] = s[n + 2] = s[n + 3] = '.';
        s[n + 4] = '\0';
        printf("%s", s + 1);
    }
    return 0;
}


Measured memory_bytes: 3824
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
void Iswap(int *a,int *b){
  int t=*a;
  *a=*b;
  *b=t;
}
void Fswap(double *a,double *b){
  double t=*a;
  *a=*b;
  *b=t;
}
void Lswap(ll *a,ll *b){
  ll t=*a;
  *a=*b;
  *b=t;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}
ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}
int main(void){
  int a[4];
  FOR(i,4)INI(a[i]);
  a[0]--;
  a[2]--;
  char s[2][4]={"Yes","No"};
  PRS(s[a[0]/a[3]<a[2]/a[1]]);
  return 0;
}

Measured memory_bytes: 1636
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define deb(a) cout << a << ": "
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
int cnt[N];
void sliczny() {
    int n;
    cin >> n;
    for(int x=1; x<=sqrt(n); x++) {
        for(int y=1; y<=sqrt(n); y++) {
            for(int z=1; z<=sqrt(n); z++) {
                int v = x*x + y*y + z*z + x*y + y*z + z*x;
                if(v > n) {
                    break;
                } 
                else {
                    cnt[v]++;
                }
            }
        }
    }
    for(int i=1; i<=n; i++) {
        cout << cnt[i] << '\n';
    }
}

int32_t main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
  //cin >> T; 
    for(int t = 1; t <= T; t++) {
    //cout << "Case #" << t << ": ";
        sliczny();
    }
  return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;



void solve() {
    int N; cin >> N;
    string S; cin >> S;

    if (N % 2 != 0) {
        cout << "No"; 
        return;
    } else {
        for (int i = 0; i < N/2; i++) {
            if (S[i] != S[i+N/2]) {
                cout << "No"; 
                return;
            }
        }
    }

    cout << "Yes";
    // cout << ans << "\n";
}

signed main() {
    solve();
    return 0;
}   


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n,m;
    while(1){
        scanf("%d %d",&n,&m);
        if(n==0 && m==0)
            break;
        int map[1000]={0},place=n;
        int count=n,t,t1=n;
        while(t1 != 0){
            t=m;
            while(t){
                place++;
                if(place > n)
                {
                    place=1;
                }
                if(map[place] == 0){
                    t--;
               }
            }
            map[place]=1;
            t1--;
        }
        printf("%d\n",place);
    }
    return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;
int main(){
        map<int,int> mp;
        int N,tmp;
        cin >> N;
        rep(i,N){
                cin>>tmp;
                mp[tmp]++;
        }
        int ans = 0;
        for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
                if(itr->second%2!=0) ans++;
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define ll unsighned long int
 
int main(){
    unsigned long int n,k;
    cin >> n >> k;
    vector<unsigned long int> v;
    for(unsigned long int i = 0; i < n; ++i){
        unsigned long int a;
        cin >> a;
        v.push_back(a);
    }

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

    sort(v.begin(),v.end());//cout << "a";
//cout << v.size();
    unsigned long int ans = 0;

    for(unsigned long int i = 0; i < v.size() - k; ++i){//cout << "b";
        ans += v[i];
    }

    cout << ans << endl;
 
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+7;
const ll mod=1e9+7;
ll d[N];
ll arr0[N];//前缀 
ll arr1[N];//后缀 
int main(){
	ll n,m;
	cin>>n>>m;
	for(ll i=1;i<=n+1;i++) d[i]=i-1; 
	for(ll i=1;i<=n+1;i++) {
		arr0[i]=arr0[i-1]+d[i]; 
	}
	for(ll i=n+1;i>=1;i--) {
		arr1[i]=arr1[i+1]+d[i]; 
	}
	reverse(arr1+1,arr1+1+n+1);
	ll ans=0;
	for(ll i=m;i<=n+1;i++){
		ans=ans+arr1[i]-arr0[i]+1;
		ans=ans%mod;
	}
	cout<<ans<<endl;
	return 0;
}

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

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

N, M, C = lr()
B = np.array(lr())
A = np.array([lr() for _ in range(N)])
answer = ((A*B).sum(axis=1) + C > 0).sum()
print(answer)


Measured memory_bytes: 21780
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)


Measured memory_bytes: 5980
X, K, D = map(int, input().split())
if X == 0:
  if (K % 2 == 0):
    a = 0
  else:
    a = D
else:
  if X < 0:
    X = -X
  s = int(X/D)
  if K <= s:
    a = X - K * D
  else:
    if (K - s) % 2 == 1:
      a = abs(X - (s + 1) * D)
    else:
      a = abs(X - s * D)
print(a)

Measured memory_bytes: 9156
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
using namespace std;

#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

void sout(string* a, string* b) {
	if (*a > * b) {
		string c = *a;
		*a = *b;
		*b = c;
	}
}

int combination(int n, int k) {
	if (n > k && k > 0) {
		return (combination(n - 1, k) + combination(n - 1, k - 1));
	}
	else
		return 1;
}

int main() {
	int n;
	cin >> n;
	vector<int> b(n - 1);
	rep(i, n - 1) cin >> b.at(i);
	int sum = b.at(0) + b.at(n - 2);
	for (int i = 1; i < n - 1; i++) {
		sum += min(b.at(i - 1), b.at(i));
	}
	cout << sum << endl;
}

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define ll long long
#define mod 1000000007

using namespace std;

int main()
{
  int a, b, h;
  cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>

int f[110][110], d[110][110];
#define cmin(a, b) (a > (b) ? a = (b) : 0)
int main()
{
	int n, m; scanf("%d%d", &n, &m);
	memset(d, 63, sizeof (d));
	for (int i = 1; i <= m; ++i)
	{
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		d[a][b] = d[b][a] = f[a][b] = f[b][a] = c;
	}
	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				cmin(d[i][j], d[i][k] + d[k][j]);
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (f[i][j] && d[i][j] < f[i][j])
				++ans;
	printf("%d\n", ans >> 1);
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
using namespace std;
int		cnt;

int		main(void)
{
	int		N;
	cin >> N;
	vector<int> p(N);
	for (int i = 0; i < N; i++)
		cin >> p.at(i);
	vector<int> tmp(N);
	tmp = p;
	sort(tmp.begin(), tmp.end());
	for (int i = 0; i < N; i++)
	{
		if (tmp.at(i) != p.at(i))
			cnt++;
	}
	cout << (cnt <= 2 ? "YES" : "NO") << endl;
}


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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

int main()
{
    Fast_IO();
    ll n; cin >> n;
    ll a[n]; f(i,0,n-1) cin >> a[i];
    ll cc = 0;
    f(i,0,n-1) {
    	if(i % 2 == 0) {
    		if(a[i] % 2) {
    			cc++;
    		}
    	}
    }
    cout << cc;
    return 0;
}

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

int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;
    auto f=[](ll i,ll t){
        return i/t;
    };
    auto solve=[&](ll s){
        return f(s,c)+f(s,d)-f(s,lcm(c,d));
    };
    cout<<(b-a)-(solve(b)-solve(a));
}

Measured memory_bytes: 3624
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<s32>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

const int N = 3e4 + 5;
int dp[N][3];

void clear_dp(int n){
    for(int i = 0;i < n;i++)
        for(int j = 0;j < 3;j++)
            dp[i][j] = -1;
}

void inc(string &str){
    int sum = 0,carry = 1;
    int n = str.length();
    for(int i = n - 1;i >= 0;i--){
            int a = str[i] - '0';
            a += carry;
            sum = a % 10;
            carry = a / 10;
            str[i] = (sum + 48);
    }
    if(carry) str = to_string(carry) + str;
}

int is_subsequence(int i,int j,string &a,string &b){
    if(j < 0) return 1;
    if(i < 0) return 0;
    if(dp[i][j] != -1)
        return dp[i][j];
    if(a[i] == b[j])
        return (dp[i][j] = (1 & is_subsequence(i - 1,j - 1,a,b)));
    else
        return (dp[i][j] = is_subsequence(i - 1,j,a,b));
}

int main()
{
	FASTIO;
	int n; cin >> n;
	string str; cin >> str;
	string i = "000";
	int cnt = 0;
	while(i != "1000"){
        clear_dp(n);
        cnt += is_subsequence(n - 1,2,str,i);
        inc(i);
	}
	cout << cnt << ln;
	return 0;
}


Measured memory_bytes: 3072
#include<stdio.h>
#include<math.h>
int main(){
	int H,W;
	int A[101][101]={0};
	int i,j,m,n,g,min;
	scanf("%d%d",&H,&W);
	for(i=1;i<=H;i++)for(j=1;j<=W;j++)scanf("%d",&A[i][j]);
	for(i=1;i<=H;i++){
		for(j=1;j<=W;j++){
			g=0;
			for(m=1;m<=H;m++){
				for(n=1;n<=W;n++){
					if(m==i || n==j)continue;
					else if(abs(m-i)==abs(n-j))g+=A[m][n]*abs(m-i);
					else if(abs(m-i)<abs(n-j))g+=A[m][n]*abs(m-i);
					else if(abs(m-i)>abs(n-j))g+=A[m][n]*abs(n-j);
				}
			}
			if((i==1 && j==1)||(g<min))min=g;
		}
	}
	printf("%d\n",min);
	return 0;
}



Measured memory_bytes: 2140
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n,d[110],mxd;
int cnt,head[110],to[210],nxt[210];
long long son[110],mx[110];
void add(int x,int y)
{
	cnt++;
	to[cnt]=y;
	nxt[cnt]=head[x];
	head[x]=cnt;
}
int bfs(int s)
{
	memset(d,-1,sizeof(d));
	queue<int> q;
	while (!q.empty())
	{
		q.pop();
	}
	d[s]=0;
	q.push(s);
	int x;
	while (!q.empty())
	{
		x=q.front();
		q.pop();
		for (int i=head[x];i;i=nxt[i])
		{
			int y=to[i];
			if (d[y]!=-1)
			{
				continue;
			}
			d[y]=d[x]+1;
			q.push(y);
		}
	}
	return x;
}
void dfs(int x,int f)
{
	int s=0;
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==f)
		{
			continue;
		}
		d[y]=d[x]+1;
		dfs(y,x);
		s++;
	}
	son[d[x]]=max(son[d[x]],1LL*s);
	mxd=max(mxd,d[x]);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	int g=bfs(1);
	g=bfs(g);
	int dis=d[g]/2+1;
	printf("%d ",dis);
	long long ans=1e18;
	for (int i=1;i<=n;i++)
	{
		memset(son,0,sizeof(son));
		d[i]=0;
		mxd=0;
		dfs(i,0);
		if (mxd>=dis)
		{
			continue;
		}
		for (int j=n;j>=0;j--)
		{
			if (!son[j])
			{
				mx[j]=1;
			}
			else
			{
				mx[j]=son[j]*mx[j+1];
			}
		}
		ans=min(ans,mx[0]);
	}
	for (int i=1;i<n;i++)
	{
		int x=to[i<<1];
		int y=to[i*2-1];
		memset(son,0,sizeof(son));
		mxd=0;
		d[x]=d[y]=0;
		dfs(x,y);
		dfs(y,x);
		if (mxd>=dis)
		{
			continue;
		}
		for (int j=n;j>=0;j--)
		{
			if (!son[j])
			{
				mx[j]=1;
			}
			else
			{
				mx[j]=son[j]*mx[j+1];
			}
		}
		ans=min(ans,mx[0]*2);
	}
	printf("%lld\n",ans);
    return 0;
}
//银花珠树晓来看，宿醉初醒一倍寒。
//——王初《望雪》

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <queue>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int gcd(int a, int b) {
    if (b == 0)
        return a;

    return gcd(b, a % b);
}

int main(){
    int K, a;
    ll s=0;
    cin >> K;

    for(int i=1;i<K+1;i++){
        for(int j=1;j<K+1;j++){
            a = gcd(i, j);
            for(int k=1;k<K+1;k++){
                s += gcd(a, k);
            }
        }
    }

    cout << s << endl;

    return 0;
}



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

int dp[5005][5005];

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  for (int i=n-1;i>=0;i--) {
	for (int j=n-1;j>=0;j--) {
      if (s[i] != s[j]) dp[i][j] = 0;
      else dp[i][j] = dp[i+1][j+1]+1;
    }
  }
  int ans = 0;
  rep(i,n) rep(j,n) {
    if (i >= j) continue;
    int now = min(dp[i][j], j-i);
    ans = max(ans, now);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 98048
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int L = sc.nextInt();

		List<String> inputList = new ArrayList<>();
		sc.nextLine();
        for (int i = 0; i < N; i++) {
        	inputList.add(sc.nextLine());
        }

        Collections.sort(inputList);

        StringBuffer sb = new StringBuffer();
        for (String input : inputList) {
        	sb.append(input);
        }

        System.out.println(sb.toString());

	}
}

Measured memory_bytes: 21972
def bridges(E, s):
    N = len(E)
    preorder = [-1] * N # a dfs preordering of each vertex
    lowpt = [N] * N # for finding a cut-vertex
    bridge = []
    stack = [(s, -1, 0)] # (vertex, parent, status)
    pre_num = 0 # current preordering
    while stack:
        v, p, st = stack.pop()
        if st == 0 and preorder[v] < 0: # visited v for the first time
            preorder[v] = pre_num
            lowpt[v] = pre_num
            pre_num += 1
            n_children = 0
            for u in E[v]:
                if preorder[u] >= 0:
                    if u != p: # the edge (v, u) is a back edge, which is not in dfs search tree
                        lowpt[v] = min(lowpt[v], preorder[u])
                    continue
                if n_children == 0:
                    stack += [(v, p, 2), (u, v, 0)]
                    n_children += 1
                else:
                    stack += [(v, p, 1), (u, v, 0)]
                    n_children += 1
            if n_children == 0: # v is a leaf of the dfs search tree
                lowpt[p] = min(lowpt[p], lowpt[v])
                if lowpt[v] > preorder[p]: bridge.append((v, p) if v < p else (p, v))
        elif st == 0 and preorder[v] >= 0: # the edge (v, p) is a back edge
            continue
        elif st == 1: # now searching
            continue
        else: # search finished
            if p != -1:
                lowpt[p] = min(lowpt[p], lowpt[v])
                if lowpt[v] > preorder[p]: bridge.append((v, p) if v < p else (p, v))
    return bridge

N, M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    s, t = map(int, input().split())
    E[s].append(t); E[t].append(s)
br = sorted(bridges(E, 0))
for s, t in br:
    print(s, t)


Measured memory_bytes: 17728
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct pos{
	int x;
	int y;
	int s;//0-25 a-z
	int step;
};
struct po{
	int x;
	int y;
	int s;//0-25 a-z
};

bool operator<(const po left, const po right){
	return left.x == right.x ? left.y == right.y ?left.s<right.s : left.y < right.y : left.x < right.x;
}
bool operator==(const po left, const po right){
	return left.x == right.x&&left.y == right.y&&left.s == right.s;
}

int main() {
	int w, h;
	while (cin >> w >> h, w){
		vector<vector<char>> cell(h, vector<char>(w));
		set<char> sc;
		int sx;
		int sy;
		int gx;
		int gy;
		REP(i, h){
			REP(j, w){
				cin >> cell[i][j];
				//if ('a' <= cell[i][j] && cell[i][j]<='z')
				if (cell[i][j] == '@'){
					sy = i;
					sx = j;
					cell[i][j] = '.';
				}
				if (cell[i][j] == '<'){
					gy = i;
					gx = j;
					cell[i][j] = '.';
				}
			}
		}
		set<po> G;
		queue<pos> Q;
		int ans = -1;
		G.insert({ sx, sy, 0 });
		Q.push({ sx, sy, 0, 0 });

		while (!Q.empty()){
			pos p = Q.front(); Q.pop();
			if (p.x == gx&&p.y == gy){
				ans = p.step;
				break;
			}

			REP(i, 4){
				if (((('A' <= cell[p.y + dy[i]][p.x + dx[i]] && cell[p.y + dy[i]][p.x + dx[i]]<='Z') && (1 << (cell[p.y + dy[i]][p.x + dx[i]] - 'A'))  & p.s)) || (cell[p.y + dy[i]][p.x + dx[i]] == '.') || ('a' <= cell[p.y + dy[i]][p.x + dx[i]] && cell[p.y + dy[i]][p.x + dx[i]] <= 'z')){
					po c;
					c.x = p.x + dx[i];
					c.y = p.y + dy[i];
					c.s = p.s;
					if ('a' <= cell[p.y + dy[i]][p.x + dx[i]] && cell[p.y + dy[i]][p.x + dx[i]] <= 'z')
						c.s ^= 1 << (cell[p.y + dy[i]][p.x + dx[i]] - 'a');
					if (G.find(c) == G.end()){
						G.insert(c);
						Q.push({ c.x, c.y, c.s, p.step + 1 });
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 15568
A,B,K=map(int,input().split())


k=0
for i in range(100):
    if A%2==1:
        A-=1
    B=B+A//2
    A=A-A//2
    k+=1
    if k== K:
        print(A,B)
        break
    if B%2==1:
        B-=1
    A=A+B//2
    B=B-B//2
    k+=1
    if k== K:
        print(A,B)
        break

Measured memory_bytes: 9200
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n,m;
int a[50010];

void solve(){
    cin >> n >> m;
    int S=0;
    rep(i,m){
        cin >> a[i];
        S+=a[i];
    }
    if(n>=S)cout << n-S << endl;
    else cout << -1 << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 3652
while True:
    num_str = input().split()
    H, W = [int(i) for i in num_str]
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i != 0 and i != H - 1:
                if j == 0 or j == W - 1:
                    print("#", end="")
                else:
                    print(".", end="")
            else:
                print("#", end="")
        print()
    print()


Measured memory_bytes: 7012
import bisect

while True:
    n = int(input())
    if not n:
        break
    cards = [None, None]
    cards[0] = sorted(map(int, (input() for _ in range(n))))
    cards[1] = sorted(set(range(1, 2 * n + 1)).difference(cards[0]))

    turn = 0
    field = 0
    while True:
        idx = bisect.bisect(cards[turn], field)
        if idx < len(cards[turn]):
            field = cards[turn].pop(idx)
            if not cards[turn]:
                break
        else:
            field = 0
        turn = (turn + 1) & 1
    print(len(cards[1]))
    print(len(cards[0]))

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

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

    ll syou = n / (a+b);
    ll amari = n % (a+b);
     
    ll res = 0;
    res += syou*a;
    if(amari >= a) res += a;
    else res += amari;

    cout << res << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define gcd __gcd
#define pcount __builtin_popcount
#define pcountll __builtin_popcountll
#define nxtperm next_permutation
//primitive roots: 998244353 - 3; 7340033 - 5
//#pragma 03
//#pragma GCC target ("sse4.2")

const ll mod = 1000000007;		const double PI = acos(-1.);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef complex<double> cd;

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
	{
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
	{
        static const uint64_t kawaii = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + kawaii);
    }
};

int n, m; 
char a[1005][1005];
int dp[1005][1005]; 

signed main()
{
//	freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
// 	fast_cin();
	cin >> n >> m;
	for(int i=0;i<n;i++) cin >> a[i]; 
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) 
		{
			if(i == 1 and j == 1) 
			{
				dp[i][j] = 1; 
				continue; 
 			} 
			if(a[i-1][j-1] == '#') continue; 
			dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod; 
		}
	}
	cout << dp[n][m]; 
}

/*
	Test input:
*/


Measured memory_bytes: 5120
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, A, B, h[112345];
LL low, high, mid;

bool check(LL T)
{
	LL res = 0;
	rep(i, N)
	{
		if (h[i] > B*T)
		{
			res += (h[i] - B*T) / (A - B);
			if ((h[i] - B*T) % (A - B) != 0) { ++res; }
		}
	}
	return (res <= T);
}

int main()
{
	in >> N >> A >> B;
	rep(i, N) { in >> h[i]; }

	std::sort(h, h + N);
	low = 0; high = h[N - 1] / B + 1;
	while (high - low > 1)
	{
		mid = (high + low) / 2;
		if (check(mid)) { high = mid; }
		else { low = mid; }
	}

	out << high << std::endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

int main(){
  	ll n,k; cin >> n >> k;
    vector<int> a(n);
    rep(i,n){
        int aa; cin >> aa;
        aa--;
        a[i]=aa;
    }
    vector<int> lop;
    vector<int> visited(n,-1);
    int now=0;
    int count=0;
    int num;
    int ini;
    for(;;){
        if(visited[now]!=-1){
            ini=visited[now];
            num=count-ini;
            break;
        }
        visited[now]=count;
        lop.push_back(now);
        now=a[now];
        count++;
    }
    if(k<ini) cout << lop[k]+1 << endl;
    else cout << lop[ini+(k-ini)%num]+1 << endl;
return 0;
}




Measured memory_bytes: 5888