akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

	//------------------------------------------

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}
	//------------------------------------------
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

	//------------------------------------------



	public void exec() throws Exception{
		final long A = sc.nextLong();
		final long B = sc.nextLong();
		final long K = sc.nextLong();
		if(A>=K) {
			out.println(A-K+" "+B);
			return;
		}
		if((A+B) >= K) {
			out.println(0+" "+(B+A-K));
			return;
		}
		out.println("0 0");
	}
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
bool x[maxn],y[maxn];
char maz[maxn][maxn];

int n,m;
int main(){
    cin>>n>>m;
    for (int i=0;i<n;i++) scanf("%s",maz[i]);

    for (int i=0;i<n;i++){
        bool flag = true;
        for (int j=0;j<m;j++) if (maz[i][j] == '#') {flag = false;break;}
        x[i] = flag;
    }
    for (int j=0;j<m;j++){
        bool flag = true;
        for (int i=0;i<n;i++) if (maz[i][j] == '#') {flag = false;break;}
        y[j] = flag;
    }
    for (int i=0;i<n;i++) if (!x[i]){
        for (int j=0;j<m;j++) if (!y[j]) cout<<maz[i][j];
        cout<<endl;
    }
    return 0;
}


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

const int N = 2e5 + 5;

typedef long double ld;
typedef long long type;

struct line { type b, m; };

int nh, pos;
line hull[N];

bool check(line s, line t, line u){
  //attention for overflow
  return ld (u.b - t.b)/(t.m - u.m) > ld (t.b - s.b)/(s.m - t.m);
}

void update(line s){
  if(nh == 1 and hull[nh-1].b == s.b) nh--;
  if(nh > 0 and s.m >= hull[nh-1].m) return;
  while(nh >= 2 and !check(hull[nh-2], hull[nh-1], s)) nh--;
  pos = min(pos, nh);
  hull[nh++] = s;
}

type eval(int id, type x) { return hull[id].b + hull[id].m*x; }

type query(type x){
  while(pos+1 < nh and eval(pos, x) > eval(pos+1, x)) pos++;
  return eval(pos, x);
}

int n;
type dp[N], c, h[N];
line s;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> c;
  for(int i = 1; i <= n; i++) cin >> h[i];

  dp[1] = 0;
  s = {c + h[1]*h[1] + dp[1], -2*h[1]};
  update(s);
  for(int i = 2; i <= n; i++) {
    dp[i] = h[i]*h[i] + query(h[i]);
    s = {c + h[i]*h[i] + dp[i], -2*h[i]};
    update(s);
  }
  cout << dp[n] << "\n";
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   int n;
   ll k;
   cin>>n>>k;
   vector<int> a(n);
   rep(i, n) cin>>a[i];

   sort(a.rbegin(), a.rend());
   int l=0, r=200005;
   while(l+1<r){
      int m=(r+l)/2;
      ll km=0;
      rep(i, n){
         int ijo=m-a[i];
         int c= a.rend() - lower_bound(a.rbegin(), a.rend(), ijo);
         km+= c;
      }

      if(km>=k) l=m;
      else r=m;
   }

   vector<ll> sa(n+1);
   sa[0]=0;
   rep(i, n) sa[i+1]=sa[i] +a[i];

   ll tot=0;
   ll km=0;
   rep(i, n){
      int ijo=l-a[i];
      int c=a.rend() - lower_bound(a.rbegin(), a.rend(), ijo);
      km+=c;
      tot+=sa[c]+(ll)a[i]*c;
   }
   tot-= (ll)l*(km-k);

   cout<<tot<<endl;
   return 0;
}


Measured memory_bytes: 4584
N=int(input())
S=[]
for i in range(N):
    S.append(int(input()))
    
S.sort()

ans=sum(S)
if ans%10==0:
    for i in range(N):
        if S[i]%10!=0:
            print(ans-S[i])
            exit()
    print(0)
    exit()

print(ans)

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

using namespace std;
using namespace __gnu_pbds;

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

#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define md(l, r) l + (r - l) / 2
#define ll long long
#define btw(a, l, r) a.begin() + l, a.begin() + r + 1
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int(x.size()))
#define sqr(x) (x) * (x)
#define endl '\n'

#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define clr(x, y) memset((x), (y), sizeof (x))
#define ld long double

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<vector<pair<int, int> > > vvpii;
typedef vector<vector<pair<ll, ll> > > vvpll;
typedef pair<int, pair<int, int> > piii;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef vector<vector<ll> > vvll;
typedef vector<pair<ll, pair<ll, ll> > > vplll;
typedef pair<ll, ll> pll;

const ld eps = -1e9;
const long long N = 200001, P = 1e9 + 7, P1 = 1e9 + 13, iINF = 1e9, INF = 2e18, K = 73, K1 = 79;

ll dstF(ll x, ll y, ll xx, ll yy) {
    return (sqr(x - xx) + sqr(y - yy));
}

