akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int Head[N],Next[N<<1],Adj[N<<1],tot=0;
inline void addedge(int u,int v){
	Next[++tot]=Head[u],Head[u]=tot,Adj[tot]=v;
	Next[++tot]=Head[v],Head[v]=tot,Adj[tot]=u;
}
int L[N],R[N];
bool flag,p[N];
inline void check(int x,int f,bool t){
	p[x]=t;
	if (L[x]==R[x]) {
		if ((L[x]&1)!=t) {
			flag=false;
			return;
		}
	}
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=f) check(Adj[e],x,t^1);
}
inline int Min(int a,int b){
	return a<b?a:b;
}
inline int Max(int a,int b){
	return a>b?a:b;
}
inline void dfs(int x,int f){
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=f){
			dfs(Adj[e],x);
			L[x]=Max(L[Adj[e]]-1,L[x]);
			R[x]=Min(R[Adj[e]]+1,R[x]);
		}
}
inline void dfs2(int x,int f){
	if (f){
		L[x]=Max(L[f]-1,L[x]);
		R[x]=Min(R[f]+1,R[x]);
		if (L[x]>R[x]){
			puts("No");
			exit(0);
		}
	}
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=f)
			dfs2(Adj[e],x);
}
int a[N];
inline void getans(int x,int f,int lst){
	if (L[x]<=lst-1) a[x]=--lst;
	else a[x]=++lst;
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=f) getans(Adj[e],x,lst);
}
int main (){
	memset (L,-0x3f,sizeof(L));
	memset (R,0x3f,sizeof(R));
	int n;scanf ("%d",&n);
	for (int i=1,u,v;i<n;i++){
		scanf ("%d%d",&u,&v);
		addedge(u,v);
	}
	int m;scanf ("%d",&m);
	int rt=1;
	for (int i=1,x,v;i<=m;i++){
		scanf ("%d%d",&x,&v);
		rt=x;
		L[x]=R[x]=v;
	}
	flag=true,check(rt,0,L[rt]&1);
	if (!flag) {
		puts("No");
		return 0;
	}
	dfs(rt,0);
	dfs2(rt,0);
	puts("Yes");
	getans(rt,0,L[rt]-1);
	for (int i=1;i<=n;i++) printf ("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>
int main(void){
    int a,b,c,d=0,i=0;
    scanf("%d%d%d",&a,&b,&c);
    while(1){
        i++;
        d=d+a;
        if(i%7==0)d=d+b;
        if(c<=d){
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include <vector>

int main () {
  int a, b, c, cnt = 0;
  std::cin >> a >> b >> c;
  for (int i = a; i <= b; i++)
  {
    if (c % i == 0)
      cnt++;
  }
  std::cout << cnt << std::endl;
  return 0;
}


Measured memory_bytes: 3108
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
#include<iomanip>
#include<numeric>
using namespace std;

int main(){
  string s;

  //cout<<"a"<<endl;

  cin>>s;
//  cout<<"b "<<s<<endl;


  int l=s.length();
  vector<char> t(l);
//  cout<<l<<" "<<s[0]<<endl;

  for(int i=0;i<l;i++)t.at(i)=s[i];
//  cout<<"f "<<t.at(0)<<endl;
  sort(t.begin(),t.end());
  //for(int i=0;i<l;i++)cout<<t.at(i);
  bool flag=true;
  for(int i=0;i<l/2;i+=2)if(t.at(i)!=t.at(i+1))flag=false;
  if(flag&&l%2==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int main()
{
	int n, m;
	char ch;
	while (cin >> n, n) {
		vector< pair<char, char> > v(n);
		for (int i = 0; i < n; i++) {
			cin >> v[i].first >> v[i].second;
		}
		cin >> m;
		string str;
		str.reserve(m);
		for (int i = 0; i < m; i++) {
			cin >> ch;
			for (int j = 0; j < v.size(); j++) {
				if (ch == v[j].first) {
					ch = v[j].second;
					break;
				}
			}
			str += ch;
		}
		cout << str << endl;
	}
	return 0;
}

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

#define pb push_back
#define ll long long
#define pi pair<int,int>
#define pii pair<int,pi>
#define pl pair<ll,ll>
#define pll pair<ll,pl>
#define debug cout<<"debugging"<<endl
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int I_LIMIT = 999999999;
ll L_LIMIT = 19999999999999999;
ll mod = 1000000007;
vector <int> v[100005];

void solve()
{
    int n,i;
    cin>>n;
    int A[n][2];
    for(i=0;i<n;i++)
        cin>>A[i][0]>>A[i][1];
    
    for(i=0;i<=n-3;i++)
    {
        if(A[i][0]==A[i][1] && A[i+1][0]==A[i+1][1] && A[i+2][0]==A[i+2][1])
        {
            cout<<"Yes\n";
            return;
        }
    }
    cout<<"No\n";
    return;
}
int main()
{
    IOS;
    solve();
}


Measured memory_bytes: 5988
from collections import Counter


class SmallestPrimeFactors:
    def __init__(self, n):
        self.spf = list(range(n + 1))
        self.spf[0] = -1
        self.spf[1] = -1
        for i in range(2, int(n ** 0.5) + 1):
            if self.spf[i] == i:
                for j in range(i * i, n + 1, i):
                    if self.spf[j] == j:
                        self.spf[j] = i

    def is_prime(self, x):
        return self.spf[x] == x

    def __traverse(self, x):
        if self.spf[x] == x:
            return [x]
        nxt = x // self.spf[x]
        return self.__traverse(nxt) + [self.spf[x]]

    def factor(self, x):
        if x < 2:
            return []
        return self.__traverse(x)


spf = SmallestPrimeFactors(1_000_000)
N = int(input())
ans = 0
for C in range(1, N):
    fac = Counter(spf.factor(N - C))
    tmp = 1
    for v in fac.values():
        tmp *= v + 1
    ans += tmp
print(ans)

Measured memory_bytes: 86832
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
using namespace std;

int main() {
	char ch = getchar();
	int res = 0, ans;
	while(ch < '0' || ch > '9') ch = getchar();
	while(ch >= '0' && ch <= '9') res *= 10,res += ch - '0',ans += ch - '0',  ch = getchar();
	if(res % ans == 0) printf("Yes\n");
	else printf("No\n");
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;
int min(int a,int b){
    return (a<b)?a:b;
}
int max(int a,int b){
    return (a>b)?a:b;
}
int fp(int a,int b){
    if(b==0) return 1;
    int x=fp(a,b/2);
    x=(x*x)%mod;
    if(b&1) x=(x*a)%mod;
    return x;
}


signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 int n,x=0,y,k;
 cin>>n;
 int a[n+1];
 for(int i=1;i<=n;i++)
 {
    cin>>a[i];
    x^=a[i];
 }
 for(int i=1;i<=n;i++)
 {
    cout<<(a[i]^x)<<" ";
 }


}

Measured memory_bytes: 5180
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
#define lp(k,a) for(int k=1;k<=a;k++)
#define lp0(k,a) for(int k=0;k<a;k++)
#define lpn(k,n,a) for(int k=n;k<=a;k++)
#define lpd(k,n,a) for(int k=n;k>=a;k--)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define ll long long
#define MAX 100000

using namespace std;

char s[10];
int ha[1000];
int a,b,c,d;
int re=0;
int main()
{
   // freopen("in.txt","r",stdin);
    cin>>a>>b>>c>>d;
    b--; d--;
    lpn(i,a,b)
     ha[i]+=1;
     lpn(i,c,d)
      ha[i]+=1;
    lpn(i,0,100)
    {
        if(ha[i]==2)
            re++;
    }
    cout<<re<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

double p[3005],dp[3005][3005];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n;
  cin>>n;
  forn(i,1,n+1){
    cin>>p[i];
  }
  dp[0][0]=1.0;
  for(ll i=1;i<=n;i++){
    for(ll j=0;j<=i;j++){
      double a=0.0,b=0.0;
      if(j<=i-1)
        a=dp[i-1][j]*(1.0-p[i]);
      if(j>=1 && j<=i)
        b=dp[i-1][j-1]*p[i];
      dp[i][j]=a+b;
    }
  }
  double ans=0;
  for(ll i=0;i<=n;i++)
    if(i>n-i)
      ans+=dp[n][i];
  cout<<fixed<<setprecision(10)<<ans<<endl;
  return 0;
}


Measured memory_bytes: 69120
from __future__ import division
import sys
if sys.version_info[0]>=3: raw_input=input

X=4
Y=2
i=0
m={}
prev={}
v=[]
for i in range(X*Y): v.append(str(i))
m[''.join(v)]=[0,0]
prev[''.join(v)]=[''.join(v),None]
q=[v]
while len(q)>0:
	v=q.pop(0)
	coor=m[''.join(v)][0]
	x=coor%X
	y=coor//X
	depth=m[''.join(v)][1]
	nextstr=''.join(v)
	if 0<x:
		v[coor],v[coor-1]=v[coor-1],v[coor]
		if ''.join(v) not in m:
			m[''.join(v)]=[coor-1,depth+1]
			q.append(v[:])
			prev[''.join(v)]=[nextstr,'R']
		v[coor],v[coor-1]=v[coor-1],v[coor]
	if x<X-1:
		v[coor],v[coor+1]=v[coor+1],v[coor]
		if ''.join(v) not in m:
			m[''.join(v)]=[coor+1,depth+1]
			q.append(v[:])
			prev[''.join(v)]=[nextstr,'L']
		v[coor],v[coor+1]=v[coor+1],v[coor]
	if 0<y:
		v[coor],v[coor-X]=v[coor-X],v[coor]
		if ''.join(v) not in m:
			m[''.join(v)]=[coor-X,depth+1]
			q.append(v[:])
			prev[''.join(v)]=[nextstr,'D']
		v[coor],v[coor-X]=v[coor-X],v[coor]
	if y<Y-1:
		v[coor],v[coor+X]=v[coor+X],v[coor]
		if ''.join(v) not in m:
			m[''.join(v)]=[coor+X,depth+1]
			q.append(v[:])
			prev[''.join(v)]=[nextstr,'U']
		v[coor],v[coor+X]=v[coor+X],v[coor]

try:
	while True:
		v=raw_input().split()
		print(m[''.join(v)][1])
except EOFError:
	pass

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

typedef long long ll;
#define PB push_back

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	int h[n];
	for (int i = 0; i < n; ++i) cin >> h[i];
	int ans = 0;
	int a = 0;
	for (int i = 0; i < n - 1; ++i) {
		if (h[i + 1] <= h[i]) a++;
		else {
			a = 0;
		} 
		ans = max(a, ans);
	}
	cout << ans;
}

Measured memory_bytes: 640
import numpy as np
import sys
import distutils.util

h, w, k = (int(x) for x in input().split())
count = 0
map = ''
for i in range(h):
    map += sys.stdin.readline().replace('\n','')
map2 = [True]*len(map)
for i in range(len(map)):
    if map[i]=='.': map2[i]=False
map2 = np.array(map2, dtype=bool).reshape((h, w))

for i in range(2**h):
    tmp = bin(i)[2:]
    tmp = '0'*(h-len(tmp)) + tmp
    a = list((bool(distutils.util.strtobool(tmp[i]))
              for i in range(len(tmp))))
    tmp = np.array(a*w).reshape(w, h).transpose()
    for j in range(2**w):
        tmp2 = bin(j)[2:]
        tmp2 = '0'*(w-len(tmp2)) + tmp2
        b = list((bool(distutils.util.strtobool(tmp2[i]))
                  for i in range(len(tmp2))))
        tmp2 = np.array(b*h).reshape(h, w)
        if sum(sum(list(tmp & tmp2 & map2)))==k: count+=1

print (count)


Measured memory_bytes: 27516
#include "bits/stdc++.h"
using namespace std;
int main() {
	int R, G, B, N;
	cin >> R >> G >> B >> N;
	int r = N / R, g = N / G;
	long long ans = 0;
	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= g; j++) {
			if ((N - i * R - j * G) % B == 0 && (N - i * R - j * G) / B >= 0) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            List<List<int>> lstBng = new List<List<int>>();
            string[] sS;
            for (int i = 0; i < 3; i++)
            {
                sS = System.Console.ReadLine().Trim().Split(' ');
                List<int> lstRow = new List<int>();
                for (int j = 0; j < sS.Length; j++)
                {
                    lstRow.Add(int.Parse(sS[j]));
                }
                lstRow.Add(0);                                                              // 判別用フラグ(合致カウント)
                lstBng.Add(lstRow);                                                         // Bingo 横
            }
            string s2 = System.Console.ReadLine().Trim();
            int iN = int.Parse(s2);
            List<int> lstCal = new List<int>();
            for (int i = 0; i < iN; i++)
            {
                lstCal.Add(int.Parse(System.Console.ReadLine().Trim()));
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            lstBng.Add(new List<int>() { lstBng[0][0], lstBng[1][0], lstBng[2][0], 0 });    // Bingo縦
            lstBng.Add(new List<int>() { lstBng[0][1], lstBng[1][1], lstBng[2][1], 0 });    // Bingo縦
            lstBng.Add(new List<int>() { lstBng[0][2], lstBng[1][2], lstBng[2][2], 0 });    // Bingo縦
            lstBng.Add(new List<int>() { lstBng[0][0], lstBng[1][1], lstBng[2][2], 0 });    // Bingo斜
            lstBng.Add(new List<int>() { lstBng[0][2], lstBng[1][1], lstBng[0][2], 0 });    // Bingo斜
            for (int k = 0; k < lstCal.Count; k++)
            {
                for (int i = 0; i < lstBng.Count; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (lstBng[i][j] == lstCal[k]) { lstBng[i][3] += 1; }               // ヒットしたらその行/列/斜の合致カウント+1
                    }
                }
            }
            string sOut = "No";
            for (int i = 0; i < lstBng.Count; i++)
            {
                if (lstBng[i][3] >= 3) { sOut = "Yes"; break; }                             // 合致カウント3以上の行/列/斜はビンゴ
            }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	String ans = "No";
	int[][] ai = new int[3][3];
	for(int i = 0 ; i < 3; i++) {
		for(int j = 0; j < 3; j++) {
			ai[i][j] = sca.nextInt();
		}
	}
	boolean[][] flag = new boolean[3][3];
	for(int i = 0 ; i < 3; i++) {
		for(int j = 0; j < 3; j++) {
			flag[i][j] = false;
		}
	}
	int n = sca.nextInt();
	int[] b = new int[n];
	for(int i = 0; i < n; i++) {
		b[i] = sca.nextInt();
		for(int j = 0 ; j < 3; j++) {
			for(int k = 0; k < 3; k++) {
				if(b[i] == ai[j][k]) {
					flag[j][k] = true;
				}
			}
		}
	}

	if(flag[0][0] == true && flag[0][1] == true && flag[0][2] == true) {
		ans = "Yes";
	}
	else if(flag[1][0] == true && flag[1][1] == true && flag[1][2] == true) {
		ans = "Yes";
	}
	else if(flag[2][0] == true && flag[2][1] == true && flag[2][2] == true) {
		ans = "Yes";
	}
	else if(flag[0][0] == true && flag[1][0] == true && flag[2][0] == true) {
		ans = "Yes";
	}
	else if(flag[0][1] == true && flag[1][1] == true && flag[2][1] == true) {
		ans = "Yes";
	}
	else if(flag[0][2] == true && flag[1][2] == true && flag[2][2] == true) {
		ans = "Yes";
	}
	else if(flag[0][0] == true && flag[1][1] == true && flag[2][2] == true) {
		ans = "Yes";
	}
	else if(flag[0][2] == true && flag[1][1] == true && flag[2][0] == true) {
		ans = "Yes";
	}
	System.out.println(ans);

	// 後始末
	sca.close();
	}
}

Measured memory_bytes: 23764
//abc118_c.cpp
//Sun Mar 10 15:04:03 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n;
	cin >> n;

	int a[n];
	int mina = 1000000001;
	for (int i=0;i<n;i++){
		cin >> a[i];
		if (mina>a[i]){
			mina = a[i];
		}
	}

	int ans = 1000000001;
	while (ans != mina){
		ans = mina;
		for (int i=0;i<n;i++){
			int temp = a[i]%mina;
			if (temp>0 && mina>temp){
				mina = temp;
				break;
			}
		}
	}


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 640
A=gets.to_i
B=gets.to_i
C=gets.to_i
X=gets.to_i
y=0
(0..A).each do |a|
  (0..B).each do |b|
    (0..C).each do |c|
      y+=1 if 500*a+100*b+50*c == X
    end
  end
end
puts y

Measured memory_bytes: 1788
void main(){
	int n = inelm();
	( n*(1+n)/2 ).writeln();
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


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

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> v{ a, b, c };
  sort( v.begin(), v.end() );
  cout << v[2] - v[0] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cmath>
#include <iomanip>

struct Closed_Section_Double {
    bool valid; // 条件を満たす範囲が見つかったか。falseの場合、begin,endは意味を持たない。
    double begin; // [begin, end]で条件が成り立つ。
    double end;
    Closed_Section_Double(bool _valid, double _begin, double _end) { valid = _valid; begin = _begin; end = _end; }
};
 
Closed_Section_Double binary_search_double(double L, double R, double eps, std::function<bool(double)> func) {
    const bool resL = func(L);
    const bool resR = func(R);
    if (resL && resR) {
        return Closed_Section_Double(true, L, R);
    } else if (!resL && !resR) {
        return Closed_Section_Double(false, 0, 0);
    } else {
        double lb = L;
        double ub = R;
        while (eps < ub - lb && eps < (ub-lb)*2/(fabs(ub)+fabs(lb))) {
            double mid = (lb + ub) / 2;
            if (resL == func(mid)) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        if (resL) {
            return Closed_Section_Double(true, L, lb);
        } else {
            return Closed_Section_Double(true, ub, R);
        }
    } 
}

// end of template

double a, b, x;

double calc(double ang) {
    if (b*cos(ang) > a*sin(ang)) {
        double tmp = 0.5*a*a*a*tan(ang);
        return a*a*b - tmp;
    } else {
        return 0.5*a*b*b/tan(ang);
    }
}
 
int main(int argc, char **argv) {
    std::cout << std::fixed << std::setprecision(15);
    std::cin >> a >> b >> x;
 
    const double PI = acos(-1.0);
    const double EPS = 1.0e-12;

    if (a*a*b - EPS < x) {
        std::cout << 0.0 << std::endl;
        return 0;
    }
 
    auto cs = binary_search_double(EPS, 90.0-EPS, EPS, [&](double ang){
        return x < calc(PI/180.0 * ang);
    });
    std::cout << cs.end << std::endl;
}

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

int main(){
  long long N,x,a[105];
  cin>>N>>x;
  for(int t=0;t<N;t++)cin>>a[t];
  sort(a,a+N);

  int cont=0;
  for(int t=0;t<N;t++){
    if(x<=0)break;
    x-=a[t];
    if(x>=0){
    cont++;
    }
  }
  if(x>0)cont--;
  cout<<cont<<"\n";
  return 0;
}


Measured memory_bytes: 256
import collections
A,B = input().split()
A,B = int(A),int(B)
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A = collections.Counter(prime_factorize(A)).keys()
B = collections.Counter(prime_factorize(B)).keys()


cms = []
for a in A:
    for b in B:
        if(a==b):
            cms.append(a)
print(len(cms)+1)

Measured memory_bytes: 3316
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define dep(i, s, t) for(i = s; i >= t; --i)

using namespace std;

int n, ans;

int main() {
	int i, x, t, la;
	scanf("%d", &n);
	la = -1; t = 0;
	rep(i, 1, n) {
		scanf("%d", &x);
		if(x == la) ++t;
		else {ans += t/2; t = 1;}
		la = x;
	}
	ans += t/2;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
def zero_count(n)
  return 0 if n % 2 == 1
  n = n / 2
  count = 0
  div = 5
  exp = 1
  while div <= n
    count += n / div
    exp += 1
    div = 5**exp
  end
  count
end
puts zero_count(gets.to_i)


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

using namespace std;

int main(){
    string s;
    cin >> s;
    string w;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '0'){
            w = w + '0';
        }else if(s[i] == '1'){
            w = w + '1';
        }else{
            if(w.length() == 0){
                continue;
            }else{
                w.pop_back();
            }
        }
    }

    cout << w << endl;


    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
        int n;
        scanf("%d", &n);
        int hole[n], isIn[110], size=0, i;
        for(i=0; i<n; i++) hole[i]=0;
        for(i=0; i<110; i++) isIn[i]=0;

        for(i=0; i<n; i++){
                int c;
                scanf("%d", &c);
                if(c>0){
                        if(isIn[c-1]){
                                printf("%d\n", i+1);
                                return 0;
                        }
                        hole[size] = c;
                        size++;
                        isIn[c-1] = 1;
                }else{
                        if(size==0 || !isIn[-c-1] || hole[size-1]!=-c){
                                printf("%d\n", i+1);
                                return 0;
                        }
                        hole[size-1] = 0;
                        size--;
                        isIn[-c-1] = 0;
                }
        }
        puts("OK");
        return 0;
}


Measured memory_bytes: 2112
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

// Pは順列
// |P| = N
// LIS(P) = A
// LDS(P) = B
// Pを求めよ(ないかも)
// 1<=N,A,B<=3*10^5
// LISとLDSで重複している要素はたかだか1つなので
// A + B <= N + 1
// Nが大きすぎると駄目で
// 最大のケースで例えばA=2, B=3とすると
// N = A*B=6で
// 3, 2, 1, 6, 5, 4
// のように構成できる
// N <= A * B
// A + B - 1 <= N <= A*B
// 構成の仕方
// とりあえず先頭にB個の要素で{B, B-1, ,,,.,1}
// あとは大きさB以下で後ろに同様の単調減少列をくっつけていく

const int N_MAX = 3e5;
int N, A, B;
int ans[N_MAX];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    cin >> N >> A >> B;
    rep(i, N)ans[i] = i + 1;
    if (A + B - 1 <= N && N <= (ll)A*B) {
        reverse(ans, ans + B);
        for (int i = 1, k = B; i < A; ++i) {
            // n個の元をm個に分割
            // 分割の大きさCは
            // 1<=C<=min(n-(m-1), B)
            int n = N - k, m = A - i;
            int C = min(n - m + 1, B);
            reverse(ans + k, ans + k + C);
            k += C;
        }
        rep(i, N)cout << ans[i] << (i != N - 1 ? ' ' : '\n');
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fore(b,c) for(int val0=b;val0<c;val0++)
#define forr(k,c,s) for(int k=c;k<s;k++)
#define pb push_back
#define mmp make_pair
#define oset(T) tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long double ld;
typedef vector<vii> al;
typedef vector<ll> vl;
const int INF = 1e9;
const ll INFL = 1LL<<61;
int g[2020][2020],h[2020][2020];
ii dp[2020][2020];
int main() {
	ios::sync_with_stdio(0);cout.precision(20);cout.tie(0);cin.tie(0);
	int n,m;
	cin >> n >> m;
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			char c;
			cin >> c;
			g[i][j] = (c == '#');
		}
	}
	for(int i=0;i<n-1;i++) {
		for(int j=0;j<m-1;j++) {
			h[i][j] = 1-((g[i][j] + g[i+1][j] + g[i][j+1] + g[i+1][j+1])%2);
		}
	}
	int ma = max(n,m);
	for(int i=0;i<n;i++) {
		for(int j=0;j<m-1;j++) {
			if(h[i][j]) {
				if(i > 0) {
					h[i][j] = max(h[i-1][j]+1,2);
				} else {
					h[i][j] = 2;
				}
			}
		}
		stack<int> st;
		int v,mc = 0;
		int id = 0;
		while(id < m-1) {
			if(st.empty() || h[i][st.top()] <= h[i][id]) {
				st.push(id++);
			} else {
				v = h[i][st.top()];
				st.pop();
				mc = v*(id+1);
				if(!st.empty()) {
					mc = v*(id-st.top());
				}
				ma = max(ma,mc);
			}
		}
		while(!st.empty()) {
			v = h[i][st.top()];st.pop();
			mc = v*(id+1);
			if(!st.empty()) {
				mc = v*(id-st.top());
			}
			ma = max(ma,mc);
		}
	}
	cout << ma << '\n';
}

Measured memory_bytes: 33152
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

n, x, d = [int(item) for item in input().split()]

if d == 0:
    if x == 0:
        print(1)
    else:
        print(n+1)
    exit()

range_in_kXmodD = dict() 
for i in range(0, n+1):
    kXmodD = i * x % d
    start = (i * x) // d + i * (i - 1) // 2
    end = (i * x) // d + i * (n - i + n - 1) // 2 + 1
    if kXmodD not in range_in_kXmodD:
        range_in_kXmodD[kXmodD] = []
    range_in_kXmodD[kXmodD].append((start, 1))
    range_in_kXmodD[kXmodD].append((end, -1))

ans = 0
for key in range_in_kXmodD.keys():
    range_in_kXmodD[key].sort()
    ret = 0
    cnt = 0
    prev = None 
    for val, c in range_in_kXmodD[key]:
        if prev != None and cnt > 0:
            ret += val - prev
        cnt += c
        prev = val
    ans += ret

print(ans)

Measured memory_bytes: 84528
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
const int INF = 1e9;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */

double pow(double a)
{
	return a*a;
}

int main()
{
	int N, M;
	cin>>N>>M;
	
	vector<double> L(N), A(N), B(N);
	rep(i, N) {
		cin>>L[i]>>A[i]>>B[i];
	}
	
	double ans = 0;
	for (int S=0; S<1<<N; S++) {
		if (__builtin_popcount(S) == M) {
			double tmp=0;
			
			for (int i=0; i<N; i++) {
				if (!(1<<i & S)) continue;
				for (int j=i+1; j<N; j++) {
					if (!(1<<j & S)) continue;
					tmp += pow(L[i]-L[j]) + pow(A[i]-A[j]) + pow(B[i]-B[j]);
				}
			}
			ans = max(ans, tmp);
		}
	}
	
	cout << fixed << setprecision(15);
	cout << ans << endl;
}

Measured memory_bytes: 1296
input = STDIN.read.to_i

def count_yakusu(n)
  ct = 0
  for i in 1..n
    if n % i == 0
      ct = ct + 1
    end
  end
  return ct
end

ct = 0
for i in 1..input
  if i % 2 == 1 && count_yakusu(i) == 8
    ct = ct + 1
  end
end

print ct


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
  int n;
  double ans = 0.0, a;
  cin >> n;
  for(int i = 1; i <= n; ++i) {
    cin >> a;
    ans += 1.0/a;
  }
  ans = 1.0/ans;
  cout << setprecision(16) << ans << endl;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline

# C - management
N = int(input())
A = list(map(int, input().split()))
dic = dict()

for i in range(1, N + 1):
	dic[i] = 0

for a in A:
	dic[a] += 1

for v in dic.values():
	print(v)

Measured memory_bytes: 40076
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
inline int read()
{
	rg int res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int ans;
char s[5], t[5];
int main()
{
	rg int nt;
	scanf("%s%s", s, t);
	for (int i = 0; i < 3;i++)
		ans += s[i] == t[i];
	cout << ans << endl;
	return 0;
}
//A

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    char S[11],U[11],V[11];
    string A,B,C;
    int a,b;
    while(cin>>S>>U>>a>>b){
        cin>>V;
        A=S;B=U;C=V;
        if(C==A) a--;
        if(C==B) b--;
        cout<<a<<" "<<b<<endl;
    }

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;typedef long long lint;typedef vector<lint> liv;
//#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define linf 1152921504606846976
#define MAXN 100010
#define md 1000000007//998244353

#define _vcppunko4(tuple) _getname4 tuple
#define _getname4(_1,_2,_3,_4,name,...) name
#define _getname3(_1,_2,_3,name,...) name
#define _trep2(tuple) _rep2 tuple
#define _trep3(tuple) _rep3 tuple
#define _trep4(tuple) _rep4 tuple
#define _rep1(n) for(lint i=0;i<n;++i)
#define _rep2(i,n) for(lint i=0;i<n;++i)
#define _rep3(i,a,b) for(lint i=a;i<b;++i)
#define _rep4(i,a,b,c) for(lint i=a;i<b;i+=c)
#define _trrep2(tuple) _rrep2 tuple
#define _trrep3(tuple) _rrep3 tuple
#define _trrep4(tuple) _rrep4 tuple
#define _rrep1(n) for(lint i=n-1;i>=0;i--)
#define _rrep2(i,n) for(lint i=n-1;i>=0;i--)
#define _rrep3(i,a,b) for(lint i=b-1;i>=a;i--)
#define _rrep4(i,a,b,c) for(lint i=a+(b-a-1)/c*c;i>=a;i-=c)
template<class T>
istream& operator>>(istream& is,vector<T>& vec);
template<class T,size_t size>
istream& operator>>(istream& is,array<T,size>& vec);
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p);
template<class T>
ostream& operator<<(ostream& os,vector<T>& vec);
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p);
template<class T>
istream& operator>>(istream& is,vector<T>& vec){ for(T& x: vec) is>>x;return is; }
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p){ is>>p.first;is>>p.second;return is; }
//template<class T>
//ostream& operator<<(ostream& os,vector<T>& vec){ os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; }
//template<class T>
//ostream& operator<<(ostream& os,deque<T>& deq){ os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; }
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p){ os<<p.first<<" "<<p.second;return os; }

inline void in(){}
template <class Head,class... Tail>
inline void in(Head&& head,Tail&&... tail){ cin>>head;in(move(tail)...); }
template <class T>
inline bool out(T t){ cout<<t<<'\n';return 0; }
inline bool out(){ cout<<'\n';return 0; }
template <class Head,class... Tail>
inline bool out(Head head,Tail... tail){ cout<<head<<' ';out(move(tail)...);return 0; }

#define rep(...) _vcppunko4((__VA_ARGS__,_trep4,_trep3,_trep2,_rep1))((__VA_ARGS__))
#define rrep(...) _vcppunko4((__VA_ARGS__,_trrep4,_trrep3,_trrep2,_trrep1))((__VA_ARGS__))
#define lin(...) lint __VA_ARGS__;in(__VA_ARGS__)
#define stin(...) string __VA_ARGS__;in(__VA_ARGS__)
#define vin(type,name,size) vector<type> name(size);in(name)

int main(){
	lin(n,q);
	stin(s);
	vector<lint>l(q),r(q),a(n),su(n+1),su2(n+1);
	rep(i,q)in(l[i],r[i]);
	if(s[0]=='A')a[0]=1;
	rep(i,1,n){
		if(a[i-1]==1){
			if(s[i]=='C')a[i]=2;
			else a[i-1]=0;
		}
		if(s[i]=='A')a[i]=1;
	}
	rep(i,n){
		su[i+1]=su[i],su2[i+1]=su2[i];
		if(a[i]==1)++su[i+1];
		if(a[i]==2)++su2[i+1];
	}
	rep(Q,q){
		cout<<su2[r[Q]]-su[l[Q]-1]<<endl;
	}
}

Measured memory_bytes: 4992
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N, X := sc.nextInt(), sc.nextInt()
	L := sc.nextIntSlice(N)
	before := 0
	count := 1
	for i := 0; i < N; i++ {
		if before+L[i] > X {
			break
		}
		before += L[i]
		count++
	}
	fmt.Println(count)
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
#include <complex>
#include <cassert>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define deb(a) cerr<< #a << "= " << (a)<<"\n";

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef complex<double> base;
typedef vector<int> vi;
typedef pair<int,int> pii;

template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream; }
ll fpow(ll x, ll p, ll m){ll r=1; for (;p;p>>=1){ if (p&1) r=r*x%m; x=x*x%m; } return r;}
ll inv(ll a, ll b){ return a<2 ? a : ((a-inv(b%a,a))*b+1)/a%b; }
int gcd(int a, int b){ if (!b) return a; return gcd(b,a%b);}
ll gcd(ll a, ll b){ if (!b) return a; return gcd(b,a%b);}

const ll maxv=101000;

ll N,a[2010]; bool v[2][maxv*2+40];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	
	int i,k; ll sum=0,dif=0;
	for (i=1; i<=N; i++){
		cin >> a[i];
		sum+=a[i];
	}
		
	v[0][maxv]=1; 
	bool l=0;
	for (i=1; i<=N; i++){
		l=!l;
		memset(v[l],0,sizeof(v[l]));
		
		for (k=-maxv; k<=maxv; k++)
			if (v[!l][k+maxv]){
				if (abs(k+a[i])<=maxv) v[l][k+a[i]+maxv]=1;
				if (abs(k-a[i])<=maxv) v[l][k-a[i]+maxv]=1;
			}
	}
	
	for (i=maxv; i<=2*maxv; i++)
		if (v[l][i]){
			dif=i-maxv;
			
			break;
		}
		
	cout << (sum+dif)/2 << "\n";
	return 0;
}



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

