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

ll par[200010],ranki[200010]; 

void init(int n){
  fr(i,n){
    par[i]=i;
    ranki[i]=0;
  }
}

int find(int x){
  if(par[x]==x) return x;
  else return par[x]=find(par[x]);
}
 
void unit(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;
  if(ranki[x]<ranki[y]) par[x]=y;
  else par[y]=x;
  if(ranki[x]==ranki[y]) ranki[x]++;
}
 
bool same(int x,int y){
  return find(x)==find(y);
}


struct road{
  ll dm,cd,ct;
  bool operator<(const road& right) const{
    return ct<right.ct;
  }
};
vector<road> roads;


int main(){
  ll n,d,a[200010],ans=0,cnt=0;
  cin>>n>>d;
  fr(i,n) cin>>a[i];
  priority_queue<P,vector<P>,greater<P>> q;
  fr(i,n){
    while(!q.empty()){
      ll j=q.top().second;
      if(a[j]>a[i]){
        q.pop();
        continue;
      }
      else{
        roads.push_back((road){i,j,a[i]+a[j]+d*(i-j)});
        break;
      }
    }
    q.push(make_pair(a[i]-d*i,i));
  }
  while(!q.empty()) q.pop();
  for(int i=n-1;i>=0;i--){
    while(!q.empty()){
      ll j=q.top().second;
      if(a[j]>a[i]){
        q.pop();
        continue;
      }
      else{
        roads.push_back((road){i,j,a[i]+a[j]+d*(j-i)});
        break;
      }
    }
    q.push(make_pair(a[i]+d*i,i));
  }
  init(n);
//  for(auto it=roads.begin();it!=roads.end();it++) cout<<(*it).dm<<" "<<(*it).cd<<" "<<(*it).ct<<endl;
  sort(roads.begin(),roads.end());
  for(auto it=roads.begin();cnt<n-1;it++){
    road r=*it;
    if(same(r.dm,r.cd)) continue;
    unit(r.dm,r.cd);
    ans+=r.ct;
    cnt++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 21884
N=int(input())
B=list(map(int,input().split()))
T=True
L=[]
while(T):
    if len(B)==0:
        break
    t=False
    for i in range(len(B)-1,-1,-1):
        if i+1==B[i]:
            L.append(B.pop(i))
            t=True
            break
    if not t:
        T=False
if T:
    for i in L[::-1]:
        print(i)
else:
    print(-1)


Measured memory_bytes: 38580
from collections import Counter

N = int(input())
A = list(map(int,input().split()))

c = Counter(A)

hen = []

for i,j in zip(c.keys(),c.values()):
    if 2 <= j <= 3:
        hen.append([i,2])
    elif j >= 4:
        hen.append([i,4])


hen.sort(reverse=True)

##print(hen)
ans = 0
finished = False
choosen = False

for i,j in hen:
    if choosen:
        ans *= i
        finished = True
        break

    if j == 2:
        ans = i
        choosen = True
    else:
        ans = i**2
        finished = True
        break

print(ans if finished else 0)

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

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


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

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

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

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

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

ll f(ll h,ll w,ll i) {
  ll ans=100000001,ans2=100000001;
  ll ss = h*w;
  ll t = i * w;
  ll r = (h - i)*(w/2);
  ll s = ss - t - r;
  ans = min(ans,max(t,max(r,s))-min(t,min(r,s)));

  r = w*((h-i)/2);
  s = ss - t - r;
  ans2 = min(ans2,max(t,max(r,s))-min(t,min(r,s)));
  return min(ans,ans2);
}

int main() {
  ll h,w;
  cin >> h >> w;

  ll ans = 100000001;
  orep(i,h/2) ans=min(ans,f(h,w,i));
  swap(h,w);
  orep(i,h/2) ans=min(ans,f(h,w,i));
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};




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

    int n;
    cin >> n;
    vector<int> b(n);
    rep(i,n){
        cin >> b[i];
    }
    vector<int> ans;
    auto c = b;
    for(int i = 0;i < n;++i){
        for(int j = n;j > 0;--j){
            if(b.empty()) break;
            if(b.size() < j) continue;
            if(b[j-1] == j) {
                ans.push_back(j);
                b.erase(b.begin()+j-1);
                break;
            }
        }
    }
    if(ans.size() == c.size()){
        reverse(all(ans));
        rep(i,ans.size()){
            cout << ans[i] << endl;
        }
    }else {
        cout << -1 << endl;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()
#define INF 1e9 + 7
using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (b + c - a < 0) {
        cout << 0 << endl;
    } else {
        cout << b + c - a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
//#include <cmath>
#include <vector>
// #include <algorithm>
// #include <bits/stdc++.h>
using namespace std;

int main() {
  long A, B, C, K;

  cin >> A >> B >> C >> K;

  long sum = 0;
  
  // A
  for (long i=0; i<A && i<K; i++) {
    sum++;
  }

  // B
  for (long i=0; i<B && i<K-A; i++) {
  }

  // C
  for (long i=0; i<C && i<K-A-B; i++) {
    sum--;
  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 3540
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N;
int a, b;
vector<int> v[100010];
int d0[100010];
int dn[100010];
/*==================================================*/
/*function*/
void dfs0(int node, int step){
    if(d0[node] <= step) return;
    d0[node] = step;

    REP(i,0,v[node].size()){
        dfs0(v[node][i], step+1);
    }
}
void dfsn(int node, int step){
    if(dn[node] <= step) return;
    dn[node] = step;

    REP(i,0,v[node].size()){
        dfsn(v[node][i], step+1);
    }
}

/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,N-1){
        cin>>a>>b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }

    REP(i,0,N) d0[i] = INF;
    REP(i,0,N) dn[i] = INF;
    dfs0(0,0);
    dfsn(N-1,0);

    int b = 0, w = 0;
    REP(i,0,N){
        if(d0[i] <= dn[i]){
            b++;
        }else{
            w++;
        }
    }

    if(b > w){
        cout<<"Fennec"<<endl;
    }else{
        cout<<"Snuke"<<endl;
    }

    return 0;
}


Measured memory_bytes: 11136
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <map>
#define MAXN 200005
#define MAXM
#define LL long long
#define LD long double
using namespace std;

int n, tag, a[MAXN];

map<int, int>::iterator it;

bool check(int mid)
{
	map<int, int> num;
	for(int i=2; i<=n; i++)
	{
		if(a[i]>a[i-1]) continue;
		int temp=a[i];
		while(num[temp]>=mid)
		{
			temp--;
			if(temp==0) return false;
		}
		num[temp]++;
		num.erase(num.lower_bound(temp+1), num.end());
	}
	return true;
}

int main()
{
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
	{
		scanf("%d", &a[i]);
		if(i>1 && a[i]<=a[i-1]) tag=1;
	}
	if(!tag) {printf("1\n"); return 0;}
	int l=1, r=4e5, ans=0;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid)) ans=mid, r=mid-1;
		else l=mid+1;
	}
	printf("%d\n", ans+1);
}


Measured memory_bytes: 1024
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");
    const set = new Set(S);
    const unique = [...set];
    
    if(set.size !== 2) {
        console.log("No");
        return;
    }
    
    for(let i in unique) {
        if(S.filter(n=>n===unique[i]).length !== 2) {
            console.log("No");
            return;
        }
    }
    
    console.log("Yes");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 22964
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

typedef pair<long long, long long> P;

int v, e, r;

struct edge {
	int to;
	long long cost;
	edge(int _to, long long _cost) :to(_to), cost(_cost) {}
};
vector<edge> G[100010];	//??£??\?????????
long long d[100010];	//?§????r??????????????¢

void dijkstra(int start) {
	//(d[i],i)????????¢???priority_queue?????????
	//d????°?????????????????????????
	priority_queue<P, vector<P>, greater<P>> que;	
	
	for (int i = 0; i < v; i++)d[i] = 1e12;
	d[start] = 0;				//?§????????????¢???0?????????
	que.push(P(d[r], r));	//?????\???????§????????????±???push

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;

		if (d[v] < p.first)continue;	//???????????¢?????´??°??§???????????¨???
		

		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			//??????v????????????????????£??????????????¢?????´??°??§?????????,
			//?????\????????´??°?????????????????¢??¨??????????????¢???push
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	cin >> v >> e >> r;
	for (int i = 0; i < e; i++) {
		int s, t, d;
		cin >> s >> t >> d;
		G[s].push_back(edge(t, d));
	}
	dijkstra(r);
	for (int i = 0; i < v; i++) {
		if (d[i] != 1e12)cout << d[i] << endl;
		else cout << "INF" << endl;
	}
}

Measured memory_bytes: 19452
import numpy as np

a = int(input())
b = int(input())
c = int(input())
x = int(input())

ax_a = np.linspace(0, 500*a, a+1)
ax_b = np.linspace(0, 100*b, b+1)
ax_c = np.linspace(0, 50*c, c+1)

aa, bb, cc = np.meshgrid(ax_a, ax_b, ax_c)
grid = aa+bb+cc
ans = (grid==x).sum()
print(ans)


Measured memory_bytes: 17556
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int count=1;
		
		while(true){
			int x=sc.nextInt();
			if(x==0){break;}
			System.out.println("Case "+count+": "+x);
			count++;
			
		}
	}

}