ld dstSqrtF(ll x, ll y, ll xx, ll yy) {
    return (sqrt(sqr(x - xx) + sqr(y - yy)));
}

ll _bp(ll val, ll st, ll p) {
    if (st == 0) {
        return 1;
    }
    ll temp = _bp(val, st / 2, p);
    temp = sqr(temp);
    temp %= p;
    if (st % 2 == 1) {
        temp *= val;
        temp %= p;
    }
    return temp;
}

ll _bp(ll val, ll st) {
    if (st == 0) {
        return 1;
    }
    ll temp = _bp(val, st / 2);
    temp = sqr(temp);
    if (st % 2 == 1) {
        temp *= val;
    }
    return temp;
}

ll nok(ll a, ll b) {
    return (a / __gcd(a, b) * b);
}


ll fact[1001000];

void buildFacts(ll n, ll p) {
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % p;
    }
}

ll C(ll n, ll k, ll p = -1) {
    if (p == -1) {
        ll x = fact[n];
        ll y = (fact[k] * fact[n - k]);
        return (x / y);
    } else {
        ll x = fact[n];
        ll y = (fact[k] * fact[n - k]) % p;
        x = (x * _bp(y, p - 2, p)) % p;
        return x;
    }
}
ll n, dp[5000];

void solve() {
    ll n;
    cin >> n;
    dp[0] = 1;
    for (int i = 3; i <= n; i++) {
        for (int i1 = 3; i1 <= i; i1++) {
            dp[i] += dp[i - i1];
            dp[i] %= P;
        }
    }
    cout << dp[n];
}

signed main() {
    //freopen("checklist.in", "r", stdin);
    //freopen("checklist.out", "w", stdout);
    //fast_io;
    int q;
    q = 1;
    //cin >> q;
    while (q != 0) {
        solve();
        --q;
    }
}

/*
*/


Measured memory_bytes: 3684
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
typedef std::pair<int, int> P;
int INF = 1e9;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main(){
    int H, W;
    std::cin >> H >> W;
    char c[H][W];
    int d[H][W];
    int count = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++) {
            std::cin >> c[i][j];
            d[i][j] = INF;
            if(c[i][j] == '.')count++;
        }
    }
    std::queue<P> q;
    q.push(P(0, 0));
    d[0][0]= 1;
    c[0][0] = '#';
    while(!q.empty()){
        P t = q.front();
        q.pop();
        for(int i = 0; i < 4; i++){
            int x = t.first + dx[i], y = t.second + dy[i];
            if(0 <= x && x < H && 0 <= y && y < W && c[x][y] == '.'){
                d[x][y] = std::min(d[x][y], d[t.first][t.second] + 1);
                c[x][y] = '#';
                q.push(P(x, y));
            }
        }
    }
    if(d[H - 1][W -1] == INF){
        std::cout << -1 << std::endl;
        return 0;
    }
    std::cout << count - d[H - 1][W - 1] << std::endl;
}

Measured memory_bytes: 256
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input())for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))


Measured memory_bytes: 11700
h = int(input())
K = list(map(int, input().split()))

K.insert(0, 0) # 1-origin

for i in range(1, h + 1):
    s = f'node {i}: key = {K[i]}, '

    parent = i // 2
    left = 2 * i
    right = 2 * i + 1

    if parent >= 1:
        s += f'parent key = {K[parent]}, '
    if left <= h:
        s += f'left key = {K[left]}, '
    if right <= h:
        s += f'right key = {K[right]}, '

    print(s)


Measured memory_bytes: 5628
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    cout << a[0] * a[1] * 0.5 << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
dp = [1000000001 for i in range(N+1)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))
print(dp[N-1])


Measured memory_bytes: 53240
H,W=gets.split.map &:to_i
a=[nil]+H.times.map{[nil]+gets.split.map(&:to_i)}

move = []
coin = a[1][1].odd?
1.upto(H) do |i|
  (W-1).times do |k|
    j = i.odd? ? 1+k : W-k
    d = i.odd? ? 1 : -1
    if coin
      move << [i, j, i, j+d]
      coin = nil if a[i][j+d].odd?
    else
      coin = a[i][j+d].odd?
    end
  end
  next if i==H
  j = i.odd? ? W : 1
  if coin
    move << [i, j, i+1, j]
    coin = nil if a[i+1][j].odd?
  else
    coin = a[i+1][j].odd?
  end
end
p move.size
puts move.map{|i| i*" "}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using comd = complex<double>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

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

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}
const int MAX =1000001;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int tmp=0,k = 1,n;
  vector<int> suqnum(0),odd(0);
  while(tmp < MAX){
    tmp = k * (k + 1) * (k + 2) / 6;
    suqnum.pb(tmp);
    if(tmp%2==1){
      odd.pb(tmp);
    }
    ++k;
  }