struct node{
  int key;
  struct node *p;
  struct node *l;
  struct node *r;
};

typedef struct node *NodePointer;

NodePointer r,NIL;

NodePointer getMinimum(NodePointer x){
  while(x->l != NIL){
    x = x->l;
  }
  return x;
}


NodePointer find(NodePointer x,int k){
  while(x != NIL && k != x->key){
    if(k < x->key){
      x = x->l;
    }else{
      x = x->r;
    }
  }
  return x;
}

NodePointer getSuccessor(NodePointer x){
  NodePointer k;
  if(x->r != NIL){
    return getMinimum(x->r);
  }

  k = x->p;
  while(k != NIL && x ==k->r){
    x = k;
    k = k->p;
  }

  return k;
  
}

void delete(NodePointer z){
  NodePointer x;
  NodePointer y;

  if(z->l == NIL || z->r == NIL){
    y = z;
  }else{
    y = getSuccessor(z);
  }

  if(y->l != NIL){
    x = y->l;
  }else{
    x = y->r;
  }

  if(x != NIL){
    x->p = y->p;
  }

  if(y->p == NIL){
    r = x;
  }else{
    if(y == y->p->l){
      y->p->l = x;
    }else{
      y->p->r = x;
    }
  }

  if(y != z){
    z->key = y->key;
  }
}