Measured memory_bytes: 41588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b,  x;

            var word = Console.ReadLine().Split(' ');

            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);

            if( b < n * a )
                x = b;
            else
                x = n * a;

            Console.WriteLine(x);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 11092
import math
a,b,h,m=map(int, input().split())
L=float(6*m)
l=float(30*h+m/2)
x=0
x=min(abs(L-l),360-abs(L-l))/180
c=a**2+b**2-2*a*b*math.cos(x*math.pi)
print(math.sqrt(c))


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

#define ll long long

vector <long> arr;
int n,k;
ll dp[303][303][303];

long f(int prev, int cur, int ck);

int main()
{
    cin>>n>>k;
    arr.push_back(0);

    long tmp;

    for(int i=0; i<302; i++)
    {
        for(int j=0; j<302; j++)
        {
            for(int k=0; k<302; k++)
                dp[i][j][k] = -1;
        }
    }

    for(int i=0; i<n; i++)
    {
        cin>>tmp;
        arr.push_back(tmp);
    }

    long ans = f(0, 1, 0);
    cout<<ans;
    return 0;
}

long f(int prev, int cur, int ck)
{
    if(cur>n) return 0;
    if(dp[prev][cur][ck] != -1) return dp[prev][cur][ck];

    long val = max((long)0, arr[cur]-arr[prev] );
    ll l1 = f(cur, cur+1, ck) + val;
    ll l2 = ck<k ? f(prev, cur+1, ck+1): 1000000000000000;
    dp[prev][cur][ck] = min(l1, l2);

    return dp[prev][cur][ck];
}