//   reverse(all(suqnum));
//   reverse(all(odd));
  int *dp = new int[tmp+1];
  int *dp2 = new int[tmp+1];
  rep(i,suqnum.size()){
    dp[suqnum[i]] = 1;
  }
  rep(i,odd.size()){
    dp[odd[i]] = 1;
  }
  rep(j,suqnum.size()){
    rep(i,1000000){
      if(i - suqnum[j] >= 0){
        if(dp[i] != 0){
          dp[i] = min(dp[i],dp[i-suqnum[j]]+1);
        }
        else{
          dp[i] = dp[i-suqnum[j]]+1;
        }
      }
    }
  }
  rep(j,odd.size()){
    rep(i,1000000){
      if(i - odd[j] >= 0){
        if(dp2[i] != 0){
          dp2[i] = min(dp2[i],dp2[i-odd[j]]+1);
        }
        else{
          dp2[i] = dp2[i-odd[j]]+1;
        }
      }
    }
  }
  while(cin >> n){
    if(n == 0)break;
    cout << dp[n] << " " << dp2[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 10900
#include<iostream>
using namespace std;
int main(void)
{
	int i,a,b,cnt=0;
	cin>>a>>b;
	for(i=a;i<=b;i++) if(i/10000==i%10&&i/1000%10==i%100/10) cnt++;
	cout<<cnt<<endl;
	return 0;
}

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

long long k, a, b;
int main()
{
	std::cin >> k >> a >> b;

	if (a > k)
		std::cout << k + 1 << std::endl;
	else {
		int n = (k - a + 1) / 2;
		std::cout << std::max(k + 1, n*b - (n - 1)*a + (k - a + 1) % 2) << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
//BISMILLAHIR RAHMANIR RAHIM
//RABBI ZIDNI ILMA
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define endl "\n"
#define inf (1LL<<61)
#define pi acos(-1)
#define mod 1000000007
#define MOD 998244353
#define all(x) x.begin(), x.end()
#define int_pow(n, p) (ll)(pow(n, p) + 0.5)
#define fastio ios_base::sync_with_stdio(0);cout<< fixed<< setprecision(10);
#define debug(x) cout<<"["<<#x<<": "<<x<<"]\n"
#define debug2(x, y) cout<<"["<<#x<<": "<<x<<"]"<<"  ["<<#y<<": "<<y<<"]\n"
#define debug3(x, y, z) cout<<"["<<#x<<": "<<x<<"]"<<"  ["<<#y<<": "<<y<<"]"<<"  ["<<#z<<": "<<z<<"]\n"
#define debug4(x, y, z, k) cout<<"["<<#x<<": "<<x<<"]"<<"  ["<<#y<<": "<<y<<"]"<<"  ["<<#z<<": "<<z<<"]"<<"  ["<<#k<<": "<<k<<"]\n"

const ll N = 2e3 + 9;

ll dp[N];

int main()
{
    fastio
    dp[3] = 1;
    for(int i=4; i<=2000; i++){
        dp[i] = 1;
        for(int j=0; j+3<=i; j++){
            dp[i] += dp[j];
            dp[i] %= mod;
        }
    }
    ll n;
    cin>> n;
    cout<< dp[n];
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
#define read(num) scanf("%d", &num)
#define readll(num) scanf("%lld", &num)
#define read2(num1, num2) scanf("%d%d", &num1, &num2)
#define read3(num1, num2, num3) scanf("%d%d%d", &num1, &num2, &num3)
#define reads(str) scanf("%s", str)
#define readc(ch) scanf("%c", &ch)
#define f first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<long long, long long>
#define vi vector<int>
#define ll long long

ll fact[200005],ifact[200005];
ll M=998244353;
ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a%M;
    }
    ll k=power(a,b/2)%M;
    if(b%2){
        return (k%M*k%M*a%M)%M;
    }
    return (k%M*k%M)%M;
}
ll ncr(ll n,ll r){
    int val=fact[n];
    val=(val%M*ifact[r]%M*ifact[n-r]%M)%M;
    return val;
}
void factorial(){
    fact[0]=fact[1]=1;
    for(int i=2;i<=200000;i++){
        fact[i]=(fact[i-1]%M*i%M)%M;
    }
    ifact[200000] = power(fact[200000],M-2)%M;
    for(int i=199999;i>=0;i--){
        ifact[i] = (ifact[i+1]%M*(i+1)%M)%M;
        // ifact[i] = power(fact[i],M-2)%M;
    }
}
int main(){
 ll n,m,k;
 cin>>n>>m>>k;
 ll ans=0;
 factorial();
 for(int i=0;i<=k;i++){
	 ans=(ans+(ncr(n-1,i)%M*m%M*power(m-1,n-1-i)%M))%M;
 }
 cout<<ans;
} 


Measured memory_bytes: 6728
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
	int n;
  	double t,a;
    cin >> n;
  	cin >> t >> a;
  	double h[n];
  	double min = 100000000;
  	int ans;
  	for(int i=0;i<n;i++){
    	cin >> h[i];
      	double tem = t - h[i]*0.006;
      	if(min>abs(tem-a)){
			min = abs(tem-a);
          	ans=i;
        }
    }
  	cout << ans+1 << endl;
  	return 0;
}


Measured memory_bytes: 256
import sys
import math
from operator import itemgetter

input = sys.stdin.readline


def main():
    N = int(input())
    AB = [[int(x) for x in input().split()] for _ in range(N)]
    CD = [[int(x) for x in input().split()] for _ in range(N)]

    AB.sort(key=itemgetter(1), reverse=True)
    CD.sort(key=itemgetter(0))

    ans = 0
    used = set()
    for i, cd in enumerate(CD):
        c, d = cd[0], cd[1]
        for j, ab in enumerate(AB):
            if j in used:
                continue
            a, b = ab[0], ab[1]
            if c > a and d > b:
                used.add(j)
                ans += 1
                break

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/*

ALDS_1_7_C:Tree Walk

树的遍历：
	前序遍历
	中序遍历
	后序遍历



*/
#include <iostream>
using namespace std;
#define Max 10000
#define Nil -1

struct Node {
	int p, r, l;
};
Node T[Max];
int n;


void preorder(int u) {
	if (u == Nil) {
		return;
	}
	cout << " " << u;
	preorder(T[u].l);
	preorder(T[u].r);
}

void inorder(int u) {
	if (u == Nil)return;
	inorder(T[u].l);
	cout << " " << u;
	inorder(T[u].r);
}
void postorder(int u) {
	if (u == Nil)
		return;
	postorder(T[u].l);
	postorder(T[u].r);
	cout << " " << u;
}


int main()
{
	int v, r, l,i;
	cin >> n;
	for (i = 0; i < n; i++)T[i].p = Nil;
	for (i = 0; i < n; i++) {
		cin >> v >> l >> r;
		T[v].l = l;
		T[v].r = r;
		if (l != Nil)T[l].p = v;
		if (r != Nil)T[r].p = v;
	}
	int root = 0;
	for (i = 0; i < n; i++) {
		if (T[i].p == Nil)
			root = i;

	}

	cout << "Preorder" << endl;
	preorder(root);
	cout << endl;
	cout << "Inorder" << endl;
	inorder(root);
	cout << endl;
	cout << "Postorder" << endl;
	postorder(root);
	cout << endl;





	return 0;
}


Measured memory_bytes: 3124
from collections import deque

S = deque(input())
q = int(input().strip())


rev_count = 0
for i in range(q):
  query = input()
  if query[0] == "1":
    rev_count += 1
  elif query[0] == "2":
    query = query.strip().split(" ")
    if rev_count & 1 == 1:
      if query[1] == "1":
        S.append(query[2])
      else:
        S.appendleft(query[2])
    else:
      if query[1] == "1":
        S.appendleft(query[2])
      else:
        S.append(query[2])

if rev_count & 1 == 1:
  S.reverse()

print("".join(S))

Measured memory_bytes: 8692
#include<iostream>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
static const int MAX = 100;

int N, V[MAX][MAX], ans;
pair<int, int> G[MAX][MAX];

void dfs( int y , int x , int id ){
    V[y][x] = id;
    int nx = G[y][x].first;
    int ny = G[y][x].second;
    if ( V[ny][nx] == id ) ans++;
    if ( V[ny][nx] == 0 ) dfs(ny, nx, id);
}

void solve(){
    rep(i, N) rep(j, N) V[i][j] = 0;
    int ncomp = 0;
    ans = 0;

    rep(i, N) rep(j, N){
	if ( V[i][j] == 0 ){
	    ncomp++;
	    dfs(i, j, ncomp);
	}
    }
    cout << ans << endl;
}

main(){
    int px, py;
    while( cin >> N && N ){
	rep(y, N) rep(x, N){
	    cin >> px >> py;
	    G[y][x] = make_pair(px, py);
	}
	solve();
    }
}

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

#define int long long

signed main(){

  string s;
  char t = 'X';
  int con = 0;

  cin>>s;

  for(int i = 0; i < s.size(); i++){
    if(s[i] != t){
      t = s[i];
      con++;
    }
  }

  cout<<con-1<<endl;

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=200005;
int a[N],f1[N],f2[N],n,ans,l;
void solve(){
	memset(f1,0,sizeof f1);
	memset(f2,0,sizeof f2);
	for (int i=1;i<=n;i++)f1[i]=f1[i-1]+a[i];
	for (int i=n;i;i--)f2[i]=f2[i+1]+l-a[i];
	ans=max(ans,a[n]);
	for (int i=1;i<n;i++){
		int p=i+((n-i)>>1);
		if ((n-i)&1)ans=max(ans,(f2[p+2]+f1[p]-f1[i-1])*2+l-a[p+1]);
		else ans=max(ans,(f2[p+1]+f1[p-1]-f1[i-1])*2+a[p]);
	}
}
signed main(){
	scanf("%lld%lld",&l,&n);
	for (int i=1;i<=n;i++)scanf("%lld",&a[i]);
	solve();
	reverse(a+1,a+n+1);
	for (int i=1;i<=n;i++)a[i]=l-a[i];
	solve();
	printf("%lld\n",ans);
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static final long MOD = 1_000_000_007;

	public static void main(String[] args) {
		int N = sc.nextInt();
		double[] P = new double[N];
		for (int i = 0; i < N; i++) {
			P[i] = sc.nextDouble();
		}
		double[][] dp = new double[N + 1][N + 1];
		dp[0][0] = 1;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j <= i; j++) {
				dp[i + 1][j + 1] += dp[i][j] * P[i];
				dp[i + 1][j] += dp[i][j] * (1 - P[i]);
			}
		}
		double ans = 0;
		for (int i = N; i > N / 2; i--) {
			ans += dp[N][i];
		}
		System.out.printf("%.10f\n", ans);
	}
}

Measured memory_bytes: 122612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long N, M;
    cin >> N >> M;
    long long H[N];
    vector<bool> flag(N - 1, true);
    long long a, b;
  
    for (int i = 0; i < N; i++){
        cin >> H[i];
    }
  
    for (int k = 0; k < M; k++){
        cin >> a >> b;
        if(H[a - 1] == H[b - 1]){
          flag[b - 1] = false;
          flag[a - 1] = false;
        }else if(H[a - 1] > H[b - 1]){
            flag[b - 1] = false;
        }else if (H[a - 1] < H[b - 1]){
            flag[a - 1] = false;
        }
    }
  
    long long ans = 0;
    for (int j = 0; j < N; j++){
        if(flag[j]){
            ans++;
        }
    }
 
    cout << ans << endl;
}

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