void insert(int k){
  NodePointer y = NIL;
  NodePointer x = r;

  NodePointer z = (NodePointer)malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->l;
    }else{
      x = x->r;
    }
  }
  z->p = y;

  if(y == NIL){
    r = z;
  }else if(z->key < y->key){
    y->l = z;
  }else{
    y->r = z;
  }
}

void inorder(NodePointer u){
  if(u == NIL){
    return;
  }
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
  
}

void preorder(NodePointer u){
  if(u == NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
  
}

void print(){
  inorder(r);
  puts("");
  preorder(r);
  puts("");
  
}

int main(){
  int n,i,j,z,k;
  char s[10];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",s);
    if(s[0] == 'f'){
      scanf("%d",&k);
      NodePointer t = find(r,k);
      if(t == NIL)printf("no\n");
      else printf("yes\n");

    }else if(s[0] == 'i'){
      scanf("%d",&z);
      insert(z);
    }else if(s[0] == 'd'){
      scanf("%d",&z);
      delete(find(r,z));
    }else{
      print();
    }
  }

  return 0;
}



Measured memory_bytes: 20460
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

const int MAXR = 21;
const int MAXC = 21;
const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};

struct State {
  int i, j, d, m;
  State();
  State(int i, int j, int d, int m) 
    : i(i), j(j), d(d), m(m) {}
};