Measured memory_bytes: 217344
#include<iostream>
#include<cstring>
using namespace std;
string s;
int cnt,ans;
 
int main() {
	cin >> s;
	for(int i = 0;i < s.size();i++)
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
			cnt++;
		else {
			ans = max(ans,cnt);			
			cnt = 0;
		}
	ans = max(ans,cnt);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;



int main()
{
	int n;
	cin >> n;
	int dp[100006];
	
	dp[0] = 0;
	
	for (int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + 1;
		for (int j = 6; j <= i; j *= 6) {
			dp[i] = min(dp[i-j]+1, dp[i]);
		}
		for (int j = 9; j <= i; j *= 9) {
			dp[i] = min(dp[i -j] +1, dp[i]);
		}
	}

	cout << dp[n] << endl;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b)     for(int i=a;i>=b;--i)
#define init(a, x) memset(a,x,sizeof(a))
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))

ll power(ll x, ll a)
{
    ll sum=1;
    while(a>0)
    {
        if(a&1==1)
        {
            sum=x*sum;
            sum%=mod;
        }
        a>>=1;
        x=x*x;
        x%=mod;
    }
    return sum;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,n,m,k,q; 
    t = 1;
    // cin>>t;
    while(t--)
    {
    	cin>>n;
    	if(n==1)
    	{
    		cout<<0<<endl;
    		continue;
    	}
    	else
    	{
    		ll ans = power(10,n);
    		ans += power(8,n);
    		ll ans1 = power(9,n);
    		// ans1 %= mod;
    		ans1 *= 2;
    		ans1 %= mod;
    		ans %= mod;
    		cout<<(ans-ans1+mod)%mod<<endl;
    	}
    }
    return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
const int maxn=100005;
long long tot,n,r,a[maxn],t;
void solve() {
    if (n==1) {
        puts("YES");
        return;
    }
    if ((tot<<1)%(n*(n+1))) {
        puts("NO");
        return;
    }
    r=tot/(n*(n+1)/2);
    for (int i=0;i<n;++i) {
        a[i]-=r;
        if (a[i]%n||a[i]>0) {
            puts("NO");
            return;
        }
        t+=a[i]/(-n);
    }
    puts(t==r?"YES":"NO");
}
int main()
{
    scanf("%lld",&n);
    for (int i=1;i<=n;++i) {
        scanf("%lld",&a[i]);
        tot+=a[i];
        a[i-1]=a[i]-a[i-1];
    }
    a[0]=a[0]-a[n];
    solve();
    return 0;
}


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

long long t[200010];
int main(){
    long long n, c, k;
    cin >> n >> c >> k;
    for(int i = 0;i < n;i++) cin >> t[i];

    int pe = 1;
    int ans = 0;
    sort(t, t+n);
    long long mi = t[0]+k;
    t[n] = 2000000004;
    for(int i = 1;i < n;i++){
        if(pe == c){
            ans++;
            pe = 0;
            mi = t[i]+k;
        }
        if(mi < t[i]){
            mi = t[i]+k;
            pe = 1;
            ans++;
        }else{
            pe++;
        }
    }
    if(pe > 0){
        ans++;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    for(int i;i<4;i++){
        cin>>a>>b;
        if(a==1){cout<<6000*b<<endl;}
        if(a==2){cout<<4000*b<<endl;}
        if(a==3){cout<<3000*b<<endl;}
        if(a==4){cout<<2000*b<<endl;}
    }
}


Measured memory_bytes: 3084
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];

const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}