int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> p(n);
    rep(i,n){
        cin>>p[i].first;
        p[i].second = i;
    }
    sort(p.begin(),p.end());
    rep(i,n){
        cout<<p[i].second+1<<endl;
    }
}


Measured memory_bytes: 1664
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#define fi(p) for(int i=0;i<(p);i++)
using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int N;
	cin >> N;
	int num = N;
	int count = 0;
	int res;


	while (num != 0) {
		num /= 10;
		count++;
	}

	if (count == 1) {
		res = N;
	}
	else if (count == 2) {
		res = 9;
	}
	else if (count == 3) {
		res = 9 + N - 99;
	}
	else if (count == 4) {
		res = (10-1) + (1000-100);
	}
	else if (count == 5) {
		res = (10 - 1) + (1000 - 100) + (N-9999);
	}
	else {
		res = (10 - 1) + (1000 - 100) + (100000 - 10000);
	}
	cout << res << endl;
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<i64,i64>;

int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<char>> grid(H,vector<char>(W));
    int ans = 0;
    rep(h,H)rep(w,W){
        cin >> grid[h][w];
        if(grid[h][w] == '.') ans++;
    }

    vector<vector<int>> dist(H,vector<int>(W,0));
    queue<P> que;
    que.push({0,0});
    dist[0][0] = 1;

    const int d[4] = {1, -1, 0, 0};
    while(!que.empty()){
        P p = que.front();
        que.pop();

        int h = p.first;
        int w = p.second;

        for(int i = 0; i < 4; i ++){
            int nh = h + d[i];
            int nw = w + d[i^2];

            if(nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if(grid[nh][nw] == '#' || dist[nh][nw]) continue;

            dist[nh][nw] = dist[h][w] + 1;
            que.push({nh, nw});
        }
    }

    if(dist[H-1][W-1] == 0) cout << -1 << endl;
    else cout << ans - dist[H-1][W-1] << endl;
}


Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
char S[100005],T[100005];
int hei1[100005],hei2[100005];
int n,m;
void gen(char* S,int* hei){
  int n=strlen(S);
  REP(i,n){
    hei[i+1]=hei[i]+(S[i]=='A'?1:-1);
  }
}
int main(){
#ifdef LOCAL_REDIR
  freopen("/home/hog/Dropbox/pg/working/in.txt","r",stdin);
#endif
  vector<int> tmp={1,2,3};
  scanf("%s%s",S,T);
  gen(S,hei1);
  gen(T,hei2);
  n=strlen(S);
  m=strlen(T);

  int q;cin>>q;
  REP(hoge,q){
    int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
    --a;--c;
    int x=hei1[b]-hei1[a],y=hei2[d]-hei2[c];
    x=(x%3+3)%3;y=(y%3+3)%3;

    puts(x==y?"YES":"NO");
  }


  return 0;
}