int R, C;
char G[MAXR][MAXC];
bool vis[MAXR][MAXC][4][16];

bool canFinish() {
  State s(0,0,0,0);
  queue<State> que;
  que.push(s);
  fill(vis[0][0][0], vis[MAXR][0][0], false);
  vis[s.i][s.j][s.d][s.m] = true;

  while(!que.empty()) {
    s = que.front();
    que.pop();

    if(isdigit(G[s.i][s.j])) {
      s.m = G[s.i][s.j] - '0';
    } else {
      switch(G[s.i][s.j]) {
      case '<':
	s.d = 2;
	break;
      case '>':
	s.d = 0;
	break;
      case '^':
	s.d = 3;
	break;
      case 'v':
	s.d = 1;
	break;
      case '_':
	if(s.m == 0) s.d = 0;
	else s.d = 2;
	break;
      case '|':
	if(s.m == 0) s.d = 1;
	else s.d = 3;
	break;
      case '?':
	s.d = -1;
	break;
      case '.':
	//
	break;
      case '@':
	return true;
      case '+':
	s.m = (s.m+1)%16;
	break;
      case '-':
	s.m = (s.m-1+16)%16;
	break;
      }
    }

    vector<State> next;
    if(s.d == -1) {
      for(s.d = 0; s.d < 4; ++s.d) {
	next.push_back(s);
      }
    } else {
      next.push_back(s);
    }

    for(int k = 0; k < next.size(); ++k) {
      State &t = next[k];
      t.i = (t.i + di[t.d] + R) % R;
      t.j = (t.j + dj[t.d] + C) % C;
      if(vis[t.i][t.j][t.d][t.m]) continue;
      vis[t.i][t.j][t.d][t.m] = true;
      que.push(t);
    }
  }
  return false;
}