signed main() {
	int sx, sy, tx, ty,a,b;
	cin >> sx >> sy >> tx >> ty;
	a = tx - sx;
	b = ty - sy;
	rep(i, a) {
		cout << "R";
	}
	rep(i, b) {
		cout << "U";
	}
	rep(i, a) {
		cout << "L";
	}
	rep(i, b) {
		cout << "D";
	}
	cout << "L";
	rep(i, b + 1) {
		cout << "U";
	}
	rep(i, a + 1) {
		cout << "R";
	}
	cout << "DR";
	rep(i, b + 1) {
		cout << "D";
	}
	rep(i, a + 1) {
		cout << "L";
	}
	cout << "U" << endl;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
int ans;
int main(){
	while(cin>>n,n){
		int p;
		string str1;
		cin>>p;
		cin>>str1;
		ans = 0;
		int cnt = 0;
		for(int i = 0;i <p;){
			if(str1.substr(i,3)=="IOI"){
				cnt++;
				if(cnt>=n)
					ans++;
			}else{
				cnt = 0;
			}
			if(cnt ==0)i++;
			else i+=2;
		}
		cout <<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 2120
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
struct edge{ ll to, cost; };
const ll INF = 100100100100100;
const int MAX_V = 200005;
int V,E;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(int s){
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        for(int i=0; i<G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin >> V;
    E = V-1;
    V++;
    rep(i,E){
        ll from,to,cost;
        cin >> from >> to >> cost;
        edge e1, e2;
        e1.to = to; e1.cost = cost;
        e2.to = from; e2.cost = cost;
        G[from].push_back(e1);
        G[to].push_back(e2);
    }
    int q,k;
    cin >> q >> k;

    dijkstra(k);

    rep(i,q){
        int x,y;
        cin >> x >> y;
        cout << d[x] + d[y] << endl;
    }

    return 0;
}

Measured memory_bytes: 13184
#include<stdio.h>

int main(void){


int a,b,c;


int tmp,i,j;


scanf("%d %d %d",&a,&b,&c);


if(a>b){


tmp  =  a;


a = b;


b = tmp;


}


if(a>c){


tmp = a;


a = c;


c = tmp;


}


if(b>c){


tmp = b;


b = c;


c = tmp;


}


printf("%d %d %d\n",a,b,c);


return 0;


}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int prime[maxn];
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    for (int i = 2; i < maxn; ++i)
        if (!prime[i]) {
            for (int j = 2 * i; j < maxn; j += i)
                prime[j] = 1;
        }
    int x; cin >> x;
    for (int i = x; i < maxn; ++i)
        if (!prime[i]) {
            cout << i << '\n';
            break;
        }
    return 0;
}

Measured memory_bytes: 640
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-01 20:30:43
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

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

  vector<int> num(10, -1);

  for (int i = 0; i < m; ++i) {
    int s, c; cin >> s >> c;
    --s;
    if (num[s] == -1) {
      if (n > 1 && s == 0 && c == 0) {
        cout << -1 << endl; return 0;
      } else {
        num[s] = c;
      }
    } else {
      if (num[s] != c) {
        cout << -1 << endl; return 0;
      } else {
        ;
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    if (num[i] == -1) {
      if (i == 0 && n > 1) {
        cout << 1;
      } else {
        cout << 0;
      }
    } else {
      cout << num[i];
    }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
using System;

namespace A
{
    class Bord
    {
        public int[] row = new int[8];
        public bool[] col = new bool[8];
        public bool[] dpos = new bool[15];
        public bool[] dneg = new bool[15];
        public bool[] check = new bool[9];

        public void putQueen(int i, ref Bord bord)
        {
            int j, k=i+1;
            if (i == 8)
            {
                print(bord);
            }
            else
            {
                for (j = 0; j < 8; j++)
                {
                    if (bord.col[j] == false && bord.dpos[i + j] == false && bord.dneg[i - j + 7] == false)
                    {
                        bord.row[i] = j;
                        bord.col[j] = bord.dpos[i + j] = bord.dneg[i - j + 7] = true;

                        for (k = i + 1; k < 9; k++)
                        {
                            if (bord.check[k] == false)break;
                        }

                        putQueen(k, ref bord);
                        bord.col[j] = bord.dpos[i + j] = bord.dneg[i - j + 7] = false;
                    }
                }
            }
        }

        public void print(Bord bord)
        {
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (bord.row[i] == j) Console.Write("Q");
                    else Console.Write(".");
                }
                Console.WriteLine();
            }
        }
    }

    class A
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine()), i;
            Bord bord = new Bord();
            bord.check[8] = false;
            for (i = 0; i < 15; i++)
            {
                if (i < 8)
                {
                    bord.row[i] = -1;
                    bord.col[i] = false;
                    bord.check[i] = false;
                }
                bord.dpos[i] = false;
                bord.dneg[i] = false;
            }

            for (i = 0; i < k; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int m = int.Parse(input[0]);
                int n = int.Parse(input[1]);

                bord.row[m] = n;
                bord.col[n] = bord.dpos[n + m] = bord.dneg[m - n + 7] = true;
                bord.check[m] = true;
            }
            int a = 0;
            for (int b = 0; b < 8; b++)
            {
                if (bord.check[a] == true) a++;
                else break;
            }
            bord.putQueen(a, ref bord);
        }
    }
}



Measured memory_bytes: 19972
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;
int *N;
int n;

bool can_make(int m, int i, int p){
    if(i == n){
       return (m == p) ? true:false;
    } 
    return can_make(m+N[i], i+1, p) || can_make(m, i+1, p);
}

int main(){
    int t;
    scanf("%d", &n);
    N = (int *)calloc(n, sizeof(int));
    for(int i=0; i<n; i++){
        scanf("%d", &N[i]);
    }
    scanf("%d", &t);
    for(int i=0; i<t; i++){
        int p;
        scanf("%d", &p);
        if(can_make(0, 0, p)){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}



Measured memory_bytes: 3232
#include<iostream>
using namespace std;
int main(){
	int n,k;
	while(1){
		int a[100000];
		cin>>n>>k;
		if(n==0&&k==0)break;
		int max=0,sum;
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;i<n;i++){
			sum=0;
			if(i+k-1<n){
				for(int j=0;j<k;j++){
					sum+=a[i+j];
				}
				if(max<sum){
					max=sum;
				}
			}
			else break;
		}
		cout<<max<<endl;
	}
}

Measured memory_bytes: 3484
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 998244353
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  ll n,c=1LL;cin>>n;
  vector<ll> a(n);
  map<ll,ll> m;
  rep(i,n){
    cin>>a[i];
    m[a[i]]++;
    if(i==0&&a[i]!=0){
      cout<<0;return 0;
    }
    if(i!=0&&a[i]==0){
      cout<<0;return 0;
    }
  }
  sort(all(a));
  ll e=0LL,g=1LL;
  bool f=false;
  reps(i,1,n){
    if(m[i]==0){
      cout<<0;return 0;
    }
    rep(j,m[i]){
      g=g*m[i-1]%M;
      
    }
    c+=m[i];
    if(c==n)break;
  }
  cout<<g;
}

Measured memory_bytes: 7296
#include<stdio.h>
 
int main()
{
  int a=0;
  scanf("%d", &a);
  if(a==000)printf("0");
  if(a==001 || a==100)printf("1");
  if(a==10)printf("1");
  if(a==11 || a==110)printf("2");
  if(a==101)printf("2");
  if(a==111)printf("3");
  return 0;
}

Measured memory_bytes: 128
object Main extends App {
    val N = readLong
    val max = Math.sqrt(N)
    def calc(i:Long, currentAns:Long):Long =  {
        if(i > max) {
            currentAns
        } else {
            var ans = currentAns
            if(N % i == 0) {
                val sum = N / i + i
                if(sum < currentAns) {
					ans = sum
                }
            }
            calc(i + 1, ans)
        }
    }
    var ans = calc(1, N + 1)
    println(ans - 2)        

}

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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string a, b, c; cin >> a >> b >> c;

  reverse(all(a));
  reverse(all(b));
  reverse(all(c));

  int turn = 0;
  while (true) {
    if (turn == 0) {
      if (a.empty()) {
        cout << "A\n";
        return (0);
      }
      turn = a.back() - 'a';
      a.pop_back();
    } else if (turn == 1) {
      if (b.empty()) {
        cout << "B\n";
        return (0);
      }
      turn = b.back() - 'a';
      b.pop_back();
    } else {
      if (c.empty()) {
        cout << "C\n";
        return (0);
      }
      turn = c.back() - 'a';
      c.pop_back();
    }
  }
  
  return (0);
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;



int main(){
  int n;
  cin >> n;
  int mini=inf,maxi=-1;
  rep(i,n){
    int a; cin>>a;
    mini = min(mini,a);
    maxi = max(maxi,a);
  }
  
  cout << maxi-mini << endl;
  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 ll long long

typedef pair<ll, ll> LP;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	vector<LP> ab(n);
	REP(i, n){ cin >> ab[i].first >> ab[i].second; }
	sort(ab.begin(), ab.end());
	ll cnt = 0;
	REP(i, n){
		cnt += ab[i].second;
		if (cnt>=k){
			cout << ab[i].first << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#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 <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
//fenwick tree
int n,tree[200005];
int query(int x){
	x++;
	int ans=0;
	while(x>0){
		ans+=tree[x];
		x-=x&(-x);
	}
	return ans;
}
void modify(int id,int v){
	id++;
	while(id<=n){
		tree[id]+=v;
		id+=id&(-id);
	}
}
//main part
char S[200005];
vector<int> ch[26];
vector<int> h1;
int grp[200005],opp[200005];
int main(){
	scanf("%s",S);
	n=strlen(S);
	rep(k,n)ch[S[k]-'a'].push_back(k);
	int cnt=0;
	rep(k,26)if(ch[k].size()&1)cnt++;
	if(cnt>1){
		printf("-1\n");
		return 0;
	}
	rep(i,26){
		int j=0;
		for(;j+j+1<ch[i].size();j++)grp[ch[i][j]]=0;
		if(j+j+1==ch[i].size())grp[ch[i][j++]]=-1;
		for(;j<ch[i].size();j++){
			grp[ch[i][j]]=1;
			opp[ch[i][j]]=ch[i][ch[i].size()-j-1];
		}
	}
	int sz0=0;
	long long ans=0LL;
	rep(k,n){
		if(grp[k]==1)h1.push_back(opp[k]);
		else if(grp[k]==0){
			sz0++;
			ans+=h1.size();
		}else ans+=h1.size()+((n-1)>>1)-sz0;
	}
	rep(k,h1.size()){
		ans+=query(h1[k]);
		modify(h1[k],1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
#define PRYES(x) PR((x) ? "Yes" : "No")
const long long INF = numeric_limits<long long>::max();
// SourceTest用出力マクロ
#ifdef SOURCE_TEST
#define SPR(x) PR(x)
#define SPS(x) PS(x)
#else
#define SPR(x) \
    {}
#define SPS(x) \
    {}
#endif
int main() {
    string str;
    cin >> str;

    if (str[str.length() - 1] == 's') {
        str += "es";
    } else {
        str += "s";
    }
    PR(str);
    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll n, l;
    cin >> n >> l;
    
    ll t, a, idx = -1;
    cin >> t;
    REP(i, n - 1){
        cin >> a;
        if(t + a >= l && idx == -1){
            idx = i;
        }
        t = a;
    }
    
    if(idx != -1){
        cout << "Possible" << '\n';
        for(ll i = n - 1; i > idx + 1; i--){
            cout << i << '\n';
        }
        for(ll i = 1; i <= idx + 1; i++){
            cout << i << '\n';
        }
    }
    else{
        cout << "Impossible" << '\n';
    }
}

Measured memory_bytes: 768
def bal(c,d,m,n):
  if c < d:
    return bal(d,c,m,n)
  else:
    if c % d == 0:
      return m*n/d
    else:
      return bal(d,c%d,m,n)

s = input().split()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
e = int(bal(c,d,c,d))
n = b - (b//c) - (b//d) + (b // e)
m = (a-1) - ((a-1) // c) - ((a-1) // d) + ((a-1) // e)
print(n-m)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int r, c, j, i;
	int a[101][101] = {0};

	scanf("%d %d", &r, &c);
	for (i = 0;i < r;i++)
	{
		for (j = 0;j < c;j++)
		{
			scanf("%d", &a[i][j]);
			a[i][c] += a[i][j];
			a[r][j] += a[i][j];
		}
		a[r][c] += a[i][c];
	}
	for (i = 0;i <= r;i++)
	{
		for (j = 0;j <= c;j++)
		{
			printf("%d", a[i][j]);
			if (j < c)
			{
				printf(" ");
			}
			else
			{
				printf("\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

LL dp[112345] = {};
LL ans[112345] = {};
LL M;
VVI g;

LL dfs1(int v, int p){
    LL res = 1;
    for(int u : g[v]){
        if(u == p) continue;
        res = res * (dfs1(u,v) + 1) % M;
    }
    return dp[v] = res;
}

void dfs2(int v, int p){
    ans[v] = dp[v];
    LL sz = SZ(g[v]);
    VL left(sz+1,1),right(sz+1,1);
    REP(i,sz) left[i+1] = left[i] * (dp[g[v][i]]+1) % M;
    REP(i,sz) right[i+1] = right[i] * (dp[g[v][sz-1-i]]+1) % M;
    REP(i,sz){
        int u = g[v][i];
        if(u == p) continue;
        LL tmp1 = dp[v];
        LL tmp2 = dp[u];
        dp[v] = left[i] * right[sz-1-i] % M;
        dp[u] = dp[u] * (dp[v]+1) % M;
        dfs2(u,v);
        dp[v] = tmp1;
        dp[u] = tmp2;
    }
}



signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; 
    cin >> N >> M;
    g.resize(N);
    REP(i,N-1){
        int x,y; cin >> x >> y;
        x--; y--;
        g[x].eb(y);
        g[y].eb(x);
    }
    dfs1(0,-1);
    dfs2(0,-1);
    REP(i,N){
        cout << ans[i] << endl;
    }


}

Measured memory_bytes: 23168
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#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 all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    map<int,int> m;
    vector<pair<pi,pi > >data;
    pair<pi,pi> d;
    rep(i,n){
      cin>>d.second.first>>d.second.second>>d.first.first>>d.first.second;
      d.second.first=(-d.second.first);
      d.first.second=(-d.first.second);
      data.pb(d);
    }
    sort(all(data));reverse(all(data));
    int win=0;
    rep(i,n){
      if(win<10&&m[data[i].second.second]<3){
	cout<<-data[i].second.first<<endl;
	m[data[i].second.second]++;
	win++;
      }else if(win<20&&m[data[i].second.second]<2){
	cout<<-data[i].second.first<<endl;
	m[data[i].second.second]++;
	win++;
      }else if(win<26&&m[data[i].second.second]==0){
	cout<<-data[i].second.first<<endl;
	m[data[i].second.second]++;
	win++;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3088
N,S=map(int,input().split())
A=list(map(int,input().split()))
mod=998244353
DP=[0]*(S+1)
DP[0]=pow(2,N,mod)
INV=pow(2,mod-2,mod)
for a in A:
    for i in range(S-a,-1,-1):
        DP[i+a]=(DP[i]*INV+DP[i+a])%mod       
print(DP[S])

Measured memory_bytes: 68404
#include "bits/stdc++.h"

using namespace std;

#ifdef LOCAL
#include "debug.hpp"
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }  
  vector<int> b = x;
  sort(x.begin(), x.end());
  int mid1 = (n - 1)/2;
  int mid2 = n/2;
  for (int i = 0; i < n; i++) {
    if (b[i] <= x[mid1]) cout << x[mid2] << '\n';
    else cout << x[mid1] << '\n'; 
  }
  return 0;
}

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

vector<ll> enumDivisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n; ++i){
    if (n % i != 0) continue;
    res.push_back(i);
    if (i*i != n) res.push_back(n/i);
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  int ans = 0;
  for(ll x: enumDivisor(n)){
    if(x == 1) continue;
    ll tmp = n;
    while(tmp%x == 0) tmp /= x;
    tmp %= x;
    if(tmp==1) ++ans;
  }
  ans += enumDivisor(n-1).size() - 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3612
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException{
		CountingRoads solver = new CountingRoads();
		solver.readInput();
		solver.solve();
		solver.writeOutput();
	}

	static class CountingRoads {
		private int n;
		private int m;

		private int a[];
		private int b[];

		private Scanner scanner;
		private int output[];

		public CountingRoads() {
			scanner = new Scanner(System.in);

		}
		public void readInput() {
			n = scanner.nextInt();
			m = scanner.nextInt();

			output = new int[n];
			Arrays.fill(output, 0);

			for(int i=0; i<m; i++) {
				for(int j=0; j<2; j++) {
					output[scanner.nextInt()-1]++;
				}
			}

		}

		public void solve() {
		}
		public void writeOutput() {
			for(int o:output) {
				System.out.println(o);
			}
		}
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int n;
	cin >> n;
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (mp.count(a)) {
			mp[a]++;
			if (1 < mp[a]) {
				cout << "NO" << endl;
				return 0;
			}
		}
		else mp[a] = 1;
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 9728