Measured memory_bytes: 1536
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char) 
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
    
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let n: usize = read();
  let mut d: Vec<usize> = Vec::new();
  for _ in 0..n { d.push(read()); }
  
  let mut sum = 0;
  for i in 0..n {
    for j in 0..n {
      if i != j {
        sum += d[i] * d[j];
      }
    }
  }
  
  println!("{}", sum / 2);
}

Measured memory_bytes: 4352
import java.util.*;
public class Main{
static int[]check;//1=checked,0=yet,2=checking
static int[][]graph;
    static int[]dis;//-1=cannot arrive
static int n;
final static int MAX=100;
	public static void main(String[] args) {
		int i,j,s,pn,num;
		// TODO Auto-generated method stub
		Scanner sca = new Scanner(System.in);
		n=sca.nextInt();
		check=new int[MAX+1];
		dis=new int[MAX+1];
		graph=new int[MAX+1][MAX+1];
		for(i=1;i<=n;i++){
			num=sca.nextInt();
			pn=sca.nextInt();
			for(j=0;j<pn;j++){
				s=sca.nextInt();
				graph[num][s]=1;
			}
		}
		breadthexpl(1);
	}
	public static void breadthexpl(int now){
	    int i,j,hz;
	    Queue<Integer> que= new ArrayDeque<>();
	    que.offer(now);
	    while(que.peek()!=null){
		hz=que.poll();
		for(j=1;j<=n;j++){
		    if(graph[hz][j]!=0&&check[j]==0){
			check[j]=2;
			dis[j]=dis[hz]+1;
     		      if(dis[hz]==-1&&dis[j]!=-1)dis[hz]++;
			que.offer(j);
		    }
		    check[hz]=1;
		}
	    }
	    for(i=1;i<=n;i++){
		if(check[i]==0)dis[i]=-1;
		System.out.println(i+" "+dis[i]);
	    }
	    
	}

}


