akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<algorithm>
int main() {
    int n,x,d;
    scanf("%d%d%d",&n,&x,&d);
    if(d==0) return !printf("%d",x==0?1:n+1);
    typedef long long ll;
    typedef std::pair<ll,ll> P;
    if(d<0) d=-d,x=-x;
    auto work=[&](ll x) {
        if(x>=0) return x/d;
        return -((-x)/d)-((-x)%d==0?0:1);
    };
    std::map<ll,std::vector<P> > f;
    ll L=0,R=0;
    for(int i=0;i<=n;i++) {
        ll pt=work(1LL*i*x);
        ll m=1LL*i*x%d;
        if(m<0) m+=d;
        f[m].push_back(P(L+pt,R+pt));
        L+=i;R+=n-i-1;
    }
    ll ans=0;
    for(auto &v:f) {
        std::sort(v.second.begin(),v.second.end());
        ll L=v.second[0].first,R=v.second[0].second;
        for(P c:v.second) {
            if(c.first-1>R) {
                ans+=R-L+1;
                L=c.first,R=c.second;
            }
            else R=std::max(R,c.second);
        }
        ans+=(R-L+1);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 22144
#include<stdio.h>
int main(void)
{
	int n,k;
	int x1[50],y1[50],d1[50],x2[50],y2[50],d2[50];
	long long int sum;
	int area[102],flg[102];
	int y[102],d[102];
	int i,j,ii,jj,wk,p,c;
	
	scanf("%d %d",&n,&k);
	
	for(i=0;i<n;i++)	{
		scanf("%d %d %d %d %d %d",&x1[i],&y1[i],&d1[i],&x2[i],&y2[i],&d2[i]);
	}
	sum=0;
	for(i=0;i<n;i++)	{
		y[i]=y1[i];
		y[i+n]=y2[i];
		d[i]=d1[i];
		d[i+n]=d2[i];
	}
	for(i=0;i<n*2-1;i++)	{
		for(j=i+1;j<n*2;j++)	{
			if(y[i]>y[j])	{
				wk=y[i];
				y[i]=y[j];
				y[j]=wk;
			}
		}
	}
	for(i=0;i<n*2-1;i++)	{
		for(j=i+1;j<n*2;j++)	{
			if(d[i]>d[j])	{
				wk=d[i];
				d[i]=d[j];
				d[j]=wk;
			}
		}
	}
	sum=0;
	for(ii=0;ii<n*2;ii++)	{
		for(jj=0;jj<n*2;jj++)	{
			p=0;
			for(i=0;i<n;i++)	{
				if(y[ii]>=y1[i] && y[ii]<y2[i] && d[jj]>=d1[i] && d[jj]<d2[i])	{
					area[p]=x1[i];
					flg[p]=0;
					area[p+1]=x2[i];
					flg[p+1]=1;
					p+=2;
				}
			}
			for(i=0;i<p-1;i++)	{
				for(j=i+1;j<p;j++)	{
					if(area[i]>area[j])	{
						wk=area[i];
						area[i]=area[j];
						area[j]=wk;
						wk=flg[i];
						flg[i]=flg[j];
						flg[j]=wk;
					}
				}
			}
			c=0;
			for(i=0;i<p-1;i++)	{
				if(flg[i]==0)	c++;
				if(flg[i]==1)	c--;
				if(c>=k)	{
					sum+=(long long int)(area[i+1]-area[i])*(y[ii+1]-y[ii])*(d[jj+1]-d[jj]);
				}
			}
		}
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 600
s = input()
q = int(input())
for i in range(q):
	t_s = input().split()
	if t_s[0] == 'replace':
		a = int(t_s[1])
		b = int(t_s[2])
		p = t_s[3]
		s = s[0:a] + p + s[b+1:len(s)]
	elif t_s[0] == 'reverse':
		a = int(t_s[1])
		b = int(t_s[2])
		p = s[a:b+1]
		s = s[0:a] + p[::-1] + s[b+1:len(s)]
	elif t_s[0] == 'print':
		print(s[int(t_s[1]):int(t_s[2])+1])


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define PR pair<LL,LL>
const int N=20;
LL a[N];
vector< PR > vp[N][N];
PR calpr(PR u,PR v,LL t){
    LL num=u.sc+v.fr+t;
    return mp(u.fr+num,v.sc+num);
}
LL calval(PR t,LL u,LL v){
    return t.fr*u+t.sc*v;
}
void pus(int n,int l,int r,int u1,int v1,int u2,int v2){
    if (l>r) return;
    PR m1,m2;
    LL val1=1e18,val2=1e18;
    int len=r-l+1;
    for (int k=l;k<=r;k++){
        int l1=k-l,l2=r-k;
        for (auto u:vp[l1][l]) for (auto v:vp[l2][k+1]){
            PR t=calpr(u,v,a[k]);
            LL valt1=calval(t,u1,v1);
            if (valt1<val1) m1=t,val1=valt1;
            if (len>n-2) continue;
            LL valt2=calval(t,u2,v2);
            if (valt2<val2) m2=t,val2=valt2;
        }
    }
    vp[len][l].pb(m1);
    if (len==n-2) vp[len][l].pb(m2);
}
void work(int n){
  //  pus(n,1,n-2,1,2,1,3);
  //  pus(n,2,n-1,2,3,3,2);
  //  pus(n,3,n,  2,1,3,1);

    pus(n,1,n-1,1,2,0,0);
    pus(n,2,n,  2,1,0,0);

    pus(n,1,n,  1,1,0,0);
}
int main(){
   // freopen("in.txt","r",stdin);
   // freopen("out.txt","w",stdout);
    int n;cin>>n;
    for (int i=0;i<n;i++) scanf("%lld",a+i);
    LL ans=a[0]+a[n-1];n-=2;

    for (int i=1;i<=n;i++) vp[1][i].pb(mp(a[i],a[i])),vp[0][i].pb(mp(0,0));
    vp[0][n+1].pb(mp(0,0));

    for (int p=2;p<=n-2;p++){
        for (int i=1;i+p-1<=n;i++){
            int j=i+p-1;
            for (int k=i;k<=j;k++){
                int l1=k-i,l2=j-k;
                for (auto u:vp[l1][i]) for (auto v:vp[l2][k+1]){
                    vp[p][i].pb(calpr(u,v,a[k]));
                }
            }
        }
    }

    work(n);
    PR p=vp[n][1][0];
    ans+=p.fr+p.sc;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 231768
#include <iostream>

#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main(){
  int N;
  string s, t;
  cin >> N >> s >> t;
  //入力終了

  //文字列tの，t_start番目からsに連結させる
  int t_start;

  //t_startの最大値(開始場所をできるだけ右にずらす)
  int max_start = 0;
  rep(i, N){
    t_start = 0;
    int j = i;
    //sのi文字目以降と，tの0文字目以降を見ていく
    //一致する限り右にずらせる
    while(s[j++] == t[t_start] && j<=N)
      t_start++;
    //tの開始位置を最大化
    if(t_start > max_start)
      max_start = t_start;
  }

  //必ずsは出力される
  cout << s.size() + (t.size()-max_start) << endl;
  
  //実際の文字列
  /*cout << s ;
  if(max_start < N){
    rep(i, t.size()-max_start)
      cout << t[i+max_start];
    cout << endl;
    return 0;
  }
  cout << endl;*/
  
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<ll, ll, ll> iii;

const int N = 51;
const int M = 2460;
int n, m, s, u, v, a, b;
int C[N], D[N];
vector<iii> e[N];
ll dp[N][M];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(dp, 0x3f, sizeof dp);

  cin >> n >> m >> s;
  s = min(s, 2450);
  for (int i = 0; i < m; ++i) {
    cin >> u >> v >> a >> b;
    e[u].push_back(iii(v, a, b)); // to, money, time
    e[v].push_back(iii(u, a, b));
  }

  for (int i = 1; i <= n; ++i) {
    cin >> C[i] >> D[i];
  }

  dp[1][s] = 0;
  priority_queue<iii, vector<iii>, greater<iii>> pq;
  pq.push(iii(0, 1, s));
  while (pq.size()) {
    iii cur = pq.top(); pq.pop();
    // time, point, money
    ll ct = get<0>(cur), u = get<1>(cur), cm = get<2>(cur);
    for (auto [v, m, t] : e[u]) {
      if (cm >= m && dp[v][cm - m] > ct + t) {
        dp[v][cm - m] = ct + t;
        pq.push(iii(ct + t, v, cm - m));
      }
    }
    if (dp[u][min(2450LL, cm + C[u])] > ct + D[u]) {
      dp[u][min(2450LL, cm + C[u])] = ct + D[u];
      pq.push(iii(ct + D[u], u, min(2450LL, cm + C[u])));
    }
  }

  for (int i = 2; i <= n; ++i) {
    ll ans = 0x3f3f3f3f3f3f3f3f;
    for (int j = 0; j <= 2450; ++j) {
      ans = min(ans, dp[i][j]);
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 7268
#include<bits/stdc++.h>
#define int long long
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)

inline int read() 
{
	char cc = getchar(); int cn(0), flus(1);
	while(cc < '0' || cc > '9') {if(cc == '-') flus = -flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - 48; cc = getchar();}
	return cn * flus;
}

const int MAXN = 1e5 + 10;
const int Mod = 998244353, G = 3;

int n, x, ans;

void solve(int len, int a)
{
//	printf("solve %d %d \n",len,a);
	if(!a) 
	{
		ans -= len;
		return ;
	}
	ans += (len) / a * a * 2;
//	printf("ans = %d \n",ans);
	solve(a, len % a);
}

signed main()
{
	n = read(), x = read();
	ans += n;
	solve(n - x, x);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3692
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

int main() {
    ll n;
    cin >> n;
    if ((n % 2) == 1) {
        cout << 0 << endl;
        return 0;
    }
    ll c = 0;
    n = n / 10;
    c += n;
    ll tmp = n;
    while (tmp > 0) {
        tmp = tmp / 5;
        c = c + tmp;
    }
    cout << c << endl;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


void func(long long K){

    queue<lli> q;
    REP(i,1,10)q.push(i);

    lli cnt=0;
    while(q.size()){
        cnt++;
        lli num = q.front();
        q.pop();

        if(cnt==K){
            cout<<num<<endl;
            return;
        }
        lli t=num%10;
        if(t!=0)q.push(num*10+t-1);
        q.push(num*10+t);
        if(t!=9)q.push(num*10+t+1);
    }
}

int main(){
    // cout << fixed << setprecision(5);

    long long K;
    scanf("%lld",&K);
    func(K);
    return 0;
}


Measured memory_bytes: 1792
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

pub trait LexicalPermutation {
  /// Return `true` if the slice was permuted, `false` if it is already
  /// at the last ordered permutation.
  fn next_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T] where T: Ord {
  /// Original author in Rust: Thomas Backman <serenity@exscape.org>
  fn next_permutation(&mut self) -> bool {
    // These cases only have 1 permutation each, so we can't do anything.
    if self.len() < 2 { return false; }

    // Step 1: Identify the longest, rightmost weakly decreasing part of the vector
    let mut i = self.len() - 1;
    while i > 0 && self[i-1] >= self[i] {
      i -= 1;
    }

    // If that is the entire vector, this is the last-ordered permutation.
    if i == 0 {
      return false;
    }

    // Step 2: Find the rightmost element larger than the pivot (i-1)
    let mut j = self.len() - 1;
    while j >= i && self[j] <= self[i-1]  {
      j -= 1;
    }

    // Step 3: Swap that element with the pivot
    self.swap(j, i-1);

    // Step 4: Reverse the (previously) weakly decreasing part
    self[i..].reverse();

    true
  }
}
fn main() {
  let n: usize = read();
  let x: Vec<isize> = read_vec();

  let x_min = x.iter().min().unwrap();
  let x_max = x.iter().max().unwrap();
  let mut min_sum = 1001001001001;

  for i in *x_min..*x_max {
    let mut sum = 0;
    for j in &x  {
      sum += ((i - j) as isize).pow(2);
    }
    if sum < min_sum { min_sum = sum; }
  }
  if min_sum == 1001001001001 { min_sum = 0; }
  println!("{}", min_sum);
}

Measured memory_bytes: 4352
n, x, *A = map(int, open(0).read().split())
s = 0
if A[0] > x:
    s += A[0] - x
    A[0] = x
for i in range(1, n):
    if A[i] + A[i-1] > x:
        s += A[i] + A[i-1] - x
        A[i] = x - A[i-1]
print(s)

Measured memory_bytes: 14092
h, w = map(int, input().split())
mapping = []
judge = "".join(["."]*w)
t = 0
for i in range(h):
  key = input()
  if key != judge:
    mapping.append([])
    for j in range(w):
      mapping[-1].append(key[j])
  else:
    t += 1

for i in range(w-1, -1, -1):
  for j in range(h-t):
    if mapping[j][i] == "#":
      break
    if j == h-t-1:
      for l in range(h-t):
        mapping[l].pop(i)

for i in range(h-t):
  print("".join(mapping[i]))

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>

using namespace std;

int main() {
	long long int n;
	cin >> n;
	vector<long long int> a(3 * n);
	vector<long long int> b, c;
	priority_queue<long long int, vector<long long int>, greater<long long int> > pqb;
	long long int bb = 0;
	for (long long int i = 0; i < 3 * n; i++) {
		cin >> a[i];
		if (i < n) {
			pqb.push(a[i]);
			bb += a[i];
		}
		else {
			c.push_back(a[i]);
		}
	}
	sort(c.begin(), c.end());
	long long int cc = 0;
	priority_queue<long long int, vector<long long int>, greater<long long int> > pqc;
	for (long long int i = 0; i < 2 * n; i++) {
		if (i < n) {
			cc += c[i];
		}
		else {
			pqc.push(c[i]);
		}
	}
	long long int ans = bb - cc;
	map<long long int, long long int> mp;
	for (long long int i = n; i < 2 * n; i++) {
		if (a[i] > pqb.top()) {
			bb -= pqb.top();
			pqb.pop();
			bb += a[i];
			pqb.push(a[i]);
		}
		if (a[i] <= pqc.top()) {
			cc -= a[i];
			cc += pqc.top();
			pqc.pop();
			while (!pqc.empty()) {
				if (mp[pqc.top()] > 0) {
					mp[pqc.top()]--;
					pqc.pop();
				}
				else {
					break;
				}
			}
		}
		else {
			mp[a[i]]++;
		}
		ans = max(ans, bb - cc);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12016
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    char x,y,z;
    scanf("%d",&a);
    scanf("%c",&x);
    scanf("%c",&y);
    scanf("%c",&z);
    scanf("%d",&b);
    if(y=='+')
    {
        cout<<a+b<<endl;
    }else
    cout<<a-b<<endl;
    return 0;
}


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

#define int long long
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
vector<vector<int>> adj;
vector<bool> vis;

void dfs(int child)
{
	vis[child] = true;
	for(auto &it:adj[child])
	{
		if(!vis[it])
		{
			dfs(it);
		}
	}
}		
signed main()
{
    flash
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		int m;
		cin>>m;
		adj.resize(n+1);
		vis.resize(n+1);
		while(m--)
		{
			int a,b;
			cin>>a>>b;
			adj[a].pb(b);
			adj[b].pb(a);
		}
		int ans = 0;
		for(int i=1;i<=n;++i)
		{
			if(!vis[i])
			{
				dfs(i);
				ans++;
			}
		}
		cout<<ans-1;
    }
    return 0;
}


Measured memory_bytes: 9780
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    int d,g,point,ans=100000000;
    cin>>d>>g;
    vi p,c;
    rep(i,d){
        int pi,ci;
        cin>>pi>>ci;
        p.push_back(pi);
        c.push_back(ci);
    }
    rep(i,(1<<d)){
        int count=0;
        point=0;
        int rm;
        rep(j,d){
            if(i&(1<<j)){
                point+=p.at(j)*100*(j+1);
                point+=c.at(j);
                count+=p.at(j);
            }
            else{
                rm=j;
            }
        }
        if(point<g){
            int time=100*(rm+1);
            int need=(g-point+time-1)/time;
            if(need>=p.at(rm)){
                continue;
            }
            count+=need;
        }
        ans=min(ans,count);
    }
    cout<<ans;
}

Measured memory_bytes: 256
//atcb095b.java
import java.io.*;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] m = new int[n];
		int sum, ans=0, min=1000;

		for (int i=0; i<n; i++) {
			m[i] = sc.nextInt();
			if(m[i] < min) min = m[i];
			x -= m[i];
			ans++;
		}
		ans = ans + x/min;
		System.out.println(ans);
		sc.close();
	}
}	


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef pair<ll, int> ll_i;

int main() {
    ll n,m,d;
    cin >> n >> m >> d;
    double tmp = 2.0*(m - 1)*(n - d) / (double)(n*n);
    if (d == 0){
        cout << tmp / 2.0 << endl;
    } else {
        cout << fixed << setprecision(10) << tmp << endl;
    }
	return 0;
}

Measured memory_bytes: 256
f (a,0) = (a,1,0)
f (a,b) = 
    let (d,y',x') = f (b, (a`mod`b))
    in
        (d,x',y'-(a`div`b)*x')


ans [a,b] = 
    let (d,x,y) = f (a,b)
    in
        (d,x,y)


main = do
    l <- getLine
    let i = map read $ words l :: [Int]
        (g,x,y) = ans i
    putStrLn $ unwords $ map show [x,y]


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

using namespace std;

int main(void) {
	string Nstr;
	cin >> Nstr;
	int K;
	cin >> K;
	long long ans = 0;
	bool bounded0 = true;
	for(int x0 = 0; x0 < Nstr.length(); ++x0) {
		long long ans0 = 0;
		bounded0 = (x0 == 0);
		for(int v0 = 1; v0 <= (bounded0 ? (Nstr[x0] - '0') : 9); ++v0) {
			if(K == 1) {
				++ans0;
			} else {
				bool bounded1 = (bounded0 && (v0 == Nstr[x0] - '0'));
				for(int x1 = x0 + 1; x1 < Nstr.length(); ++x1) {
					long long ans1 = 0;
					for(int v1 = 1; v1 <= (bounded1 ? (Nstr[x1] - '0') : 9); ++v1) {
						if(K == 2) {
							++ans1;
						} else {
							bool bounded2 = (bounded1 && (v1 == Nstr[x1] - '0'));
							for(int x2 = x1 + 1; x2 < Nstr.length(); ++x2) {
								long long ans2 = 0;
								for(int v2 = 1; v2 <= (bounded2 ? (Nstr[x2] - '0') : 9); ++v2) {
									++ans2;
								}
								ans1 += ans2;
								if(bounded2 && Nstr[x2] != '0') bounded2 = false;
							}
						}
					}
					ans0 += ans1;
					if(bounded1 && Nstr[x1] != '0') bounded1 = false;
				}
			}
		}
		ans += ans0;
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[] h = new int[n];
    for(int i = 0; i < n; i++){
      h[i] = scanner.nextInt();
    }
    
    boolean result = true;
    
    for(int i = n - 1; i > 0; i--){
      if(h[i-1] > h[i] + 1){
        result = false;
      }else if(h[i-1] > h[i]){
        h[i-1]--;
      }
    }

    System.out.println(result ? "Yes" : "No");
  }
}


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> pos(n+1,1);
    for(int i=0;i<m;i++){
        int c,d;
        cin>>c>>d;
        for(int j=c;j<d;j++) pos[j]=3;
    }
    cout<<accumulate(pos.begin(),pos.end(),0)<<endl;
    
    return 0;
}


Measured memory_bytes: 3120
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
vector<int> e[100010];
long long dp[100010][2];
void dfs(int v, int p = -1) {
	dp[v][0] = dp[v][1] = 1;
	for (int i = 0; i < e[v].size(); i++) {
		int w = e[v][i];
		if (w == p) continue;
		dfs(w, v);
		dp[v][0] = dp[v][0] * (dp[w][0] + dp[w][1]) % mod;
		dp[v][1] = dp[v][1] * dp[w][0] % mod;
	}
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		--u; --v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(0);
	long long ans = (dp[0][0] + dp[0][1]) % mod;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 14208
#include <stdio.h>

int main(){
    int n=0;
    scanf("%d\n", &n);
    int a[200];
    int m=0;

    for(int i=0;i<n;i++){
        scanf("%d", &a[i]);
    }

    while(1){
    for(int j=0;j<n;j++){
        if(a[j]%2 == 0){
            a[j] = a[j]/2;
        }
        else{
              printf("%d",m);
            return 0;
        }
    }
    m++;
    }
}


Measured memory_bytes: 128
import numpy as np
n = input()
n = int(n)
data = input().split()
count = 0

for i in np.arange(1, n-1):
  a = int(data[i-1])
  b = int(data[i])
  c = int(data[i+1])
  arr = np.array([a, b, c])
  arr = np.sort(arr)
  if arr[1] == b:
    count += 1

print(count)

Measured memory_bytes: 21276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];
    reverse(all(A));
    
    rep(i,N){
        cout << A[i];
        if (i != N - 1) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3148
def examD():
    def f(b, n):
        if n < b:
            return n
        else:
            return f(b, n // b) + n % b
    n = I(); s = I()
    ans = -1
    if s==n:
        ans = n+1
    else:
        loop = int(n**(0.5))
        for b in range(2,loop+1):
            if f(b,n)==s:
                ans = b
                break
    if ans==-1:
        for p in range(loop+1,0,-1):
            b = (n-s)//p + 1
            if b >= 2 and f(b,n)==s:
                    ans = b
                    break

    print(ans)

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()


Measured memory_bytes: 43136
// #pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma vector temporal
// #pragma simd
// #pragma GCC diagnostic ignored "-W"

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>
#include<functional>
#include<complex>
#include<climits>

// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define MS(x,v) memset((x),(v),sizeof(x))
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)
#define CPPinput ios_base::sync_with_stdio(0); cin.tie(0)
#define FIN(fname) freopen(fname,"r",stdin)
#define FOUT(fname) freopen(fname,"w",stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#include"/home/edison/Coding/cpp/template/debug.cpp"
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define DEBUG 1
#define exit(x) cout<<"exit code "<<x<<endl, exit(0)
#else
#define PDE(...) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>
#endif

void JIZZ(string output=""){cout<<output; exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

int main(){
    CPPinput;
    int n,m,d; cin>>n>>m>>d;
    int c2,c1,c0;
    if(d==0){
        c2=0; c1=n; c0=0;
    }
    else if(d*2<=n){
        c2=n-d*2; c1=d*2; c0=0;
    }
    else{
        c2=0; c1=d*2; c0=n-d*2;
    }
    PDE(c0,c1,c2);
    double ex=((double)c1/n+(double)c2/n*2)/n;
    cout<<fixed<<setprecision(20)<<pow(ex,1)*(m-1)<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();

        int n = in.intNext();
        int[] nums = in.nextIntArray(n);

        int res = 0;
        int minVal = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            if (nums[i] <= minVal) {
                minVal = nums[i];
                res += 1;
            }
        }
        out.println(res);

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 47552
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<numeric>
#include<climits>
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	// それぞれ、n-1番目、0番目の動物
	vector<vector<int>> ans{ vector<int>{1,1},vector<int>{1,-1},vector<int>{-1,1},vector<int>{-1,-1} };
	char c;
	for (int i = 0; i < n; i++) {
		cin >> c;
		int k = 1;
		if (c == 'x') k = -1;
		for (int j = 0; j < 4; j++) {
			ans[j].push_back(k*ans[j][i] * ans[j][i + 1]);
		}
	}
	for (int j = 0; j < 4; j++) {
		if (ans[j][n] == ans[j][0] && ans[j][n + 1] == ans[j][1]) {
			for (int i = 1; i <= n; i++) {
				if (ans[j][i] == 1) {
					cout << 'S';
				}
				else {
					cout << 'W';
				}
			}
			cout << endl;
			return 0;
		}
	}

	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 2020
L, R = map(int, input().split())
if R - L > 2017 or L % 2019 > R % 2019:
  print(0)
  exit()
a = 2018
for i in range(L, R):
  for j in range(L + 1, R + 1):
    a = min(a, i * j % 2019)
print(a)

Measured memory_bytes: 2940
n = int(input())

if(n < 10):
    ans = n
elif(10 <= n and n < 100):
    ans = 9
elif(100 <= n and n < 1000):
    ans = (n - 90)
elif(1000 <= n and n < 10000):
    ans = 909
elif(10000 <= n and n < 100000):
    ans = (n-9090)
else:
    ans = 90909

print(ans)


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

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  long double a,b;
  std::cin>>a>>b;
  
  int64_t result=a*b;
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 3812
import itertools
import sys

N = int(input())
if N < 3:
  print(0)
  sys.exit()

lis = list(map(int, input().split()))
count = 0
for tri in itertools.combinations(lis, 3):
  if tri[0] != tri[1] and tri[1] != tri[2] and tri[2] != tri[0]:
    if tri[0]+tri[1] > tri[2] and tri[1]+tri[2] > tri[0] and tri[2]+tri[0] > tri[1]:
      count += 1
print(count)

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n, m;
int deg[100005];
int a[100005], b[100005];
int par[100005];

vector<int> tedge[100005];

int f(int x){
	if(par[x] == x){
		return x;
	}else{
		return par[x] = f(par[x]);
	}
}

void dfs(int cur, int prev, int edgeid){
	for(auto id: tedge[cur]){
		int to = a[id] + b[id] - cur;
		if(to != prev){
			dfs(to, cur, id);
		}
	}
	if(edgeid == -1){
		return;
	}
	if(deg[cur] & 1){
		// point parent edge to cur
		a[edgeid] = prev;
		b[edgeid] = cur;
		deg[cur]++;
	}else{
		// point parent edge to parent
		a[edgeid] = cur;
		b[edgeid] = prev;
		deg[prev]++;
	}
}

int main(){
	scanf("%d %d", &n, &m);
	
	if(m & 1){
		printf("-1\n");
		return 0;
	}
	
	for(int i = 1; i <= n; i++){
		par[i] = i;
	}
	
	for(int i = 1; i <= m; i++){
		scanf("%d %d", &a[i], &b[i]);
		int pa = f(a[i]);
		int pb = f(b[i]);
		if(pa == pb){
			// point a[i] -> b[i]
			deg[b[i]]++;
		}else{
			par[pa] = pb;
			tedge[a[i]].push_back(i);
			tedge[b[i]].push_back(i);
		}
	}
	
	dfs(1, 0, -1);
	
	for(int i = 1; i <= m; i++){
		printf("%d %d\n", b[i], a[i]); // well... ugly fix it is :)
	}
	return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long ul;
// for文短縮類
#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--)
// iteratorのbeginとendをまとめて渡す
#define ALL(x) (x).begin(), (x).end()
//略
#define PB push_back  // vectorヘの挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素
//出力
#define COUT(x) cout << (x) << endl
#define SCOUT(x) cout << (x) << " "
#define ENDL cout << endl
/************ Combination wtih MOD ************
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// preprocess for some tables
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// combination
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*******************************************************/
/********** UnionFind ***************
struct UnionFInd {
vector<ll> par;
UnionFInd(ll N) : par(N) {
for (ll i = 0; i < N; i++) {
par[i] = i;
}
}
ll root(ll x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(ll x, ll y) {
ll rx = root(x);
ll ry = root(y);
if (rx == ry) return;
par[rx] = par[ry];
}
bool same(ll x, ll y) {
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
};
*************************************/

const int MOD = 1000000007;
int main(int argc, char *argv[])
{
    // input高速化。cinとcoutの結合解除。scanfとprintfは使えない。
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    ll n;
    cin >> n;
    vector<ll> a(n);

    REP(i, n)
    {
        ll ai;
        cin >> ai;
        a[i] = ai;
    }

    vector<vector<ll>> dp(n + 1, vector<ll>(3, 0));

    ll ans = 1;

    for (int i = 1; i < n + 1; i++)
    {
        ll b = a[i - 1];
        ll cnt = 0;
        REP(j, 3){
            dp[i][j] = dp[i - 1][j];
        }
        REP(j, 3)
        {
            if (dp[i - 1][j] == b)
                cnt += 1;
        }
        if (cnt != 0)
        {
            REP(j, 3)
            {
                if (dp[i - 1][j] == b)
                {
                    dp[i][j] += 1;
                    break;
                }
            }
        }

        ans *= cnt;
        ans %= MOD;

        
    }
    cout << ans << endl;
}

Measured memory_bytes: 9524
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
using namespace std;

int main(void){
    int n,m;
    while(cin>>n>>m && n&&m){
        vector<int> v(n),sai(m);
        rep(i,0,n)cin>>v[i];
        rep(i,0,m)cin>>sai[i];
        
        int index=0;
        rep(i,0,m){
            index+=sai[i];
            //cout<<index<<endl;
            if(index>=n-1){
                cout<<i+1<<endl;
                break;   
            }
            if(v[index]==0)continue;
            if(v[index]<0)index-=(-v[index]);
            else index+=v[index];
            //cout<<index<<endl;
            if(index>=n-1){
                cout<<i+1<<endl;
                break;   
            }
        }
    }
    
    
    return 0;
}



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

bool compare(pair<string,int> a, pair<string,int> b){
    if(a.first==b.first){
        return a.second > b.second;
    }else{
        return a.first < b.first;
    }
}

main(){
    int n,i;
    cin >> n;
    pair<pair<string,int>,int> rest[110];
    for(i=0;i<n;i++) cin>> rest[i].first.first >> rest[i].first.second;
    for(i=0;i<n;i++){
        rest[i].first.second *= -1;
        rest[i].second=i+1;
    }
     
   sort(rest,rest+n);
   for(i=0;i<n;i++) cout << rest[i].second << endl;  


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	ll ans1=0,ans2=0,sum=0;
	bool flg=true;
	rep(i,n){
		sum+=a.at(i);
		if(flg){
			if(sum<=0){
				ans1+=-sum+1;
				sum=1;
			}
			flg=false;
		}
		else{
			if(sum>=0){
				ans1+=sum+1;
				sum=-1;
			}
			flg=true;
		}
	}
	sum=0;
	flg=false;
	rep(i,n){
		sum+=a.at(i);
		if(flg){
			if(sum<=0){
				ans2+=-sum+1;
				sum=1;
			}
			flg=false;
		}
		else{
			if(sum>=0){
				ans2+=sum+1;
				sum=-1;
			}
			flg=true;
		}
	}
	cout << min(ans1,ans2) << endl;
}

Measured memory_bytes: 640
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;

struct edge {
    int from, to;
    int cost;
};

const ll MOD = 1E+09 + 7;
const int INF = 1E09;
const int MAX_N = 1E+05;

int K, d[MAX_N];
vector<edge> G[MAX_N];

void bfs_01(int s);

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

    cin >> K;

    for (int i = 0; i < K; i++) {
        edge e1 = { i, (i + 1) % K, 1 };
        G[i].push_back(e1);
        edge e10 = { i, (10 * i) % K, 0 };
        G[i].push_back(e10);
    }
    fill(d, d + K, INF);
    bfs_01(1);

    /*
    for (int i = 0; i < K; i++) {
        cout << "i = " << i << ", d = " << d[i] << "\n";
    }
    */

    cout << d[0] + 1 << "\n";

    return 0;
}

void bfs_01(int s)
{
    deque<P> dq;
    dq.push_front(P(s, 0)); //第一要素は頂点ID、第二要素は暫定の最短距離
    d[s] = 0;
    while (!dq.empty()) {
        P p = dq.front();
        dq.pop_front();
        int v = p.first;
        if (d[v] < p.second)
            continue;
        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;
                if (e.cost == 1) {
                    dq.push_back(P(e.to, d[e.to]));
                } else {
                    dq.push_front(P(e.to, d[e.to]));
                }
            }
        }
    }
}

Measured memory_bytes: 9900
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
#define fin {cout<<"No"<<endl;return 0;}
//template
//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  v[0]--;
  for(int i=1;i<N;i++){
    if(v[i-1]<v[i])v[i]--;
    if(v[i-1]>v[i])fin;
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
// #define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const int INF = -1;
ll dp[100005][13];

signed main(void) {
	string S;
	cin >> S;

	string ans = "Sunny";
	if (S == "Sunny") {
		ans = "Cloudy";
	} else if (S == "Cloudy") {
		ans = "Rainy";
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
N, Q = map(int, input().split())

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N + 1)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

for _ in range(Q):
    p, x = map(int, input().split())
    counter[p - 1] += x

stack = [(0, -1)]
while stack:
    s, parent = stack.pop()
    counter[s] += counter[parent]
    for n in edge[s]:
        if n == parent:
            continue
        stack.append((n, s))

ans = " ".join(map(str, counter[:N]))
print(ans)

Measured memory_bytes: 65280
import java.util.Scanner;

public class Main {

	public static void main(String... nui) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		System.out.println((s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2) ||
				s.charAt(1) == s.charAt(2) && s.charAt(2) == s.charAt(3)) ? "Yes" : "No");
	}

}


Measured memory_bytes: 23764
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	char cn[200010];
	fread(cn, 1, 200010, stdin);

	int L = 0, R = 200000;
	while (L + 1 < R) {
		int M = (L + R) / 2;
		if (cn[M] >= '?') L = M;
		else R = M;
	}
	for (char* i = cn; i < cn + R; i++) {
		if (*i == '?') *i = 'D';
	}
	fwrite(cn, 1, R, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3192
#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;



int main(){

	
	int N, T, E;
	cin >> N >> T >> E;

	int min = T - E , max = T + E;

	int b = -1;
	for (int i = 0; i < N; i++){
		int n;
		cin >> n;
		for (int j = min; j <= max; j++){
			if (j%n == 0){
				b = i + 1;
			}
		}

		if (b != -1)break;
		
	}
	cout << b << endl;
	return 0;

}

Measured memory_bytes: 1164
import queue

def bfs(u):
    q = queue.Queue()
    q.put(u)
    
    while not q.empty():
        v = q.get()
        color[v] = 'black'
        ans.append(v)
        for w in Adj[v]:
            indeg[w] -= 1
            if indeg[w] == 0 and color[w] == 'white':
                q.put(w)
                
    return
        

n,m = map(int,input().split())
color = ['white' for _ in range(n)]
Adj = [[] for _ in range(n)]
indeg = [0]*n
ans = []
for i in range(m):
    s,t = map(int,input().split())
    Adj[s].append(t)
    indeg[t] += 1
    
for i in range(n):
    if indeg[i] == 0 and color[i] == 'white':
        bfs(i)
        
for i in range(n):
    print(ans[i])


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

int main(){
  string S;
  cin >> S;
  int N, M;
  N = S.size();
  M = 0;
  if (N % 2 == 0){
    for (int i = 0; i < N / 2; i++){
      if (S.at(i) != S.at(N - 1 - i)){
        M = M + 1;
      }
    }
  }
  else {
    for (int i = 0; i < (N - 1) / 2; i++){
      if (S.at(i) != S.at(N - 1 - i)){
        M = M + 1;
      }
    }
  }
  cout << M << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;
bool dp[101][10001];

int main(){
  int N;
  cin >> N;
  vector<int> s(N+1);
  REPS(i,N) cin >> s[i];
  dp[0][0] = true;
  REPS(i,N){
    REP(j,10001){
      dp[i][j] = dp[i-1][j];
      if(j >= s[i]) dp[i][j] = dp[i][j] || dp[i-1][j-s[i]];
    }
  }
  int ans = 0;
  RREP(i,10000){
    if(i%10 != 0 && dp[N][i]){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1280
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int fiveHundred = sc.nextInt();
    int oneHundred = sc.nextInt();
    int fifty = sc.nextInt();
    int totalYen = sc.nextInt();
    int[] coins = new int[51];
    int count = 0;
    for (int i = 0; i <= 50; i++) {
      coins[i] = i;
    }
    for (int j = 0; j <= fiveHundred; j++) {
      for (int k = 0; k <= oneHundred; k++) {
        for (int l = 0; l <= fifty; l++) {
          if (500 * j + 100 * k + 50 * l == totalYen) {
            count++;
          }
        }
      } 
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<algorithm>
using namespace std;

void rist_hen(int hu);
vector<int> batu;
int ristl[1111],ristr[1111];
int n,flag;

int main(){
  string str[3] = {"Fizz" , "Buzz" , "FizzBuzz" };
  int m;
  string s;
  while(cin >> n >> m && n && m){
    flag = n;
    for(int i=0;i<n;i++){
      ristl[i] = i-1;
      ristr[i] = i+1;
    }
    ristr[n-1] = 0;
    ristl[0] = n-1;
    batu.clear();
    int now = 0;
    for(int i=1;i<=m;i++){
      cin >> s;
      if(flag == 1) continue;
      if(i%3 == 0 && i%5 == 0){
	if(s != str[2]) rist_hen(now);
      }
      else if(i%3 == 0){
	if(s != str[0]) rist_hen(now);
      }
      else if(i%5 == 0){
	if(s != str[1]) rist_hen(now);
      }
      else {
	stringstream ss;
	ss << i;
	string tmp = ss.str();
	if(s != tmp) rist_hen(now);
      }
      now = ristr[now];
    }
    int ans[111111];
    int cou = 0;
    for(int i=1;i<=n;i++){
      vector<int>::iterator it;
      it = find(batu.begin(),batu.end(),i);
      if(it != batu.end());
      else{
	ans[cou] = i;
	cou++;
      }
    }
    for(int i=0;i<cou;i++){
      cout << ans[i];
      if(cou-1 == i) cout << endl;
      else cout << " ";
    }
  }
}

void rist_hen(int hu){
  //cout << "HU = " << hu << endl;
  ristl[ristr[hu]] = ristl[hu];
  ristr[ristl[hu]] = ristr[hu];
  batu.push_back(hu+1);
  flag--;
  return;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    int a, b, c;
    cin >> a >> b >> c;
    map<int, int> mp;
    mp[a]++;
    mp[b]++;
    mp[c]++;

    cout << mp.size() << endl;
    return 0;
}

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

#define Fast           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO             freopen("in.txt", "r", stdin)
#define FC             freopen("out.txt", "w", stdout)
#define aise           cout<<"aise"<<endl
#define pb             push_back
#define pf             push_front
#define ppb            pop_back
#define ppf            pop_front
#define mp             make_pair
#define ll             long long
#define all(x)         x.begin(), x.end()
#define mset(v, a)     memset(v, a, sizeof(v))
#define pll            pair< ll, ll >
#define pd             pair< double, double >
#define ff             first
#define ss             second
#define pi             acos(-1.0)
#define mxN            2010
#define inf            1e14
#define mod            1000000007
#define tc             ll tc;scanf("%lld",&tc);while(tc--)

//NCR iterative
/*voidcomb_table(intN)
{
    for(inti=0; i<=N; ++i)
    {
        for(intj=0; j<=i; ++j)
        {
            if(j==0or j==i)
            {
                C[i][j]=1LL;
            }
            else
            {
                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
            }
        }
    }
}*/


//NCR recursive
/*ll dp[55][55];

ll NCR(ll n,ll r)
{

    if(n==r)
        return dp[n][r]=1;
    if(r==0)
        return dp[n][r]= 1;
    if(r==1)
        return dp[n][r]=n ;
    if(dp[n][r] != -1)
        return dp[n][r];
    return dp[n][r] = NCR(n-1,r)+NCR(n-1,r-1);
}*/

//Sieve:
/*bool Flag[1000010];
vector<ll> Prime;

void sieve()
{

    ll val=sqrt(1000010);
    for(ll i=4;i<=1000005; i+=2) Flag[i]=1;
    for(ll i=3;i <= val;i+=2)
    {

        if(Flag[i]==0)
        {

            for(ll j=i*i;j<=1000005;j+=i) Flag[j]=1;
        }
    }
    Flag[1]=1;
    for(ll i=1;i<=1000000;i++)
        if(Flag[i]==0) Prime.pb(i);
}*/


//Conversion
/*string bin(ll x)
{

    string ret;
    while(x)
    {

        ll t=x%2;
        char c;
        if(t==1)
            c='1';
        else
            c='0';
        ret.pb(c);
        x/=2;
    }
    reverse(all(ret));
    return ret;
}*/

/*ll lcm(ll x, ll y)
{

    ll ret=__gcd(x,y);
    return (x*y)/ret;
}*/

/*ll dx[]= {0,0,1,-1};
ll dy[]= {1,-1,0,0};*/

ll col[100010];
vector<pll> adj[100010];
bool vis[100010];

void dfs(ll nd, ll cl)
{

    vis[nd]=1;
    col[nd]=cl;
    ll rev;
    if(cl==1) rev=0;
    else rev=1;
    for(ll i=0;i<adj[nd].size();i++)
    {

        ll v=adj[nd][i].ff;
        ll dis=adj[nd][i].ss;
        if(vis[v]) continue;
        if(dis%2) dfs(v,rev);
        else dfs(v,cl);
    }
}

int main()
{

    ll n, ans = 0;
    cin >> n;
    for(ll i = 0; i < n; i++)
    {

        ll a;
        cin >> a;
        ans = __gcd(ans, a);
    }
    cout << ans;
}


Measured memory_bytes: 5984
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();

		System.out.println(a % x == 0 ? b / x - a / x + 1 : b / x - a / x);

	}

}


Measured memory_bytes: 23892