int main() {
  while(cin >> R >> C) {
    for(int i = 0; i < R; ++i) {
      for(int j = 0; j < C; ++j) {
	cin >> G[i][j];
      }
    }
    if(canFinish()) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define vp vector <pi>
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1n(x,n) for(int x = 1; x <= n ;++ x)
#define forn1(x,n) for(int x = 1; x < n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC optimize ("Ofast")
void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F &f, R&... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

int main(){
	IOS

	ll n,m;
	cin>>n>>m;
	vl v(n);
	cin>>v;
	priority_queue<ll> p;

	forn(i,n)
	{
		p.push(v[i]);
	}
	ll temp;
	while(m)
	{
		temp = p.top();
		p.pop();
		p.push(temp/2);
		m--;
	}
	ll sum = 0;
	while(!p.empty())
	{
		sum += p.top();
		p.pop();
	}
	cout<<sum;
 
	return 0;	
}

Measured memory_bytes: 2168
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
L=[0]
R=[0]
for i in range(n-1):
    L.append(gcd(L[i],a[i]))
    R.append(gcd(R[i],a[-1-i]))
MAX=0
for i in range(n):
    MAX=max(MAX,gcd(L[i],R[-1-i]))
print(MAX)

Measured memory_bytes: 16144
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const string NO = "IMPOSSIBLE";

void solve(long long A, long long B){
  if((A+B)%2){
    cout<<NO<<endl;
  }else{
    cout<<(A+B)/2<<endl;
  }
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=2e5+4;
const int mod=998244353;
int dp[N];
int pre[N];
void solve(){
    memset(dp,0,sizeof dp);
    memset(pre,0,sizeof pre);
    int n,k; cin>>n>>k;
    std::vector<pair<int,int>> v;
    while(k--){
        int a,b; cin>>a>>b;
        v.push_back({a,b});
    }
    dp[1]=1;
    pre[0]=0,pre[1]=1;
    for(int i=2;i<=n;i++){
        for(auto j:v){
            int r=max(0LL,i-j.first);
            int l=max(0LL,i-j.second-1);
            dp[i]=(dp[i]+pre[r]-pre[l])%mod;
        }
        pre[i]=pre[i-1]+dp[i];
    }
    cout<<dp[n]<<endl;
}   
int32_t main(){
    int tt; 
    tt=1;
    // cin>>tt;
    for(int t=1;t<=tt;t++){
        solve();
    }
}

  

Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long INF = 100000000000LL;
    int A,B,Q;
    std::cin >> A >> B >> Q;
    vector<long long> s(A+2),t(B+2),x(Q);
    s[0]=-INF,s[A+1]=INF;
    t[0]=-INF,t[B+1]=INF;
    for (int i=1;i<=A;i++) std::cin >> s[i];
    for (int i=1;i<=B;i++) std::cin >> t[i];
    for (int i=0;i<Q;i++) std::cin >> x[i];
    
    long long x0,d;
    int is1,is2,ism,it1,it2,itm;
    for (int i=0;i<Q;i++) {
        long long x0 = x[i];
        is1=0;
        is2=A+1;
        while (is2-is1>1) {
            ism = (is1+is2)/2;
            if (s[ism] < x0) is1 = ism;
            else is2 = ism;
        }
        it1=0;
        it2=B+1;
        while (it2-it1>1) {
            itm = (it1+it2)/2;
            if (t[itm] < x0) it1 = itm;
            else it2 = itm;
        }
        long long ans = INF;
        for (int j=0;j<2;j++) {
            d = abs(s[is1+j] - x0) + min(abs(t[it1]-s[is1+j]), abs(t[it1+1]-s[is1+j]));
            if (ans>d) {
                ans = d;
            }
        }
        for (int j=0;j<2;j++) {
            d = abs(t[it1+j] - x0) + min(abs(s[is1]-t[it1+j]), abs(s[is1+1]-t[it1+j]));
            if (ans>d) {
                ans = d;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 3712
use std::str::FromStr;
use std::fmt::Debug;
use std::collections::BinaryHeap;

fn read_line<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

fn main() {
    let vec: Vec<i32> = read_line();
    let arr: Vec<i64> = read_line();
    let (_n, m) = (vec[0], vec[1]);

    let mut heap: BinaryHeap<i64> = BinaryHeap::new();

    for i in 0..arr.len() { heap.push(arr[i]); }

    for _ in 0..m {
        let n: i64 = heap.pop().unwrap();
        heap.push(n / 2);
    }
    let ans: i64 = heap.iter().sum();
    println!("{}", ans);
}

Measured memory_bytes: 8444
#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;
using pii = pair<int, int>;
set<int> s;
int main(){
    int n;
    scanf("%d",&n);
    int x;
    for(int i =0;i<n;i++){
        scanf("%d",&x);
        if(s.count(x)) return !printf("NO");
        s.insert(x);
    }
    printf("YES");


}


Measured memory_bytes: 9600
#include <vector>
#include <iostream>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int n;
vector<int> a, col, tree;

int merge(int l, int r) {
	if (col[l] < col[r]) return l;
	return r;
}

void update(int ui, int uval, int l, int r, int ind) {
	if (l == r) {
		if (l == ui) {
			col[ui] = uval;
			tree[ind] = l;
			return;
		}
	}

	if (ui < l or r < ui) return;

	int mid((l + r) >> 1);
	if (ui <= mid) update(ui, uval, l, mid, 2 * ind);
	else update(ui, uval, mid + 1, r, 2 * ind + 1);

	tree[ind] = merge(tree[2 * ind], tree[2 * ind + 1]);
	return;
}

int query(int ql, int qr, int qval, int l, int r, int ind) {
	if (col[tree[ind]] >= qval) return -1;

	if (qr < l or r < ql) return -1;

	if (l == r) return l;

	int mid((l + r) >> 1);

	int left = query(ql, qr, qval, l, mid, 2 * ind);
	if (left != -1) return left;

	int right = query(ql, qr, qval, mid + 1, r, 2 * ind + 1);
	return right;

}

int main() {

	cin >> n;
	a.resize(n, 0); for (int i = 0; i <= n - 1; i++) cin >> a[i];
	col.resize(n, -1);
	tree.resize(4 * n + 1, 0);

	int mx = 0;

	for (int i = 0; i <= n - 1; i++) {
		int j = query(0, mx - 1, a[i], 0, n - 1, 1);

		if (j != -1) update(j, a[i], 0, n - 1, 1);
		else {
			update(mx, a[i], 0, n - 1, 1);
			mx++;
		}
	}

	cout << mx;

	return 0;
}

Measured memory_bytes: 5464
N,M=map(int,input().split())
l=list(map(int,input().split()))
w=[2,5,5,4,5,6,3,7,6]
l.sort()
dp=[0]*(max(N+1,8))
for j in l:
   dp[w[j-1]]=j
for i in range(N):
   if dp[i]!=0:
      for j in l:
         if w[j-1]+i<=N:
            dp[i+w[j-1]]=max(dp[i+w[j-1]],dp[i]*10+j)
print(dp[N])

Measured memory_bytes: 20480
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	LL N;
	cin >> N;

	vector<LL> A(N);
	rep(i, N)cin >> A[i];

	vector<LL> A_buff(N);
	rep(i, N) A_buff[i] = A[i];
	sort(RALL(A_buff));

	LL max_num = A_buff[0];
	LL next_max_num = A_buff[1];

	for (LL i = 0; i < N; i++)
	{
		if (A[i] == max_num) {
			cout << next_max_num << endl;
		}
		else {
			cout << max_num << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 4736