Measured memory_bytes: 28276
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    int ans = 1;
    while ((ans + 1) * (ans + 1) <= n)
    {
        ans++;
    }
    cout << ans * ans << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  if(N % 10 == 2 ||N % 10 == 4 ||N % 10 == 5 ||N % 10 == 7||N % 10 == 9 ){
    cout << "hon" << endl;}
  else if(N % 10 == 3){
    cout << "bon" << endl;}
  else { 
    cout << "pon" << endl;}
}


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


int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);

  for(int i = 0; i < N; i++) cin >> h[i];
  sort(h.begin(), h.end());
  
  ll ans = 1000000000000;

  for(int i = 0; i <= N - K; i++) {
      if(ans > h[i + K - 1] - h[i]) ans = h[i + K - 1] - h[i];
  }
  
  cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
// #define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=1e5+5;
vector<int> g[N];
int p[N],u[N];
void dfs(int v,int f=0){
    for(int to:g[v]){
        if(to^f){
            dfs(to,v);
        }
    }
    if(!u[v]){
        if(f&&!u[f]){
            u[v]=u[f]=1;
        }else{
            cout<<"First\n";
            exit(0);
        }
    }
}
int32_t main(){
    int n;
    cin>>n;
    forn(i,n-1){
        int a,b;
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs(1);
    cout<<"Second\n";
    return 0;
}

Measured memory_bytes: 9552
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll N,M,ans = 0,pena=0;
    cin >> N >> M;
    vector<bool> fla(N+10);
    vector<ll> p(M);
    vector<string> S(M);
    vector<ll> wa(N+10);

    for(ll i = 0;i < N+10;i++){
        fla.at(i) = false;
        wa.at(i) = 0;
    }
    for(ll i = 0;i < M;i++){
        cin >> p.at(i) >> S.at(i);
    }

    for(ll i = 0;i < M;i++){
        if(fla.at(p.at(i)) == true)
            continue;
        else if(fla.at(p.at(i)) == false and S.at(i) == "WA")
            wa.at(p.at(i))++;
        else if(fla.at(p.at(i)) == false and S.at(i) == "AC"){
            ans++;
            pena += wa.at(p.at(i));
            fla.at(p.at(i)) = true;
        }

    }
    cout << ans << " " << pena << endl;

    return 0;
}

Measured memory_bytes: 7996
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue<int>
#define PQR priority_queue<int,VE,greater<int>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}
const long long MOD = 1000000007;
const long long INF = 1LL << 50;
// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<VE>a(n, VE(n - 1));
	rep(i, n) {
		rep(j, n - 1) {
			cin >> a[i][j];
			a[i][j]--;
		}
		reverse(ALL(a[i]));
	}
	vector<P>q;
	auto check = [&](int i) {
		if (a[i].size() == 0)return;
		int j = a[i].back();
		if (a[j].size() == 0)return;
		if (a[j].back() == i) {
			P p(i, j);
			if (p.second < p.first)swap(p.first, p.second);
			q.push_back(p);
		}
	};
	rep(i, n)check(i);
	int day = 0;
	while (!q.empty()) {
		day++; sort(ALL(q));
		q.erase(unique(ALL(q)), q.end());
		vector<P>prevQ;
		swap(prevQ, q);
		for (P p : prevQ) {
			int i = p.first, j = p.second;
			a[i].pop_back(); a[j].pop_back();
		}
		for (P p : prevQ) {
			int i = p.first, j = p.second;
			check(i); check(j);
		}
	}
	rep(i, n) {
		if (a[i].size() != 0) {
			COUT(-1); return 0;
		}
	}
	COUT(day);
	return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cassert>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <cstring>
#include <cmath>
#include <tuple>
#include <complex>
#include <bitset>
#include <climits>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pld = pair<LD, LD>;


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

    int N;
    LL K;
    cin >> N >> K;

    vector<int> nrs(N + 1);
    for (int i = 1; i <= N; ++i)
    {
        cin >> nrs[i];
    }

    vector<int> path(N + 1), last_idx(N + 1);
    for (int cur_nr = nrs[1], i = 1; ; ++i)
    {
        if (i == K)
        {
            cout << cur_nr;
            return 0;
        }
        if (last_idx[cur_nr])
        {
            int mod = i - last_idx[cur_nr];
            int res_idx, cur_mod;
            for (cur_mod = (res_idx = last_idx[cur_nr]) % mod; cur_mod != K % mod; cur_mod = (cur_mod + 1) % mod, ++res_idx)
                ;
            // cerr << "Res idx :) : " << res_idx << endl;
            cout << path[res_idx];
            return 0;
        }

        path[i] = cur_nr;
        last_idx[cur_nr] = i;
        cur_nr = nrs[cur_nr];
    }
}


Measured memory_bytes: 5584
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	n := nextInt()

	res := n - 1
	s := int(math.Sqrt(float64(n))) + 1
	for i := s; i >= 2; i-- {
		if n%i == 0 {
			res = i + n/i - 2
			break
		}
	}

	fmt.Println(res)
}


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

using namespace std;

#define LL long long
#define int long long
#define fi first
#define se second
#define double long double
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

constexpr int N = 1e6+5;
constexpr int M = 1e9+7;

// #define DEBUG 1  //调试开关
struct IO {
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;

    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); }

    inline char gc() {
        if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
        return p1 == p2 ? ' ' : *p1++;
    }
    inline bool blank(char ch) {
        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
    }
    template <class T>
    inline void read(T &x) {
    double tmp = 1;
    bool sign = 0;
    x = 0;
    char ch = gc();
    for (; !isdigit(ch); ch = gc())
        if (ch == '-') sign = 1;
    for (; isdigit(ch); ch = gc()) x = x * 10 + (ch - '0');
    if (ch == '.')
        for (ch = gc(); isdigit(ch); ch = gc())
        tmp /= 10.0, x += tmp * (ch - '0');
    if (sign) x = -x;
    }
    inline void read(char *s) {
    char ch = gc();
    for (; blank(ch); ch = gc())
        ;
    for (; !blank(ch); ch = gc()) *s++ = ch;
    *s = 0;
    }
    inline void read(char &c) {
    for (c = gc(); blank(c); c = gc())
        ;
    }
    inline void push(const char &c) {
    #if DEBUG  //调试，可显示字符
    putchar(c);
    #else
    if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
    *pp++ = c;
    #endif
    }
    template <class T>
    inline void write(T x) {
    if (x < 0) x = -x, push('-');  // 负数输出
    static T sta[35];
    T top = 0;
    do {
        sta[top++] = x % 10, x /= 10;
    } while (x);
    while (top) push(sta[--top] + '0');
    }
    template <class T>
    inline void write(T x, char lastChar) {
    write(x), push(lastChar);
    }
} io;

int a, b, c, d;

signed main() {
    fastio;
    cin >> a >> b >> c >> d;
    while (a > 0 && c > 0) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}

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

typedef long long ll;

const int Maxn = 5005;
const int mod = 1000000007;

int pw[Maxn];
int n;
int a[Maxn];
int par[Maxn], siz[Maxn];
bool spec[Maxn];
vector <int> seq;
int dp[Maxn];
int res;

int getPar(int x) { return par[x] == x? x: par[x] = getPar(par[x]); }

void unionSet(int a, int b)
{
    a = getPar(a), b = getPar(b);
    if (a == b) return;
    if (siz[a] < siz[b]) swap(a, b);
    siz[a] += siz[b]; par[b] = a;
    spec[a] |= spec[b];
}

int main()
{
    scanf("%d", &n);
    pw[0] = 1;
    for (int i = 1; i < Maxn; i++)
        pw[i] = ll(pw[i - 1]) * (n - 1) % mod;
    for (int i = 1; i <= n; i++) {
        par[i] = i; siz[i] = 1;
        scanf("%d", &a[i]);
        spec[i] = a[i] == -1;
    }
    for (int i = 1; i <= n; i++) if (a[i] != -1)
        unionSet(i, a[i]);
    for (int i = 1; i <= n; i++) if (a[i] == -1)
        seq.push_back(siz[getPar(i)]);
    for (int i = 1; i <= n; i++) if (getPar(i) == i && !spec[i])
        res = (res + pw[seq.size()]) % mod;
    sort(seq.begin(), seq.end());
    for (int i = 0; i < seq.size(); i++) {
        for (int j = i; j >= 1; j--)
                dp[j + 1] = (dp[j + 1] + ll(dp[j]) * j % mod * seq[i]) % mod;
        dp[1] = (dp[1] + seq[i]) % mod;
    }
    for (int i = 0; i < seq.size(); i++)
        res = (res + ll(seq[i] - 1) * pw[int(seq.size()) - 1]) % mod;
    for (int j = 2; j <= seq.size(); j++)
        res = (res + ll(dp[j]) * pw[int(seq.size()) - j]) % mod;
    res = (mod - res) % mod;
    res = (res + ll(n) * pw[seq.size()]) % mod;
    printf("%d\n", res);
    return 0;
}


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

using namespace std;

int main() {
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   long long n;
   cin >> n;
   cout << n * (n + 1LL) / 2LL - n << endl;
   return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

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

const int maxn=100+10;
int n;
int a[maxn<<1];
ll Ans;

inline void file() {
	freopen("AGC001E.in","r",stdin);
	freopen("AGC001E.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int main() {
//	file();
	n=read();
	For (i,1,n<<1) a[i]=read();
	sort(a+1,a+(n<<1)+1);
	for (int i=1;i<=(n<<1);i+=2) Ans+=a[i];
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <cstring>
using namespace std;

using P = pair<int, int>;

vector<int> G[100000];
int dist[100000];

void bfs() {
	memset(dist, -1, sizeof(dist));
	dist[0] = 0;
	
	queue<P> Q;
	Q.push(make_pair(0, 0));
	while (!Q.empty()) {
		auto p = Q.front(); Q.pop();
		
		for (int to : G[p.first]) {
			if (dist[to] < 0) {
				dist[to] = p.second + 1;
				Q.push(make_pair(to, p.second + 1));
			}
		}
	}
}

int main() {
	int N;
	cin >> N;
	
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		a--;
		
		G[i].push_back(a);
	}
	
	bfs();
	
	cout << dist[1] << endl;
	
    return 0;
}

Measured memory_bytes: 6144
a,b,c = list(map(int, input().split()))

if a==b==c:
    if a&1:
        print(0)
    else:
        print(-1)
    exit()

ans=0    
while all(i&1==0 for i in [a,b,c]):
    a,b,c = (b+c)//2, (a+c)//2, (a+b)//2
    ans+=1

print(ans)

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Yulian
 */

#include <iostream>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>


#include <iostream>

#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>



#include <assert.h>

constexpr unsigned long  long int SIZE = 50000;
using namespace std;
class C {
public:
	void solve(std::istream& in, std::ostream& out) {
    ios::sync_with_stdio(false);
		int t, x;
//    t = p = 1;
    in >> x;

    long long int ps[SIZE];
    ps[0] = 0;
    unsigned int i;
    for(i = 1; i < SIZE; ++i){
      ps[i] = i + ps[i-1];
      if(ps[i] >= x){
        --i;
        break;
      }
    }
    if(ps[i] != x){
      ++i;
    }

    out << i << endl;
//    while(p != x){
//      ++t;
//      if(abs(p - x) >= t){
//        if(p < x){
//          p += t;
//        }else{
//          p -= t;
//        }
//      }else{
//        if(p < x){
//          ++p;
//        }else{
//          --p;
//        }
//      }
//    }
//    out << t << endl;
	}
};


int main() {
	C solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

int main(){

  	int n; cin >> n;
  	long double sum = 0.0;
  	vector<int> arr(n);
  	for(int i = 0; i < n; ++i) cin >> arr[i], sum += (1.0*arr[i]);
  
  	long long avg1 = sum/n;
  	long long avg2 = sum/n +1;
  
  	long long cost1 = 0; long long cost2 = 0;
  	for(int i = 0; i < n; ++i){
    	cost1 += (arr[i]-avg1)*(arr[i]-avg1);
      	cost2 += (arr[i]-avg2)*(arr[i]-avg2);
    }
  
  	cout << min(cost1,cost2) << "\n";
  	


}

Measured memory_bytes: 256
n=int(input())
l=[[] for i in range(10)]
s=input()
ans=0
for i,j in enumerate(s):
    l[int(j)].append(i+1)
for i in range(1000):
    z=str(i).zfill(3)
    n1,n2=False,False
    if l[int(z[0])] and l[int(z[2])]:
        n1=l[int(z[0])][0]
        n2=l[int(z[2])][-1]
    if n1 and n2:
        if [k for k in l[int(z[1])] if n1<k<n2]:
            ans+=1
print(ans)

Measured memory_bytes: 4596
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] numArray = new int[50 + 1];
        for(int i = 0; i < m; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            numArray[a]++;
            numArray[b]++;
        }

        for(int i = 1; i <= n; i++){
            System.out.println(numArray[i]);
        }
    }    
}

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

// #define for(i, m, n) for(int i = m; i < n; i++)
// #define INF 2e9

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

    vector<int> nl(N);

    for (int i=0; i<Q; i++) {
        cin >> a;
        nl[a-1]++;
    }

    for (int point: nl) {
        if ((K - (Q - point)) > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024